So Easy MicroPython — Dweet.io, IoT Cloud Platform

Yungger
3 min readApr 28, 2021

--

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

from MyREST_Dweet import myDweet
my = myDweet("YOUR_TOPIC")
my.send({'temperature': 13, 'humidity': 33})

*** MyREST_Dweet is a library I designed for a MCU to upload and download data to/from Dweet.io Cloud platform in very easy and fast way. Using the codes as above, so a MCU will send out temperature and humidity of sensor data to Dweet.io. ***

Step 1: Upload libraries to your MCU

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

  • MyREST: A basic library for using Restful API communication
  • MyREST_Dweet: A specific function library for accessing data on Dweet.io 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 to my other article “So Easy MicroPython — WiFi Connection, MCU as IoT” . ***

The following examples, basically need to include the following statements onto the top of your script:

from MyREST_Dweet import myDweet
my = myDweet("YOUR_TOPIC")

Example 1:Upload/Write data to Dweet.io

my.send({'temperature': 13, 'humidity': 33})

Example 2:Download/Read data from Dweet.io

print('\n >>> Read the latest data from Dweet.io:', my.read())

Example 3:Control your IoT device, LED for example

from machine import Pin
led = Pin(2, Pin.OUT)

for i in range(5):
my.send({'led': (i % 2)}) # upload data
res = json.loads(my.readLast()) # download data
if len(res) > 0:
on_off = res['with'][0]['content']['led']
print('\n >>> LED: ', on_off)
led.value(on_off)

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 😘 😘 !!

--

--