OTA ticket queue system management by broadcasting continuous Essid renaming, build up 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 weeks I was thinking about several use cases that will demonstrate the effectiveness of the main idea I exposed here.

One of those is a device that let you to broadcast the current number of a queue ticket system by using the continuous essid renaming technique.

This tutorial will require an ESP32 board (I used also a ESP8266 for testing purposes) , wiring a pair of buttons and upload some code to the board.

First of all you need to flash the board with Micropython, if you don’t know how to do it, 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 and you can proceed wiring the buttons, it should be pretty easy, just connect the ground and two buttons on Pin 0 and on Pin 12.

Super easy! I imagined this setup because you can pack it in a really small case, with just two button and a battery inside and it is ready to be used in production.

The board I used has an integrated OLED, if your board has no display, please change the line

use_display=True

to

use_display=False

It’s the coding time:

#a POC of  queue manager with two button to increment and decrement #the current value and broadcast it by wifiimport machine
from machine import I2C, Pin
import time
import network
#set to True to enable a display, False to disable it
use_display=True
if use_display:
#display setup, i have a 128x32 oled on this board, tune the values to your display
import ssd1306
rst = Pin(16, Pin.OUT)
rst.value(1)
scl = Pin(5, Pin.OUT, Pin.PULL_UP)
sda = Pin(4, Pin.OUT, Pin.PULL_UP)
i2c = I2C(scl=scl, sda=sda, freq=450000)
oled = ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x3c)
#service function to redraw a display with a string
def draw_display(text):
if use_display:
oled.fill(0)
oled.text(str(text),5,15)
oled.show()
else:
print('You are at:', counter)
#service function to generate the network name
def essid_rename(actual_counter):
essid=essid_base+str(actual_counter)
ap_if.config(essid=essid, authmode=network.AUTH_WPA_WPA2_PSK, password='some random char 12345678900000**')
ap_if.active(True)
#setup the button up to pin 12
button_up = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP)
#setup the button down to pin 0
button_down = machine.Pin(0, machine.Pin.IN, machine.Pin.PULL_UP)
#seconds of sleep between consecutive button press, to avoid multiple readings
button_pause=0.1
#counter value
counter=0
#combo button status, to avoid increment and decrement counter after a combo pressure
combo=False
#setup wireles interface
ap_if = network.WLAN(network.AP_IF)
#configure a string for the essid base name
essid_base="It's the turn of:"
#just clean the oled
draw_display("Press a button")
print("Press a button...")
#let's start an infinite loop to keep checking the status of the buttons
while True:
#reset function, pressing both buttons will reset the counter to 0
if not button_up.value() and not button_down.value():
print('Combo Button pressed!', counter)
counter=0
combo=True
draw_display('Reset complete')
time.sleep(2)
draw_display('We serve:'+str(counter))
essid_rename(counter)
if not button_up.value() and not combo:#up button counter
counter+=1
print('Button up pressed!', counter)
draw_display('We serve:'+str(counter))
essid_rename(counter)
time.sleep(button_pause)
if not button_down.value() and not combo:#down button counter plus negative number check
if counter>0:
counter-=1
else:
counter=0
print('Button down pressed!', counter)
draw_display('We serve:'+str(counter))
essid_rename(counter)
time.sleep(button_pause)
#reset combo button status
combo=False

You can download the sources from the usual Git repository:

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

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 queue-manager.py main.py

And your messages broadcaster is ready to go!

--

--

Nicola Guglielmi

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