So Easy MicroPython - ThingsBoard, IoT Cloud Platform

by Yungger Chen in Circuits > Microcontrollers

982 Views, 3 Favorites, 0 Comments

So Easy MicroPython - ThingsBoard, IoT Cloud Platform

dashboard.png

*** Just add 2~3 lines, then your MCU will be an IoT device of ThingsBoard enabled***


from MyREST_TBChain import myThingsBoard

my = myThingsBoard(key="YOUR_DEVICE_TOKEN")

my.send({'temperature': 27.6, 'humidity': 68})


*** This is a very useful library I designed to let your MCU upload and download data to/from ThingsBoard Cloud platform in very easy and fast way. Just like the codes above, your MCU will send out data of temperature and humidity to ThingsBoard. ***

*** Before next demonstration, you should have your account on the cloud platform, we will not take more time to introduce it step by step since anyone can easily get help from official website ***

Upload Libraries to Your MCU

First, You need to upload the libraries to your MCU board:

  • MyREST_TBChain: A specific function library for accessing data on ThingsBoard platform
  • MyWifi: A basic library for WiFi connection (Optional, if your code already make the MCU connect to WiFi)

*** If you have no idea how to upload File to your MCU, read my another article "So Easy MicroPython - ESP8266/ESP32 MCU File Management" first.

*** If you are interested in MyWifi library or no idea how to use it, read my another article "So Easy MicroPython - My WiFi Connection"

Example 1: Upload Data to ThingsBoard Platform

chart_1.png
data_read.jpg

# Connect to WiFi, it cab be omitted if your MCU already get on WiFi in your existing codes

from MyWifi import myWifi

my_wifi = myWifi("YOUR_WIFI_SSID", "YOUR_WIFI_PWD")

my_wifi.connect()

# Only add these 3 lines, then your MCU can upload data to ThingsBoard platform

from MyREST_TBChain import myThingsBoard

my = myThingsBoard(key="YOUR_DEVICE_TOKEN")

my.send({'temperature': 27.6, 'humidity': 68})

Example 2: Get User Token From ThingsBoard Platform

my_jwt_token.jpg

# Connect to WiFi, it cab be omitted if your MCU already get on WiFi in your existing codes

from MyWifi import myWifi

my_wifi = myWifi("YOUR_WIFI_SSID", "YOUR_WIFI_PWD")

my_wifi.connect()

# Only add these 3 lines, then your MCU can get authorization token from ThingsBoard

from MyREST_TBChain import myThingsBoard

my = myThingsBoard()

print("My ThingsBoard JWT Token:", my.getAuthToken("YOUR_TB_USER", "YOUR_TB_PWD"))

*** You MUST have a JWT Token released by ThinsBoard, before reading data from it. You can ignore this example, if you already have one.

Example 3:Read Data From ThingsBoard Platform

data_read.jpg

# Connect to WiFi, it cab be omitted if your MCU already get on WiFi in your existing codes

from MyWifi import myWifi

my_wifi = myWifi("YOUR_WIFI_SSID", "YOUR_WIFI_PWD")

my_wifi.connect()

# Only add these 3 lines, then your MCU can read data from ThingsBoard

from MyREST_TBChain import myThingsBoard

my = myThingsBoard()

print('\n\nGet data :', my.read("temperature,humidity", "YOUR_TB_DEVICE_ID", "YOUR_TB_TOKEN"))

That's So Easy, Hope to Help a Little Bit !

如此簡單 MicroPython - ThingsBoard 物聯網

Posted by Yungger

If it help you, and want to give some encouragement, just go HERE 😘 😘 !!