NorthernMan54 / homebridge-mcuiot

Homebridge platform plugin that support's a network of nodemcu's running nodemcu-dht-yl69-mdns to display Temperature and Humidity.
30 stars 12 forks source link

[Feature Request] Integration of deepsleep into homebridge-mcuiot lua #16

Closed chimcen closed 5 years ago

chimcen commented 5 years ago

Hi,

can you integrate the deep sleep mode as option in your project?

NorthernMan54 commented 5 years ago

This particular project is not suited to deep sleep, as it is based on the server pulling data from the device. You would need to look for a project that pushes data to the server.

Or if it is just temperature data your looking for, one of the 433 MHz temperature sensor from accurite and rtl_433

Sent from my iPad

On Oct 1, 2018, at 8:10 AM, chimcen notifications@github.com wrote:

Hi,

can you integrate the deep sleep mode as option in your project?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

chimcen commented 5 years ago

Thank you for this info - its a good option, but i‘m need the complete data (temp,humi,baro)...

You‘re right - but i‘ve another idea: Actually you projekt write the data from the sensors for each one in a single json file on the raspberry. I using atm Eve app for showing the data and it uses this files for showing the graphs, too.

If i‘m now set in homebridge that the data from the sensors will be grabbed every 10min and add in the end of main.lua the call for deepsleep to 9min, the node will be woke up after 9min (D0-RST) and waits for the next data grab... again and again. This way i‘m lossing for 9min the realtime measurements, but the graph data (in this case 10min old data) in Eve app is precise enough for me...

I‘ve tried this already by adding the deepsleep call after sending line (for the json table) in main.lua and it works - but at my browser the values won‘t be actualized - only if i‘m stop actualiting the web page.

I know, the reason is my faulty integration in main.lua...

Can you help me insert the deepsleep line into main.lua the correct way?

NorthernMan54 commented 5 years ago

Do you know parameters you looking for on deep Sleep?

Sent from my iPad

On Oct 4, 2018, at 3:49 PM, chimcen notifications@github.com wrote:

Thank you for this info - its a good option, but i‘m need the complete data (temp,humi,baro)...

You‘re right - but i‘ve another idea: Actually you projekt write the data from the sensors for each one in a single json file on the raspberry. I using atm Eve app for showing the data and it uses this files for showing the graphs, too.

If i‘m now set in homebridge that the data from the sensors will be grabbed every 10min and add in the end of main.lua the call for deepsleep to 9min, the node will be woke up after 9min (D0-RST) and waits for the next data grab... again and again. This way i‘m lossing for 9min the realtime measurements, but the graph data (in this case 10min old data) in Eve app is precise enough for me...

I‘ve tried this already by adding the deepsleep call after sending line (for the json table) in main.lua and it works - but at my browser the values won‘t be actualized - only if i‘m stop actualiting the web page.

I know, the reason is my faulty integration in main.lua...

Can you help me insert the deepsleep line into main.lua the correct way?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

chimcen commented 5 years ago

Yes... i've created a file "dsleep.lua" with following content:

`SLEEP_TIME = 10 -- Zeit in Sekunden. Max. 71 Minuten (= 4294 Sek.)

pin=4 gpio.mode(pin, gpio.OUTPUT)

for i=1,3 do gpio.write(pin,1) tmr.delay(1000000) gpio.write(pin,0) tmr.delay(1000000) end

node.dsleep(SLEEP_TIME * 1000000)`

and added the line node.dsleep(10 * 1000000) into main.lua

the problem is - if i'm isert this at the end (before "return module") the function will be executed direktly on bootup when the modules will be loaded... when i inserted this after sending (&removing the table), it gernarally works, but bcause of the missing end in the script, the json output will not be executed completly...

NorthernMan54 commented 5 years ago

As lua uses callbacks and events for anything that takes time, you should trigger going into deep sleep once the socket connection disconnects. This will ensure that the message is sent before deep sleep is triggered. Take a look at the documentation for net.socket:on() and the disconnect event. I think this is what your looking for.

chimcen commented 5 years ago

Thank you - i‘ll try to understand this, but i‘m honest...i don‘t know about this stuff :(