psieg / Lightpack

Lightpack and Prismatik open repository
GNU General Public License v3.0
1.55k stars 185 forks source link

Ping other device every second #88

Open dmadison opened 7 years ago

dmadison commented 7 years ago

On my Adalight setup, the device code is configured so that it shuts off the lights if there has been no signal for a set period of time. If the experimental "Send data only if colors changed" option is enabled, the lights will shut off if there is no update to the edges of the display (e.g. typing this issue on Github).

I haven't checked the implementation, but under the 'experimental' features there is an option to "Ping Lightpack device every second". Could this feature be extended to include other devices (specifically Adalight)?

psieg commented 7 years ago

It could, if Adalight supports a ping command (i.e. do nothing but don't sleep). I don"t know that protocol, but quick googling revealed most implementations know only one command. Can you provide a protocol reference or reference implementation for your device?

dmadison commented 7 years ago

There isn't a dedicated ping command, but from what I can tell it shouldn't need one.

The protocol itself is fairly barebones: on every loop it moves available data from the serial buffer to a buffer array, and then switches between header searching and data parsing modes. In the 'header searching' mode, it looks for a matching magic word (typically "Ada") and a checksum. In the 'data parsing' mode it blindly matches the serial data to the LED color data, and when the color array is full it latches.

If the device doesn't receive serial data for over a second it sends an acknowledgement string (again, "Ada"), and if it doesn't receive any serial data for a set period of time it shuts off the LEDs.

So here's the trick: if you send the device serial data (any serial data) that doesn't match the magic word + checksum, assuming it has already latched and is in the "header searching" mode, the device will stay awake with the current color set.

I've tested this via Processing and it seems to work with any string I throw at it, regardless of length or content so long as it doesn't match the magic word and checksum. The likely candidate would probably be "Ada\n", if we wanted to stick with convention, although it would probably be better to avoid 'Ada' altogether in case a checksum accidentally matches.

Here is the original device-side Adalight code if you'd like to take a look.

psieg commented 7 years ago

Does the problem also occur in moodlight mode? Why not just leave the experimental option off if it causes trouble? I'm not sure how much of a performance impact it has

dmadison commented 7 years ago

In the 'Mood lamp' mode, the device times out regardless of the 'Send data only if colors changed' setting.

At the moment I do have the 'colors changed' option off, but since the framework was already there to ping the Lightpack devices I thought it would be worthwhile to create the feature request.

LunarLanding commented 3 years ago

+1 from me. Please bring back the ping option. The device will suddenly turn off even eventually even with "Send data only if colors changed" on. I'm using an Arduino, so I can look at the code.

zomfg commented 3 years ago

There is nothing to bring back since ping never did anything other than Lightpack "send data only if changed" has to be off, not on, if you have builtin timeout in your firmware (the option phrasing might be confusing) Also, in the current version all 3 modes should send data at least once a second regardless if colors change or not, even the static mood lamp, so you should be fine with just unchecking "send data only..."

LunarLanding commented 3 years ago

@zomfg thanks. I'll try to figure it out, must be on the arduino side.