Upload and visualize your sensor data on Ctrl platform

In this last tutorial, you will start collecting actual sensor data and utilize the internet connectivity to turn your Starter Kit into an IoT Edge Device.

Hook up with F1 Sensor Shield

  • Stack the F1 Sensor Shield on top of the Starter Kit as shown below:  [Photos]
  • F1 Sensor Shield comes with 4 sensors and we will take the temperature and relative humidity sensor SHT30 as an example.
  • Type the following commands in the REPL terminal to query the devices on the I2C Bus
from machine import Pin, I2C
from lib import sht4x
i2c = I2C(1, scl=Pin(16), sda=Pin(15), freq=100000)
i2c.scan()
  • Note we are using 100KHz clock rate to accommodate devices with slower clock
  • [65] should appear as a status return from the last command, which is the I2C address of SHT30 sensor
  • You can further try out the follow commands to monitor current temperature every 0.5 second
sht = sht4x.SHT4X(i2c)

sht.heater_power = sht4x.HEATER20mW

while True:
temperature, relative_humidity = sht.measurements
print(f"Temperature: {temperature:.2f}°C")
print(f"Relative Humidity: {relative_humidity/100:.2%}")
print("")
time.sleep(0.5)

This will be the foundation of this data uploading tutorial.

 

Upload sensor data to Ctrl platform

The default main.py of the Starter Kit has handled the establishment of internet connection via LTE. Base on the default main.py, we will integrate the sensor data uploading functionality to main.py.

Code Change on main.py

Below the following code:

import LTE
LTE=LTE.LTE()

Add import I2C and SHT30 sensor library:

from machine import Pin, I2C
from lib import sht4x
i2c = I2C(1, scl=Pin(16), sda=Pin(15), freq=100000)

After the following LTE connection handling code, add the measurement and sensor data reading loop:

sht = sht4x.SHT4X(i2c)

sht.heater_power = sht4x.HEATER20mW

while True:
     temperature, relative_humidity = sht.measurements
     print(f"Temperature: {temperature:.2f}°C")
     print(f"Relative Humidity: {relative_humidity/100:.2%}")
     print("")
     time.sleep(0.5)

To support data uploading to Ctrl platform, we need to import SGW Ctrl library:

from SGW import ctrl

Then in the measurement and sensor data reading loop, we use data uploading function (ctrl.signal) to replace terminal printing:

ctrl.signal("Temperature”, {temperature:.2f})
ctrl.signal("Relative Humidity”, {relative_humidity/100:.2})

To avoid overwhelming of data, we can change the sleep time to 10 seconds:

 time.sleep(10)

Verification of sensor data on Ctrl platform

  • Now, the py is ready to turn F1 Sensor Shield and Starter Kit combo as a simple IoT edge device to report sensor data periodically.
  • Use the Run file on device feature to test out the code
  • Login to Ctrl platform and select your device on the left pane  [Image]
  • Click open “Signals” to observe sensor data is coming in in 10 seconds interval  [Image]
  • You can further enhance the experience by using the “Widget” function in Ctrl platform  [Image]

 

Configure edge device setting via Ctrl platform

  • [TBD – depends on Ctrl-to-Device implementation]

This is the end of the beginner tutorial, please visit doc.F1.sgwireless.com to look for more advanced tutorial which will cover Wi-Fi configuration, LoRa, BLE (Device and Gateway) and more.