Open MichaelGaylor opened 5 years ago
I'm interested in an solution too, as it looks I'm struggling with the same problem. My setup is based on an SIM800 model & ESP8266 using TinyGSM.
I'm not certain if this is caused by: https://github.com/vshymanskyy/TinyGSM/issues/166#issuecomment-408465045
It is mentioned that the SIM800 doesn't support "REST calls using HTTPS", but maybe @witnessmenow as author of the Universal-Arduino-Telegram-Bot is able to tell if we hit this bug & maybe able to create an workaround.
I got it working - send and receive message in telegram group. my setup as below after every send message, i have to stop the client, else I will get a "chat not found error". part of my code as below...
//include files required
// TinyGSM Client for Internet connection TinyGsmClient client(modem); SSLClient secure_presentation_layer(&client); SSLClient abmSSL(&client); SSLClient telegramSSL(&client); HttpClient http_client = HttpClient(secure_presentation_layer, hostname0, port0); //secure HttpClient http_client1 = HttpClient(abmSSL, hostname1, port0); // secure HttpClient bot_telegram = HttpClient(telegramSSL, hostname3, port0); // secure UniversalTelegramBot bot(BOTtoken, bot_telegram); //secure ... void setup() //Add CA Certificate secure_presentation_layer.setCACert(root_ca); abmSSL.setCACert(root1_ca); telegramSSL.setCACert(TELEGRAM_CERTIFICATE_ROOT); // api.telegram.org
//setup telegram bot.sendMessage(CHAT_ID, "Bot Started", ""); delay(3000); bot_telegram.stop();
void loop() {
if (millis() > lastTimeBotRan + botRequestDelay) { int numNewMessages = bot.getUpdates(bot.last_message_received + 1); Serial.println("New telegram message= " +String(numNewMessages)); while(numNewMessages) { Serial.println("got response"); handleNewMessages(numNewMessages); numNewMessages = bot.getUpdates(bot.last_message_received + 1); } lastTimeBotRan = millis(); esp_task_wdt_reset(); bot_telegram.stop(); delay(10000); }
fbi1671, can i have your complete code?
Hi this is firstly a great library but I need some help please im pulling my hair out. I can send a message but not receive any... here is the code and the serial responses. ( it is connected fine and Im using the SIM800L with the MEGA Arduino. I send messages but it just ignores them ? I am able to use the library to post new messages to Telegram no problem so I'm a little confused why it never sees any messages. I appreciate anyone's input on this as I've spent 2 days and not getting very far LOL Please Help even willing to part with cash to support the owner develop the Library as It certainly look superb and I love Telegram ...…...
// Select your modem: #define TINY_GSM_MODEM_SIM800 // #define TINY_GSM_MODEM_SIM808 // #define TINY_GSM_MODEM_SIM900 // #define TINY_GSM_MODEM_A6 // #define TINY_GSM_MODEM_A7 // #define TINY_GSM_MODEM_M590
define TINY_GSM_MODEM_SIM800
include
//#include
include
define Serial Serial
//#include
//SoftwareSerial SerialAT(7, 8); // RX, TX
define SerialAT Serial1
include
include
StreamDebugger debugger(SerialAT, Serial);
TinyGsm modem(debugger);
//TinyGsm modem(SerialAT);
const char apn[] = "payandgo.o2.co.uk"; //apn const char user[] = "payandgo"; //username const char pass[] = "password"; //pass
// Initialize Telegram BOT
define BOTtoken "xxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxx" // your Bot Token (Get from Botfather)
TinyGsmClientSecure client(modem); //TinyGsmClient client(modem);
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 = 13; int ledStatus = 0; enum ledModes {ON = 0, OFF, BLINK, PWM}; // define modes of operation for LED (inverse polarity) enum ledModes ledmode = OFF; // Start with off
void setup() { //bot.longPoll = 60; Serial.begin(9600); delay(10);
// Set GSM module baud rate
SerialAT.begin(9600); bot._debug=true; // uncomment to see debug messages from bot library delay(3000);
Serial.println(F("Initializing modem...")); modem.restart(); delay(5000);
String modemInfo = modem.getModemInfo();
Serial.print(F("Modem: "));
Serial.println(modemInfo);
// Unlock your SIM card with a PIN
//modem.simUnlock("0000");
modem.sendAT(GF("+CIPSSL=1")); //enable ssl. maybe don't need modem.waitResponse();
if (!modem.hasSSL()) { Serial.println("SSL is not supported by this modem"); delay(5000); return; }
//wait for network Serial.print(F("Waiting for network...")); if (!modem.waitForNetwork()) { Serial.println(" fail"); delay(5000); return; } Serial.println(" OK");
// connect to gprs Serial.print(F("Connecting to ")); Serial.print(apn); if (!modem.gprsConnect(apn, user, pass)) { Serial.println(" fail"); delay(20000); return; } else {Serial.println(" OK");}
//not needed actually IPAddress local = modem.localIP(); modem.waitResponse(); Serial.println(local); delay(10000);
pinMode(ledPin, OUTPUT); // initialize digital ledPin as an output.
delay(10);
digitalWrite(ledPin, LOW); // initialize pin as off
} //...................................................................................
//....................................................................................
void loop() { if (millis() > Bot_lasttime + Bot_mtbs) { int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
} }
And the serial report.
OK AT&FZ
OK ATE0 ATE0
OK AT+CPIN?
ERROR AT+CPIN?
RDY
+CFUN: 1
ERROR AT+CPIN?
+CPIN: READY
+CPIN: READY
OK ATI
Call Ready
SMS Ready
SIM800 R14.18
OK Modem: Call Ready SMS Ready SIM800 R14.18 AT+CIPSSL=1
OK AT+CIPSSL=?
+CIPSSL: (0-1)
OK Waiting for network...AT+CREG?
+CREG: 0,1
OK OK Connecting to payandgo.o2.co.ukAT+CIPSHUT
SHUT OK AT+CGATT=0
OK AT+SAPBR=3,1,"Contype","GPRS"
OK AT+SAPBR=3,1,"APN","payandgo.o2.co.uk"
OK AT+SAPBR=3,1,"USER","payandgo"
OK AT+SAPBR=3,1,"PWD","password"
OK AT+CGDCONT=1,"IP","payandgo.o2.co.uk"
OK AT+CGACT=1,1
OK AT+SAPBR=1,1
OK AT+SAPBR=2,1
+SAPBR: 1,1,"10.160.131.179"
OK AT+CGATT=1
OK AT+CIPMUX=1
OK AT+CIPQSEND=1
OK AT+CIPRXGET=1
OK AT+CSTT="payandgo.o2.co.uk","payandgo","password"
OK AT+CIICR
OK AT+CIFSR;E0
10.160.131.179
OK AT+CDNSCFG="8.8.8.8","8.8.4.4"
OK OK AT+CIFSR;E0
10.160.131.179
OK 10.160.131.179 GET Update Messages [BOT]Connecting to server AT+CIPCLOSE=1
ERROR AT+CIPSSL=1
OK AT+CIPSTART=1,"TCP","api.telegram.org",443
OK
1, CONNECT OK AT+CIPRXGET=4,1
+CIPRXGET: 4,1,0
OK AT+CIPSTATUS=1
+CIPSTATUS: 1,0,"TCP","149.154.167.220","443","CONNECTED"
OK .... connected to server AT+CIPSEND=1,81
DATA ACCEPT:1,2 AT+CIPRXGET=4,1
+CIPRXGET: 4,1,0
OK AT+CIPSTATUS=1
+CIPSTATUS: 1,0,"TCP","149.154.167.220","443","CONNECTED"
OK
+CIPRXGET: 1,1
1, CLOSED AT+CIPRXGET=4,1
+CIPRXGET: 4,1,0
OK AT+CIPSTATUS=1
+CIPSTATUS: 1,0,"TCP","149.154.167.220","443","CLOSED"
OK Received empty string in response! GET Update Messages [BOT]Connecting to server AT+CIPCLOSE=1
ERROR AT+CIPSSL=1
OK AT+CIPSTART=1,"TCP","api.telegram.org",443
OK
1, CONNECT OK AT+CIPRXGET=4,1
+CIPRXGET: 4,1,0
OK AT+CIPSTATUS=1
+CIPSTATUS: 1,0,"TCP","149.154.167.220","443","CONNECTED"
OK .... connected to server AT+CIPSEND=1,81
DATA ACCEPT:1,2 AT+CIPRXGET=4,1
+CIPRXGET: 4,1,0
OK AT+CIPSTATUS=1
+CIPSTATUS: 1,0,"TCP","149.154.167.220","443","CONNECTED"
OK
+CIPRXGET: 1,1
1, CLOSED AT+CIPRXGET=4,1
+CIPRXGET: 4,1,0
OK AT+CIPSTATUS=1
+CIPSTATUS: 1,0,"TCP","149.154.167.220","443","CLOSED"
OK Received empty string in response! GET Update Messages [BOT]Connecting to server AT+CIPCLOSE=1
ERROR AT+CIPSSL=1
OK AT+CIPSTART=1,"TCP","api.telegram.org",443
OK
1, CONNECT OK AT+CIPRXGET=4,1
+CIPRXGET: 4,1,0
OK AT+CIPSTATUS=1
+CIPSTATUS: 1,0,"TCP","149.154.167.220","443","CONNECTED"
OK .... connected to server AT+CIPSEND=1,81
DATA ACCEPT:1,2 AT+CIPRXGET=4,1
+CIPRXGET: 4,1,0
OK AT+CIPSTATUS=1
+CIPSTATUS: 1,0,"TCP","149.154.167.220","443","CONNECTED"
OK AT+CIPRXGET=4,1
+CIPRXGET: 1,1
+CIPRXGET: 4,1,407
OK AT+CIPRXGET=2,1,63
1, CLOSED
ERROR