OTA Weather data broadcasting by continous Essid renaming with ESP32 and Micropython

This tutorial is part of multiple use cases collected on the main article.

Nicola Guglielmi
3 min readJan 9, 2020

In the last day I was wondering how I can use an ESP32 and a BME280 sensor to read data and broadcast in a local area.

I began thinking about the possibility to just broadcast the values I’m reading from the sensors as the name of a Wireless network and this article is born.

You need just an ESP32 board and a sensor of your choice, I’m using the BME280. (If you like you can make a POC with the ESP32 internal temperature reader)

First of all you need to flash the board with Micropython, if you don’t know how to do, please check the first part of this tutorial and come back after flashing it to the board:

Flashing Micropython

Now you should have Micropython flashed on the board, you can go on wiring the sensor.

Wire up your board, for mine I used the pin 21 and 22 that are the one of I2C bus, connected to SDA and SDL on the board, plus GDN and VIN.

Wiring details:

Wiring details

Just few lines of code, you need to download the bme280 lib from here:

Download from here

and upload it to the board with the usual commands:

ampy -p COM5 put BME280.py

Now it’s the time to write the script bmessid.py:

#An idea to broadcast some weather data as a wifi essid
import machine
import BME280
import time
import network
#set the rate of data refresh, in seconds
refreshtime=60
# ESP32 - Pin assignment
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21), freq=10000)
#setup wireles interface
ap_if = network.WLAN(network.AP_IF)
while True:
bme = BME280.BME280(i2c=i2c)
temp = bme.temperature
humi = bme.humidity
pres = bme.pressure
print("_____________________")
print("Temperature :",temp)
print("Humidity :",humi)
print("Pressure :",pres)
print("_____________________")
essid='Temp:'+temp+" Humi:"+humi+" Pres:"+pres
ap_if.config(essid=essid, authmode=network.AUTH_WPA_WPA2_PSK, password='some random char 12345678900000**')
ap_if.active(True)
time.sleep(60)

You can download the sources from the Git repository:

https://github.com/nicolaguglielmi/continuous-essid-renaming/

and upload it to the board with the usual commands (renaming it on upload to main.py, will autostart the script each time the board starts) :

ampy -p COM5 put bmessid.py main.py

Rename it main.py to let the script to autostart each time the board boots…

…and your ESP32 is broadcasting weather data through the wifi.

You will see the data changing each 60 seconds plus some extra for the wifi scan timing of the device.

You can easily create a set of sensor for various scenarios and broadcast weather data nearby…like this example

--

--

Nicola Guglielmi

Google Cloud Architect & Authorized Trainer • Team Manager • Community Leader