Code Monkey home page Code Monkey logo

universal-arduino-telegram-bot's People

Contributors

bolukan avatar fritsjan avatar gerasdf avatar gianbacchio avatar gmcode85 avatar happyfacade avatar jamesmyatt avatar jjjpolo avatar malte-j avatar mrsuhov avatar nechry avatar pascalguenther avatar pro2xy avatar rafaelcbarbosa avatar rusboard avatar solcer avatar vsinitski avatar witnessmenow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

universal-arduino-telegram-bot's Issues

Response message

Hi, i've the following problem, i need that the bot when receive a command wait for another message, and process it. How i can do that, Thanks in Advance.

wifiManager.setSTAStaticIPConfig

hello
when i use wifimanager with static ip

IPAddress ip (192, 168, 1, 59);
IPAddress gateway(192, 168, 1, 1);
IPAddress mask (255, 255, 255, 0);

wifiManager.setSTAStaticIPConfig(ip, gateway, mask);

the esp8266nodemcu dont receives nothing
if I let wifimanager in dhcp mode dhcp then it works fine and receives every command fro telelegram


#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>

//WIFIMANAGER
#include <DNSServer.h>            //Local DNS Server used for redirecting all rs to the configuration portal
#include <ESP8266WebServer.h>     //Local WebServer used to serve the configuration portal
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager WiFi Configuration Magic

#define BOT_TOKEN_LENGTH 46
char BOTtoken[BOT_TOKEN_LENGTH] =  "----MYTOKEN----";  

WiFiClientSecure client_secure;
UniversalTelegramBot *bot;

int Bot_mtbs = 1000; //mean time between scan messages
long Bot_lasttime;   //last time messages' scan has been done


IPAddress ip     (192, 168,   1, 59);
IPAddress gateway(192, 168,   1,  1);
IPAddress mask(255, 255, 255,  0);

void handleNewMessages(int numNewMessages) {
  for (int i = 0; i < numNewMessages; i++) {
    String chat_id = String(bot->messages[i].chat_id);
    String text_bot=bot->messages[i].text.substring(1,bot->messages[i].text.length());
    if (text_bot.equals("X")) {
      bot->sendMessage(chat_id, "X", "");
    }
    if (text_bot.equals("Y")) {
      bot->sendMessage(chat_id, "Y", "");
    }

    if (text_bot.equals("start") || text_bot.equals("help")) {
      String help= "/X \n";
      help+= "/Y";
      bot->sendMessage(chat_id, help, "");
    }
  }
}

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

 //IF I COMENT NEXT LINE IT WORKS FINE OTHERWISE DONT RECEIVES NOTHING
  wifiManager.setSTAStaticIPConfig(ip, gateway, mask);

  wifiManager.autoConnect("AP_door", "pwd");
  if (WiFi.status() == WL_CONNECTED) {
    bot = new UniversalTelegramBot(BOTtoken, client_secure);
    Serial.println("WiFi connected");
    Serial.print(WiFi.localIP());
    Serial.println("/");
  } 
}

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

Too long messages put the library into an endless polling loop

Issue:

Sending messages longer than maxMessageLength defined in UniversalTelegramBot.h sends the device into an endless polling loop where it polls the same message Id till infinity.

Proposed Fix:
Cut off message and terminate at maxMessageLength in UniversalTelegramBot.cpp::sendGetToTelegram:

if (mess.length() >= maxMessageLength)
{
	mess = mess.substring(0,maxMessageLength-5);
	mess = mess + "\"\}\}\]\}";
}

For full code see attached modified cpp.
UniversalTelegramBot.cpp.txt

How to tell if bot is valid

Hi,
is there a way to know that the bot is valid when it is created?
I would like to know that the token is valid and that I have a valid bot that I can use and if not then prompt for a valid token.
Thanks.

SIM800 support

Hi! It is possible add support of SIM800 module in this library? I think it will be useful feature, because it can use gprs connection.

ESP8266 crashes when used with low RAM/Heaps available. EXCEPTION (29)

Hello
I ran into a problem which i tried to investigate in the last week.
I'm using an ESP8266, wemos D1mini, and was able to reproduce the crash using the PhotoFromURL example.
This submitted issue might probably be a dublicate of #51 and #52 . Feel free to move and modify my post in any way you see fit.
Also note that this issue might be caused by ArduinoJSON or another library which Universal-Arduino-atelegram-Bot relies upon.

The crash occurs when sending messages. In my project the ESP crashes after sending 2-5 messages. Using the unmodified PhotoFromURL example it takes about 100-300 messages within ~3 minutes, which resulted in an Exception (29) crash.
I slightly modified the example and filled the RAM with a big global char array and wrote ESP.GetFreeHeap() to the serial output, which triggers the crash after sending ~10 messages.

The exception always occurs when the free heap size decreses beneath ~6500-5700.
The free heap size increases automatically when ~3min have passed. I assume the old buffers or something gets deleted when they are older than ~3min. The RAM gets filled the fastest when alternating between different messages, using my sketch: /get_test_photo and /status .
I enabled the _debug bool in UniversalTelegramBot.h

This is the modified sketch:
telegram_exceptionist.zip

Here 3 possible combinations and their outcome:

telegram_exeptionist.ino using WiFiClientSecure without filling RAM (no char array):
Sketch uses 296285 bytes (28%) of program storage space. Maximum is 1044464 bytes.
Global variables use 40484 bytes (49%) of dynamic memory, leaving 41436 bytes for local variables. Maximum is 81920 bytes.
Uploading 300432 bytes

free heaps:
at start 17300 B
crashes after 6160 B
(this was almost impossible since 100-300 messages have to be sent, but the RAM starts to free up again after ~3min.)

Serial output: [expand] GET Update Messages .... connected to server

{"ok":true,"result":[{"update_id":72978882,
"message":{"message_id":1980,"from":{"id":xxxxxxxx,"is_bot":false,"first_name":"Dejan","last_name":"Lauber","language_code":"en-US"},"chat":{"id":xxxxxxxx,"first_name":"Dejan","last_name":"Lauber","type":"private"},"date":1508349619,"text":"/status","entities":[{"offset":0,"length":7,"type":"bot_command"}]}}]}

incoming message length357
Creating DynamicJsonBuffer

got response
handleNewMessages
1
free heap: 6344 B

msg length: 298
sendMessage start: 8789721 ms
SEND Post Message

Exception (29):
epc1=0x4000e1b2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000

ctx: cont
sp: 3fff0ee0 end: 3fff1500 offset: 01a0

stack>>>
3fff1080: 3fff03f4 000013d6 000013d6 40223beb
3fff1090: 00000208 3fff560c 3fffad2c 40223d84
3fff10a0: 00000104 00009ca0 00001394 3fff560c
3fff10b0: 00000040 00000082 3fffad14 40224036
3fff10c0: 00800000 00000080 00000000 00000041
3fff10d0: 00000040 0000003f 40205f50 00000041
3fff10e0: 3fffb6bc 3fff560c 3fff6844 3fff48b4
3fff10f0: 3fffbbd0 ffffffff 3fff560c 3fff560c
3fff1100: 00000040 3fff560c 3fffad14 3fff560c
3fff1110: 00000040 3fff560c 3fffad14 40224b92
3fff1120: 3fff579c 0000003f fdd3d074 00000001
3fff1130: 3fff560c 3fffa51c 3fffad14 00000001
3fff1140: 00000010 3fff560c 0000000f 40224ded
3fff1150: 3fff6844 3fff489c 0000000f 00000001
3fff1160: 00000001 3fffa6c4 3fff28c9 40223c50
3fff1170: 00000100 3fffa1a4 3fff282f 00000000
3fff1180: 00000100 3fffa1a4 3fff282f 40225e79
3fff1190: 3fff11c0 00000000 000000d0 00000030
3fff11a0: 73020732 79a2f204 3fff9904 00000004
3fff11b0: 00000004 3fff92e4 3fff2829 40221f84
3fff11c0: 57cc0203 f0c9c297 a217994f 3da31a57
3fff11d0: f8f06d78 322787ff 99383f74 a472b73f
3fff11e0: 039c900d df83dd48 41806564 07324e89
3fff11f0: 00000004 3fff2829 3fff92e4 40222385
3fff1200: 00000000 600011f0 3fff9904 3fffa8d4
3fff1210: 00000000 00000004 00000004 40203097
3fff1220: 3fff282d 3fff2829 3fff671c 00001200
3fff1230: 000012a0 3fff3a94 00000034 00000004
3fff1240: 3fff92e4 3fff2829 00000004 00000004
3fff1250: 00000004 3fff2829 3fff92e4 40221d7c
3fff1260: 00000000 3fff2829 3fff92e4 40222124
3fff1270: 00000010 3ffe915c 00000011 401004d8
3fff1280: 3fff12d0 0000000e 00000010 00000000
3fff1290: 3fff1e94 3ffe915c 3fff92e4 01000000
3fff12a0: 3fff12d0 3fff02bc 3fff92e4 40221ed4
3fff12b0: 3ffe915c 00000000 3fff1edc 00001387
3fff12c0: 00861f55 3fff02bc 3fff1edc 40203509
3fff12d0: 000001bb 3fff9904 3fff02bc 402029ee
3fff12e0: c5a79a95 3fff0418 3fff1338 3fff1390
3fff12f0: 000001bb 3fff02bc 3ffe915c 40203719
3fff1300: 3ffe9780 c5a79a95 3ffe9780 c5a79a95
3fff1310: 3fff139c 3fffad90 3fff0248 40204ab5
3fff1320: 3fff1350 00000001 3ffe91b9 3fff143c
3fff1330: 00000040 3fff1390 3fffa8bc 0000000f
3fff1340: 00000000 0000003c 3fff1390 40205a7f
3fff1350: 3fff03f4 000006d1 3fff1390 40205ab1
3fff1360: 00863e1e 3fffad90 3fff1390 40205b74
3fff1370: 3ffe93ec 3fffad90 3fff0248 3fff143c
3fff1380: 00863e1e 3fffad90 3fff0248 40204cf8
3fff1390: 3fff54bc 0000003f 0000003c 3fff4e0c
3fff13a0: 0000000f 00000000 3fff5504 0000003f
3fff13b0: 0000003c 3fffad90 00000000 40203cb0
3fff13c0: 00000010 3fff1430 3fff1430 3fff143c
3fff13d0: 3fff0248 3fff1430 3fffad90 40204dc9
3fff13e0: 3ffe9620 000005f5 3fffae94 00000400
3fff13f0: 3fff1448 00000000 3fff1430 40205b02
3fff1400: 3ffe937d 00000000 3fff0254 00000000
3fff1410: 3fff0418 00000000 3fff0254 40202164
3fff1420: 00000000 3fff25e0 3fff026c 402059d4
3fff1430: 3fff4df4 0000000f 00000000 3fff50a4
3fff1440: 0000012f 0000012a 3fff4ddc 0000000f
3fff1450: 00000009 3fff25d4 0000012f 0000012a
3fff1460: 00000000 00000000 00000000 00000000
3fff1470: 00000000 00000001 3ffe91b9 40206378
3fff1480: 00000000 3fff4984 0000000f 00000005
3fff1490: 3fff9ffc 0000000f 00000007 3fffa18c
3fff14a0: 0000000f 00000009 3fff0418 402056c5
3fff14b0: 00000001 00000001 3fff0418 402056f0
3fff14c0: 3fffdad0 3fff02d8 3fff0418 3fff04d4
3fff14d0: 3fff0244 3fff0248 00000001 40202389
3fff14e0: 3fffdad0 00000000 3fff04cc 40205f9c
3fff14f0: feefeffe feefeffe 3fff04e0 40100718
<<<stack<<<

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

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

wdt reset

telegram_exeptionist.ino using WiFiClientSecure and filling RAM:
Sketch uses 296389 bytes (28%) of program storage space. Maximum is 1044464 bytes.
Global variables use 50580 bytes (61%) of dynamic memory, leaving 31340 bytes for local variables. Maximum is 81920 bytes.
Uploading 300544 bytes

free heaps:
at start 7400 B
crashes after 6000 B

Serial output: [expand] GET Update Messages .... connected to server

{"ok":true,"result":[{"update_id":72978902,
"message":{"message_id":2016,"from":{"id":xxxxxxxx,"is_bot":false,"first_name":"Dejan","last_name":"Lauber","language_code":"en-US"},"chat":{"id":xxxxxxxx,"first_name":"Dejan","last_name":"Lauber","type":"private"},"date":1508350789,"text":"/status","entities":[{"offset":0,"length":7,"type":"bot_command"}]}}]}

incoming message length357
Creating DynamicJsonBuffer

got response
handleNewMessages
1
free heap: 6000 B

msg length: 298
sendMessage start: 29404
SEND Post Message

Exception (29):
epc1=0x4000e1b2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000

ctx: cont
sp: 3fff3650 end: 3fff3c70 offset: 01a0

stack>>>
3fff37f0: 3fff2b64 000009db 000009db 40223c0f
3fff3800: 00000208 3fffbf7c 3fff5e3c 40223da8
3fff3810: 00000104 00004cc8 00000999 3fffbf7c
3fff3820: 00000040 00000082 3fff5e24 4022405a
3fff3830: 00800000 00000080 00000000 00000041
3fff3840: 00000040 0000003f 40205f74 00000041
3fff3850: 3fff8e54 3fffbf7c 3fff9edc 3fff9c0c
3fff3860: 3fff9368 ffffffff 3fffbf7c 3fffbf7c
3fff3870: 00000040 3fffbf7c 3fff5e24 3fffbf7c
3fff3880: 00000040 3fffbf7c 3fff5e24 40224bb6
3fff3890: 3fff9eb4 0000003f 9ff4c9ed 00000001
3fff38a0: 3fffbf7c 3fff5e0c 3fff5e24 00000001
3fff38b0: 00000010 3fffbf7c 0000000f 40224e11
3fff38c0: 3fff9edc 3fff9bf4 0000000f 00000001
3fff38d0: 00000001 3fff6724 3fffa03e 40223c74
3fff38e0: 00000100 3fff9aa4 3fff9fb7 00000000
3fff38f0: 00000100 3fff9aa4 3fff9fb7 40225e9d
3fff3900: 3fff3930 00000000 000000d0 00000030
3fff3910: 02efe630 9225d911 6acfa58b 00000004
3fff3920: 00000004 3fff6144 3fff9fb1 40221fa8
3fff3930: c4ec0203 96fdef07 74983f52 13204e31
3fff3940: 14fb0e32 6663e8ed a078d46e 1493c32d
3fff3950: 44b68c7d de41381b 0b599e8c e63010c9
3fff3960: 00000004 3fff9fb1 3fff6144 402223a9
3fff3970: 74189ebf 4b3693ed bb2b5f8c 3fff611c
3fff3980: 00000000 00000004 00000004 402030bb
3fff3990: 3fff9fb5 3fff9fb1 3fff997c 00001200
3fff39a0: 000012a0 3fffb21c 00000034 00000004
3fff39b0: 3fff6144 3fff9fb1 00000004 00000004
3fff39c0: 00000004 3fff9fb1 3fff6144 40221da0
3fff39d0: 00000000 3fff9fb1 3fff6144 40222148
3fff39e0: 00000010 3ffe91c4 00000011 401004d8
3fff39f0: 3fff3a40 0000000e 00000010 00000000
3fff3a00: 3fff7c7c 3ffe91c4 3fff6144 01000000
3fff3a10: 3fff3a40 3fff031c 3fff6144 40221ef8
3fff3a20: 3ffe91c4 00000000 3fff4be4 00001387
3fff3a30: 0000734e 3fff031c 3fff4be4 4020352d
3fff3a40: 000001bb 3fff5eec 3fff031c 40202a12
3fff3a50: c6a79a95 3fff2b88 3fff3aa8 3fff3b00
3fff3a60: 000001bb 3fff031c 3ffe91c4 4020373d
3fff3a70: 3ffe97e8 c6a79a95 3ffe97e8 c6a79a95
3fff3a80: 3fff3b0c 3fff69c0 3fff02a8 40204ad9
3fff3a90: 3fff3ac0 00000001 3ffe9221 3fff3bac
3fff3aa0: 00000040 3fff3b00 3fff6104 0000000f
3fff3ab0: 00000000 0000003c 3fff3b00 40205aa3
3fff3ac0: 3fff2b64 00000111 3fff3b00 40205ad5
3fff3ad0: 00009220 3fff69c0 3fff3b00 40205b98
3fff3ae0: 3ffe9454 3fff69c0 3fff02a8 3fff3bac
3fff3af0: 00009220 3fff69c0 3fff02a8 40204d1c
3fff3b00: 3fff4e2c 0000003f 0000003c 3fff60ec
3fff3b10: 0000000f 00000000 3fff60a4 0000003f
3fff3b20: 0000003c 3fff69c0 00000000 40203cd4
3fff3b30: 00000010 3fff3ba0 3fff3ba0 3fff3bac
3fff3b40: 3fff02a8 3fff3ba0 3fff69c0 40204ded
3fff3b50: 3ffe9688 0000010b 3fff6ac4 00000400
3fff3b60: 3fff3bb8 00000000 3fff3ba0 40205b26
3fff3b70: 3ffe93e5 00000000 3fff02b4 00000000
3fff3b80: 3fff2b88 00000000 3fff02b4 40202164
3fff3b90: 00000000 3fff9838 3fff02cc 402059f8
3fff3ba0: 3fff4e14 0000000f 00000000 3fff687c
3fff3bb0: 0000012f 0000012a 3fff4dfc 0000000f
3fff3bc0: 00000009 3fff982c 0000012f 0000012a
3fff3bd0: 00000000 00000000 00000000 00000000
3fff3be0: 00000000 00000001 3ffe9221 4020639c
3fff3bf0: 00000000 3fff9c54 0000000f 00000005
3fff3c00: 3fff9c3c 0000000f 00000007 3fffbfdc
3fff3c10: 0000000f 00000009 3fff2b88 402056e9
3fff3c20: 00000001 00000001 3fff2b88 40205714
3fff3c30: 3fffdad0 3fff2a48 3fff2b88 3fff2c44
3fff3c40: 3fff02a4 3fff02a8 00000001 40202389
3fff3c50: 3fffdad0 00000000 3fff2c3c 40205fc0
3fff3c60: feefeffe feefeffe 3fff2c50 40100718
<<<stack<<<

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

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

wdt reset

telegram_exeptionist.ino using HTTPSredirect and filling RAM:
I followed @witnessmenow 's suggestion in issue #52 to try HTTPSredirect instead of WiFiClientSecure. The same crash occurs.

Sketch uses 297021 bytes (28%) of program storage space. Maximum is 1044464 bytes.
Global variables use 51076 bytes (62%) of dynamic memory, leaving 30844 bytes for local variables. Maximum is 81920 bytes.
Uploading 301168 bytes

free heaps:
at start 6800 B
crashes after 5700 B

Serial output: [expand] GET Update Messages .... connected to server

{"ok":true,"result":[{"update_id":72978915,
"message":{"message_id":2047,"from":{"id":xxxxxxxx,"is_bot":false,"first_name":"Dejan","last_name":"Lauber","language_code":"en-US"},"chat":{"id":xxxxxxxx,"first_name":"Dejan","last_name":"Lauber","type":"private"},"date":1508501057,"text":"/status","entities":[{"offset":0,"length":7,"type":"bot_command"}]}}]}

incoming message length357
Creating DynamicJsonBuffer

got response
handleNewMessages
1
free heap: 5728 B

msg length: 298
sendMessage start: 72291
SEND Post Message

Exception (29):
epc1=0x4000e1b2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000

ctx: cont
sp: 3fff3840 end: 3fff3e60 offset: 01a0

stack>>>
3fff39e0: 3fff2d4c 00000ea0 00000ea0 40223d13
3fff39f0: 00000208 3fff6b3c 3fff558c 40223eac
3fff3a00: 00000104 000072f0 00000e5e 3fff6b3c
3fff3a10: 00000040 00000082 3fff62ec 4022415e
3fff3a20: 00800000 00000080 00000000 00000041
3fff3a30: 00000040 0000003f 40206078 00000041
3fff3a40: 3fffb66c 3fff6b3c 3fff678c 3fff7204
3fff3a50: 3fffbb80 ffffffff 3fff6b3c 3fff6b3c
3fff3a60: 00000040 3fff6b3c 3fff62ec 3fff6b3c
3fff3a70: 00000040 3fff6b3c 3fff62ec 40224cba
3fff3a80: 3fff69bc 0000003f 6f7c523c 00000001
3fff3a90: 3fff6b3c 3fff62d4 3fff62ec 00000001
3fff3aa0: 00000010 3fff6b3c 0000000f 40224f15
3fff3ab0: 3fff678c 3fff69ec 0000000f 00000001
3fff3ac0: 00000001 3fff901c 3fff9159 40223d78
3fff3ad0: 00000100 3fff698c 3fff9157 00000000
3fff3ae0: 00000100 3fff698c 3fff9157 40225fa1
3fff3af0: 3fff3b20 00000000 000000d0 00000030
3fff3b00: ef97ef1c 9225d911 6acfa58b 00000004
3fff3b10: 00000004 3fff4fc4 3fff9151 402220ac
3fff3b20: 93e30203 bef4ae17 a98b23cf c47e77fe
3fff3b30: c7563393 db3e7a9b b440ae97 61e79a97
3fff3b40: 4b0c879a cf60bb60 4e4c5ee3 ef1ce98f
3fff3b50: 00000004 3fff9151 3fff4fc4 402224ad
3fff3b60: 74189ebf 4b3693ed bb2b5f8c 3fff50dc
3fff3b70: 00000000 00000004 00000004 402030c3
3fff3b80: 3fff9155 3fff9151 3fff63e4 00001200
3fff3b90: 000012a0 3fffa3bc 00000034 00000004
3fff3ba0: 3fff4fc4 3fff9151 00000004 00000004
3fff3bb0: 00000004 3fff9151 3fff4fc4 40221ea4
3fff3bc0: 00000000 3fff9151 3fff4fc4 4022224c
3fff3bd0: 00000010 3ffe936c 00000011 401004d8
3fff3be0: 3fff3c30 0000000e 00000010 00000000
3fff3bf0: 3fff68a4 3ffe936c 3fff4fc4 01000000
3fff3c00: 3fff3c30 3fff2bac 3fff4fc4 40221ffc
3fff3c10: 3ffe936c 00000000 3fff480c 00001387
3fff3c20: 00011b13 3fff2bac 3fff480c 40203535
3fff3c30: 000001bb 3fffbf04 3fff2bac 40202a1a
3fff3c40: c5a79a95 3fff2d70 3fff3c98 3fff3cf0
3fff3c50: 000001bb 3fff2bac 3ffe936c 40203745
3fff3c60: 3ffe9960 c5a79a95 3ffe9960 c5a79a95
3fff3c70: 3fff3cfc 3fff7238 3fff0428 40204bdd
3fff3c80: 3fff3cb0 00000001 3ffe922b 3fff3d9c
3fff3c90: 00000040 3fff3cf0 3fff6bc4 0000000f
3fff3ca0: 00000000 0000003c 3fff3cf0 40205ba7
3fff3cb0: 3fff2d4c 000003b4 3fff3cf0 40205bd9
3fff3cc0: 000139a7 3fff7238 3fff3cf0 40205c9c
3fff3cd0: 3ffe95d2 3fff7238 3fff0428 3fff3d9c
3fff3ce0: 000139a7 3fff7238 3fff0428 40204e20
3fff3cf0: 3fff6534 0000003f 0000003c 3fff657c
3fff3d00: 0000000f 00000000 3fff8fbc 0000003f
3fff3d10: 0000003c 3fff7238 00000000 40203dd8
3fff3d20: 00000010 3fff3d90 3fff3d90 3fff3d9c
3fff3d30: 3fff0428 3fff3d90 3fff7238 40204ef1
3fff3d40: 3ffe9800 00000480 3fff733c 00000400
3fff3d50: 3fff3da8 00000000 3fff3d90 40205c2a
3fff3d60: 3ffe9563 00000000 3fff0434 00000000
3fff3d70: 3fff2d70 00000000 3fff0434 40202164
3fff3d80: 00000000 3fff6a10 3fff044c 40205afc
3fff3d90: 3fff6bac 0000000f 00000000 3fff8e84
3fff3da0: 0000012f 0000012a 3fff6b94 0000000f
3fff3db0: 00000009 3fff6a04 0000012f 0000012a
3fff3dc0: 00000000 00000000 00000000 00000000
3fff3dd0: 00000000 00000001 3ffe922b 402064a0
3fff3de0: 00000000 3fff688c 0000000f 00000005
3fff3df0: 3fff4e64 0000000f 00000007 3fff67b4
3fff3e00: 0000000f 00000009 3fff2d70 402057ed
3fff3e10: 00000001 00000001 3fff2d70 40205818
3fff3e20: 3fffdad0 3fff2c30 3fff2d70 3fff2e2c
3fff3e30: 3fff0424 3fff0428 00000001 40202389
3fff3e40: 3fffdad0 00000000 3fff2e24 402060c4
3fff3e50: feefeffe feefeffe 3fff2e40 40100718
<<<stack<<<

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

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

wdt reset

Notes

when the ESP crashes and dumps its stack, it waits 3s until the last line "wdt reset" happens.
i installed and tried the Arduino ESP8266/ESP32 Exception Stack Trace Decoder with an interesting first line. Apart from that i'm not sure what to look for..

The decoded output: [expand]

Exception 29: StoreProhibited: A store referenced a page mapped with an attribute that does not permit stores
Decoding 35 results
0x40223c0f: AES_cbc_decrypt at /Users/igrokhotkov/e/axtls/e1/crypto/aes.c line 337 (discriminator 2)
0x40223da8: trim at /Users/igrokhotkov/e/axtls/e1/crypto/bigint.c line 1203
0x4022405a: bi_terminate at /Users/igrokhotkov/e/axtls/e1/crypto/bigint.c line 119
0x40205f74: String::substring(unsigned int, unsigned int) const at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/WString.cpp line 618
0x40224bb6: bi_set_mod at /Users/igrokhotkov/e/axtls/e1/crypto/bigint.c line 749
0x40224e11: precompute_slide_window at /Users/igrokhotkov/e/axtls/e1/crypto/bigint.c line 1327
: (inlined by) bi_mod_power at /Users/igrokhotkov/e/axtls/e1/crypto/bigint.c line 1372
0x40223c74: htonl at /Users/igrokhotkov/e/axtls/e1/ssl/os_port.h line 209 (discriminator 2)
: (inlined by) AES_cbc_decrypt at /Users/igrokhotkov/e/axtls/e1/crypto/aes.c line 347 (discriminator 2)
0x40225e9d: RSA_print at /Users/igrokhotkov/e/axtls/e1/crypto/rsa.c line 230
0x40221fa8: verify_digest at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 610
: (inlined by) basic_read at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 1336
0x402223a9: process_server_hello at /Users/igrokhotkov/e/axtls/e1/ssl/tls1_clnt.c line 293
: (inlined by) do_clnt_handshake at /Users/igrokhotkov/e/axtls/e1/ssl/tls1_clnt.c line 89
0x402030bb: ClientContext::_consume(unsigned int) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp line 517
: (inlined by) ClientContext::read(char*, unsigned int) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/include/ClientContext.h line 175
0x40221da0: verify_digest at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 709
: (inlined by) basic_read at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 1336
0x40222148: send_client_hello at /Users/igrokhotkov/e/axtls/e1/ssl/tls1_clnt.c line 200
: (inlined by) do_client_connect at /Users/igrokhotkov/e/axtls/e1/ssl/tls1_clnt.c line 153
0x401004d8: malloc at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/umm_malloc/umm_malloc.c line 1664
0x40221ef8: basic_read at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 1381
0x4020352d: WiFiClientSecure::_connectSSL(char const*) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp line 517
0x40202a12: WiFiClient::connect(IPAddress, unsigned short) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiClient.cpp line 327
0x4020373d: WiFiClientSecure::connect(char const*, unsigned short) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp line 265
0x40204ad9: ArduinoJson::Internals::JsonSerializer > >::serialize(ArduinoJson::JsonVariant const&, ArduinoJson::Internals::JsonWriter >&) at /home/brian/share/arduino/libraries/UniversalTelegramBot/src/UniversalTelegramBot.cpp line 283
0x40205aa3: UpdaterClass::UpdaterClass() at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/Updater.cpp line 373
0x40205ad5: _GLOBAL__sub_D__ZN12UpdaterClassC2Ev at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/Updater.cpp line 375
0x40205b98: String::reserve(unsigned int) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/WString.cpp line 589
0x40204d1c: UniversalTelegramBot::sendPostToTelegram(String, ArduinoJson::JsonObject&) at /home/brian/share/arduino/libraries/UniversalTelegramBot/src/UniversalTelegramBot.cpp line 283
0x40203cd4: ArduinoJson::JsonObject& ArduinoJson::JsonObject::createNestedObject_impl (char const*) at /home/brian/share/arduino/libraries/UniversalTelegramBot/src/UniversalTelegramBot.cpp line 283
0x40204ded: StringSumHelper at /home/brian/share/arduino/libraries/UniversalTelegramBot/src/UniversalTelegramBot.cpp line 283
: (inlined by) UniversalTelegramBot::sendPostMessage(ArduinoJson::JsonObject&) at /home/brian/share/arduino/libraries/UniversalTelegramBot/src/UniversalTelegramBot.cpp line 462
0x40205b26: String::init() at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/WString.cpp line 589
: (inlined by) String::invalidate() at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/WString.cpp line 135
0x40202164: handleNewMessages(int) at /home/brian/share/arduino/telegram_exceptionist/telegram_exceptionist.ino line 65
0x402059f8: Print::println(unsigned int, int) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/Print.cpp line 76
0x4020639c: ArduinoJson::Internals::JsonBufferAllocated::operator new(unsigned int, ArduinoJson::JsonBuffer*) at /home/brian/share/arduino/libraries/ArduinoJson/src/ArduinoJson/Data/JsonBufferAllocated.hpp line 19
0x402056e9: HardwareSerial::begin(unsigned long, SerialConfig, SerialMode, unsigned char) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/HardwareSerial.cpp line 193
0x40205714: _GLOBAL__sub_I__ZN14HardwareSerialC2Ei at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/HardwareSerial.cpp line 197
0x40202389: loop at /home/brian/share/arduino/telegram_exceptionist/telegram_exceptionist.ino line 111
0x40205fc0: operator delete(void*) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/abi.cpp line 57
0x40100718: cont_norm at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/cont.S line 109

Build options:

Board: "Wemos D1 R2 & mini"
CPU Frequency: "80MHz"
Flash Size: "4M (3M SPIFFS)"
Upload Speed: "921600"

Other things i've tried:

Different USB Power adapter. no effect.
I got the same crash on another ESP8266, with different power adapter and cable.
470uF Capacitor is in place on the 5V rail.
Added a 2200uF Capacitor to the 3.3V rail. no effect.
changed to 1M flash size. no effect.
changed clock to 160mhz. no effect.

If anyone has a clue on how to resolve this issue, or an idea on what to try next, let me know.

Best regards,
dejan lauber

PS: The ESP8266 and this telegram library blew my mind! Awesome work!

bot.getUpdates -- many, many questions

First of all thanks for sharing your library. I am using it on a ESP32 dev module (ESP-WROOM-32).
I'm having a lot of issues with this method bot.getUpdates() because it generates a

core 1 panic'ed: LoadProhibited

with a bunch of register dump.
This is very easy to reproduce. I am using your example code with my own bot token.
I simply leave the chip running in a loop, polling for new updates every 5 seconds. Eventually, like after about 3 or 4 minutes, I will receive updates for an inexisting telegram message.

In order for me to explain this better, I looked into the code of bot.getUpdates() and I noticed a couple of "interesting" things:
1 - the update code always brings 1 update at a time, no more. So why are we using an array?
2 - this function bot.getUpdates returns the amount of new updates found (if there are any). And this is always going to be 1
3 - the method posting to telegram.org is using the

define HANDLE_MESSAGES 1

to limit the amount of updates that we receive everytime. But if ever something goes wrong with this request, or we get more than one update, the function getUpdate will crash.

This being said, let's look at the sequence of events causing my crash.
1 - loop forever, call bot.getUpdates() every 5 seconds
2 - return value of bot.getUpdates() is always zero
3 - after about 3 or 4 minutes, return value of bot.getUpdates is 1073492764 !!! Bingo

As you can see that return value should never exceed 1 but in this case it does. My assumption is that something in the Bot Heap is getting screwed up.
I am using the library available from the Arduino libraries manager.
Do you have any tips as to where I should start debugging first ?
What could be wrong ?
I have tried this code on a 8266 ESP-12F and have not had any issues whasoever.

Support for Yùn board

I was trying to make it work with my Yùn board, I figured it was just a matter of using BridgeSSLClient instead of WiFiSSLClient, but I didn't succeed to make It work.
Enabling debug I get:

GET Update Messages
.... connected to server
got response
handleNewMessages
2027 

(the last value might vary)
At this point I have no idea on how to make it work.

Make Port number configurable in code

As pointed out in #67 , Although Telegram's documentation states it requires HTTPS, at least some endpoints support HTTP

If the port number was configurable in code users would have the option of using HTTP if they wanted (by also passing in a non HTTPS client)

Support ESP32

#62

Need to fix tests on it and Add some examples, but looks like it is working well for people

problem in WifiManager example

hi
when i try to read saved bot token its wrong and return this:
read bot token
⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
can anyone help me?

Issues Sending Messages

Hello,

I am trying to get EchoBot to work, but bot.sendMessage() isn't sending messages.

I checked the boolean return of sendMessage; returns true. EchoBot is otherwise working -- I am able to print the bot's last received messages to the serial monitor.

Any help would be much appreciated!
Thanks,
-Ian

Nothing happens

Hi all!
I'm use Arduino UNO R3 with Ethernet Shield W5100. Here is the code:

`
#include <ArduinoJson.h>
#include <UniversalTelegramBot.h>
#include <Ethernet.h>
#include <SPI.h>

// Initialize Telegram BOT

#define BOTtoken "123456789:abcdefghijklmnopABCDEFGHIJKLMNOPxxx"

//const char* BotName = ""; // ---- what is it?
//const char* BotUsername = ""; // ---- what is it?

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetClient client;

int Bot_mtbs = 1000; //mean time between scan messages
long Bot_lasttime; //last time messages' scan has been done
UniversalTelegramBot bot(BOTtoken, client);

void setup() {
Serial.begin(9600);
Ethernet.begin(mac);
Serial.println (Ethernet.localIP());
}

void loop() {

int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
while(numNewMessages) {
  Serial.println("got response");
  for(int i=0; i<numNewMessages; i++) {
    bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].text, "");
  }
  numNewMessages = bot.getUpdates(bot.last_message_received + 1);
}
Bot_lasttime = millis();

delay(1000);
}`

In serial port monitor, I see my Arduino gets the IP address, and after that - nothing ...

Help me please, if somebody can)))

Get more users for the library

I think Telegram is great for communicating with arduino boards as you can do it from anywhere in the world effortlessly and personally I think this library is the best Telegram library available for Arduino (obviously I would think that :) ) but I dont think its used that much.

Anyone have any suggestions where to post or share it to get more users?

I will hopefully in the next few weeks start making some videos for youtube so I think some Telegram ones would be pretty interesting to people, so that might help

i have a w5200 Ethernet shield

hi I have a W5200 Ethernet shield and I haven't wifi module and I want to use my shield instead wifi and i have a question that how to use W5200 + UniversalArduinoTelegramBot ?

Use advantage of Telegram's POLL mode in func "getUpdate" to provide more efficiency

Hi,

I use this bot through mobile 3G connection and I found that it eats a lot of mobile traffic.
I investigated this misadvantage and found the solution.

Telegram provides POLL mode of the connection. We should use special option in the query to say how long we can wait for the data. In current release bot sends update query every 1 second and immediately gets back empty message. To solve it, I modified the code of bot:

  1. In header "UniversalTelegramBot.h" add new definition "#define POLL_TIME_WAIT 60 // seconds"
    Higher value is better for traffic economy

  2. In source "UniversalTelegramBot.cpp" add some modifications:

  • function UniversalTelegramBot::sendGetToTelegram(String command):
    main loop:
    while (millis() - now < (POLL_TIME_WAIT*1000+1000)) {....}

  • function UniversalTelegramBot::getUpdates(long offset)
    String command = "bot"+_token+"/getUpdates?offset="+String(offset)+"&limit="+String(HANDLE_MESSAGES)+"&timeout="+string(POLL_TIME_WAIT);

I successfully tested these code improvements.

Thanks for your attention.

P.S. I'm too lazy to make new fork.

P.P.S. Telegram answers empty after 50 seconds wait. It means, that maximum value for POLL_TIME_WAIT is 50 secs

BulkMessages example is not compiling on Travis with Platformio (Compiling fine in Arduino IDE)

As per title

Here is an example of a failed build

/tmp/tmpfRZHsn/src/BulkMessages.ino: In function 'ArduinoJson::JsonObject& getSubscribedUsers(ArduinoJson::JsonBuffer&)':
/tmp/tmpfRZHsn/src/BulkMessages.ino:113:36: error: 'class ArduinoJson::JsonBuffer' has no member named 'parseObject'
JsonObject& users = jsonBuffer.parseObject(file_content);

I'm guessing the platformio config or Travis config needs to be tweaked

ESP12 Exception (29)

Basic Infos

i am writing a code that give weather forecast from wunderground.com website with HTTP request, and i want send to me this forecast in telegram. i use UniversalTelegramBot library to send message in telegram. so this code have to part:
1- give weather forecast from wunderground.com
2- send this forecast in telegram Bot
Each part work as well , but when i merge two part i give Exception (29) error :(

Hardware

Hardware: NodeMcu Lua WIFI Board Based on ESP8266 CP2102 Module (ESP-12E)
Core Version: I do not know!!!
because i flash my esp with ESP8266Flasher.exe
my setings in ESP8266Flasher is in this picture:

Settings in IDE

Module: Adafruit HUZZAH esp8266
Flash Size: 4MB(3MB SPIFFS)
CPU Frequency: 80Mhz
Upload Using: SERIAL 115200

Sketch

https://pastebin.com/0z9YFd06

Debug Messages

https://pastebin.com/suesbtiv

Send Image from SPIFF

Hi,

Can you add an example how to send an Image from SPIFF?
Let's say I have a picture on the storage of my ESP8266 in /picture/1.jpg and I like to send this one.
Keep in mind this is different from the PhotoFromSD example.

Regards

i have problem with WiFiClientSecure :(

hi
i am thanks for your help to peaple for publishin your good project
in this code i want give data from google Sheet and send data in telegram bot,
i use this project to give data from google sheet:
https://github.com/lorol/Googlesheet_DHT_simple
and use this project for recive and send data from telegram robat:
https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
i use esp8266
i merge two above project but i cant compile because i give error , because two project use WiFiClientSecure.h library , and same client :(

i changed the client name , and code ha been compiled, but in serial monitor , program crashed
i changed "HTTPSRedirect* client= nullptr;" to "HTTPSRedirect* test= nullptr;" and change every client in the code to test,
i also change below code, in the next change

WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

to :

WiFiClientSecure test;
UniversalTelegramBot bot(BOTtoken, test);

and you can see my Serial monitor in both time:

Starting ...
Connecting to hooshmandsazan3
.

WiFi connected

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

ctx: cont 
sp: 3fff0fd0 end: 3fff18e0 offset: 01a0

>>>stack>>>
3fff1170:  00410000 3fffb59c 3fffb75c 40224e3f  
3fff1180:  3fffb63c 3fffb87c 00000081 40225aa1  

i add Serial.println() in the code for debugging
this is my code:

#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include "HTTPSRedirect.h"




//======================From Telegram===============================
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>

#define BOTtoken "339475786:AAH7IjXu51xPom_sMx8IRnvQbcTD5FfO2Wc"  // your Bot Token (Get from Botfather)
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

int Bot_mtbs = 1000; //mean time between scan messages
long Bot_lasttime;   //last time messages' scan has been done
bool Start = false;

const int ledPin = 2;
int ledStatus = 0;

void handleNewMessages(int numNewMessages) {
  //Serial.println(F("handleNewMessages"));
  //Serial.println(String(numNewMessages));

  for (int i=0; i<numNewMessages; i++) {
    String chat_id = String(bot.messages[i].chat_id);
    String text = bot.messages[i].text;

    String from_name = bot.messages[i].from_name;
    if (from_name == "") from_name = "Guest";

    if (text == "/ledon") {
      digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
      ledStatus = 1;
      bot.sendMessage(chat_id, "Led is ON", "");
    }

    if (text == "/ledoff") {
      ledStatus = 0;
      digitalWrite(ledPin, LOW);    // turn the LED off (LOW is the voltage level)
      bot.sendMessage(chat_id, "Led is OFF", "");
    }

    if (text == "/status") {
      if(ledStatus){
        bot.sendMessage(chat_id, "Led is ON", "");
      } else {
        bot.sendMessage(chat_id, "Led is OFF", "");
      }
    }

    if (text == "/start") {
      String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
      welcome += "This is Flash Led Bot example.\n\n";
      welcome += "/ledon : to switch the Led ON\n";
      welcome += "/ledoff : to switch the Led OFF\n";
      welcome += "/status : Returns current status of LED\n";
      bot.sendMessage(chat_id, welcome, "Markdown");
    }
  }
}
//***************************************************************************




#define WRITE_INTERVAL_MINITES 1

#define MAX_CONNECT 200 //reuse 2 times same clent
#define MAX_ERROR 100 //restart everything

const char *ssid =  "sajjad";
const char *pass =  "1q2w3e4r5t6y";

const char* host = "script.google.com";
const int httpsPort = 443;

int seconds = (WRITE_INTERVAL_MINITES * 60) - 20; // schedule first sending to TS in 20 sec after start

char *GScriptId = "AKfycbxRzkMt87iyiyU9EDY6REoRDpl5C9oHdjVyCSF6A4QN7jkNMGHD";   // Put your  GScriptId   here

// Access to Google Spreadsheet
String url = String("/macros/s/") + GScriptId + "/exec?";


HTTPSRedirect* test = nullptr;


float hum;
float tem;

void setup() {
  Serial.begin(115200);
  Serial.println();
  delay(200);
  Serial.println(F("Starting ..."));

  delay(200);
 
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);
  if (WiFi.status() != WL_CONNECTED) WiFi.begin(ssid, pass);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500); 
    Serial.println(F("."));
  }
  Serial.println("");
  Serial.println("WiFi connected");
  pinMode(ledPin, OUTPUT); // initialize digital ledPin as an output.
  delay(10);
  digitalWrite(ledPin, LOW); // initialize pin as off
}

void loop() {
  Serial.println("1");
  
  //==============================From telegram=========================================
  if (millis() > Bot_lasttime + Bot_mtbs)  {
    Serial.println("2");
    int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    
    while(numNewMessages) {
      Serial.println("3");
      Serial.println("got response");
      handleNewMessages(numNewMessages);
      numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    }
    Serial.println("4");
    Bot_lasttime = millis();
  }
  //***********************************************************************
  Serial.println("5");
  static int error_count = 0;
  static int connect_count = 0;
  static bool flag = false;

  if (!flag){
    Serial.println("6");
    test = new HTTPSRedirect(httpsPort);
    flag = true;
    test->setPrintResponseBody(true); // or false and use String getResponseBody();
    Serial.println("6a");
    test->setContentTypeHeader("application/json");  
    Serial.println("6b");
    if (!test->connected()) test->connect(host, httpsPort);
    Serial.println("6c");
    ++connect_count;
    Serial.println("6d");
  }

   // 30 sec after writing 
  

    if (test != nullptr){
      Serial.println("7");
      if (!test->connected()){
        test->connect(host, httpsPort);
      }
    }
    else{
      Serial.println(F("Error2 creating client object!"));
      error_count = -10;
      Serial.println("7a");
    }
    Serial.println("7b");
    Serial.println(F("========================="));
    if (test->GET(url + String("readrow=last"), host)){
      Serial.println("8");
      DynamicJsonBuffer jsonBuffer;
      JsonObject& json = jsonBuffer.parseObject(test->getResponseBody());
      //json.printTo(Serial);
      String Timestamp = json["values"][0];
      int MaxT0        = json["values"][1];
      int minT0        = json["values"][2];
      String Con0      = json["values"][3];
      int Hu0          = json["values"][4];
      String WS0       = json["values"][5];
      String WD0       = json["values"][6];

      int MaxT1        = json["values"][7];
      int minT1        = json["values"][8];
      String Con1      = json["values"][9];
      int Hu1          = json["values"][10];
      String WS1       = json["values"][11];
      String WD1       = json["values"][12];

      int MaxT2        = json["values"][13];
      int minT2        = json["values"][14];
      String Con2      = json["values"][15];
      int Hu2          = json["values"][16];
      String WS2       = json["values"][17];
      String WD2       = json["values"][18];

      int MaxT3        = json["values"][19];
      int minT3        = json["values"][20];
      String Con3      = json["values"][21];
      int Hu3          = json["values"][22];
      String WS3       = json["values"][23];
      String WD3       = json["values"][24];
      
      float TEMP       = json["values"][25];
      float Hu         = json["values"][26];
      
      Serial.println(Timestamp);
      Serial.println(MaxT0);
      Serial.println(minT0);
      Serial.println(Con0);
      Serial.println(Hu0);
      Serial.println(WS0);
      Serial.println(WD0);

      Serial.println("");
      Serial.println(MaxT1);
      Serial.println(minT1);
      Serial.println(Con1);
      Serial.println(Hu1);
      Serial.println(WS1);
      Serial.println(WD1);

      Serial.println("");
      Serial.println(MaxT2);
      Serial.println(minT2);
      Serial.println(Con2);
      Serial.println(Hu2);
      Serial.println(WS2);
      Serial.println(WD2);

      Serial.println("");
      Serial.println(MaxT3);
      Serial.println(minT3);
      Serial.println(Con3);
      Serial.println(Hu3);
      Serial.println(WS3);
      Serial.println(WD3);

      Serial.println("");
      Serial.println(TEMP);
      Serial.println(Hu);      
      ++connect_count;
    } else {
      Serial.println("9");
      ++error_count;
      Serial.println(F("GET Last row val failed!"));
      seconds = 10; // stage again in 10 sec
    }


   if (error_count > MAX_ERROR){
    Serial.println("10");
     Serial.println(F("Errors > MAX_ERROR...")); 
     //delete client;
     //client = nullptr;
     //connect_count = -1;
     //error_count = 0;
     //flag = false;
     ESP.restart(); 
   }

   if (connect_count > MAX_CONNECT){
      Serial.println("11");
      Serial.println(F("Connects > MAX_CONNECT... rebuild"));
      connect_count = -1;
      flag = false;
      delete test;
     
      //return;  //where?
   }
   
   seconds++;
   delay(1000); //1 sec loop
}

when the code arive to "6b" program go to hang,
when arive to :
if (!test->connected()) test->connect(host, httpsPort);
this is my output:

Starting ...
Connecting to sajjad
.
.
.
.
.
.
.
.

WiFi connected
1
2
4
5
6
6a
6b

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

ctx: cont 
sp: 3fff1000 end: 3fff1850 offset: 01a0

>>>stack>>>
3fff11a0:  3fff073c 000011c9 000011c9 4022ab8c  
3fff11b0:  3fff1584 00000012 00000003 00000000  

please help me please :(

How do I set the password?

I want to set up a password to control the robot
That means asking the password when start the robot
and then control led??!

Create /debug command in library

Write function in library, that enable /debug from Telegram. That not enable it in code and recompile all again. Just send /debug and debug enabled and may see in Serial.

i have a problem :(

what is this ERRor?

In file included from FlashLED.ino:3:0:
J:\Program Files\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src/UniversalTelegramBot.h:27:25: fatal error: ArduinoJson.h: No such file or directory
#include <ArduinoJson.h>
^
compilation terminated.
Error compiling.

Library needs to be tested on 101 based boards

I do not have a compatible board to test on 101 based boards (Arduino WiFi Shield 101 or the MKR1000 board)

Does someone have one of the above that could help test? It should work out of the box, but can't be sure!

Investigate why there is a while loop for sending message

I dont think its needed. Its in several places too

  while (millis() < sttime+8000) { // loop for a while to send the message
      String command = "bot"+_token+"/sendMessage";
      String response = sendPostToTelegram(command, payload);
      if (_debug) Serial.println(response);
      sent = checkForOkResponse(response);
      if (sent) {
        break;
      }

Sending Images

I was wondering to use arducam and send pictures through telegram bot to implement a very simple home monitoring system #

Improve examples

The examples do not show the best way of using the library and need to be improved

ESP32 will send duplicate messages.

Hi all.

So I have been testing the port of the ESP32. It works well except I will get duplicate messages at random.
I switched on debugging to get the message info. I also logged a support call with Telegram. I gave them the message id when I receive duplicates and they told me that the messages is sent more than one.

I will send the message only once on my end as I can see that in the serial feed.

with the debug switched on I will see 2 outputs for every message sent.

Like this.

SEND Post Message
[BOT Client]Connecting to server

{"ok":true,"result":{"message_id":2750,"from":{"id":yyyyyy,"is_bot":true,"first_name":"Open Automation Alerts","username":"OpenAutomationBot"},"chat":{"id":xxxxxxxx,"first_name":"Jaco","last_name":"Fourie","type":"private"},"date":1519390520,"text":"Web Test"}}

{"ok":true,"result":{"message_id":2750,"from":{"id":yyyyyyy,"is_bot":true,"first_name":"Open Automation Alerts","username":"OpenAutomationBot"},"chat":{"id":xxxxxxx,"first_name":"Jaco","last_name":"Fourie","type":"private"},"date":1519390520,"text":"Web Test"}}
Closing client

But yet I will get duplicates from time to time like this one .

photo_2018-02-23_14-57-43

Telegram checked on their end with the message ID and they say it is being sent more than once.

"Our devs have been checking it, there is nothing wrong on our side, somehow your code is sending the message several times :("

Do anybody else see this ? I can see I only fire the code once as the debug info only shows once.

Unable to send messages

I tested the FlashledBot example, I changed the SSID and the password.
The ESP8266 connects sucessfully and can receive all of my messages via telegram, but it wont respond. I added a simple Serial.println to print the variable "text" to confirm that my messages arrive.

Furthermore I had a problem with the ArduinoJSON Lib.
The Arduino IDE couldn't find the ArduinoJSON lib, I checked the installation path twice, but still the IDE couldn't find the lib. To solve this I had to copy the complete ArduinoJSON lib to the same directory as the FlashledBot example.
Maybe a bad link or something like that?

SendMessage formatted

Hey,

Is there a way to send a message and also specifying format options, e.g. that the text is bold, underlined etc?
Using the normal whittecards like the asteriks *test* is not recognized by telegram for some reason

WiFiClientSecure can not connect

hi,
i have a issue with the connection,
in UniversalTelegramBot::sendGetToTelegram sometimes client->connect(HOST, SSL_PORT) return 0,
that mean client could not connect to server.
At the beginning it works well, but after a while the connection is lost.
this is my code in loop function

int Bot_mtbs = 3500;
void loop() {
if (millis() > Bot_lasttime + Bot_mtbs) {
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);

while(numNewMessages) {
  Serial.println("got response");
  for (int i=0; i<numNewMessages; i++) {
    bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].text, "");
  }
  numNewMessages = bot.getUpdates(bot.last_message_received + 1);
}

Bot_lasttime = millis();

}
}

secure one to one telegram communication

hi , sorry to open ticket for my question but I really appreciated to have your advise. Actually I intend to make secure one to one communication between my ESP module and my phone (or couple of allowed phones), There is ESP8266WebServer, hosting web page, and intend to register allowed phones numbers by it, what is your suggestion to find id number of allowed phones and made secure communication
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.