|
1 year ago | |
---|---|---|
docker | 1 year ago | |
include | 1 year ago | |
lib | 1 year ago | |
src | 1 year ago | |
test | 1 year ago | |
.gitignore | 1 year ago | |
README.md | 1 year ago | |
history.txt | 1 year ago | |
platformio.ini | 1 year ago |
This repo holds the code needed to program an relay controlled by an esp microcontroller.
The code is developed using the PlatformIO framework.
To be able to run you must fill the file consts.h
with the following contents
#ifndef _CONSTS_H
#define _CONSTS_H
#define MQTT_PORT <mqtt_port>
#define MQTT_SERVER "<mqtt_hostname>"
#define WIFI_SSID "<wifi_ssid>"
#define WIFI_PASSWORD "<wifi_password>"
#define MQTT_TOPIC_COMMANDS "<mqtt_topic_commands>"
#define MQTT_TOPIC_RESPONSES "<mqtt_topic_responses>"
#define DELAY_STEP 1000
#define RECONNECT_DELAY 2000
#define SERIAL_FREQ 115200
#endif
After the custom configuration entries are setup you must install platformIO to be able to compile the code and upload into the esp32
# Download libraries defined in platformio.ini
pio lib install
# Check the libraries were installed
pio lib list
# Compile the code
pio run
# Upload the code
pio run -t upload
# Monitor via serial port
pio run -t monitor
You need to follow the documentation and connect the FTDI Controller (I personally use this one) to the onboard esp.
If all went ok you should be able to see logs via dmesg
[ +0,003234] ftdi_sio 2-2:1.0: FTDI USB Serial Device converter detected
[ +0,000068] usb 2-2: Detected FT232RL
[ +0,001370] usb 2-2: FTDI USB Serial Device converter now attached to ttyUSB0
Before upload the code into the microcontroller we need to ensure that we have a mqtt broker running. For this we run the command docker/start-mosquitto.sh
.