So Easy MicroPython — ThingsBoard, IoT Cloud Platform

*** Just simply add 2~3 lines, then your MCU (ESP8266 or ESP32) can be a ThingsBoard enabled IoT device***

from MyREST_TBChain import myThingsBoard
my = myThingsBoard(key="YOUR_DEVICE_TOKEN")
my.send({'temperature': 27.6, 'humidity': 68})

*** MyREST_TBChain is a library I designed for a MCU (ESP8266/ESP32) to upload/download data to/from ThingsBoard platform in very easy and fast way. your MCU can send out data of temperature and humidity to ThingsBoard, just as simple as adding codes above. ***

*** Before moving to next demonstration, you should have your ThingsBoard account already. ***

Step 1: Upload libraries to your MCU

First, download the libraries by its link and upload them to your MCU !

  • MyREST_TBChain: A specific function library for accessing data on ThingsBoard platform
  • MyWifi: A basic library for WiFi connection (No need, if your MCU can connect to WiFi already by your own script)

*** If no idea how to upload files to your MCU board, you can read my other article “So Easy — ESP8266/ESP32 File Management” first. ***

Step 2: Lets’ learn some examples

Example 0: Let MCU connect to your WiFi AP first

from MyWifi import myWifi
my = myWifi(YOUR_WIFI_SSID, YOUR_WIFI_PWD)
my.connect()

As an IoT device, to make your MCU connect to Internet is essentially true always. And how to do it, no matter to use your own codes or use MyWifi library. JUST need to connect it to Internet, since called an “IoT” device !!!

*** If you want to know how easy I can simply add 2~3 lines to the script, have my MCU connect to WiFi , then you might be interested to refer my other article “So Easy MicroPython — WiFi Connection, MCU as IoT” . ***

Example 1:Upload/Write data to ThingsBoard

from MyREST_TBChain import myThingsBoard
my = myThingsBoard(key="YOUR_DEVICE_TOKEN")
my.send({'temperature': 27.6, 'humidity': 68})

Example 2: Get JWT/User token from ThingsBoard

from MyREST_TBChain import myThingsBoard
my = myThingsBoard()
print("My ThingsBoard JWT Token:", my.getAuthToken("YOUR_TB_USER", "YOUR_TB_PWD"))

Example 3:Download/Read data from ThingsBoard

*** You MUST have a JWT Token released by ThinsBoard, before reading data from it. ***

from MyREST_TBChain import myThingsBoard
my = myThingsBoard()
print('\n\nGet data :', my.read("temperature,humidity", YOUR_TB_DEVICE_ID, auth=YOUR_TB_AUTH_TOKEN))
My DHT22 sensor data on ThingsBoard

DEMO:

This demo shows how to upload testing dataset to ThingsBoard, and the live chart updated simultaneously.

That’s all, so easy right ? Hope this helps !

Posted by Yungger

If it really help you, you are welcome to clap your hands clicking on top-left icon, or want to buy me a coffee to encourage me to write more, I thank you too 😘 😘 !!

Maker & Freelancer