Skip to content

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

Open
@mino-sp

Description

@mino-sp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions