vshymanskyy / TinyGSM

A small Arduino library for GSM modules, that just works
GNU Lesser General Public License v3.0
1.91k stars 709 forks source link

How can i send a simple SMS? #2

Closed vittorioexp closed 7 years ago

vittorioexp commented 7 years ago

How can i send a simple SMS? And could you tell me how long does it take to send it?

vshymanskyy commented 7 years ago

Hi. Currently sending SMS is not supported, but it is planned to be added in future. PRs are always welcome ;)

vshymanskyy commented 7 years ago

You can now try:

modem.sendSMS("+380679837464", "some text");

or for Unicode (needs data length):

  modem.sendSMS_UTF16("+380679837464", u"Привіііт!", 10);
facetime88 commented 7 years ago

Hi, how do we get the status result of the sent sms whether success or fail?

roboticboyer commented 6 years ago

I have tried the function: modem.sendSMS("0xxxxxxxxx", "Text here"); I have received the SMS, but its text is wrong

The same using: modem.sendSMS("0xxxxxxxxx", String ("Text here"));

Please could you double check?

ClemensGruber commented 6 years ago

Same problem here with res = modem.sendSMS(SMS_TARGET, "Hello from TinyGSM");

I got ßeiØΠ-70V

hubaksis commented 6 years ago

@ClemensGruber Can you turn on debug and check what is actually going on from the modem's point of view?

ClemensGruber commented 6 years ago

For res = modem.sendSMS(SMS_TARGET, "Hello from TinyGSM"); DBG("SMS:", res ? "OK" : "fail");

I got on serial SMS: OK

hubaksis commented 6 years ago

I mean all AT communication between your controller and the modem. Check the HttpClient example, it's here:

#define DUMP_AT_COMMANDS

...
#ifdef DUMP_AT_COMMANDS
  #include <StreamDebugger.h>
  StreamDebugger debugger(SerialAT, Serial);
  TinyGsm modem(debugger);
#else
  TinyGsm modem(SerialAT);
#endif

Then you'll see all AT communication.

ClemensGruber commented 6 years ago

The SMS function seems not to be very complicated.

My output is (AT and debug from AllFunctions.ino

AT+CMGF=1

OK
AT+CMGS="+49[numberdeleted]"

>Hello from TinyGSM 
+CMGS: 14

OK
SMS: OK
ClemensGruber commented 6 years ago

An article about SMS encoding: "7 Things You Need to Know about International SMS" https://www.telesign.com/blog/post/7-things-you-need-to-know-about-international-sms/

I don't know yet on which position the problem is. I have a German SIM card mobile phone with German UI and also a German operator. Does this matter?

ClemensGruber commented 6 years ago

I used till now AllFunctions.ino as is with all sample / example code. Now I deleted some code that is not necessary before the SMS example and the text is displayed accurate on the phone.

hubaksis commented 6 years ago

For some reason I can't send SMS at all from my modem. Not sure were issue is. Sorry, can't confirm. This line: +CMGS: 14 (I think) indicates the number of characters the modem received. Hello from TinyGSM length is 18. Maybe this is the issue?

Try the following: (I saw your code before you deleted it) Change res = modem.sendSMS("number", "Hello from TinyGSM"); to res = modem.sendSMS("number", String("Hello from TinyGSM")); I'm not a C++ expert, but I think you should send to the function object types that it expects. You are sending char* instead of String.

ClemensGruber commented 6 years ago

I think I got it, the bad boy is

  String ussd_balance = modem.sendUSSD("*111#");
  DBG("Balance (USSD):", ussd_balance);

  String ussd_phone_num = modem.sendUSSD("*161#");
  DBG("Phone number (USSD):", ussd_phone_num);

With this functions the modem is set to HEX mode via AT+CSCS="HEX"

and it is never set back to GSM

hubaksis commented 6 years ago

Oh, the version that I am using already has this fix. Not sure where I got it :)

bool sendSMS(const String& number, const String& text) {
    sendAT(GF("+CMGF=1"));
    waitResponse();
    sendAT(GF("+CSCS=\"GSM\""));
    waitResponse();
    sendAT(GF("+CMGS=\""), number, GF("\""));
...
ClemensGruber commented 6 years ago

@hubaksis Thanks for your help! Without your comment and the provoken motivation to have a second look this night I would not have solved this issue -- although it was a stupid cause. ;-)

hubaksis commented 6 years ago

@ClemensGruber No worries. I'm glad that you could find a cause of the problem.

ClemensGruber commented 6 years ago

Seems to be fixed for some modems, e.g. the M590 but not for the SIM800.

hubaksis commented 6 years ago

I've created a pull request.

ClemensGruber commented 6 years ago

Spotted already and liked! :-) Thanks!

udayan-santu commented 3 years ago

Can anybody pls tell me why this code not sending sms..

`// SIM card PIN (leave empty, if not defined) const char simPIN[] = ""; // Your phone number to send SMS: + (plus sign) and country code, for Hungary +36, followed by phone number String mobile_number = "01954004571"; // Configure TinyGSM library

define TINY_GSM_MODEM_SIM800 // Modem is SIM800

define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb

include

// TTGO T-Call pins

define MODEM_RST 5

define MODEM_PWKEY 4

define MODEM_POWER_ON 23

define MODEM_TX 27

define MODEM_RX 26

// Set serial for debug console (to Serial Monitor, default speed 115200)

define SerialMon Serial

// Set serial for AT commands (to SIM800 module)

define SerialAT Serial1

// Define the serial console for debug prints, if needed //#define DUMP_AT_COMMANDS

ifdef DUMP_AT_COMMANDS

include

StreamDebugger debugger(SerialAT, SerialMon); TinyGsm modem(debugger);

else

TinyGsm modem(SerialAT);

endif

define IP5306_ADDR 0x75

define IP5306_REG_SYS_CTL0 0x00

void setup() { // Set console baud rate SerialMon.begin(115200); // Set modem reset, enable, power pins pinMode(MODEM_PWKEY, OUTPUT); pinMode(MODEM_RST, OUTPUT); pinMode(MODEM_POWER_ON, OUTPUT); digitalWrite(MODEM_PWKEY, LOW); digitalWrite(MODEM_RST, HIGH); digitalWrite(MODEM_POWER_ON, HIGH); // Set GSM module baud rate and UART pins SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX); delay(3000); // Restart SIM800 module, it takes quite some time // To skip it, call init() instead of restart() SerialMon.println("Initializing modem"); modem.init();

} void loop() { modem.sendSMS("+8801954004571", "some text"); delay(10000); }`

SRGDamia1 commented 3 years ago

You probably need to check your network registration status first.