Instant Messenger for ESPs and Arduinos - Part 2

Hello everyone

since our technical department is currently quite busy, the 2nd part of the blog article has been a bit of a wait-and-see. Thanks to the support of a forward-looking customer, I can provide you with the program code for the ESP today.

Here you can find the first part of the article.

How libraries are installed should be clear from the last 200 blog posts, which is why I will only address this topic on the sidelines today. 

Anyone who frequently recreates projects from the Internet knows how important it is to select the right version of the respective library. A good example is the board definitions of the ESPs together with the MQTT libraries. Here you can spend hours troubleshooting, or use the versions that are stored in the respective instructions.

Also the following program code for communication via the Telegram messenger does not work with every version version.

 

#define BOTtoken "xxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  Your bot token (get from botfather, see part 1)

#include <ESP8266WiFi.H>
#include <WiFiClientSecure.H>
#include <UniversalTelegramBot.H>                  // UniversalTelegramBot V1.1.0 & ArduinoJson V5.13.5

Wi-Fi data for the router
Char Ssid[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx";           Wi-Fi SSID Name
Char Password[] = "xxxxxxxxxxxxxxxxxxxxxxx";          Wi-Fi password

WiFiClientSecure Client;                           SSL Client
UniversalTelegramBot Offered(BOTtoken, Client);

Int Bot_mtbs = 1000;                               Average time between message scans
Long Bot_lasttime;                                 Messages were last scanned

Void Setup() {             Serial.Begin(115200);   Wifi.Fashion(WIFI_STA);                             Wi-Fi Station Mode    Wifi.disconnect();                               Disconnect Wi-Fi if already connected   Delay(100);   Serial.Print("Connect Wi-Fi: ");   Serial.println(Ssid);                               Wifi.Begin(Ssid, Password);                      Connecting Wi-Fi   while (Wifi.Status() != WL_CONNECTED) {          Wait until Wi-Fi is connected     Serial.Print(".");     Delay(500);   }   Serial.println("");   Serial.println("Wi-Fi is connected");            Wi-Fi is connected   Serial.Print("IP Address: ");                       Serial.println(Wifi.localIP());                  with the following IP address   }    Void Loop() {    String chat_id = "xxxxxxxxxxxxxx";                 Chat ID
String Text = "AZ-Delivery makes it possible!";       Message to be sent
String parses = "";   Serial.println("Send message");   Serial.println(Offered.Sendmessage(chat_id, Text, parses)); Sending message    Delay(5000);

Esp.deepSleep(0);                                  ESP sleep lay
}

 

Now your ESP can send push messages via Telegram.

 

Until the next article :) 

 

Basics software

5 comments

Thorsten

Thorsten

Gibts das auch irgendwo für MicroPython?
Danke vorab
Grüße
Thorsten

Klaus

Klaus

Ich finde es immer wieder beindruckend wie sich die Autoren um ihre Blog Follower und deren Probleme kümmern.
Vielen Dank

Roland

Roland

Servus,

hab den skatch kopiert und meine Daten angepasst, will ich auf einen esp8266 spielen, Bibliotheken hab ich runtergelanden, aber habe den fehler "Error: stray `\302 und 240

Steffen

Steffen

Versuch’ doch mal im Boardverwalter “esp8266 by ESP8266 Comunity” in Version 2.4.2 zu installieren. Die neueren Versionen haben bei mir ebenfalls nicht zuverlässig funktioniert.

Gast

Gast

Hallo,

bei mir werden keine Nachrichten versendet (bzw. kommen nicht an)

Serial.println(bot.sendMessage(chat_id, text, parses)); gibt 0 zurück

BOTtoken & Chat-ID stimmen – habe sie über curl an Konsole getestet – funktioniert
WLAN ist auch verbunden.

Gibt es eine Möglichkeit, die Rückmeldung auszulesen? Selbst wenn ich bewusst eine falsche BOTtoken / Chat-ID eingebe gibt bot.sendMessage 0 zurück.

Vielen Dank.

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN