MicroPython on ESP8266: sending data to ThingSpeak

When you play with new microcontroller, first thing you usually do is driving an LED. That’s a classic “Hello World!” project for microcontrollers. That’s what I did when I was playing first time with ESP8266 and MicroPython. Let’s move on, and implement another classic project — measuring temperature and humidity with DHT22 sensor. But we don’t want to be quiet, so we are going to share this so important data on the Internet. ThingSpeak will help us with it. Let’s add a new warrior to the army of Internet of Shit!

Hardware and circuit: ESP8266 (ESP-07) and DHT22

This project is based on my previous post — Getting started with ESP8266 and MicroPython. Everything what was described there applies here.

  • A switch on GPIO5 which is used to turn on configuration mode which I'll explain below.
  • A switch on GPIO4 which is not used. I added it just in case because I had a unit with two switches.

Starting a Wi-Fi access point on ESP8266

We’re done with hardware, let’s talk about software. I put sources to a repo on https://github.com/artem-smotrakov/yellow-duck

$ git clone https://github.com/artem-smotrakov/yellow-duck
  • When the board starts, it check if config mode switch is on (see is_config_mode function).
  • In case configuration mode is on, the board sets up a Wi-Fi access point, and starts a local web server (see start_access_point and start_local_server functions).
  • When a user connects to this Wi-Fi access point, the web server offers to set SSID and password for Wi-Fi network which should be used then.
  • When a user provides SSID/password, the web server stores it to a configuration file on ESP8266, and reboots the board (see write_wifi_configand reboot functions).
  • At this point, a user should also turn off config mode.
  • After reboot, the board connects to specified Wi-Fi network (see connect_to_wifi function).
  • In case of successful connection, it turns on LD1 (see turn_on_wifi_led function).

Visualizations on ThingSpeak

These charts show temperature and humidity in my room. Here is a public channel for that:


I write about Java, security, electronics and DIY

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store