shurillu / CTBot

A simple (and easy to use) Arduino Telegram BOT Library for ESP8266/ESP32
MIT License
152 stars 35 forks source link

Why my bot get messages starting with 't'? #121

Open mino-sp opened 7 months ago

mino-sp commented 7 months ago

Hi all,

I am trying to develop a chatbot for plant monitoring, but it get messages only if the text string start with 't'

May you kindly help me to check what am I doing wrong here? Thank you.

Here's the code:

include "CTBot.h"

include "Agrumino.h"

include "ArduinoJson.h"

Agrumino agrumino;
CTBot myBot;

String ssid = "ssid";
String pass = "pass"; String token = "......................................";
uint8_t led = 2;

void setup() { Serial.begin(9600);

agrumino.setup(); agrumino.turnBoardOn();

myBot.wifiConnect(ssid, pass);

myBot.setTelegramToken(token);

if (myBot.testConnection()) Serial.println("\ntestConnection OK"); else Serial.println("\ntestConnection NOK");

}

void loop() { float temperature = agrumino.readTempC()-8; unsigned int soilMoisture = agrumino.readSoil(); float illuminance = agrumino.readLux(); float batteryVoltage = agrumino.readBatteryVoltage();

TBMessage msg; String t = String(temperature); String h = String(soilMoisture); String l = String(illuminance); String b = String(batteryVoltage);

//As you can see I've changed some variables so to make them starting with t (i.e. 'tLuce') and the sensor board is working.

if (CTBotMessageText == myBot.getNewMessage(msg)) {
    Serial.println(msg.text);
if (msg.text.equalsIgnoreCase("Temperatura")) {                                        
  myBot.sendMessage(msg.sender.id, "misuro la temperatura...");  
  myBot.sendMessage(msg.sender.id, "ci sono " + t + "° C");
}
else if (msg.text.equalsIgnoreCase("tUmidità")) {                                   
  myBot.sendMessage(msg.sender.id, "misuro l'umidità..."); 
  myBot.sendMessage(msg.sender.id, "l'umidità è " + h + "%");
}

else if (msg.text.equalsIgnoreCase("tLuce")) {
myBot.sendMessage(msg.sender.id, "misuro la luce..."); myBot.sendMessage(msg.sender.id, "la luce presente è " + l); } else if (msg.text.equalsIgnoreCase("tBatteria")) {
myBot.sendMessage(msg.sender.id, "misuro la batteria..."); myBot.sendMessage(msg.sender.id, "la batteria ha " + b + "V"); } else {
String reply; reply = (String)"Ciao " + msg.sender.username + (String)". Cosa vuoi sapere di Planty?"; myBot.sendMessage(msg.sender.id, reply); } }

delay(500); }

here's the serial monitor output:

11:53:27.689 -> Turning board on... 11:53:27.722 -> Lux Ver. 110 11:53:27.754 -> initLuxSensor → OK 11:53:27.754 -> initSoilSensor → OK 11:53:27.786 -> initTempSensor → OK 11:53:27.818 -> initGPIOExpander → OK 11:53:35.690 -> 11:53:35.690 -> testConnection OK 11:54:14.602 -> tluce 11:54:56.416 -> temp 11:56:01.033 -> tbatteria

and here's the chat:

Screenshot 2024-05-02 alle 12 01 27
shurillu commented 7 months ago

Hello mino-sp, thank you for using the library. First of all, which version of:

Moreover, which version of Agrumino do you have (I have probably a V4A - week 14/2019). You can find the release version in the bottom right corner of the coin battery holder. Anyway, I ran the echoBot example on my Agrumino and just works, without the "t" issue. After that, I managed to run your sketch with my Agrumino without an issue (I removed all "t" from "Batteria", "Umidità", "Luce"). I'm wondering it is an issue related to the libraries. Here my test rig:

Stefano