Use the Blecon Modem from an MCU
Using the Modem API from an MCU
Introduction
This guide covers getting started using the Blecon Device SDK with a supported Zephyr board. This example uses the ST Nucleo L433-RC-P, however most boards supporting with an UART supporting hardware flow control can be made to work as well.
The Blecon Device SDK allows you to use a Blecon modem directly from your device. Initially, the SDK supports the Zephyr operating system.
If you're not familiar with Zephyr, please head first to the relevant documentation.
The aim of this getting started guide is to help you evaluate the Blecon Device SDK by compiling, flashing and running a simple example.
Prerequisite: Flash and Connect a Blecon Modem
The Nucleo board will drive a Blecon modem connected to its UART. First, you'll need to flash a supported Blecon modem platform with the latest modem firmware. Follow the modem getting started guide for more details.
You can then connect your modem to the Nucleo board.
See the Modem Firmware Releases page for the relevant pinout for other modems.
5V
5V
GND
GND
D0 / UART1 RX / PA10
TX
D0 / P1.01
D1 / UART1 TX / PA9
RX
D1 / P1.02
D2 / UART1 RTS / PA12
CTS
D3 / P1.04
D10 / UART1 CTS / PA11
RTS
D2 / P1.03
Prerequisite: Set-up a Blecon hotspot
Install the Blecon app or Set up a Blecon Hotspot.
Set up your development environment
Make sure your environment is set up to build for Zephyr by following through the corresponding getting started guide. This guide shows you how to install all the tools you will need for this quickstart.
We will start by setting up a west workspace containing the Blecon Device SDK.
Initialising the SDK's west workspace
First, initialise a west workspace for the SDK:
$ west init -m https://github.com/blecon/blecon-device-sdk
=== Initializing in /Users/blecon/ws/test
--- Cloning manifest repository from https://github.com/blecon/blecon-device-sdk
Cloning into '/Users/blecon/ws/test/sdk-test/.west/manifest-tmp'...
remote: Enumerating objects: 91, done.
remote: Counting objects: 100% (91/91), done.
remote: Compressing objects: 100% (62/62), done.
remote: Total 91 (delta 19), reused 86 (delta 14), pack-reused 0
Receiving objects: 100% (91/91), 143.61 KiB | 738.00 KiB/s, done.
Resolving deltas: 100% (19/19), done.
--- setting manifest.path to blecon-device-sdk
=== Initialized. Now run "west update" inside /Users/blecon/ws/test/sdk-test.
Update the workspace:
$ west update
=== updating nrf (nrf):
--- nrf: initializing
Initialized empty Git repository in /Users/donatiengarnier/ws/test/sdk-test/nrf/.git/
--- nrf: fetching, need revision v2.4.0
warning: redirecting to https://github.com/nrfconnect/sdk-nrf/
remote: Enumerating objects: 169039, done.
...
Build & flash the example application
We will now build the application and flash it on the DK.
Compiling the example for the Nucleo L433-RC-P
Use west build to compile the example. You can have a look at the application's configuration in the its prj.conf file.
$ west build -b nucleo_l433rc_p -s blecon-device-sdk/examples/zephyr/hello-world
...
[167/167] Linking C executable zephyr/zephyr.elf
Memory region Used Size Region Size %age Used
FLASH: 81532 B 256 KB 31.10%
RAM: 52424 B 64 KB 79.99%
IDT_LIST: 0 GB 32 KB 0.00%
Flashing the Nucleo L433-RC-P with the example
You can now flash the example with west.
$ west flash
-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner openocd
-- runners.openocd: Flashing file: /Users/blecon/ws/test/build/zephyr/nucleo_l433rc_p/zephyr/zephyr.hex
Open On-Chip Debugger 0.12.0
...
wrote 81536 bytes from file /Users/blecon/ws/test/build/zephyr/nucleo_l433rc_p/zephyr/zephyr.hex in 1.980365s (40.207 KiB/s)
Connect the device to you network
Reading the device's URL
Connect a serial terminal (baudrate 115200bps) to the DK to read the device's unique URL.
$ screen /dev/tty.usbmodem0006836592911 115200
uart:~$ *** Booting Zephyr OS build v3.6.0 ***
uart:~$ Device URL: https://blecon.dev/27c6dcd1-1920-4a27-b80c-03debc122c4b
You can also type blecon announce
command in the Zephyr shell to identify your device with your hotspot.
uart:~$ blecon announce
Once obtained, you can register this device with your network.
Make a first request
Making requests
You can now go back to the serial terminal - you should shortly see a first request being made!
$ screen /dev/tty.usbmodem0006836592911 115200
...
Connected, sending request.
Got response: Hello blecon!
To make further requests, use the blecon connection_initiate command:
uart:~$ blecon connection_initiate
uart:~$ Connected, sending request.
Data sent
Data received
Frame: Hello blecon!
All received
Request successful
Disconnected
What is happening behind the scenes?
Please have a look at the example's source code and review the program's control flow.
Once the Blecon library is initialised, a connection is requested. Once the connection is made (and a corresponding callback is raised), the program sends a request. As part of preparing the request, the program queues one operation to send data (the ASCII string "Hello blecon!") and one to receive the response.
Callbacks are raised when these operations complete.
Refer to the Modem API Referencefor details on the various functions calls and callbacks.
Summary
This simple example showcases how you can use Blecon from an MCU running Zephyr to send and receive data to a cloud service using Bluetooth Low Energy.
To explore Blecon further, book a technical meeting or email us at [email protected]
Last updated