那曲檬骨新材料有限公司

電子發燒友App

硬聲App

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示
電子發燒友網>電子資料下載>電子資料>使用Wemos D1 Mini使用Telegram應用程序進行智能家居控制

使用Wemos D1 Mini使用Telegram應用程序進行智能家居控制

2022-12-29 | zip | 0.00 MB | 次下載 | 免費

資料介紹

描述

Telegram bot 是應用程序編程接口或也稱為“API,它允許程序員在本教程案例中同時集成兩個不同的應用程序,稱為帶有 ESP8266 的聊天應用程序 Telagram。

由于 TelegramBOT API 令牌的存在,它可以連接在電報聊天和硬件系統之間,例如,它將集成在使用 Arduino IDE 編程的迷你 Wemos D1 與此應用程序之間。

該項目使用了電報機器人 API 和 Wemos,將用于制作智能家居來控制燈和門。

1. 安裝 Telegram 機器人庫

2.源代碼

#include 
#include 
#include 
#include 
Servo myservo;
char ssid[] = "KAMAR KOS 7";     // your network SSID (name)
char password[] = "dasarlemahkaunak"; // your network key
#define BOTtoken "883873080:AAGkP-oNlzMgOS44X1jhE43C0_9JwwMCBPw"  // your Bot Token (Get from Botfather)
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
int Bot_mtbs = 1000; //mean time between scan messages
long Bot_lasttime;   //last time messages’ scan has been done
bool Start = false;
  
const int ledPin1 = 0;
const int ledPin2 = 2;
int ledStatus = 0;
void handleNewMessages(int numNewMessages) {
 Serial.print("status pesan = ");
 Serial.print(String(numNewMessages));
 Serial.println(",pesan berhasil diterima\n");
 for (int i=0; i   String chat_id = String(bot.messages[i].chat_id);
   String text = bot.messages[i].text;
   String from_name = bot.messages[i].from_name;
   if (from_name == "") from_name = "Guest";
   if (text == "/led1on") {
     digitalWrite(ledPin1, HIGH);   // turn the LED on (HIGH is the voltage level)
     digitalWrite(ledPin2, LOW);
     ledStatus = 1;
     bot.sendMessage(chat_id, "Led 1 is ON", "");
   }
   if (text == "/led1off") {
     ledStatus = 0;
     digitalWrite(ledPin1, LOW);    // turn the LED off (LOW is the voltage level)
     bot.sendMessage(chat_id, "Led 1 is OFF", "");
   }
   if (text == "/led2on") {
     digitalWrite(ledPin2, HIGH);
     digitalWrite(ledPin1, LOW);// turn the LED on (HIGH is the voltage level)
     ledStatus = 1;
     bot.sendMessage(chat_id, "Led 2 is ON", "");
   }
   if (text == "/led2off") {
     ledStatus = 0;
     digitalWrite(ledPin2, LOW);    // turn the LED off (LOW is the voltage level)
     bot.sendMessage(chat_id, "Led 2 is OFF", "");
   }
   if (text == "/alloff") {
     digitalWrite(ledPin1, LOW);
     digitalWrite(ledPin2, LOW);    // turn the LED off (LOW is the voltage level)
     bot.sendMessage(chat_id, "All led is OFF", "");
   }
   if (text == "/allon") {
     digitalWrite(ledPin1, HIGH);
     digitalWrite(ledPin2, HIGH);    // turn the LED off (LOW is the voltage level)
     bot.sendMessage(chat_id, "All led is ON", "");
   }
   if (text == "/rules") {
     bot.sendMessage(chat_id, "Perintah yang dapat diproses adalah perintah yang tertera dalam menu /help, Akep_bot juga tidak mentolerir adanya kesalahan pengetikan.","");
   }
   if (text == "Akep") {
     bot.sendMessage(chat_id, "Hai " + from_name + " aku disini, ketikan /start untuk memulai bot");
   }
   if (text == "/status1") {
     if(ledStatus){
       bot.sendMessage(chat_id, "Led is ON", "");
     } else {
       bot.sendMessage(chat_id, "Led is OFF", "");
     }
   }
      if (text == "/status2") {
     if(ledStatus){
       bot.sendMessage(chat_id, "Led is ON", "");
     } else {
       bot.sendMessage(chat_id, "Led is OFF", "");
     }
   }
   if (text == "/start") {
     bot.sendMessage(chat_id,"Selamat datang di Aplikasi Bot Telegram\n hai "+ from_name +", ketikkan /help untuk melihat perintah apa saja yang tersedia pada bot");
   }
   if (text == "/help") {
     String welcome = "Hai " + from_name + " :) \n";
     welcome += "berikut perintah yang tersedia pada bot\n";
     welcome += "/rules     : aturan memakai bot\n";
     welcome += "/led1on   : menyalakan led 1\n";
     welcome += "/led1off  : mematikan led 1\n";
     welcome += "/led2on   : menyalakan led 2\n";
     welcome += "/led2off  : mematikan led 2\n";
     welcome += "/status1  : cek status led 1\n";
     welcome += "/status2  : cek status led 2\n";
     welcome += "/allon     : menyalakan kedua led\n";
     welcome += "/alloff    : mematikan kedua led\n";
     bot.sendMessage(chat_id, welcome, "Markdown");
   }
   }
 }
void setup() {
 Serial.begin(115200);
 // 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);
 Serial.println("ketikan nama bot anda pada telegram");
 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED) {
   Serial.print(".");
   delay(500);
 }
 Serial.println("");
 Serial.println("WiFi terhubung");
 Serial.print("IP address: ");
 Serial.println(WiFi.localIP());
 Serial.println("ketikan nama bot anda pada telegram ");
 Serial.println("");
 pinMode(pir, INPUT);
 pinMode(ledPin1, OUTPUT); // initialize digital ledPin as an output.
 pinMode(ledPin2, OUTPUT);
 delay(10);
 digitalWrite(ledPin1, LOW); // initialize pin as off
 digitalWrite(ledPin2, LOW);
 myservo.attach(12);
 myservo.write(180);
}
void loop() {
 if (millis() > Bot_lasttime + Bot_mtbs)  {
   int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
   while(numNewMessages) {
     Serial.println("Pesan Diterima");
     Serial.println("sedang diproses.....");
     handleNewMessages(numNewMessages);
     numNewMessages = bot.getUpdates(bot.last_message_received + 1);
   }
   Bot_lasttime = millis();
 }
}
;>

3.配置電報機器人

4. 設置設備

?

?
pYYBAGOrz3uAbU7pAAFmBbmzSYM911.png
?

5. 測試

?

?

?

?


下載該資料的人也在下載 下載該資料的人還在閱讀
更多 >

評論

查看更多

下載排行

本周

  1. 1山景DSP芯片AP8248A2數據手冊
  2. 1.06 MB  |  532次下載  |  免費
  3. 2RK3399完整板原理圖(支持平板,盒子VR)
  4. 3.28 MB  |  339次下載  |  免費
  5. 3TC358743XBG評估板參考手冊
  6. 1.36 MB  |  330次下載  |  免費
  7. 4DFM軟件使用教程
  8. 0.84 MB  |  295次下載  |  免費
  9. 5元宇宙深度解析—未來的未來-風口還是泡沫
  10. 6.40 MB  |  227次下載  |  免費
  11. 6迪文DGUS開發指南
  12. 31.67 MB  |  194次下載  |  免費
  13. 7元宇宙底層硬件系列報告
  14. 13.42 MB  |  182次下載  |  免費
  15. 8FP5207XR-G1中文應用手冊
  16. 1.09 MB  |  178次下載  |  免費

本月

  1. 1OrCAD10.5下載OrCAD10.5中文版軟件
  2. 0.00 MB  |  234315次下載  |  免費
  3. 2555集成電路應用800例(新編版)
  4. 0.00 MB  |  33566次下載  |  免費
  5. 3接口電路圖大全
  6. 未知  |  30323次下載  |  免費
  7. 4開關電源設計實例指南
  8. 未知  |  21549次下載  |  免費
  9. 5電氣工程師手冊免費下載(新編第二版pdf電子書)
  10. 0.00 MB  |  15349次下載  |  免費
  11. 6數字電路基礎pdf(下載)
  12. 未知  |  13750次下載  |  免費
  13. 7電子制作實例集錦 下載
  14. 未知  |  8113次下載  |  免費
  15. 8《LED驅動電路設計》 溫德爾著
  16. 0.00 MB  |  6656次下載  |  免費

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935054次下載  |  免費
  3. 2protel99se軟件下載(可英文版轉中文版)
  4. 78.1 MB  |  537798次下載  |  免費
  5. 3MATLAB 7.1 下載 (含軟件介紹)
  6. 未知  |  420027次下載  |  免費
  7. 4OrCAD10.5下載OrCAD10.5中文版軟件
  8. 0.00 MB  |  234315次下載  |  免費
  9. 5Altium DXP2002下載入口
  10. 未知  |  233046次下載  |  免費
  11. 6電路仿真軟件multisim 10.0免費下載
  12. 340992  |  191187次下載  |  免費
  13. 7十天學會AVR單片機與C語言視頻教程 下載
  14. 158M  |  183279次下載  |  免費
  15. 8proe5.0野火版下載(中文版免費下載)
  16. 未知  |  138040次下載  |  免費
大发888娱乐场官网官方下载| 哪个百家乐投注比较好| 太阳城大酒店| 大发888客服咨询电话| 百家乐官网怎么玩| 百家乐官网娱乐城足球盘网| 太阳百家乐路单生| 百家乐2号技术打法| 金鼎百家乐官网局部算牌法| 同乐城备用网址| 威尼斯人娱乐城客服| 百家乐视频二人雀神| 678百家乐官网博彩赌场娱乐网规则 | 百家乐网上真钱娱乐场| 博必发百家乐官网的玩法技巧和规则 | 新澳门百家乐的玩法技巧和规则| 马牌百家乐现金网| 百家乐官网英皇娱乐网| 体球网足球即时比分| 财富百家乐的玩法技巧和规则 | JJ百家乐官网的玩法技巧和规则| 百家乐官网视频游戏账号| 太阳城娱乐城官方网站| 百家乐破解分| 二代百家乐破解| 百家乐tt娱乐| 偃师市| 澳门博彩娱乐有限公司| 喜洋洋水果机遥控器| 3U百家乐的玩法技巧和规则 | 赌场百家乐官网是如何玩| 皇冠百家乐官网代理网| 仁化县| 久盛国际娱乐场| 7位百家乐扑克桌| 跨国际百家乐的玩法技巧和规则| 百家乐直杀| 百家乐vshow| 天堂鸟百家乐的玩法技巧和规则 | 百家乐官网软件代理打| 葡京百家乐官网的玩法技巧和规则 |