Open grosdax opened 3 years ago
Hello grosdax, thank you for using the library and for your suggestions, they are very useful! The only problem that I notice is the incompatibility with the ESP8266 paltform, as you pointed out. So I'm wondering if make a "wrapper, threaded" class only for the ESP32... Thanks a lot! Cheers,
Stefano
Thank you for all the good work on this library.
Just wanted to share a wrapper i wrote, it allows to have the CTBot playing in its own thread without disturbing the main thread. It does not wrap all the features, but only the one i am currently using, but it would be very straightforward to write the missing functions.
The thread is looping forever and stacking the received messages in a std::queue. The messages are removed from queue when getNewMessage is called from the main thread
The usage is very simple, after including CTBot.h, include ThreadedCTBot.h then replace your CTBot instance by a ThreadedCTBot. The thread is created in the setTelegramToken function, then all wrapped functions are simply locked by a mutex. Note that this should be only working on an ESP32.
Some additionnal work would be needed in order to make it bullet proof, but the concept does work.
and as an example, the echoBot implementation: