shurillu / CTBot

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

Bot and firebase bug #2

Closed fsanano closed 5 years ago

fsanano commented 6 years ago

Hi again. After successfull installing firebase I catch another bug. Here is my code:

#include <ESP8266WiFi.h>
#include <WiFiManager.h>

#include "CTBot.h"
#include <FirebaseArduino.h>

CTBot myBot;
CTBotInlineKeyboard myKbd;

#define LIGHT_ON_CALLBACK  "lightON"  // callback data sent when "LIGHT ON" button is pressed
#define LIGHT_OFF_CALLBACK "lightOFF" // callback data sent when "LIGHT OFF" button is pressed

#define FIREBASE_HOST "MyFirebaseHost"
#define FIREBASE_AUTH "MyFirebaseAuthToken"

uint8_t led = 2;
String token = "MyTelegramBotToken";

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

    WiFiManager wifiManager;
    wifiManager.autoConnect("TelegramBotServer");

    Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

    Serial.println("Starting TelegramBot...");

    myBot.setTelegramToken(token);

    if (myBot.testConnection()){
      Serial.println("\ntestConnection OK");
    }else{
      Serial.println("\ntestConnection NOK");
    }
    pinMode(led, OUTPUT);
    digitalWrite(led, HIGH);

    myKbd.addButton("LIGHT ON", LIGHT_ON_CALLBACK, CTBotKeyboardButtonQuery);
    myKbd.addButton("LIGHT OFF", LIGHT_OFF_CALLBACK, CTBotKeyboardButtonQuery);
    myKbd.addRow();
    myKbd.addButton("see docs", "https://github.com/shurillu/CTBot", CTBotKeyboardButtonURL);

}

void loop() {
  TBMessage msg;
  if (myBot.getNewMessage(msg)) {
    if (msg.messageType == CTBotMessageText) {
      Serial.println(msg.text);
      Serial.println(CTBotMessageText);
      if (msg.text.equalsIgnoreCase("show keyboard")) {
        myBot.sendMessage(msg.sender.id, "Inline Keyboard", myKbd);
      }
      else {
        myBot.sendMessage(msg.sender.id, "Try 'show keyboard'");
      }
    } else if (msg.messageType == CTBotMessageQuery) {
      if (msg.callbackQueryData.equals(LIGHT_ON_CALLBACK)) {
        digitalWrite(led, LOW);
        myBot.endQuery(msg.callbackQueryID, "Light on", true);
        Firebase.setBool("lightOn", true); // <--- when switch off HERE
      } else if (msg.callbackQueryData.equals(LIGHT_OFF_CALLBACK)) {
        digitalWrite(led, HIGH);
        myBot.endQuery(msg.callbackQueryID, "Light off");
        Firebase.setBool("lightOn", false);  // <--- when switch off HERE
      }
    }
  }
  delay(500);
}

When I switch of Firebase request all works fine. But when switch on I catch this errors:

Exception (29):
epc1=0x4000e1cc epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000104 depc=0x00000000

ctx: cont 
sp: 3fff1a10 end: 3fff23c0 offset: 01a0

>>>stack>>>
3fff1bb0:  00000040 3fff872c 00000000 40236a93
...
3fff23b0:  feefeffe feefeffe 3fff13a0 40100718
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(1,7)

 ets Jan  8 2013,rst cause:4, boot mode:(1,7)

wdt reset

I think it because multiple request send || receive at the same time. But I don't know how to fix it. Googling not help.

shurillu commented 6 years ago

Hello Sergey, sorry for the wait, but I were unable to manage the repository. Try to download and use the master branch: I have done some changes in the sendCommand() method. Now every time the object do an https request to the Telegram Server (sendCommand method), before terminating the method it will flush and close the connection. Let me know if it solve the issue, I can't check it because I don't use the Firebase platform.

shurillu commented 6 years ago

Hello Sergey, I published a new release (1.1.1) and will be available in the library manager soon (1-2 days). Can you check if this new release solve your issue? Please, let me know as I can close this issue (or try to find other solutions).

Stefano

shurillu commented 5 years ago

Hello Sergey, I'm closing this issue, if it still persist, please reopen it (eventually with further details).

Stefano