So Easy MicroPython - Dweet, IoT Cloud Platform
by Yungger Chen in Circuits > Microcontrollers
336 Views, 1 Favorites, 0 Comments
So Easy MicroPython - Dweet, IoT Cloud Platform
*** Just add 2~3 lines, then your MCU will be an IoT enabled device empowered by Dweet.io ***
from MyREST_Dweet import myDweet
my = myDweet("YOUR_TOPIC")
my.send({'temperature': 13, 'humidity': 33})
*** MyREST_Dweet is a very useful library I designed to let your MCU upload and download data to/from Dweet Cloud platform in very easy and fast way. Just like the codes above, your MCU will send out data of temperature and humidity to Dweet. ***
Upload Libraries to Your MCU
First, You need to upload the libraries to your MCU board:
- MyREST_Dweet: A specific function library for accessing data on Dweet.io 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 Dweet.io Platform
# 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 in dictionary to the Dweet
from MyREST_Dweet import myDweet
my = myDweet("YOUR_TOPIC")
print('\n >>> Data uploaded to Dweet (can keep in 24 hours):', my.send({'temperature': 13, 'humidity': 33}))
Example 2:Read Data From Dweet.io Platform
# 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 in list from the Dweet
from MyREST_Dweet import myDweet
my = myDweet("YOUR_TOPIC")
print('\n >>> Read the latest data from Dweet:', my.read())
Example 3:Control Your LED Using MyDweet
# Connect to WiFi, it cab be omitted if your MCU already get on WiFi in your existing codes
from MyWifi import myWifi
# Connect to WiFi
my_wifi = myWifi("YOUR_WIFI_SSID", "YOUR_WIFI_PWD")
my_wifi.connect()
# Upload and download data in dictionary to/from the Dweet, and then control the MCU's LED
from machine import Pin
led = Pin(2, Pin.OUT) led.value(1)
from MyREST_Dweet import myDweet
my = myDweet("YOUR_TOPIC")
for i in range(5):
my.send({'led': (i % 2)}) # upload data
res = my.readLast() # download data
if len(res) > 0:
on_off = res[0]['content']['led']
led.value(on_off)
*** You can download the source code [HERE] ***
That's So Easy, Hope to Help a Little Bit !
Posted by Yungger
If it help you, and want to give some encouragement, just go HERE 😘 😘 !!