Closed planer-pro closed 3 years ago
Because this my code work fine but have not deepSleep and eating more battery power;
`#include
CTBot myBot;
String ssid = "wifi"; String pass = "12345678"; String token = "my ID here";
uint32_t tm; uint32_t tId;
void setup() { Serial.begin(115200);
pinMode(pirPin, INPUT);
Serial.print("\nStarting TelegramBot...");
myBot.wifiConnect(ssid, pass);
myBot.setTelegramToken(token);
if (myBot.testConnection())
Serial.println("PASS");
else
Serial.println("FAIL");
Serial.print("Sensor calibrate...");
delay(3000);
Serial.println("COMPLETE");
}
void loop() { if (millis() - tm > 1000) { static uint8_t part; TBMessage msg;
switch (part)
{
case 0:
if (myBot.getNewMessage(msg))
{
tId = msg.sender.id;
myBot.sendMessage(tId, "ID defined. Tracking started.");
part++;
}
break;
case 1:
if (digitalRead(pirPin))
myBot.sendMessage(tId, "Motion detected!");
break;
}
tm = millis();
}
}`
Hello,
why do you do this check if (ESP.getResetReason() != "Deep-Sleep Wake")
?
When you put the ESP8266 into deepsleep, the radio is powered down so when the ESP woke up, it needs to reconnect itself to the WiFi network.
So, delete the if
mentioned above and leave the code inside his brackets and the sketch will work. In other words, you have to connect to the WiFi network and set the telegram token every time the ESP reboot.
Let me know if my solution solve your issue.
Regards,
Stefano
if (ESP.getResetReason() != "Deep-Sleep Wake") needs to do not do sensor caliblation every wakeup. Ok i fix it (move in right place), and feedback here. Thanks.
Hello, could I close the issue?
Hi,yes close please. I change library on UniversalTelegramBot in code. Thanks
Hello, how to periodic public message, and after do deep sleep for some time (4000ms)? d0-rst pin connected. Always say that "Starting TelegramBot...FAIL"
code: `#include
include "CTBot.h"
define pirPin D1//pir sens pin
define durationSleep 4 // secondes
CTBot myBot;
String ssid = "wifi"; String pass = "12345678"; String token = "my token here";//token right, checked
uint32_t tId;
void setup() { Serial.begin(115200);
}
void loop() { }`
Who know?? Anybody have example?