witnessmenow / Universal-Arduino-Telegram-Bot

Use Telegram on your Arduino (ESP8266 or Wifi-101 boards)
MIT License
1.09k stars 302 forks source link

SIM800 support #57

Closed EgorChadov closed 4 years ago

EgorChadov commented 6 years ago

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.

witnessmenow commented 6 years ago

I think it might support it using the tinygsm library

https://github.com/vshymanskyy/TinyGSM/blob/master/README.md

The telegram library uses the standard Arduino client interface for communicating with the network, and the tinygsm library provides a client wrapper around these modules

I think if you instialise a TinyGsmClientSecure object as shown in the https example of gsmtiny and pass it in the constructor of the telegram bot as the client, it should in theory work

I don't have a sim800 to test so I haven't been able to try it out. If you do try please let me know if it works!

On 20 Oct 2017 23:35, "EgorChadov" notifications@github.com wrote:

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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/issues/57, or mute the thread https://github.com/notifications/unsubscribe-auth/ABfXwtvYVuGIW0MNoIJz8mKjXDWZkTvCks5suSA2gaJpZM4QBTkb .

EgorChadov commented 6 years ago

Thank you for reply! Yes, it works! Tried to send a simple message using UniversalTelegramBot + Tinygsm libraries and message come to my chat. Very excited with that.

I think you can write that your library works with sim800l+tinygsm. Thanks for help!

witnessmenow commented 6 years ago

Awesome! Would you mind creating a pr with an example, or even if you could share it here I could add it.

Thanks!

Where did you get your module?

On 21 Oct 2017 21:55, "EgorChadov" notifications@github.com wrote:

Thank you for reply! Yes, it works! Tried to send a simple message using UniversalTelegramBot + Tinygsm libraries and message come to my chat. Very excited with that.

I think you can write that your library works with sim800l+tinygsm. Thanks for help!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/issues/57#issuecomment-338431752, or mute the thread https://github.com/notifications/unsubscribe-auth/ABfXwuos0dqX-eE6fWujY-XogbcL0rtzks5sulpLgaJpZM4QBTkb .

EgorChadov commented 6 years ago

Sure, I can create example, but only simple. I'm still very new with it.

But I have another problem now. I try your ReplyKeyboard Example with Tinygsm and that two libraries take much space. Arduino IDE says that "Not enough memory, the program may not work reliably". And then really program work not properly.

EgorChadov commented 6 years ago
#include <TinyGsmClient.h>
#include <ArduinoHttpClient.h>
#include <UniversalTelegramBot.h>

#include <SoftwareSerial.h>
SoftwareSerial SerialAT(8, 9); // RX, TX

TinyGsm modem(SerialAT);

const char apn[]  = "";   //apn
const char user[] = "";   //username
const char pass[] = "";   //pass

// Initialize Telegram BOT
#define BOTtoken ""  // your Bot Token (Get from Botfather)

TinyGsmClientSecure 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

void setup() {
  Serial.begin(9600);
  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(9600);
  delay(3000);

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

  //wait for network
  Serial.print(F("Waiting for network..."));
  if (!modem.waitForNetwork()) {
    Serial.println(" fail");
    delay(10000);
    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(10000);
    return;
  } else {Serial.println(" OK");}

  //not needed actually
  IPAddress local = modem.localIP();
  modem.waitResponse();
  Serial.println(local);
}

void loop() {
  String chat_id = ""; 
  String text = "hello!";
  String parses = "";

  Serial.println("Send message");
  Serial.println(bot.sendMessage(chat, text, parses));

  delay(50000);
}

Very simple code I used for test how it works. In future, I can add other examples if it needs.

I got this module from aliexpress. Need link? Also, you can buy it on eBay.

witnessmenow commented 6 years ago

What board are you using? Something like an uno or a nano might not have enough ram for Arduino json

EgorChadov commented 6 years ago

Ok. I got it. I'm using uno and nano for my project.

witnessmenow commented 6 years ago

Something with more ram might work better, like even an esp8266 even if you don't use WiFi

On 22 Oct 2017 17:04, "EgorChadov" notifications@github.com wrote:

Ok. I got it. I'm using uno and nano for my project.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/issues/57#issuecomment-338488656, or mute the thread https://github.com/notifications/unsubscribe-auth/ABfXwuhNiSZIGb09xShHJkliq3VVFMcmks5su2eqgaJpZM4QBTkb .

EgorChadov commented 6 years ago

Ok. Thank you for helping me! 👍

witnessmenow commented 6 years ago

No problem @EgorChadov , I was wondering if it would work before since I seen the TinyGSM library, so really happy that you confirmed it did.

Would you mind linking to the one you got? The individual module is pretty cheap, but it looks like it would be hard to work with and then all the boards seem kind of expensive!

EgorChadov commented 6 years ago

I have two versions. 1 - http://ali.pub/1y0ha9, 2 - http://ali.pub/1y0hex But you must pay attention to this module. It needs 3.3V for supply and may consume about 2A at peak. Otherwise, it may have a problem with work.

I hope it information comes handy for you!

witnessmenow commented 6 years ago

Thanks Egor!

Do you know anything about the sim900? I think the 800 only supports 2g,while the 900 supports 3g as well, but I'm not sure if it works the same as the 800!

My cell provider is 3g/4g only. You can get 2g providers in Ireland but it would be easier for me if it was 3g

On 23 Oct 2017 19:57, "EgorChadov" notifications@github.com wrote:

I have two versions. 1 - http://ali.pub/1y0ha9, 2 - http://ali.pub/1y0hex But you must pay attention to this module. It needs 3.3V for supply and may consume about 2A at peak. Otherwise, it may have a problem with work.

I hope it information comes handy for you!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/issues/57#issuecomment-338761693, or mute the thread https://github.com/notifications/unsubscribe-auth/ABfXwmF0xrhzQWUmQ_-c1qF3kHbtbt8Gks5svOGQgaJpZM4QBTkb .

EgorChadov commented 6 years ago

I think it the same modem that sim800 but it has 3g support.

I have chosen 800 because it cheaper and for arduino project doesn't need speed connection. 2g make it good as well.
But in your case, I think you need 900. Look this option - http://ali.pub/1y0wjy. It more expensive but it sim900 :)

enunugraha1 commented 6 years ago

Is it possible to use SIM 900 and use another library (not tinyGSM library)?, that I understand is the point is to make connections to internet and so I can just set SIM 900 to do as gprs modem use existing library Thanks.

witnessmenow commented 6 years ago

Why don't you want to use tinygsm?

The telegram library requires a httpclient that supports https, in theory any client that matches this should work

On 28 Nov 2017 03:34, "enunugraha1" notifications@github.com wrote:

Is it possible to use SIM 900 and use another library (not tinyGSM library)?, that I understand is the point is to make connections to internet and so I can just set SIM 900 to do as gprs modem use existing library Thanks.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/issues/57#issuecomment-347394635, or mute the thread https://github.com/notifications/unsubscribe-auth/ABfXwoDlv2N-crMxpg7_Eh8V8ftrYnsLks5s63EYgaJpZM4QBTkb .

enunugraha1 commented 6 years ago

Try once with this sketch, the SIM 900 didn't turn on automatic must be push SIM 900 power button to turn on, and there is error massage like "GSM modem not selected" tinyGSM should work with SIM 900, shouldn't it?

EgorChadov commented 6 years ago

Are you sure that SIM900 support https? As far as I know only sim800 and sim808 support ssl.

You can buy sim800l. It's not very expensive. At this post I gave two options.

enunugraha1 commented 6 years ago

I think SIM900 need firmware update to make it support HTTPS, but after searching for no one have success to do that, HTTPS AT command still get error massage. Your suggestion is better choice I can implement SIM800L + tinyGSM lib, if anyone could add more examples for that it would be great

rahmathasan commented 6 years ago

Hi, @EgorChadov , i have try to verify the code (above) with arduino ide, but there is error compiling. "Error compiling for board Arduino/Genuino Uno"

i want to build a telegram bot with arduino using sim900 or sim800L gsm module. thank you

witnessmenow commented 6 years ago

If someone can submit a PR for this against the V.1.1 branch providing an example for this I will happily include it in the next version (which I will release in a couple of weeks)

Timmae3000 commented 6 years ago

Hi anyone.

I want to build an telegram bot with a arduino and a sim800 gsm module. i've testet something with the sketch from EgorChadov from this thread.

the first message by the bot was send successfully. Great :)

But not all messages goes out or come in to the bot. So in the terminal i can see, that all 5 seconds a message was send. But in the chat with the bot it comes only 1 message per minute in. Telegram Bot can send 30 messages per minute.

When i start the arduino and a message was send i can restart the arduino and an new message was send...so i can do it 6times per minute and become 6 messages in the chat...

So anyone has an idea? :)

jimmisitepu88 commented 6 years ago

Dear @EgorChadov , I trying to compile your program:

include

include

include

include

SoftwareSerial SerialAT(8, 9); // RX, TX

TinyGsm modem(SerialAT);

const char apn[] = ""; //apn const char user[] = ""; //username const char pass[] = ""; //pass

// Initialize Telegram BOT

define BOTtoken "" // your Bot Token (Get from Botfather)

TinyGsmClientSecure 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

void setup() { Serial.begin(9600); delay(10);

// Set GSM module baud rate SerialAT.begin(9600); delay(3000);

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

//wait for network Serial.print(F("Waiting for network...")); if (!modem.waitForNetwork()) { Serial.println(" fail"); delay(10000); 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(10000); return; } else {Serial.println(" OK");}

//not needed actually IPAddress local = modem.localIP(); modem.waitResponse(); Serial.println(local); }

void loop() { String chat_id = ""; String text = "hello!"; String parses = "";

Serial.println("Send message"); Serial.println(bot.sendMessage(chat, text, parses));

delay(50000); }

but we get problem when compile,

In file included from C:\Users\JimmiSitepu\Documents\OneDrive\KERJAAN\MIKROAVR.COM\Running Project\Polmed\Jodi_team\sim800_telegram\sim800_telegram.ino:1:0:

C:\Users\JimmiSitepu\Documents\Arduino\libraries\TinyGSM-master\src/TinyGsmClient.h:64:4: error: #error "Please define GSM modem model"

error "Please define GSM modem model"

^

exit status 1 Error compiling for board Arduino Nano.

what I have to fix? Thanks Thanks

EgorChadov commented 6 years ago

Hello @jimmisitepu88, sorry for long answering.

Try add modem model after including TinyGsm library.

`// 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`

Add #define and your modem. But as far I know it works only with 800 and 808 for now.

jimmisitepu88 commented 6 years ago

Thanks a huge @EgorChadov , its work...

u-l-m-i commented 5 years ago

Hello @EgorChadov,

may I ask if you also managed to receive messages with your telegram bot & SIM800, because I'm only able to send messages, but not receive messages.

So if possible it would be really great if can provide an example

Very simple code I used for test how it works. In future, I can add other examples if it needs.

Best regards

ipungdc commented 5 years ago

Dear @EgorChadov ,

I tried your program and defined sim800L but there was an error. what's the solution ? thanks...

jimmisitepu88 commented 5 years ago

I get error to when compile that's code,.when downgrade Arduino json to.5, compile not error, but telegram bot not working

Dapatkan Outlook untuk Androidhttps://aka.ms/ghei36


From: ipungdc notifications@github.com Sent: Sunday, March 17, 2019 11:10:58 PM To: witnessmenow/Universal-Arduino-Telegram-Bot Cc: Jimmi Kardo Sitepu; Mention Subject: Re: [witnessmenow/Universal-Arduino-Telegram-Bot] SIM800 support (#57)

Dear @EgorChadovhttps://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FEgorChadov&data=02%7C01%7C%7C84f4c6d9223e4cd257fe08d6aaf3249c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636884358600544504&sdata=vA8lslvb3asrMFRFul36uftTeTgOIJFcjrVgSSTsAxw%3D&reserved=0 ,

I tried your program and defined sim800L but there was an error. what's the solution ? thanks...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fwitnessmenow%2FUniversal-Arduino-Telegram-Bot%2Fissues%2F57%23issuecomment-473680244&data=02%7C01%7C%7C84f4c6d9223e4cd257fe08d6aaf3249c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636884358600554512&sdata=fk3MCvQKJ0t2vsBHh%2Bbe7T52%2FhMoZGvV6LXSUZ3JuAM%3D&reserved=0, or mute the threadhttps://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAfY_Br7AIcFLZwePc3t5_-ufLh9Zh0LZks5vXmkSgaJpZM4QBTkb&data=02%7C01%7C%7C84f4c6d9223e4cd257fe08d6aaf3249c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636884358600564526&sdata=fADR1Ox3ndUWzY2tJDW%2B%2Fy9s0dYRxj6kl6O4aV6BvSQ%3D&reserved=0.

ipungdc commented 5 years ago

I've downgraded it, but the code still error

Pada tanggal Sen, 18 Mar 2019 pukul 01.05 Jimmi Kardo Sitepu < notifications@github.com> menulis:

I get error to when compile that's code,.when downgrade Arduino json to.5, compile not error, but telegram bot not working

Dapatkan Outlook untuk Androidhttps://aka.ms/ghei36


From: ipungdc notifications@github.com Sent: Sunday, March 17, 2019 11:10:58 PM To: witnessmenow/Universal-Arduino-Telegram-Bot Cc: Jimmi Kardo Sitepu; Mention Subject: Re: [witnessmenow/Universal-Arduino-Telegram-Bot] SIM800 support (#57)

Dear @EgorChadov< https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FEgorChadov&data=02%7C01%7C%7C84f4c6d9223e4cd257fe08d6aaf3249c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636884358600544504&sdata=vA8lslvb3asrMFRFul36uftTeTgOIJFcjrVgSSTsAxw%3D&reserved=0> ,

I tried your program and defined sim800L but there was an error. what's the solution ? thanks...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub< https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fwitnessmenow%2FUniversal-Arduino-Telegram-Bot%2Fissues%2F57%23issuecomment-473680244&data=02%7C01%7C%7C84f4c6d9223e4cd257fe08d6aaf3249c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636884358600554512&sdata=fk3MCvQKJ0t2vsBHh%2Bbe7T52%2FhMoZGvV6LXSUZ3JuAM%3D&reserved=0>, or mute the thread< https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAfY_Br7AIcFLZwePc3t5_-ufLh9Zh0LZks5vXmkSgaJpZM4QBTkb&data=02%7C01%7C%7C84f4c6d9223e4cd257fe08d6aaf3249c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636884358600564526&sdata=fADR1Ox3ndUWzY2tJDW%2B%2Fy9s0dYRxj6kl6O4aV6BvSQ%3D&reserved=0

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/issues/57#issuecomment-473690240, or mute the thread https://github.com/notifications/unsubscribe-auth/AuZhrvQaSI3xvZMFx3IKil6odhV6jPs4ks5vXoP9gaJpZM4QBTkb .

gunaone commented 4 years ago

any one was sucses with this sim800..? plase share..

Belma2010 commented 4 years ago
#include <TinyGsmClient.h>
#include <ArduinoHttpClient.h>
#include <UniversalTelegramBot.h>

#include <SoftwareSerial.h>
SoftwareSerial SerialAT(8, 9); // RX, TX

TinyGsm modem(SerialAT);

const char apn[]  = "";   //apn
const char user[] = "";   //username
const char pass[] = "";   //pass

// Initialize Telegram BOT
#define BOTtoken ""  // your Bot Token (Get from Botfather)

TinyGsmClientSecure 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

void setup() {
  Serial.begin(9600);
  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(9600);
  delay(3000);

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

  //wait for network
  Serial.print(F("Waiting for network..."));
  if (!modem.waitForNetwork()) {
    Serial.println(" fail");
    delay(10000);
    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(10000);
    return;
  } else {Serial.println(" OK");}

  //not needed actually
  IPAddress local = modem.localIP();
  modem.waitResponse();
  Serial.println(local);
}

void loop() {
  String chat_id = ""; 
  String text = "hello!";
  String parses = "";

  Serial.println("Send message");
  Serial.println(bot.sendMessage(chat, text, parses));

  delay(50000);
}

Very simple code I used for test how it works. In future, I can add other examples if it needs.

I got this module from aliexpress. Need link? Also, you can buy it on eBay.

I already use your code and add botToken and chat_id but i still didn't get the messages from the bot. Serial print "send messages" and "0", but connect to gprs is work. Did i miss any step?

witnessmenow commented 4 years ago

As far as I know the sim800 does not support TLS V1.2, so will not work with telegram anymore

fbi1671 commented 2 years ago

try the SSLClient by https://github.com/govorox

I got the esp32 to send message the telegram group, but still figuring how to retrieve message from the group

fbi1671 commented 2 years ago

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

include

include

include

include "SSLClient.h"

include "ca_cert.h"

// 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);

}

thanks @witnessmenow for the awesome library.

asus1305 commented 2 years ago

@fbi1671 i have error for this #include "SSLClient.h", #include "ca_cert.h". can u help me about this library?. thanks you

fbi1671 commented 2 years ago

hi - please send me your code, let me try to check it.

On Sat, Jan 15, 2022 at 8:16 PM asus1305 @.***> wrote:

@fbi1671 https://github.com/fbi1671 i have error for this #include "SSLClient.h", #include "ca_cert.h". can u help me about this library?

— Reply to this email directly, view it on GitHub https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/issues/57#issuecomment-1013672285, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC5JVZPN3ATZOZLEWTOLUELUWFQQTANCNFSM4EAFHENQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.*** com>

haxord7hasib commented 2 years ago

any hope for A9G gsm module ?

CIumbia44 commented 1 year ago

Has anyone made it work with SIM7600?

mr-bobur commented 1 year ago

Has anyone made it work with SIM7600?

Hi, I am also struggling to use lilygo_sim7600G_esp32 board and telegram bot, you find something useful?