Sending temperature data to....somwhere

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Tillmario
Posts: 18
Joined: Mon Nov 19, 2018 2:06 pm

Sending temperature data to....somwhere

Post by Tillmario » Tue Nov 20, 2018 5:31 pm

Hi, thanks to the help of this forum i flashed MicroPython v1.9.1-8 on my ESP2866. The board is connected to my Wifi.

I succesfully conected a DHT22, written a script (http://docs.micropython.org/en/latest/e ... dht-driver) and got my temperature as an output.
My problem now ist.... how to send it somewhere via wifi?

And where to send it best? I would like to collect the temperature data every 5 Minutes. And best case display it in some graph. it could be send to a txt-file on a RPi in the Network or something that is suited for later use in a graph. I don't know.

Help would be appreciated.
Greetings, Tom


Tillmario
Posts: 18
Joined: Mon Nov 19, 2018 2:06 pm

Re: Sending temperature data to....somwhere

Post by Tillmario » Wed Nov 21, 2018 8:17 am

Tillmario wrote:
Tue Nov 20, 2018 5:31 pm
My problem now ist.... how to send it somewhere via wifi?

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Sending temperature data to....somwhere

Post by kevinkk525 » Wed Nov 21, 2018 9:19 am

I'll make it easy for you: use mqtt and check https://www.home-assistant.io/.
But for how to use mqtt on your esp8266 you actually have to use google or the forum search and read about it yourself ;)
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Tillmario
Posts: 18
Joined: Mon Nov 19, 2018 2:06 pm

Re: Sending temperature data to....somwhere

Post by Tillmario » Wed Nov 21, 2018 11:07 am

kevinkk525 wrote:
Wed Nov 21, 2018 9:19 am
I'll make it easy for you: use mqtt and check https://www.home-assistant.io/
Thanks that is very helpful.
kevinkk525 wrote:
Wed Nov 21, 2018 9:19 am
But for how to use mqtt on your esp8266 you actually have to use google or the forum search and read about it yourself ;)
I didn't expect anyone to do that. It's just hard to look for something, if you don't know what to look for.

Thanks for the help. I'll figure out what mqtt is and how to use it.
Greetings, Tom

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Sending temperature data to....somwhere

Post by kevinkk525 » Wed Nov 21, 2018 11:29 am

Good luck! Setting up home-assistant can be a demanding process but in the end it's worth it.

mqtt client on the esp8266 is quite easy. Depending on your level of knowledge of python there are different options for mqtt. You could even use my framework https://github.com/kevinkk525/pysmartnode that takes care of everything and just implement your script into that but if you are new to programming in general or don't know how to build a custom firmware or what uasyncio is, it might be better to start small and use the umqtt library https://github.com/micropython/micropyt ... qtt.simple for esp8266 and start working with it.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
Mike Teachman
Posts: 155
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: Sending temperature data to....somwhere

Post by Mike Teachman » Wed Nov 21, 2018 8:40 pm

You might take a look at the tutorials and code examples I put together describing how to use Thingspeak and Adafruit IO with MQTT. Examples for publish and subscribe.

Thingspeak
https://github.com/MikeTeachman/micropy ... tt-esp8266

and

Adafruit IO
https://github.com/MikeTeachman/micropy ... tt-esp8266

The examples use the free heap statistics to illustrate the concepts. To publish temperature data change the following line in the example uPy publish code

Code: Select all

free_heap_in_bytes = gc.mem_free()
Substitute your reading in place of the heap statistic. And, likely change the variable name throughout to better match your temperature application.

good luck!

sspaman
Posts: 16
Joined: Fri Nov 02, 2018 5:03 pm

Re: Sending temperature data to....somwhere

Post by sspaman » Sun Dec 02, 2018 1:31 am

Hi Mike,

This is great stuff thanks for posting.

I am new to this networking using MQTT so this is a really basic question. When connecting as a subscriber to the Adafruit IO dashboard how would I send a command to turn off an LED for example?

On my Adafruit Feather Huzzah I can toggle the LED using led.ON or led.OFF. How can this command be sent from the dashboard?

Best regards,

Chris

User avatar
Mike Teachman
Posts: 155
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: Sending temperature data to....somwhere

Post by Mike Teachman » Sun Dec 02, 2018 4:35 am

Hi Chris,

That's totally doable. Go to the Adafruit IO home, then create a new Feed, called say "switch". Then, open a Dashboard, create a new Toggle block and associate that block to the feed "switch". Next, in MicroPython, subscribe to the feed "switch". MQTT will update value of that feed each time the Toggle block on the dashboard changes value. You can use the value of the feed to control the LED.

It's possible to bring in an analog value as well, using the Slider block. Or, the Text block can bring in dashboard text via MQTT. I haven't tried out the Momentary push button.

Hope that works ... Mike

Post Reply