Sending SMS using mgos_pppos_run_cmds()

I need to send sms with some data.

I use pppos internet connection, and sometimes send data throw sms.

My code

    char command[] = {(char)26};

    struct mgos_pppos_cmd cmds[] = {
        {.cmd = "AT+CMGF=1\r"},
        {.cmd = "AT+CMGS=\"+375441234567\"\r"},
        {.cmd = "Test message"},
        {.cmd = command, .cb = sms_send_cb, .cb_arg = NULL},
        {.cmd = NULL},
    };

    mgos_pppos_run_cmds(0, cmds);

the result is:

[Sep 7 15:25:46.088] mgos_net.c:89 PPP: connecting
[Sep 7 15:25:48.584] mgos_pppos.c:678 Connecting (UART2, APN ‘mts’)…
[Sep 7 15:25:48.590] mgos_pppos.c:712 Trying to connect to 25702,MTS
[Sep 7 15:25:48.595] mgos_mongoose.c:66 New heap free LWM: 186448
[Sep 7 15:25:50.282] mgos_pppos.c:285 SIM800 R14.18, IMEI: 861445032315017
[Sep 7 15:25:50.288] mgos_mongoose.c:66 New heap free LWM: 186356
[Sep 7 15:25:50.591] mgos_pppos.c:355 SIM is ready, IMSI: 257027015225845, ICCID: 89375027010052258454
[Sep 7 15:25:50.597] mgos_mongoose.c:66 New heap free LWM: 186244
[Sep 7 15:25:59.078] mgos_pppos.c:415 Connected to mobile network (home)
[Sep 7 15:25:59.477] mgos_pppos.c:468 Operator: 25702,MTS
[Sep 7 15:25:59.576] mgos_pppos.c:477 RSSI: -55
[Sep 7 15:25:59.778] mgos_pppos.c:828 Starting PPP, user ‘mts’
[Sep 7 15:25:59.784] mgos_mongoose.c:66 New heap free LWM: 178672
[Sep 7 15:25:59.787] mgos_net.c:93 PPP: connected
[Sep 7 15:25:59.798] mgos_mongoose.c:66 New heap free LWM: 175664
[Sep 7 15:25:59.804] mgos_mongoose.c:66 New heap free LWM: 175560
[Sep 7 15:26:01.707] mgos_net.c:104 PPP: ready, IP 10.69.98.37, GW 192.168.254.254, DNS 134.17.1.1, NTP 0.0.0.0

And after, when device tries to send sms, I see these messages:

[Sep 7 15:29:48.059] main.c:82 Sending SMS…
[Sep 7 15:29:52.622] mgos_pppos.c:754 Command timed out: AT+CMGS="+375441234567"
[Sep 7 15:29:59.531] mongoose.c:12127 Failed to resolve ‘time.google.com’, server 134.17.1.1
[Sep 7 15:29:59.539] mgos_mongoose.c:66 New heap free LWM: 175512
[Sep 7 15:30:01.975] mgos_mongoose.c:66 New heap free LWM: 174324
[Sep 7 15:30:02.981] mongoose.c:12127 Failed to resolve ‘time.google.com’, server 134.17.1.1
[Sep 7 15:30:09.992] mongoose.c:12127 Failed to resolve ‘time.google.com’, server 134.17.1.1
[Sep 7 15:30:25.980] mongoose.c:12127 Failed to resolve ‘time.google.com’, server 134.17.1.1
[Sep 7 15:30:33.974] mgos_pppos.c:210 Error 9 (phase 0), reconnect
[Sep 7 15:30:33.977] mgos_net.c:89 PPP: connecting
[Sep 7 15:30:36.478] mgos_pppos.c:678 Connecting (UART2, APN ‘mts’)…
[Sep 7 15:30:36.483] mgos_pppos.c:712 Trying to connect to 25702,MTS
[Sep 7 15:30:38.567] mgos_pppos.c:754 Command timed out: AT
[Sep 7 15:30:38.572] mgos_net.c:89 PPP: connecting
[Sep 7 15:30:40.977] mgos_pppos.c:678 Connecting (UART2, APN ‘mts’)…
[Sep 7 15:30:40.983] mgos_pppos.c:712 Trying to connect to 25702,MTS
[Sep 7 15:30:43.068] mgos_pppos.c:754 Command timed out: AT
[Sep 7 15:30:43.072] mgos_net.c:89 PPP: connecting
[Sep 7 15:30:45.478] mgos_pppos.c:678 Connecting (UART2, APN ‘mts’)…
[Sep 7 15:30:45.483] mgos_pppos.c:712 Trying to connect to 25702,MTS
[Sep 7 15:30:47.566] mgos_pppos.c:754 Command timed out: AT
etc…

And the network disappears…

Sms is not coming.

After sending sms I need reconnect to again.

How can I implement this?

You are mixing things up.
You are connected to a cell modem, which uses an AT command interface. Some of those commands are used to establish a PPP session between the MCU and the cell modem, which allows TCP/IP to be transported. While that session is in place, you can’t send any other AT commands without disrupting it. Depending on your cell modem, there might be a pin or even you can “escape to command mode” by sending a special character sequence that also depends on the modem, and usually is 1 second silence, three ‘+’ characters, 1 second silence, and sometimes those characters must have a 100ms spacing between them…
Once in command mode, you may issue commands, but, again, depending on the cell modem you may or may not be able to send SMS messages while a PPP session is in place. What this means is that if that is your case, you’ll have to disconnect your PPP session to send an SMS. Your mileage may vary.
In any case, you need to enable some form of logging or manually sniff your serial port to actually see what is going on down there. When the modem goes back to command mode, you’ll see some text indicating that; if you see “Command timed out:” in your log it is because the modem did not answer “OK” and that may be because it is not in command mode. Manually connect to your cell modem and manually issue those sequences, check going into and out of PPP, etc.

1 Like

Thank you so much for your answer, I understand you.
I solved the problem. There was one feature when loading a message before sending…
May be you can help me with this problem - sending email over sim800l