edfungus / Crouton

Crouton MQTT IOT Dashboard
http://crouton.mybluemix.net/
Other
291 stars 69 forks source link

Lua sensors #30

Closed XayOn closed 7 years ago

XayOn commented 7 years ago

Can you provide any lua sensor examples? I seem to have trouble connecting to the device if I start monitoring a sensor (wich would block the main thread and make mqtt unresponsive to events...). Even if I use timers and keep sending all complete deviceInfo on each update, it does not seem to make any difference and I'd prefer not to depend on external stimuli (such as an update event to the mqtt server) to send the updates.

edfungus commented 7 years ago

Adafruit has an example where a magnetic reed switch is checked on a polling basis and publishes to mqtt. I would believe it can listen to mqtt and not block because it is using a watchdog timer.

If you need something to respond faster, I would suggest trying to use an interrupt for your sensor so that you can be listening to the mqtt and only send messages when you need to. This will be tricky since you do not want your interrupt to be very long.

Hope one of those solutions helps you out! I have actually moved away from lua and just using c and c++ on my devices.