Télégramme De Bot Bibliothèque

Host a Telegram Bot on your Arduino and chat with your brand new IoT device!

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
×1

Software apps and online services

Arduino Web Editor
Arduino Web Editor

Story

Step 2 (ArduinoJson & WiFi101 Library)

Install ArduinoJson & WiFi101 Library from Library Manager.

Getting started

Step 1 (Create a new TelegramBot )

Be sure you have installed Telegram on your phone or your laptop, then, in the search bar, look for @botfather.

Talk to him and use the /newbot command to create a new bot. The BotFather will ask you for a name and username, then generate an authorization token for your new bot.

L' Nom of your bot will be displayed in contact details and elsewhere.

L' Username is a short name, to be used in mentions and telegram.me links. Your bot’s username must end in ‘bot’, e.g. ‘tetris_bot’ or ‘TetrisBot’.

Hello World

Now that we have our new bot we can set it to do what we want.

In this example we will make it turn on and off a LED by texting him a simple ‘On or Off’ message.

#include <WiFi101.h> 
#include <SPI.h>  
#include <TelegramBot.h>  
 
// Initialize Wifi connection to the router  
char ssid[] = "xxxx";             // your network SSID (name)  
char pass[] = "yyyy";            // your network key 
// Initialize Telegram BOT  
const char* BotToken = "xxxx";    // your Bot Teken  
WiFiSSLClient client;  
TelegramBot bot(BotToken,client);  
const int ledPin = 6;  // the number of the LED pin  
void setup() 
{  
 Serial.begin(115200);  
 while (!Serial) {}  //Start running when the serial is open 
 delay(3000);  
 // attempt to connect to Wifi network:  
 Serial.print("Connecting Wifi: ");  
 Serial.println(ssid);  
 while (WiFi.begin(ssid, pass) != WL_CONNECTED) 
       {  
   Serial.print(".");  
   delay(500);  
 }  
 Serial.println("");  
 Serial.println("WiFi connected");  
 bot.begin();  
 pinMode(ledPin, OUTPUT);  
}  
void loop() 
{  
 message m = bot.getUpdates(); // Read new messages  
 if (m.text.equals("On")) 
       {  
   digitalWrite(ledPin, HIGH);  
   Serial.println("message received");  
   bot.sendMessage(m.chat_id, "The Led is now ON");  
 }  
 else if (m.text.equals("Off")) 
       {  
   digitalWrite(ledPin, LOW);  
   Serial.println("message received");  
   bot.sendMessage(m.chat_id, "The Led is now OFF");  
 }  
}  

Let’s see in action

Code

 

Source : Télégramme De Bot Bibliothèque


A Propos De L'Auteur

Ibrar Ayyub

Je suis expérimenté, rédacteur technique, titulaire d'une Maîtrise en informatique de BZU Multan, Pakistan à l'Université. Avec un arrière-plan couvrant diverses industries, notamment en matière de domotique et de l'ingénierie, j'ai perfectionné mes compétences dans la rédaction claire et concise du contenu. Compétent en tirant parti de l'infographie et des diagrammes, je m'efforce de simplifier des concepts complexes pour les lecteurs. Ma force réside dans une recherche approfondie et de présenter l'information de façon structurée et logique format.

Suivez-Nous:
LinkedinTwitter

Laisser un Commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

fr_FRFrench
Faire défiler vers le Haut