From Lolly's Wiki
Revision as of 15:19, 15 April 2024 by Lollypop (talk | contribs) (→‎ESP32 WROOM32)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This is about ESP32 and ESP8622 microcontrollers

Flash the firmware

Saviour of the universe!

$ sudo apt install --yes esptool
$ wget
$ esptool --port /dev/ttyUSB0 --baud 115200 write_flash 0 ESP_Easy_mega_20200516_test_beta_ESP8266_4M1M.bin v2.8
Serial port /dev/ttyUSB0
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 3c:71:bf:2a:a6:0b
Enabling default SPI flash mode...
Configuring flash size...
Auto-detected Flash size: 4MB
Erasing flash...
Took 2.33s to erase flash block
Writing at 0x000dbc00... (87 %)


$ esptool --port /dev/ttyUSB1 --baud 512000 write_flash -fs 4MB -fm dout 0x0 bin/ESP_Easy_mega_20240414_collection_A_ESP32_4M316k.factory.bin

Connect via Serial

$ minicom -D /dev/ttyUSB0 --baudrate 115200
Welcome to minicom 2.8

Port /dev/ttyUSB0, 10:28:08

Press CTRL-A Z for help on special keys

Posssible commands via serial connection

You do not see what you type until you hit enter, then you will see the command you have entered and the result, like:



You can find all commands here: ESPEasy/docs/source/Plugin/P000_commands.repl.
This is just a subset:

Get the Allowed IP range

  • AccessInfo

Get the build number

  • Build

Clear allowed IP range for the web interface for the current session

  • ClearAccessBlock

Clear the password of the unit

  • ClearPassword

Get or set the date and time

  • Datetime[,YYYY-MM-DD[,hh:mm:ss]]

Get or set DNS configuration

  • DNS[,<IP address>]

Get or set serial port debug level

  • Debug[,<1-4, default is 2>]

Get or set the gateway configuration

  • Gateway[,<IP address>]

Run I2C scanner to find connected I2C chips. Output will be sent to the serial port

  • I2Cscanner

Get or set IP address

  • IP[,<IP address>]

Set the password of the unit

  • Password <mypassword>


  • Reboot

Reset config to factory default. Caution, all settings will be lost!

Be careful! Do you want this? This deletes the whole configuration but not the Firmware.

  • Reset

Save config to persistent flash memory

  • Save

Show settings on serial terminal

  • Settings


  • TimeZone[,<minutes from UTC>]

Get or set the status of NTP (Network Time Protocol)

  • UseNTP[,<0/1>]

Configure your local wifi credentials

  • WifiSSID <myssid>
  • WifiKey <mypassword>
  • WifiConnect



Configure MQTT connection to the broker like this:

  • Click on Add
  • Choose Type openHAB
  • Enter your parameters like this where in this example is the server your MQTT broker is running at.


Now you need to listen on MQTT events. For that you need to configure a Generic - MQTT Import device:

  • Click on Add
  • Choose Type Generic MQTT Import
  • Enter your parameters like this where MQTT is the event name for the #Rules and MQTT Topic n are the topics you listen at.


Switch relays based on MQTT events

On my relay board ESP12F_Relay_X4 I configured #MQTT and use rules to switch the 4 relays.

on system#boot do
  let,1,15                               // Relay 1 is GPIO15
  let,2,14                               // Relay 2 is GPIO14
  let,3,12                               // Relay 3 is GPIO12
  let,4,13                               // Relay 4 is GPIO13

on MQTT#Relay* do
  if %eventvalue1%<0                   
    // Values below 0 sets timer to %eventvalue1%*-1 seconds
    logentry,"%eventname%: Turn on {substring:5:11:%eventname%} (GPIO%v{substring:10:11:%eventname%}%) for %v5% seconds."
  elseif %eventvalue1%=1
    // Value equal 1 turn on relay
    logentry,"%eventname%: Turn on {substring:5:11:%eventname%} (GPIO%v{substring:10:11:%eventname%}%)."
  elseif %eventvalue1%=0
    // Value equal 0 turn off relay
    logentry,"%eventname%: Turn off {substring:5:11:%eventname%} (GPIO%v{substring:10:11:%eventname%}%)."

on Cron#Relay4 do
  logentry,"%eventname%: Turn on Relay4."

on Rules#Timer do
  logentry,"%eventname%: %eventvalue1% GPIO%v%eventvalue1%%"


interface 0 claimed by ch341 while 'brltty' sets config #1

Oct  9 14:40:06 lollybook kernel: [372389.769039] usb 3-1.4.3: ch341-uart converter now attached to ttyUSB0
Oct  9 14:40:07 lollybook kernel: [372390.769995] usb 3-1.4.3: usbfs: interface 0 claimed by ch341 while 'brltty' sets config #1
Oct  9 14:40:07 lollybook kernel: [372390.771187] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
Oct  9 14:40:07 lollybook kernel: [372390.771258] ch341 3-1.4.3:1.0: device disconnected

I found this:

for f in /usr/lib/udev/rules.d/*brltty*.rules; do
    sudo ln -s /dev/null "/etc/udev/rules.d/$(basename "$f")"
sudo udevadm control --reload-rules

But I also had to disable the brltty-udev.service

$ sudo systemctl stop brltty-udev.service
$ sudo systemctl mask brltty-udev.service
Created symlink /etc/systemd/system/brltty-udev.service → /dev/null.

After disabling brltty I finally got:

Oct  9 14:41:30 lollybook kernel: [372473.985072] ch341 3-1.4.3:1.0: ch341-uart converter detected
Oct  9 14:41:30 lollybook kernel: [372473.987063] usb 3-1.4.3: ch341-uart converter now attached to ttyUSB0