Open VarunKumaran opened 1 year ago
Hi, You can take any MQTT sketch example and use it so that it sends the message and then just remember to set GPIO16 to switch off the supply when you've finished.
I assume you're aware that it will use more battery power sending MQTT via your router and take longer, around 7 seconds, to send the message.
The ADC read takes the value from ADC(0) and converts it to an integer value by multiplying it by a factor of ten then divde it by 10 when you deal with the received message, i.e. a value of 600 from the ADC would be aout 2.46V but using the calculation above the message sent would be 24.
I'll confirm what Gadjet is saying - you want espnow first. The delay to connect upon startup and then publish is too long.. when the window sensor is off it's disconnected from Wi-Fi so when it wakes up it needs to reconnect. I have a work around though using two d1's acting as a gateway - one as a esp-now receiver and the other that's always connected to mqtt which will publish the topic. There's a total of 3 sketches; the window sensor, the espnow slave, and mqtt gateway. I'm also using node-red to notify/alert to a Sonos device using tts. It's been working great. I'll see if I can put this all together soon to share.
For anyone reading this and asking themselves why this weird calculation for the input voltage happens:
thematrixincendies Thanks for the detailed explanation, the main reason for the high resistance of the potential divider network is to reduce the quiescent current drain on the battery as it is permanently connected.
Hiiii there!!! I really love your low device and would like to do the same using only MQTT to send a message to my MQTT broker(raspberry Pi) when ever the state of the door sensor changes... Can you please help me with the code for MQTT??
And secondly can u please explain the calculation part for the battery voltage value
myData.vBatt
= (analogRead(A0) 4.2 10 / 1023);`