|
| 1 | +/** |
| 2 | + * @brief This example demonstrates how to send SMS messages using the modem on |
| 3 | + * the AVR-IoT Cellular Mini. |
| 4 | + */ |
| 5 | +#include <Arduino.h> |
| 6 | +#include <led_ctrl.h> |
| 7 | +#include <log.h> |
| 8 | +#include <lte.h> |
| 9 | +#include <sequans_controller.h> |
| 10 | + |
| 11 | +#define NUMBER "<FILL IN YOUR NUMBER WITH COUNTRY CODE, E.G., +4712345678>" |
| 12 | + |
| 13 | +void setup() { |
| 14 | + LedCtrl.begin(); |
| 15 | + LedCtrl.startupCycle(); |
| 16 | + |
| 17 | + Log.begin(115200); |
| 18 | + Log.rawf(F("\r\n\r\n")); |
| 19 | + Log.info(F("Starting SMS example. NOTE THAT THE TRUPHONE SIM CARD DOES NOT " |
| 20 | + "SUPPORT SENDING SMS TO OTHER NUMBERS THAN ITS IOT CONNECT HUB " |
| 21 | + "(NUMBER: 6260). USE ANOTHER SIM CARD WITH COMBINED DATA+SMS TO " |
| 22 | + "SEND SMS.")); |
| 23 | + |
| 24 | + if (!SequansController.begin()) { |
| 25 | + Log.error(F("Failed to start the modem")); |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + char response[128] = ""; |
| 30 | + |
| 31 | + // Configure UE for EPS combined attach |
| 32 | + ResponseResult response_result = SequansController.writeCommand( |
| 33 | + F("AT+CEMODE=2"), |
| 34 | + response, |
| 35 | + sizeof(response)); |
| 36 | + |
| 37 | + if (response_result != ResponseResult::OK) { |
| 38 | + Log.errorf(F("Error writing combined attach command, the response was: " |
| 39 | + "%s\r\n"), |
| 40 | + response); |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + // --- Start LTE modem and connect to the operator --- |
| 45 | + if (!Lte.begin()) { |
| 46 | + Log.error(F("Failed to connect to the operator")); |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + // --- Configure the UE to work under SMS text mode --- |
| 51 | + response_result = SequansController.writeCommand(F("AT+CMGF=1"), |
| 52 | + response, |
| 53 | + sizeof(response)); |
| 54 | + |
| 55 | + if (response_result != ResponseResult::OK) { |
| 56 | + Log.errorf(F("Failed to configure the UE to work under SMS text mode, " |
| 57 | + "the response was: %s\r\n"), |
| 58 | + response); |
| 59 | + return; |
| 60 | + } |
| 61 | + |
| 62 | + // --- Query the SMS service centre address to configure it is already |
| 63 | + // correctly configured --- |
| 64 | + response_result = SequansController.writeCommand(F("AT+CSCA?"), |
| 65 | + response, |
| 66 | + sizeof(response)); |
| 67 | + |
| 68 | + if (response_result != ResponseResult::OK) { |
| 69 | + Log.errorf(F("Failed to query the SMS service centre address, the " |
| 70 | + "response was: %s\r\n"), |
| 71 | + response); |
| 72 | + return; |
| 73 | + } else { |
| 74 | + char service_center_address[64] = ""; |
| 75 | + |
| 76 | + if (!SequansController.extractValueFromCommandResponse( |
| 77 | + response, |
| 78 | + 0, |
| 79 | + service_center_address, |
| 80 | + sizeof(service_center_address) - 1)) { |
| 81 | + Log.error(F("Failed to extract service center address")); |
| 82 | + return; |
| 83 | + } |
| 84 | + |
| 85 | + Log.infof(F("Got service centre addrees (this is not the SIM cards " |
| 86 | + "number by the way): %s\r\n"), |
| 87 | + service_center_address); |
| 88 | + } |
| 89 | + |
| 90 | + // --- Send SMS --- |
| 91 | + Log.infof(F("Sending SMS to %s...\r\n"), NUMBER); |
| 92 | + response_result = SequansController.writeCommand( |
| 93 | + F("AT+SQNSMSSEND=\"%s\",\"hello world\""), |
| 94 | + response, |
| 95 | + sizeof(response), |
| 96 | + NUMBER); |
| 97 | + |
| 98 | + if (response_result != ResponseResult::OK) { |
| 99 | + Log.errorf(F("Failed to send SMS, the response was: %s\r\n"), response); |
| 100 | + return; |
| 101 | + } |
| 102 | + |
| 103 | + SequansController.clearReceiveBuffer(); |
| 104 | + |
| 105 | + Log.info(F("Waiting for send confirmation...")); |
| 106 | + if (!SequansController.waitForURC(F("SQNSMSSEND"), |
| 107 | + response, |
| 108 | + sizeof(response), |
| 109 | + 40'000)) { |
| 110 | + Log.errorf(F("Timed out waiting for SMS confirmation\r\n")); |
| 111 | + return; |
| 112 | + } |
| 113 | + |
| 114 | + Log.infof(F("Got the following response: %s"), response); |
| 115 | +} |
| 116 | + |
| 117 | +void loop() {} |
0 commit comments