No description, website, or topics provided.
Python Shell
Switch branches/tags
Nothing to show
Clone or download
Latest commit 6c86a08 Jul 21, 2017
Failed to load latest commit information.
.vscode first commit Jul 18, 2017 test Jul 19, 2017 doco Jul 21, 2017 first commit Jul 18, 2017 first commit Jul 18, 2017 first commit Jul 18, 2017 first commit Jul 18, 2017 doco Jul 21, 2017

Streaming Data from ESP32 using MicroPython and MQTT


uMqtt PiP Packages


ESP32 MicroPython Firmware Flashing Process

See Adafruit MicroPython Flasing How-to Tutorial

Overview of ESP32 flashing process

  1. Install esptool
  2. Erase Flash
  3. Deploy MicroPython Firmware

Install firmware flash tool

On Windows

pip install esptool

On Mac and Linux

sudo pip install esptool

Erasing ESP32 flash --port /dev/ttyUSB0 erase_flash

Flashing ESP32 MicroPython firmware

Download ESP32 Firmware and deploy to ESP32. --chip esp32 --port /dev/ttyUSB0 write_flash 0x0000 firmware.bin

Installing Required MicroPython PIP Packages

Install the following uPip packages. You need to estabish a network connection on the ESP32 board then upip.install the umqtt packages.

import network
import upip

sta_if = network.WLAN(network.STA_IF)
sta_if.connect("Wifi SSID", "Wifi password")


MicroPython and Publish over MQTT

Deploy the and files using the Adafruit ampy package.

See Adafruit MicroPython Tool (ampy) for information on copying files to the ESP32.

pip install adafruit-ampy

ampy --port /dev/ttyUSB0 put
ampy --port /dev/ttyUSB0 put

import network
sta_if = network.WLAN(network.STA_IF)
sta_if.connect("Wifi SSID", "Wifi password")

from umqtt.robust import MQTTClient
import machine
import utime as time
import gc
import bme280

# Wifi connect established in the file. Uncomment if needed
# import network
# sta_if = network.WLAN(network.STA_IF)
# sta_if.connect("NCW", "malolos5459")

client = MQTTClient("esp32-01", "")
pin5 = machine.Pin(5, machine.Pin.OUT)

i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
bme = bme280.BME280(i2c=i2c)

def checkwifi():
    while not sta_if.isconnected():

def publish():
    count = 1
    while True:
        v = bme.values
        msg = b'{"MsgId":%u,"Mem":%u,"Celsius":%s,"Pressure":%s,"Humidity":%s}' % (count, gc.mem_free(), v[0][:-1], v[1][:-3], v[2][:-1])
        client.publish(b"home/weather", msg)
        count = count + 1



Connecting to ESP32 with Putty

Install Putty for your platform. Connect at 115200 baud rate

See Adafruit Serial REPL Tutorial.