This example walks through using the nRF9160 Feather by Circuit Dojo with the Soracom Beam service in order to publish and subscribe to topics over LTE.
The nRF9160 Feather is a powerful open-source device based around a Nordic ARM processor and NB/CATM1 radio. Its jam packed full of features and is compatible with the Zephyr Project.
All you need to try out this project is an nRF9160 Feather and a Soracom Air SIM Card. The Soracom network provides connectivity and authentication. You can then use the suite of Soracom services to collect and transmit data to any cloud service!
Soracom Air provides worldwide, commitment-free mobile data service designed for IoT and M2M with coverage in 130 countries. The IoT and M2M SIM card provides an easy-to-use, secure connectivity platform to 2G/3G/LTE/Cat-M1 data with flexible pay-as-you-go rates.
Your device authenticates and connects to the Soracom network using the Soracom Air SIM card. Instead of having to use certificates or API tokens - the SIM card acts as the key. This gives you a secure connection on 2G/3G/LTE/Cat-M1 data.
Before inserting it into your device, the SIM card needs to be registered to an account and activated. It also needs to be attached to a Group in order to configure services like Soracom Beam.
- Navigate to https://console.soracom.io/ to sign in or register a Soracom account.
- Choose Register SIM.
- Enter the ICCID and PUK (written on the back of the SIM card) and name your SIM - ideally something that signifies the device associated with it.
- Choose Create from the Group drop-down and name it something like "Feathers".
- Click Register.
- Insert the SIM card into your nRF9160 Feather.
For low-power, low-memory devices, every bit counts. Soracom Beam reduces data and power needs related to encryption, allows connection to your cloud without relay servers or SDKs, and supports certificate management for your entire IoT/M2M fleet.
- Reduce power, bandwidth and memory use
- Connect securely to your cloud of choice
- Manage credentials at scale
For example, you can configure a basic MQTT entry point on Soracom Beam that your device can connect to using built in SIM credentials. Then Soracom Beam can connect to Adafruit.io, AWS IoT, Azure IoT, and so forth using secure credentials stored in the cloud.
- Sign into the Soracom Console.
- Choose Groups from the menu.
- Choose an existing group or create one. If you haven't already, add your device's SIM to a group.
- Create a new Soracom Beam MQTT entry point.
- Configure the entry point as necessary for your cloud integration. Once saved, your Soracom Beam MQTT entry point is live.
Install the software tools necessary to compile firmware for the nRF9160.
Compiling and Programming FirmwareTo understand how and what we're doing in this example, its important to familiarize yourself with how to compile firmware and flash it to your device. Jared Wolff, creator of the nRF9160 Feather, has put together documentation that helps with that.
https://docs.jaredwolff.com/nrf9160-compiling-app.html
https://docs.jaredwolff.com/nrf9160-programming-and-debugging.html
Modify the MQTT-SIMPLE example to work with Soracom BeamThe nordic SDK comes with an example for connecting an nRF9160 to an MQTT broker over LTE. This example is set to require a secure certificate and is also missing a flag to compile the firmware for MCU boot, the means by which we flash the device.
A few modifications need to be made before compiling and flashing this firmware.
- Open the mqtt_simple example in a text/code editor, such as VSCode. The full path on Mac is /opt/nordic/ncs/v1.5.0/nrf/samples/nrf9160/mqtt_simple.
- Open the prj.conf file. Add the following line to the end. This ensures the firmware builds an app-update.bin file.
CONFIG_BOOTLOADER_MCUBOOT=y
- Elsewhere in that file, update the Application section. This is where the MQTT broker, port, and publish and subscribe topics are set. Here we set Soracom Beam as the broker and can select arbitrary topics.
# Application
CONFIG_MQTT_PUB_TOPIC="<SOME-PUBLISH-TOPIC>"
CONFIG_MQTT_SUB_TOPIC="<SOME-SUBSCRIBE-TOPIC>"
CONFIG_MQTT_CLIENT_ID="my-client-id"
CONFIG_MQTT_BROKER_HOSTNAME="beam.soracom.io"
CONFIG_MQTT_BROKER_PORT=1883
- Next, open the overlay-tls.conf file. Comment out everything. This disables TLS since we don't require a security certificate. Authentication is handled by the Soracom Global IoT SIM.
- Open the nRF Connect SDK Terminal
- Change directories to ncs/nrf/samples/nrf9160/mqtt_simple
- Build the firmware with the following command.
west build -b circuitdojo_feather_nrf9160ns
- Change directories into mqtt_simple/build/zephyr.
- Hold the Mode button on the nRF9160 and then press the RST button. Once a solid blue light is shown, the board is ready to flash.
- With the nRF9160 plugged in, run the following command to flash.
newtmgr -c serial image upload app_update.bin
Serial MonitoringThe nRF9160 MQTT Sample will log out all activity over serial at an 115200 Baud Rate. It will log out all errors, AT commands, when it connects, disconnects, and when it publishes or receives messages.
If everything worked as expected, you will have seen messages come into whatever broker you configured Soracom Beam to relay to, in my case I used Adafruit.io.
Likewise, if you published any messages to the subscribed topic set in your firmware, you should seem them appear in the Serial console.
For more specific application uses, just modify the main.c file in the mqtt_simple example directory.
Congratulations! You now know how to compile and flash firmware for a robust and certified cellular IoT device connected to the Soracom Global network!
Comments
Please log in or sign up to comment.