Last updated on: December 31, 2019
The SMS sample configures the button on the Icarus board, connects to the network and registers for SMS messages. When pressing the button, it tries to send an SMS message to a specified number. The destination phone number is declared at the top of the
main.c file and needs to be filled in before compiling the sample. The SMSC number also required for sending and SMSC is configured through the
The SMS sample enables the following settings in the
that enable the use of network connectivity and allow sending of AT commands to the modem.
Aditionally the sample enables the GPIO so that the button can be used:
The following directives make sure the internal eSIM is selected (instead of the external SIM) and set the SMSC number:
Note: the SMSC number depends on the SIM used. Make sure you set this to the proper one if using an external SIM.
The sample gets the GPIO handle from the Icarus device tree (
gpio_dev = device_get_binding(DT_GPIO_P0_DEV_NAME);) then configures the button and adds a button press callback:
gpio_pin_configure(gpio_dev, SIM_SELECT_PIN, GPIO_DIR_OUT);gpio_pin_configure(gpio_dev, BUTTON, GPIO_DIR_IN | GPIO_PUD_PULL_UP | GPIO_INT | GPIO_INT_DEBOUNCE | GPIO_INT_EDGE);gpio_init_callback(&gpio_cb, button_pressed_callback, BIT(BUTTON));gpio_add_callback(gpio_dev, &gpio_cb);gpio_pin_enable_callback(gpio_dev, BUTTON);
BUTTON defined as:
#define BUTTON SW0_GPIO_PIN
After the modem is connected to the network through the Zephyr LTEM library call:
lte_lc_init_and_connect(), it registers itself as an SMS client using the following code:
enum at_cmd_state state;at_cmd_write_with_callback("AT+CNMI=3,2,0,1", at_callback, &state);
at_callback is just a callback fromn the modem reporting the command execution status.
When the button is pressed a SMS containing the text "Button was pressed" will be sent to the number that is attributed to the
If upon sending the SMS the modem returns a
+CMS message, the modem is either not registered with the network, the SMSC number is not properly configured in the
prj.conf file or some other error ocurred. If the modem returns a message similar to:
+CMGS: 2 the SMS message was successfully sent.
If a SMS message is received, its contents will be printed on the serial terminal.
The sample uses an external library for encoding and decoding SMS messages.