Interfacing NodeMCU with Freeboard IOT dashboard using dweet io.
A brief tutorial on posting data to IOT dashboard using NodeMCU using dweet io messaging service.
- NodeMCU with micropython firmware (Refer previous post for uploading micropython firmware to nodemcu)
dweet.io is simple publishing and subscribing for machines, sensors, devices, robots, and gadgets (we just call them things). We call published messages ‘dweets’. It’s helpful to think of dweet.io as a Twitter for things, in fact.
We assign each thing a unique thing name (or you can assign your own if it’s available). Then a thing may be subscribed to, which is analogous to following someone in twitter.
Go through https://dweet.io/faq for more…
NodeMCU using Dweet io
The below code snippet connects to the wifi hotspot and post the value read over adc of nodeMCU every 5 seconds to the dweet io dashboard.
I am using a micropython http client library from https://github.com/balloob/micropython-http-client
Git clone the above library.
wlan = network.WLAN(network.STA_IF) #configure for station interface
wlan.active(True) #Enable module as station
if not wlan.isconnected():
print('connecting to network...')
while not wlan.isconnected():
print('network config:', wlan.ifconfig())
adc = machine.ADC(0)
value = adc.read()
thing = 'YOUR-THING-NAME'
url = 'http://dweet.io/dweet/for/'+thing+'?temp='+str(value)
In the above code temp =str(value) is a key value pair. You can change the key as you like.
See to that you have change the wifi ssid name and password and your thing name, and save it as main.py so that nodemcu starts running the code after initializing.
Now upload the http_client.py and main.py to nodemcu using adafruit’s ampy.
Refer previous post for procedure
ampy -p /dev/ttyUSB0 put http_client.py
ampy -p /dev/ttyUSB0 put main.py
Restart NodeMCU and you are done.
The NodeMCU connects to WIFI hotspot and starts publishing values to dweet io, which can been seen via the below url
For custom widgets like graphs, guages and string, signup with freeboard and add widgets that suit your purpose.
Add your datasource on the dashboard with type dweet.io and thing name as your-thing-name.
Now add widgets and select the type of widget to want and the value eg. datasources[“Dweet”][“temp”]
You can see the guage changes for every post from NodeMCU.
Note: I am publishing data to dweet io over unsecured connection. The http library i use dont support https. There is a micropython version of urllib that support https.