#include <Wire.h>
#include <UniversalTelegramBot.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
long Bot_lasttime;
//------- WiFi Settings -------
char ssid[] =""; // your network SSID (name)
char password[] = ""; // your network key
#define TELEGRAM_BUTTON_PIN D2
int TELEGRAM_BUTTON_PINReading;
// ------- Telegram config --------
#define BOT_TOKEN "" // your Bot Token (Get from Botfather)
#define CHAT_ID "" // 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 telegramButton1PressedFlag = false;
void setup() {
Serial.begin(9600);
// Initlaze the buttons
pinMode(TELEGRAM_BUTTON_PIN, INPUT);
// Set WiFi to station mode and disconnect from an AP if it was Previously
// connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
// Attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
IPAddress ip = WiFi.localIP();
Serial.println(ip);
ipAddress = ip.toString();
}
void telegramButton1Pressed() {
Serial.println("Telegram Button-1 Pressed");
int TELEGRAM_BUTTON_PINReading = digitalRead(TELEGRAM_BUTTON_PIN);
if(TELEGRAM_BUTTON_PINReading == 1) {
{
telegramButton1PressedFlag = true;
}
return;
}
}
void sendTelegramMessage() {
String message = "Illegal Smoking!";
if(bot.sendMessage(CHAT_ID, message, "Markdown")){
Serial.println("TELEGRAM Message Successfully sent");
}
telegramButton1PressedFlag = false;
}
void loop() {
int TELEGRAM_BUTTON_PINReading = digitalRead(TELEGRAM_BUTTON_PIN); // take a reading from the optical sensor pin
Serial.println(TELEGRAM_BUTTON_PINReading); // the analog reading of the optical sensor
if (TELEGRAM_BUTTON_PINReading == 1) {
Serial.println("sent notifcation1 to Telegram");
sendTelegramMessage();
Bot_lasttime = 0;
}
}
I am changing ESP32 to ESP8266 D1 minpro board.This is the old coding for my ESP32 its working well.When i change to ESP8266 board when the digitalReading is = 1 it only serialprint out the line of “Sent notifcation1” the “SendTelegramMessage” did not Sending the message to the group.After that it jump to digitalReading 1 again.