通用电报机器人库不适用于Arduino nano 33 IoT,但它没有显示错误



我第一次尝试了使用arduino nano 33iot和经典arduino ide的示例echobot。我使用botfather创建了一个机器人。我已经把例子的代码上传到了板子上。串行监视器告诉我它已连接到wifi,并显示了SSID, IP地址和信号强度,但当我试图使用电报机器人写一些东西时,什么也没有发生:我在机器人聊天中没有收到回声消息。有人能帮帮我吗?

这是代码:

/*******************************************************************
A telegram bot for your WifiNINA devices that responds
with whatever message you send it.
Parts:
Arduino Nano 33 IOT - https://store.arduino.cc/arduino-nano-33-iot
If you find what I do useful and would like to support me,
please consider becoming a sponsor on Github
https://github.com/sponsors/witnessmenow/

Written by Brian Lough
YouTube: https://www.youtube.com/brianlough
Tindie: https://www.tindie.com/stores/brianlough/
Twitter: https://twitter.com/witnessmenow
*******************************************************************/
// ----------------------------
// Standard Libraries
// ----------------------------
#include <SPI.h>
// ----------------------------
// Additional Libraries - each one of these will need to be installed.
// ----------------------------
#include <WiFiNINA.h>
// Library for using network deatures of the official Arudino
// Wifi Boards (MKR WiFi 1010, Nano 33 IOT etc)
// Search for "nina" in the Arduino Library Manager
// https://github.com/arduino-libraries/WiFiNINA
#include <UniversalTelegramBot.h>
// Library for connecting to Telegram
// Search for "Telegram" in the Arduino Library Manager
// Install the "Universal Telegram" one by Brian Lough
// https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
#include <ArduinoJson.h>
// Library used for parsing Json from the API responses
// Search for "Arduino Json" in the Arduino Library manager
// https://github.com/bblanchon/ArduinoJson
// Wifi network station credentials
char ssid[] = "SSID";         // your network SSID (name)
char password[] = "password"; // your network password
// Telegram BOT Token (Get from Botfather)
#define BOT_TOKEN "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
const unsigned long BOT_MTBS = 1000; // mean time between scan messages
int status = WL_IDLE_STATUS;
WiFiSSLClient client;
UniversalTelegramBot bot(BOT_TOKEN, client);
unsigned long bot_lasttime; // last time messages' scan has been done
void handleNewMessages(int numNewMessages)
{
for (int i = 0; i < numNewMessages; i++)
{
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].text, "");
}
}
void printWiFiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
void setup()
{
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < "1.0.0") {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, password);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
printWiFiStatus();
}
void loop()
{
if (millis() - bot_lasttime > BOT_MTBS)
{
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);
}
bot_lasttime = millis();
}
}

您需要将Telegram根证书添加到Wifi模块。使用Wifi101/WifiNINA固件更新程序.

请参考这里

https://support.arduino.cc/hc/en - us/articles/360016119219如何- - -证书添加到wifi -尼娜-无线- 101 -模块-

相关内容

最新更新