Universal Arduino Telegram Bot doesn't work

Hi all
I've tried for the first time the example echobot using an arduino nano 33 iot and the classical arduino ide. I have created a bot using botfather. I have uploaded the code of the example on the board. The serial monitor tells me that it's connected to the wifi and shows me the SSID the IP address and the signal strenght but when I try to write something using the telegram bot, nothing happens: I don't receive the echo message in the bot chat.
I have read the issue can be the version of the libraries...
I have tried wifinina ver 1.3 but nothing changed.
Can anybody help me?

This is the code:

// ----------------------------
// 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();
  }
}

In all examples, I can see that the bot is being declared as a global variable. This requires the BOTtoken to be available very early in the boot sequence.

Does it work for you?

I have the same issue with a MKR1010 board, it doesn't seem to be an issue with the token variable as mentioned above. Did you find any solution @Lucky-Luka ? If I do, I will come back to this post.

1 Like

I get the same issue. I have an Arduino nano iot 33, the code is the same. I don't receive the echo message in the bot chat.
Let me know If you have already solved this issue?
Thank you

P.S. I have Arduino IDE 2.0.3, I'm trying to take the same exercise with a dated version.

I finally managed to fix it and it was related to some library issue, I can't really tell which one. I wiped out all libraries and arduino IDE and did a fresh install of everything and it worked perfectly. I believe I started installing libraries like crazy (json ones, etc.) and something was not working. I'd recommend if you have another computer where you can try it, and if it works it may be something similar.

@danidetapia
Sad :frowning: I tried so many times but it doesn't work.
I tried as you suggested me to wipe out all the libraries and reinstall arduino ide. Following the results I got and the setup I used:

  1. doesn't work
  • Arduino IDE 2.0.3
  • Arduino SAMD BOARD v 1.8.13
  • UniversalTelegramBot 1.3.0
  • Arduinojson 6.19.4
  • WifiNina 1.3.0
  1. doesn't work
  • Arduino IDE 2.0.3
  • Arduino SAMD BOARD v 1.8.13
  • UniversalTelegramBot 1.3.0
  • Arduinojson 6.19.4
  • WifiNina 1.8.13

Then I decided to check if the firmware of nano 33 iot was updated. I discovered it was 1.4.4.
So I updated the firmware to 1.5.0 (the current one) and I re-did the test both wifinina 1.3.0 and 1.8.13 but, sad, doesn't work again.

Could you please check if the library versions are the same?

Thank you

WifiNina 1.8.13
UniversalTelegrambot 1.1.0 (I will upgrade later and let you know if I have any issue afer the upgrade)
Arduinojson 6.19.4
Arduino IDE 2.0.2
Arduino SAMD Board 1.8.14 (I am using the MKR1010 wifi)

not sure this will help

Did anyone find a global solution? I cannot receive anything using a Uno Wifi.

I added the debug on the library and I can see it connect to the server Okay, I added an extra send on start-up and this is transmitted / received by my phone correctly....

I tracked it down to the following fails:

bool UniversalTelegramBot::processResult(JsonObject result, int messageIndex) {
int update_id = result["update_id"];

On the Arduino Uno (and other ATmega based boards) an int stores a 16-bit (2-byte) value. On the Arduino Due and SAMD based boards (like MKR1000 and Zero), an int stores a 32-bit (4-byte) value. Update id is 4bytes.

Make it a long the same as "last_message_received", that it compared to and it works and is covered for more devices.

long update_id = result["update_id"];

Hope this helps on IOTs.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.