Telegram library for Wio Terminal

Hello guys. I have recently bought Wio Terminal Realtek 2.4GHz/5 GHz for a Smart Alert System project using telegram. However, I am facing problem compiling the code as telegram library is not compatible with the controller. Does anyone have a solution for this problem. Cheers!!!

Hi @Linggeis,

Could you share the code/ library that you tried to use here?

Best Regards,
Lakshantha

Greetings @lakshan

Thank you very much for the helping hand. First of all Kudos to you for all of the informative Youtube step by step procedures to use the Wio Terminal. The videos are explained in detail. Thank you for that. Below is the code I am trying to work on my project. I am having problem with " #include <UniversalTelegramBot.h> , #include <ArduinoJson.h>, WiFiClientSecure client; and UniversalTelegramBot bot(BOTtoken, client)". Much Appreciated.

#include “rpcWiFi.h”
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>

const char* ssid = “yourNetworkName”;
const char* password = “yourNetworkPassword”;

#define BOTtoken “yourBotToken” // My Bot Token
#define CHAT_ID “yourChatId”

WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

bool motionDetected = false;
int botRequestDelay = 1000;
unsigned long lastTimeBotRan; // Set in zero status
int val = 0; // variable for reading the pin status

const int motionSensor = 12; // PIR Motion Sensor // LDR sensor pin G4
int Alarm = 22; // LED pin G26

void ICACHE_RAM_ATTR detectsMovement ()

{
motiondetected = true;
}

void setup() {
Serial.begin(115200);
while(!Serial); // Wait for Serial to be ready

pinMode(motionSensor, INPUT_PULLUP); // PIR Motion Sensor mode INPUT_PULLUP
pinMode(Alarm, OUTPUT); // LED1 mode OUTPUT
attachInterrupt(digitalPinToInterrupt(motionSensor), detectsMovement, RISING);

// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();

Serial.println("Connecting to WiFi..");
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) 

{
Serial.print(".");
delay(500);
}

bot.sendMessage(CHAT_ID, “CDO Smart Alert started”, “”);
}

Serial.println("Connected to the WiFi network");
Serial.print("IP Address: ");
Serial.println (WiFi.localIP()); // prints out the device's IP address
}

void loop()
{
if(motionDetected)
{
bot.sendMessage(CHAT_ID, “Air FLow Alert !!! WARNING !!!”, “”);
motionDetected = false;
}
if (millis() > lastTimeBotRan + botRequestDelay)
{
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);

while(numNewMessages) 
{
  Serial.println("got response");
  handleNewMessages(numNewMessages);
  numNewMessages = bot.getUpdates(bot.last_message_received + 1);
}
lastTimeBotRan = millis();

}
}

void handleNewMessages(int numNewMessages) // Handle what happens when you receive new messages
{
Serial.println(“handleNewMessages”);
Serial.println(String(numNewMessages));

for (int i=0; i<numNewMessages; i++)
{
String chat_id = String(bot.messages[i].chat_id); // Chat id of the requester
if (chat_id != CHAT_ID)
{
bot.sendMessage(chat_id, “Unauthorized user”, “”);
continue;
}

String text = bot.messages[i].text;                                                            // Print the received message
Serial.println(text);

String from_name = bot.messages[i].from_name;

if (text == "/start") 
{
  String welcome = "Welcome, " + from_name + ".\n";
  welcome += "SMART CDO Alert \n";
  welcome += "Use the following commands to control your outputs.\n\n";
  welcome += "/Alarm_on \n";
  welcome += "/Alarm_off \n";
  bot.sendMessage(chat_id, welcome, "");
}

if (text == "/Alarm_on")                                                                     // LED text
{
  bot.sendMessage(chat_id, "ALARM ON", "");                                                  // text
  digitalWrite(Alarm, HIGH);                                                                  // LED on
}
if (text == "/Alarm_off")                                                                     // LED text
{
  bot.sendMessage(chat_id, "ALARM OFF", "");                                                  // text
  digitalWrite(Alarm, LOW);                                                                  // LED on
}

}
}

Thank you.

Best Regards,
Linggeis Daran.

Hi @Linggeis,

Thank you for the appreciation!

Can I know whether you are using this library?:

Best Regards,
Lakshantha

Hi @lakshan

Yes. I am using this library. Thank you.

Best Regards,
Linggeis Daran