NodemCU Telegram

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ESP8266TelegramBOT.h>
// Initialize Wifi connection to the router
const char* ssid = "nama_wifi_ku";
const char* password = "pass_wifi_ku";
WiFiServer server(80);
// Initialize Telegram BOT
#define BOTtoken "token_telegram_bot"  //token of FlashledBOT
#define BOTname "contoh"
#define BOTusername "contoh_bot"
TelegramBOT bot(BOTtoken, BOTname, BOTusername);
int Bot_mtbs = 1000; //mean time between scan messages
long Bot_lasttime;   //last time messages' scan has been done
bool Start = false;
 int sensor1 = digitalRead(D0);
/********************************************
 * EchoMessages - function to Echo messages *
 ********************************************/void Bot_ExecMessages() {
  for (int i = 1; i < bot.message[0][0].toInt() + 1; i++)      {
    bot.message[i][5]=bot.message[i][5].substring(1,bot.message[i][5].length());
    if (bot.message[i][5] == "ledon") {
      digitalWrite(LED_BUILTIN, LOW);   // turn the LED on (HIGH is the voltage level)
      bot.sendMessage(bot.message[i][4], "Led is ON", "");
    }
    if (bot.message[i][5] == "ledoff") {
      digitalWrite(LED_BUILTIN, HIGH);    // turn the LED off (LOW is the voltage level)
      bot.sendMessage(bot.message[i][4], "Led is OFF", "");
    }
    if (bot.message[i][5] == "sensor"){
      String updateSensor = "Disini update sensor";
      bot.sendMessage(bot.message[i][4], updateSensor, "");
    }
    if ( sensor1 == 0 ){
      Serial.println("Ada alarm di sensor 1, segera check kondisi nya");
      String msgSensor1 = "Ada alarm di sensor 1, segera check kondisi nya";
      bot.sendMessage(bot.message[i][4],msgSensor1, "");
    }
    if (bot.message[i][5] == "start") {
      String wellcome = "Wellcome from mikroavr_bot, your personal Bot on alarm realtime notification";
      String wellcome1 = "/ledon : to switch the Led ON";
      String wellcome2 = "/ledoff : to switch the Led OFF";
      String wellcome3 = "/sensor : status all sensor";
       
      bot.sendMessage(bot.message[i][4], wellcome, "");
      bot.sendMessage(bot.message[i][4], wellcome1, "");
      bot.sendMessage(bot.message[i][4], wellcome2, "");
      bot.sendMessage(bot.message[i][4], wellcome3, "");
      Start = true;
    }
  }
  bot.message[0][0] = "";   // All messages have been replied - reset new messages
}

Comments

Popular Posts