question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Changing light status works, but slowly starts to respond less till i restart the app

See original GitHub issue

Hi,

I think i need to clarify this a little. I’m making a MiLight hub proxy so that it can be used with Samsung SmartThings.

The code i have right now: note: heavily work in progress! I’m just hacking it together at the moment to get things working.

'use strict'

const milightmodule = require('node-milight-promise');
const Milight = milightmodule.MilightController;
const commands = milightmodule.commandsV6;
const discover = milightmodule.discoverBridges;
const express = require('express')
const app = express()
const bodyParser = require('body-parser')

let light = new Milight({
  ip: '10.0.3.101',
  type: 'v6'
});

/*
light.close().then(function () {
  console.log("All command have been executed - closing Milight");
});
console.log("Invocation of asynchronous Milight commands done");
*/

app.use(bodyParser.json());

function getCommandsObjectByType(type) {
  if (type == 'rgbw') {
    return commands.fullColor;
  } else if (type == 'cct') {
    return commands.white;
  }

  return commands.rgbw;
}

function handleSwitch(res, data, params, com) {
  if (data.status == 'on') {
    light.sendCommands(com.on(params.group));
  } else {
    light.sendCommands(com.off(params.group));
  }
  res.status(200).json({})
}

function handleBrightness(res, data, params, com) {
  
  console.log('Handle brightness')

  let level = parseInt(data.level);
  light.sendCommands(com.brightness(params.group, level))
  res.status(200).json({})
}

app.post('/gateways/:addr/:type/:group', (req, res) => {
  let com = getCommandsObjectByType(req.params.type);

  console.log('specific post')
  console.log(req.body)
 
  if (typeof req.body.status !== 'undefined') {
    handleSwitch(res, req.body, req.params, com);
  } else if (typeof req.body.level !== 'undefined') {
    handleBrightness(res, req.body, req.params, com);
  } else {
    console.log('  ' + typeof req.body.status)
  }

});

app.post('*', (req, res) => {
  console.log('fallback post')
  console.log(req.body)
  res.status(400).json()
});

app.listen(3000, () => {
  console.log('MiLight proxy hub is listening.')
})

That is the whole app at the moment. It’s going to be on github in this repository sometime soon: https://github.com/markg85/MiLightNodeProxy It allows me to set the light status and brightness, so far so good. And, the most awesome part, it really works on smartthings (which i import in Google Home to control the bulbs, that really works)!

I have 2 issues though.

  1. After some time the commands just start are not working anymore. This seems to point at a session timeout. Here is the output of the commands while it isn’t working.
specific post
{ status: 'on' }
2017-12-15T15:48:29.195Z Milight: bytesSent=22, buffer=[0x80,0x00,0x00,0x00,0x11,0x6E,0x00,0x00,0x25,0x00,0x31,0x00,0x00,0x01,0x01,0x07,0x00,0x00,0x00,0x01,0x00,0x3B]
2017-12-15T15:48:29.218Z Milight: bytesReceived=8, buffer=[0x88,0x00,0x00,0x00,0x03,0x00,0x25,0x01], remote=10.0.3.101
2017-12-15T15:48:29.318Z Milight: ready for next command
specific post
{ status: 'on' }
2017-12-15T15:48:29.496Z Milight: bytesSent=22, buffer=[0x80,0x00,0x00,0x00,0x11,0x6E,0x00,0x00,0x26,0x00,0x31,0x00,0x00,0x08,0x04,0x01,0x00,0x00,0x00,0x01,0x00,0x3F]
2017-12-15T15:48:29.525Z Milight: bytesReceived=8, buffer=[0x88,0x00,0x00,0x00,0x03,0x00,0x26,0x01], remote=10.0.3.101
2017-12-15T15:48:29.625Z Milight: ready for next command
specific post
{ status: 'on' }
2017-12-15T15:48:29.784Z Milight: bytesSent=22, buffer=[0x80,0x00,0x00,0x00,0x11,0x6E,0x00,0x00,0x27,0x00,0x31,0x00,0x00,0x08,0x04,0x01,0x00,0x00,0x00,0x02,0x00,0x40]
2017-12-15T15:48:29.802Z Milight: bytesReceived=8, buffer=[0x88,0x00,0x00,0x00,0x03,0x00,0x27,0x01], remote=10.0.3.101
2017-12-15T15:48:29.903Z Milight: ready for next command

And right after it reconnects, the lights work again:

2017-12-15T15:49:12.870Z Milight: bytesSent=27, buffer=[0x20,0x00,0x00,0x00,0x16,0x02,0x62,0x3A,0xD5,0xED,0xA3,0x01,0xAE,0x08,0x2D,0x46,0x61,0x41,0xA7,0xF6,0xDC,0xAF,0xD3,0xE6,0x00,0x00,0x1E]
2017-12-15T15:49:12.984Z Milight: bytesReceived=22, buffer=[0x28,0x00,0x00,0x00,0x11,0x00,0x02,0xF0,0xFE,0x6B,0x26,0x15,0x6A,0x5F,0xB8,0x80,0x30,0x00,0x01,0x9B,0x00,0x00], remote=10.0.3.101
2017-12-15T15:49:13.084Z Milight: ready for next command
2017-12-15T15:49:13.084Z Milight: Session Id: 0x9B,0x00
specific post
{ status: 'off' }
2017-12-15T15:49:38.578Z Milight: bytesSent=22, buffer=[0x80,0x00,0x00,0x00,0x11,0x9B,0x00,0x00,0x29,0x00,0x31,0x00,0x00,0x08,0x04,0x02,0x00,0x00,0x00,0x01,0x00,0x40]
2017-12-15T15:49:38.688Z Milight: bytesReceived=8, buffer=[0x88,0x00,0x00,0x00,0x03,0x00,0x29,0x00], remote=10.0.3.101
2017-12-15T15:49:38.788Z Milight: ready for next command
specific post
{ status: 'off' }
2017-12-15T15:49:38.878Z Milight: bytesSent=22, buffer=[0x80,0x00,0x00,0x00,0x11,0x9B,0x00,0x00,0x2A,0x00,0x31,0x00,0x00,0x01,0x01,0x08,0x00,0x00,0x00,0x01,0x00,0x3C]
2017-12-15T15:49:38.905Z Milight: bytesReceived=8, buffer=[0x88,0x00,0x00,0x00,0x03,0x00,0x2A,0x00], remote=10.0.3.101
2017-12-15T15:49:39.004Z Milight: ready for next command
specific post
{ status: 'off' }
2017-12-15T15:49:39.159Z Milight: bytesSent=22, buffer=[0x80,0x00,0x00,0x00,0x11,0x9B,0x00,0x00,0x2B,0x00,0x31,0x00,0x00,0x08,0x04,0x02,0x00,0x00,0x00,0x02,0x00,0x41]
2017-12-15T15:49:39.197Z Milight: bytesReceived=8, buffer=[0x88,0x00,0x00,0x00,0x03,0x00,0x2B,0x00], remote=10.0.3.101
2017-12-15T15:49:39.298Z Milight: ready for next command

Perhaps the keep-alive packet would fix this?

  1. I have a couple RGBW lights (not WW apparently) and a couple CW/WW. All are exposed with the above code and can be set on/off individually! However, if i turn on all the lights then the ones that are in the CW/WW group will turn on, but the ones with corresponding numbers in the RGBW group won’t turn on. So: CW/WW, group 1: on - goes on RGBW, group 1: on - stays off

I’m not adding any delays here so that might be a potential fix, do you know something else that might be causing this?

Bert regards, Mark

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
markg85commented, Dec 17, 2017

Sure, done. I will report back in about 12 hours or so 😃

0reactions
mwittigcommented, Dec 17, 2017

Thanks for the update! I’ll change the default value to 30000 then and I’ll look into implementing keep-alive soon which is fairly easy to do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Homekit Automations are broken in iOS 16 - Apple Community
Since iOS 16 HomeKit automations aren't triggered reliably. Simple timed automations like "Open Shutters at 9am" are triggered randomly.
Read more >
App startup time - Android Developers
This document provides information to help you optimize your app's launch time. It begins by explaining the internals of the launch process.
Read more >
Answered: Google Home slow to respond
Over the last 2 weeks my Google Home is very slow to respond. It sits and the lights spin after a command and...
Read more >
Nest camera and doorbell lights and sounds - Google Support
The status light will turn off, and then turn solid white after a few seconds. You'll need to keep holding the restart or...
Read more >
Steam Deck - Basic Use & Troubleshooting Guide
If the LED flashes after pressing the power button, the battery is currently depleted. Plug it in using the provided PSU, confirm the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found