Reputation: 3
Basically, i'm trying my hands on IOT, and i tried this simple project where the esp32 cam will take photos when motions is detected and send it to telegram using the bot, i've created the bot on telegram, with everything like token, chat id added to the code. i've succeeded in connecting to my wifi but for some reason it cannot connect to telegram, all of this code was copied for ViralScience on youtube below is the function to connect to telegram
String alerts2Telegram(String token, String chat_id)
{
const char* myDomain = "api.telegram.org";
String getAll="", getBody = "";
camera_fb_t * fb = NULL;
fb = esp_camera_fb_get();
if(!fb)
{
Serial.println("Camera capture failed");
delay(1000);
ESP.restart();
return "Camera capture failed";
}
WiFiClientSecure client_tcp;
if (client_tcp.connect(myDomain, 443))
{
Serial.println("Connected to " + String(myDomain));
}
else {
getBody = "Connection to telegram failed.";
Serial.println("Connection to telegram failed.");
}
return getBody;
}
and below is the sketch loop
void loop()
{
pinMode(gpioPIR, INPUT_PULLUP);
int v = digitalRead(gpioPIR);
Serial.println(v);
if (v==1)
{
alerts2Telegram(token, chat_id);
delay(10000);
}
delay(1000);
}
is there anything wrong in the code or it won't work because maybe this code is outdated, because the video on the tutorial itself is dated 7 june 2020?
Upvotes: 0
Views: 1959
Reputation: 52
Try to change the version of esp32 core to v1.0.4 . If you want to use version 1.0.5 or above, modify your code as below.
WiFiClientSecure client_tcp;
client_tcp.setInsecure(); //version 1.0.5 or above
Upvotes: 1