As long as we are dealing with NB-IoT, we considered of being more specific about real life examples using our Grove connector and narrowband protocol. Today we will be programming by using an MCU from Adafruit, NB-IoT module, OLED screen, and some sensors in order to show the capabilities of our new hardware on a real life NB-IoT task. Please remember that using these modules and sensors will give you a fresh start, then you can easily customise this setup with desired sensors, actuators or protocols.
We hope that you are already acquainted with our Grove connector shield. If not, these are two steps that bring you in tune! The first blogpost has the clarification about our production process and the motivation of producing this hardware. The second blogpost shows a use case with some sensors and actuators in order to test its capability. Todays blogpost will bring the narrowband connection on top.
If you want to start with NB-IoT but still didn't decide on which module you need, please refer to our guide blogpost about choosing the right module for NB-IoT.
Let's look at today's shopping list:
On the following image, you will see the components responsible for narrowband communication. You can choose which sim card you want, i.e. Vodafone, 1nce or similar. The sim card will be plugged into BC95-B8 module, which realises narrowband communication over B8 frequency band. Grove Xbee Adapter lets you connect your BC95 module directly to a Grove port.
The next image shows you the MCU, OLED and ThingForward Grove connector shield. Adafruit Feather M0 Express is a small but powerful MCU that has ATSAMD21G18 ARM Cortex M0+ processor, clocked at 48 MHz and at 3.3V logic. The OLED display is also selected from Adafruit for a perfect fit. Speaking of which, here is our connector on the bottom layer that allows you to connect all Grove sensors/actuators easily.
Now, it is time to flash the MCU and test our setup!
Please note that in order to flash the MCU, we need a PlatformIO membership or Arduino IDE. The programming libraries you need are given below, which are of course compatible with both PlatformIO, Arduino or similar.
$ git clone https://github.com/emirez/iot-nb-feather-bc95-xbee.git $ cd iot-nb-feather-bc95-xbee
Note: Don't forget to update your UDP server IP address and endpoint on the main.ino.
$ pio lib install https://github.com/thingforward/nbiot-arduino.git
$ pio lib install 135
$ pio lib install 5348
$ pio lib install 188
$ pio lib install 31
$ pio run -t upload && pio device monitor
The following image shows the result flashing. On the left side, here is our complete hardware setup. On the right side, you will see the serial monitor messages and on the bottom, the log data from our UDP server. It starts with the initialisation of BME280 sensor and then OLED. After that, the supported bands for narrowband communication will be found. As soon as NB-IoT module is started successfully, it will try to attach to the supported band, which is B8. After a successful attachment, UDP messages will be sent and they will be visible on UDP server. On the UDP server screenshot, the endpoints can be observed. The temp, humd, press messages are gathered by BME280 sensor. All the outputs can be printed on OLED screen.
Let's look at the shortened version of main code now. After the initiation of the narrowband instances, the setup function will set the baud rate of serial communication. It is the first important point because several modules support several baud rates and you need to control it from its user manual. After setting the baud rate, under the loop method, the narrowband module will be initialised. As you can see, there are several delays between the functions and methods. They can be seen as the second important point, which are vital for successful narrowband module initialisations. After the initialisation, the narrowband module will get the bands that are supported by the module, and then the active bands. Finding the active band that also supported by the module means that a stable communication between packet provider and the module can be established.
After satisfying a stable connection between the module and the packet provider, the UDP messages can be sent. For sending UDP messages, the IP address of the server and the endpoint should be specified. After sending the UDP message, the module will be initialised again, in order to build a new stable communication: It can be programmed under loop method like:
As an additional point that you need to pay attention, here comes the buffer-size. It only depends on your hardware and shouldn't be exceed on the software side. Otherwise the module couldn't be flashed or malfunctions could be observed.
That's all! Both on the hardware and software sides, deeper and more detailed applications can be tested and used in real life applications. The most important part is the stability of the narrowband communication. You need to be also careful about message transmission frequency, otherwise you can miss the upcoming messages from your module.
Thanks to ThingForward NB-IoT shield, the MCU and sensor connections can be done in seconds.
Keep following us for upcoming blogpost about IoT and its hot topics!