我的Arduino董事会和我的电报频道之间的连接不起作用

发布于 2025-01-25 09:00:32 字数 1354 浏览 4 评论 0原文

我试图将LDR传感器连接到Telegram Bot,以便我知道灯光是否绊倒,但似乎绊倒的消息没有通过。我试图重新启动芯片,但是它不断显示“ TestConnection Nok”,有人可以帮助我看看是否有解决此问题的问题?以下是我的Arduino使用的代码。

#include <WiFiClient.h> //CLIENT LIBRARY  
#include <ESP8266WebServer.h> //WEBSERVICER LIBRARY
#include <ESP8266HTTPClient.h> //HTTP CLIENT LIBRARY
#include "CTBot.h" //TELEGRAM BOT LIBRARY

CTBot myBot; //INITIALIZE TELEGRAM BOT VARIABLE

String ssid  = "CGA-Farm"    ; // ASSIGN SSID VARIABLE WITH WIFI SSID 
String pass  = "0003606367"; // ASSIGN PASS VARIABLE WITH WIFI PASSWORD
String token = "1715253121:AAHqI4O2mt11ono-wFQ-_p5UfVpu0OeekeY"; // TELEGRAM BOT TOKEN RETRIEVED FROM BOTFATHER
int CNT = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("Starting TelegramBot..."); 
  myBot.wifiConnect(ssid, pass); // CONNECT ESP TO ACCESS POINT
  myBot.setTelegramToken(token); // SET TELEGRAM BOT TOKEN
  
    if (myBot.testConnection())// DEBUG CONNECTION
    Serial.println("\ntestConnection OK");
    else
    Serial.println("\ntestConnection NOK");
}

void loop() {
  
  float reading = analogRead(A0);
  Serial.println(reading);
  
  delay(1000);
  if (reading < 800)
  {
    if (CNT < 1) 
    {
      Serial.println("No light!");
      myBot.sendMessage(-1001412490907,"GR1 Zone1 tripped!");
      CNT = CNT + 1;
    }
  } else
  {
    CNT = 0;
  }
}

Im trying to connect a ldr sensor to telegram bot, so that i know if the lights are tripping or not, but it seems like the tripped messages aren't going through. I tried to restart the chip, but it keeps showing "testconnection NOK"Can someone help me to see if there are anyways to troubleshoot this issue? Below is the code used for my arduino.

#include <WiFiClient.h> //CLIENT LIBRARY  
#include <ESP8266WebServer.h> //WEBSERVICER LIBRARY
#include <ESP8266HTTPClient.h> //HTTP CLIENT LIBRARY
#include "CTBot.h" //TELEGRAM BOT LIBRARY

CTBot myBot; //INITIALIZE TELEGRAM BOT VARIABLE

String ssid  = "CGA-Farm"    ; // ASSIGN SSID VARIABLE WITH WIFI SSID 
String pass  = "0003606367"; // ASSIGN PASS VARIABLE WITH WIFI PASSWORD
String token = "1715253121:AAHqI4O2mt11ono-wFQ-_p5UfVpu0OeekeY"; // TELEGRAM BOT TOKEN RETRIEVED FROM BOTFATHER
int CNT = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("Starting TelegramBot..."); 
  myBot.wifiConnect(ssid, pass); // CONNECT ESP TO ACCESS POINT
  myBot.setTelegramToken(token); // SET TELEGRAM BOT TOKEN
  
    if (myBot.testConnection())// DEBUG CONNECTION
    Serial.println("\ntestConnection OK");
    else
    Serial.println("\ntestConnection NOK");
}

void loop() {
  
  float reading = analogRead(A0);
  Serial.println(reading);
  
  delay(1000);
  if (reading < 800)
  {
    if (CNT < 1) 
    {
      Serial.println("No light!");
      myBot.sendMessage(-1001412490907,"GR1 Zone1 tripped!");
      CNT = CNT + 1;
    }
  } else
  {
    CNT = 0;
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇纵 2025-02-01 09:00:32

也许您的错误在序列上。Begin(9600),因为Arduino的波特率与电报机器人不兼容。尝试使用此数字更改值9600:

115200

Maybe your error is in the Serial.begin(9600) because the baud rate of the Arduino is not compatible with the Telegram bot. Try to change the value 9600 with this number :

115200

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文