ThingForward NB-IoT Shield - Real Life Example Demonstration

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 customize this setup with desired sensors, actuators or protocols.

Let's look at today's shopping list:

  1. 1x ThingForward NB-IoT Shield
  2. 1x Feather M0 Express MCU
  3. 1x Feather OLED 32x128 Grayscale
  4. 1x Dragino Quectel BC95-B8 NB Module + SIM Card + Antenna
  5. 1x Grove Xbee Adapter
  6. 1x Grove Blueberry BME280 Sensor

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.

Coding

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.

Clone our repository from GitHub

$ 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.

Install the necessary libraries

ThingForward NB-IoT Library
$ pio lib install https://github.com/thingforward/nbiot-arduino.git

Adafruit_SSD1306 library for OLED screen:
$ pio lib install 135

Grove - library for BME280 sensor:
$ pio lib install 5348

Adafruit_GFX for OLED screen:
$ pio lib install 188

Adafruit Unified Sensor library for all sensors.
$ pio lib install 31

Upload the code and open serial monitor

Type
$ 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. Thetemp, humd, pressmessages 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:

  • Attach
  • Send
  • Detach

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.

Conclusion

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.

Seite teilen