The simplest way to add cellular connectivity to your favorite Arduino MKR board

You have your favorite Arduino MKR board and would like to build DIY IOT project for  remotely located object monitoring!? So, we would like to offer simple solution to make it happen.

OVERVIEW

Some time ago we shared our experience of setting up in a minute local condition DIY IOT monitoring demo project. Now, we would like to show one more option to build similar DIY IOT solution on Arduino MKR board. As before, IOT hardware, embedded firmware and Cloud Dashboard will be setup and configured. Local temperature, humidity and pressure, as well as device vital data, like a battery level and cellular RSSI, and, location info were obtained and published to ThingsBoard cloud.

iotbotscom-qtop-bg96-arduino-mkr-bme280-thingsboard-blog

 

Arduino MKR Zero controller board, Quectel BG95 cellular modem based Arduino MKR compatible shield with LTE and GNSS antennas attached, and, BME280 sensor module were used. Previously created qTop BG96 Adafruit Feather ThingsBoard Local Condition IOT Dashboard Demo was used.

HW SETUP

IOT board

Arduino MKRZero controller board with Stacking Headers was used. BTW, we have tested several Arduino MKR boards we have : MKR Zero, MKR WiFi 1010 and MKR WAN 1300.

arduino-mkr-zero-thingsboard-dashboard

 

 

 

 

 

 

All of them have worked perfectly with our setup: You just need to change board type in Arduino IDE before sketch building and downloading.

Connectivity

As we planned, we would like to build remote device monitoring DIY IOT solution, so, we had decided to use cellular connectivity and wanted to demonstrate our newest product - qTop Cell BG95 Arduino MKR compatible shield (by IOT-BOTS.COM).

iotbotscom-qtop-cell-quectel-bg95-amc-arduinoiotbotscom-qtop-cell-quectel-bg95-amc-mkr

This device was the part of qTop family, which included Quectel and uBlox Cellular, LoRa, GNSS and sensor shields to be used together with Feather and Arduino MKR Compatible IOT boards. This board is available right now. 

qTop BG95 shield was plugged to controller board Arduino MKR Compatible Interface connectors. We set modem to run in GSM (2G) mode because of several reasons, so any 2G SIM card would perfectly worked - we used SpeedTalk Mobile SIM Card.

LTE and GNSS internal antennas with u.FL connectors were applied to qTop BG95 modem board.

Sensor

To make this Demo alive, we brought local condition monitoring feature and qJam BME280 sensor module was used for it. 

iotbotscom-qjam-iot-sensors-bme280-pressure

qJam Temperature / Humidity / Pressure BME280 module was part of the newest qJam IOT device line, developed and manufactures by IOT-BOTS.COM. Module was plugged to appropriate connector of qTop shield. I2C interface was used to communicate with module.

BTW, any other BME280 sensor module could be used as option - you just  needed to connect 3,3V power and I2C bus and check the module I2C address and change it in source code if required.

Power
To power the system, 3,7V 750 mA LiPol battery was used (any 3,7V 500...1000 mA LiPol battery could be fine, for example, this one). The battery was  connected to IOT controller board as usual. Battery can be charged by connecting MKR board to PC or USB power adapter through USB cable.
So, this was a whole HW setup used for this Demo : Arduino MKR Zero controller board with qTop BG95 AMC shield plugged in. qJam BME280 sensor module and SIM card, both inserted into qTop shield board and LTE and GNSS internal antennas attached to appropriate u.FL connectors there. LiPol battery provided a power.
iotbotscom-qtop-cell-quectel-bg95-amc-arduino-mkr-demo

THINGSBOARD CLOUD

ThingsBoard IOT open-source platform was chosen as IOT Cloud Dashboard. We reused dashboard for qTop BG96 Feather Demo - we just changed Dashboard name. No more changes required. The same sensors and device data were shown there:

- Temperature, humidity, pressure sensors data gauges;

- Battery level and cellular RSSI;

- Location, speed and GNSS info;

- Temperature, humidity, pressure sensors data timeseries charts;

- Map with device location.

You don't need to build this dashboard from scratch - ThingsBoard.io platform allows to reuse made early dashboards through Import-Export JSON format feature. So, to get this Demo dashboard you just need to make the same steps, described for qTop BG96 Feather Demo before.

After making all steps, you will be able to see Demo Dashboard fully setup and ready to go.

iotbotscom-thingsboard-add-dashboard-empty

EMBEDDED FW

Demo firmware was created using Arduino IDE. Demo sketch could be found here. It was created and built for Arduino MKR Zero board as target HW.

These components and libs (we used the latest versions) to be installed for Arduino IDE to get sketch built and flashed to target HW:

- Arduino core for the ESP32;

Adafruit_BME280_Library;

- TinyGSM Lib;

StreamDebugger Lib (if you want to turn modem AT command debug On);

- ArduinoJSON Lib.

All items could be installed through Arduino IDE or manually. You can find a lot of info on the Internet how to make installations mentioned above, so please let us skip this step.

As soon as all preparation completed, just open the sketch in IDE. To make system properly working, you need to make these changes in sketch opened:

- enter / edit APN info (check your SIM card provider);

- enter / edit ThingsBoard token (use token, copied from ThingsBoard "Token Step" completed before).

Picture below shows these places in the sketch:

iotbotscom-thingsboard-edit-token

TinyGSM Lib does not have Quectel BG95 modem as option. So, BG96 modem option was used. But, based on a new generation of Qualcomm LPWA platform with a cost-optimized architecture where WWAN (LTE Cat M1, LTE Cat NB2 and GSM) and GNSS Rx chains share some hardware blocks, the modules do not support concurrent operation of WWAN and GNSS. So, we have implemented source code to switch between WWAN and GNSS operations.

FW developed could be run in two modes : "Always On" and "One Shot". In "Always On"  mode system continuously published data with interval defined. For "One Shot"  mode, system made single publishing and moved to Deep Sleep. By default, Demo run in "Always On" mode with 5 seconds publish delay interval (not actual publishing data interval).

To set mode wanted, "demo_mode" variable should be initialized with appropriate mode define. 

 iotbotscom-sketch-mode

FW functionality:

- After power up, GPIO config was done;
- checking that qJam sensor was connected : BME280 sensor found and data received;
- turning Modem On;
- getting Modem Info;
- and, final setup() step was GNSS Searching;

In the main loop ("Always On" mode):
- doing Network registration if not done yet;
- getting BME280 sensor data;
- collecting modem / network status;
- opening TCP/IP session (if not opened yet);
- publishing info received to a cloud;
- requesting GNSS info;
- waiting for MODE_ALWAYS_ON_DELAY_TIMEOUT timeout (5 sec.).

In the main loop ("One Shot" mode):
- doing Network registration if not done yet;
- getting BME280 sensor data;
- collecting modem / network status;
- opening TCP/IP session;
- publishing info received to a cloud;
- requesting GNSS info;
- closing session opened;
- turn modem off;
- move to Deep Sleep.

HTTP and RESTful API option was used to publish data to ThingsBoard cloud.

We provided enough comments in source code, so, we hoped, it could be easily read and understood. Moreover, we put "printf" logging for all major execution steps - please see run logs below.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

***************************************************************************************************

**** IOT-BOTS.COM ****

**** qTop Quectel BG9x Shield ThingsBoard Demo ****

***************************************************************************************************

---- Setup Started ----

BME280 Sensor Found!

[6682] ### Unhandled: RDY
[6793] ### Modem: Quectel BG95-M3
[6794] ### Modem: Quectel BG95-M3
Modem: Quectel
BG95-M3
Revision: BG95M3LAR02A03
IMEI: 867730051749277
IMSI: 310260941589745
CCID: 8901260941115897457F

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
...No Data Available!

GNSS:
Quality : 2
Date : 220621
Time : 024625
Latitude : 42.52593
Longitude : -83.45726
Altitude, m : 327
Speed, km/h : 0
Heading : 0
HDOP : 2.5
Sats In Use : 04

---- Setup Done ----

---- Loop Cycle ----

Waiting for GSM network... failed

---- Loop Cycle ----

Waiting for GSM network... : Network connected
GPRS Network : Connected
Get Network Time :
Year : 2021
Month : 6
Day : 21
Hour : 22
Minute : 47
Second : 56
Time Zone : -4.00

---- Loop Cycle ----


Battery:
Voltage, mV: 3821
Voltage, %: 52

BME280 Sensor:
Temperature, F: 89.80
Pressure, hPa: 976.00
Humidity, %: 34.52

Modem Power:
Voltage, mV: 3884

Signal Quality:
RSSI: 22
[129694] ### Unhandled: OK
Connecting to "thingsboard.cloud"... : Cloud connected

HTTP Request:
POST /api/v1/pb7Vc2go03M2TmAdvzYe/telemetry HTTP/1.1
Host: thingsboard.cloud
Accept: */*
Content-Type: application/json
Content-Length: 251

{"Bat.voltage":52,"Ext.voltage":0,"RSSI":22,"Temperature":89.798,"Humidity":34.51563,"Pressure":976.0029,"latitude":"42.52593","longitude":"-83.45726","altitude":"327","speed":"0","heading":"0","nsat":"04","hdop":"2.5","date":"220621","time":"024625"}



HTTP Reply:
[130356] ### URC RECV: 0
[130374] ### DATA AVAILABLE: 73 on 0
[130388] ### DATA AVAILABLE: 10 on 0
HTTP/1.1 200
content-length: 0
date: Tue, 22 Jun 2021 02:48:04 GMT



GNSS:
...No Data Available!

---- Loop Cycle ----


GNSS:
...No Data Available!

---- Loop Cycle ----


GNSS:
Quality : 3
Date : 220621
Time : 024821
Latitude : 42.52588
Longitude : -83.45727
Altitude, m : 308
Speed, km/h : 0
Heading : 0
HDOP : 2.5
Sats In Use : 04

---- Loop Cycle ----


Battery:
Voltage, mV: 3821
Voltage, %: 52

BME280 Sensor:
Temperature, F: 89.71
Pressure, hPa: 976.03
Humidity, %: 34.83

Modem Power:
Voltage, mV: 3882

Signal Quality:
RSSI: 22

HTTP Request:
POST /api/v1/pb7Vc2go03M2TmAdvzYe/telemetry HTTP/1.1
Host: thingsboard.cloud
Accept: */*
Content-Type: application/json
Content-Length: 250

{"Bat.voltage":52,"Ext.voltage":0,"RSSI":22,"Temperature":89.708,"Humidity":34.8252,"Pressure":976.0333,"latitude":"42.52588","longitude":"-83.45727","altitude":"308","speed":"0","heading":"0","nsat":"04","hdop":"2.5","date":"220621","time":"024821"}



HTTP Reply:
[152947] ### URC RECV: 0
[152965] ### DATA AVAILABLE: 73 on 0
[152980] ### DATA AVAILABLE: 10 on 0
HTTP/1.1 200
content-length: 0
date: Tue, 22 Jun 2021 02:48:[152989] ### DATA AVAILABLE: 10 on 0
26 GMT



GNSS:
Quality : 2
Date : 220621
Time : 024833
Latitude : 42.52590
Longitude : -83.45725
Altitude, m : 313
Speed, km/h : 0
Heading : 0
HDOP : 2.4
Sats In Use : 04

---- Loop Cycle ----

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

In case, if no BME280 found, or, GNSS data was not available, that data were not published.

"All data received" log is below:

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

---- Loop Cycle ----

Battery:
Voltage, mV: 3821
Voltage, %: 52

BME280 Sensor:
Temperature, F: 85.33
Pressure, hPa: 977.10
Humidity, %: 37.59

Modem Power:
Voltage, mV: 3884

Signal Quality:
RSSI: 25

HTTP Request:
POST /api/v1/pb7Vc2go03M2TmAdvzYe/telemetry HTTP/1.1
Host: thingsboard.cloud
Accept: */*
Content-Type: application/json
Content-Length: 250

{"Bat.voltage":52,"Ext.voltage":0,"RSSI":25,"Temperature":85.334,"Humidity":37.5918,"Pressure":977.0984,"latitude":"42.52597","longitude":"-83.45730","altitude":"322","speed":"0","heading":"0","nsat":"05","hdop":"1.3","date":"220621","time":"041924"}



HTTP Reply:
[211846] ### URC RECV: 0
[211864] ### DATA AVAILABLE: 73 on 0
[211878] ### DATA AVAILABLE: 10 on 0
HTTP/1.1 200
content-length: 0
date: Tue, 22 Jun 2021 04:19:31 GMT



GNSS:
Quality : 3
Date : 220621
Time : 041937
Latitude : 42.52596
Longitude : -83.45724
Altitude, m : 320
Speed, km/h : 0
Heading : 0
HDOP : 1.3
Sats In Use : 05

---- Loop Cycle ----

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Using logging prompts incorporated, you can see what it is happening with a system: check that all HW parts found properly working, see sensor and GNSS data, get connection results and data publishing status. 

To check data receiving by cloud, you can verify it on "Latest Telemetry" tab for "qTop-Modem" device added.

iotbotscom-thingsboard-latest-telemetry

As soon as all preparations completed and device turned on you would be able to see Demo dashboard with all data displayed.

iotbotscom-bg95-arduino-mkr-thingsboard-dashboard

Now you can play with your IOT dashboard, widgets and embedded source code to make your own version of this DIY IOT solution.

Enjoy!

CONCLUSION

It was shown how to easily setup nice looking DIY IOT Cloud Dashboard for remote local condition monitoring. To see sensor data, as well as vital data, like Battery, RSSI and location of cellular connected device.

ThingsBoard DIY IOT Dashboard was created. 

Arduino MKR Zero IOT controller board, Quectel BG95 cellular module based qTop Arduino MKR compatible shield with LTE and GNSS antennas attached, and, qJam BME280 sensor module were used.

TRADEMARK NOTICE

All referenced brands, product names, service names, and trademarks are the property of their respective owners.

 

Leave a comment

Please note, comments must be approved before they are published