Send notification to telegram


#1

is it possible to send notification from esp8266 to telegram?

i check butt Esp8266 crashed.

#define _DEBUG_
#include <ESP8266WiFi.h>
#include <ThingerESP8266.h>
#include <UniversalTelegramBot.h>
#define USERNAME "iXxXX"
#define DEVICE_ID "esp8277XXx"
#define DEVICE_CREDENTIAL "XXXXXXXXXXXX"
#define SSID "erfan"
#define SSID_PASSWORD "9395602811"
#define BOT_TOKEN "479792806:AAEfUjUXPYsLHgJa10ErenxXwvG9KvXXX"  // your Bot Token (Get from Botfather)
#define CHAT_ID "7270455" // Chat ID of where you want the message to go (You can use MyIdBot to get the chat ID)
// SSL client needed for both libraries
WiFiClientSecure client;
UniversalTelegramBot bot(BOT_TOKEN, client);
String ipAddress = "";
volatile bool telegramButtonPressedFlag = false;
#define TELEGRAM_BUTTON_PIN D2
void telegramButtonPressed() {
  Serial.println("telegramButtonPressed");
  int button = digitalRead(TELEGRAM_BUTTON_PIN);
  if(button == HIGH)
  {
    telegramButtonPressedFlag = true;
  }
  return;
}
void sendTelegramMessage() {
  String message = "SSID:  ";
  message.concat(SSID);
  message.concat("\n");
  message.concat("IP: ");
  message.concat(ipAddress);
  message.concat("\n");
  if(bot.sendMessage(CHAT_ID, message, "Markdown")){
    Serial.println("TELEGRAM Successfully sent");
  }
  telegramButtonPressedFlag = false;
}
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL)
void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(TELEGRAM_BUTTON_PIN, INPUT);  
attachInterrupt(TELEGRAM_BUTTON_PIN, telegramButtonPressed, RISING);
  thing.add_wifi(SSID, SSID_PASSWORD);
  // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
  thing["led"] << digitalPin(LED_BUILTIN);
  // resource output example (i.e. reading a sensor value)
  thing["millis"] >> outputValue(millis());
  // more details at http://docs.thinger.io/arduino/
}
void loop() {
  thing.handle();
    if ( telegramButtonPressedFlag ) {
    sendTelegramMessage();    
telegramButtonPressedFlag=false;
  }
}

==========================================

[THINGER] Writing bytes: 40 [OK]
[THINGER] Authenticated
telegramButtonPressed

Exception (29):
epc1=0x4020f200 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000204 depc=0x00000000

ctx: cont
sp: 3fff0180 end: 3fff0bb0 offset: 01a0

stack>>>
3fff0320: 3fffb24c 00000082 3fffaf74 4021c05e
3fff0330: 3fffb24c 3fffaf74 00000081 4021cd5e
3fff0340: de9dd7ea 00000000 00000001 00000040
3fff0350: 3fffafa4 3fffaf8c 00000040 00000000
3fff0360: 3fffba9c 3fffb1f4 00000041 00000041
3fff0370: 00000000 00000001 00001430 00000041
3fff0380: 3fffaf5c 3fffb1f4 00000000 0000007f


#2

Please, can you format your code, like:

```cpp
Your code here
```

#3

the cod format Was corrected.

PLZ Help me


#4

Hi @Mostafa_Hasanpour,

I suppose that without the thinger.io library, your code works, is it? (adding the Wifi conection part in the setup). I know that ESP8266 can handle different sockets connections at the same time, so, it should work. We used a similar example for gathering weather from an external API. So, please, test the Telegram code first.

In the other side, it is possible to make a HTTP endpoint in the server to handle the Telegram request, so the device only calls the thinger.io endpoints with the data to send.


#5

HI
Telegram cod along work without any problem and i receive notification