ESPEasy
From Lolly's Wiki
Jump to navigationJump to search
This is about ESP32 and ESP8622 microcontrollers
Flash the firmware
Flash!
Ah-ah
Saviour of the universe!
$ sudo apt install --yes esptool
$ wget https://github.com/letscontrolit/ESPEasy/releases/download/mega-20200515/ESPEasy_mega-20200515.zip
$ esptool --port /dev/ttyUSB0 --baud 115200 write_flash 0 ESP_Easy_mega_20200516_test_beta_ESP8266_4M1M.bin
esptool.py v2.8
Serial port /dev/ttyUSB0
Connecting...
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 %)
ESP32 WROOM32
$ 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
OPTIONS: I18n
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:
>Save
OK
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
- 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
- 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
MQTT
Controller
Configure MQTT connection to the broker like this:
- Click on Add
- Choose Type openHAB
- Enter your parameters like this where banana1.fritz.box in this example is the server your MQTT broker is running at.
Device
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.
Rules
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
endon
on MQTT#Relay* do
if %eventvalue1%<0
//
// Values below 0 sets timer to %eventvalue1%*-1 seconds
//
let,5,abs(%eventvalue1%)
logentry,"%eventname%: Turn on {substring:5:11:%eventname%} (GPIO%v{substring:10:11:%eventname%}%) for %v5% seconds."
timerSet,{substring:10:11:%eventname%},%v5%
gpio,%v{substring:10:11:%eventname%}%,1
elseif %eventvalue1%=1
//
// Value equal 1 turn on relay
//
logentry,"%eventname%: Turn on {substring:5:11:%eventname%} (GPIO%v{substring:10:11:%eventname%}%)."
gpio,%v{substring:10:11:%eventname%}%,1
elseif %eventvalue1%=0
//
// Value equal 0 turn off relay
//
logentry,"%eventname%: Turn off {substring:5:11:%eventname%} (GPIO%v{substring:10:11:%eventname%}%)."
timerSet,{substring:10:11:%eventname%},0
gpio,%v{substring:10:11:%eventname%}%,0
endif
endon
on Cron#Relay4 do
logentry,"%eventname%: Turn on Relay4."
gpio,%v4%,1
timerSet,4,30
endon
on Rules#Timer do
logentry,"%eventname%: %eventvalue1% GPIO%v%eventvalue1%%"
gpio,%v%eventvalue1%%,0
endon
Problems
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")"
done
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