Changing light status works, but slowly starts to respond less till i restart the app
See original GitHub issueHi,
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.
- 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?
- 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:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Sure, done. I will report back in about 12 hours or so 😃
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.