Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
lib_deps =
https://github.com/tzapu/WiFiManager.git
https://github.com/me-no-dev/ESPAsyncWebServer.git
https://github.com/LennartHennigs/Button2.git
miq19/eModbus @ ^1.7.0
monitor_speed = 115200


[env:esp32release]
board = esp32dev
build_flags =
board = esp32dev
build_flags = -DWIFI_RST_BUTTON_PIN=0

[env:esp32debug]
board = esp32dev
build_flags = -DLOG_LEVEL=LOG_LEVEL_DEBUG
build_flags = -DLOG_LEVEL=LOG_LEVEL_DEBUG -DWIFI_RST_BUTTON_PIN=0

[env:olimex-poe]
board = esp32-poe
Expand Down
44 changes: 43 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,56 @@
#include <ModbusClientRTU.h>
#include "config.h"
#include "pages.h"
#include "Button2.h"



AsyncWebServer webServer(80);
Config config;
Preferences prefs;
ModbusClientRTU *MBclient;
ModbusBridgeWiFi MBbridge;
WiFiManager wm;
#if defined(WIFI_RST_BUTTON_PIN)
Button2 wifiButton;
#endif

// select which pin will trigger the configuration portal when set to LOW

const int timeout = 120; // seconds to run for
#ifndef LONG_PRESS_TIME
#define LONG_PRESS_TIME 3000 // 4000 milliseconds
#endif


void onLongClick(Button2 &btn){

// set configportal timeout
wm.setConfigPortalTimeout(timeout);

if (!wm.startConfigPortal()) {
dbgln("failed to connect and hit timeout");
delay(1000);
//reset and try again, or maybe put it to deep sleep
ESP.restart();
}

//if you get here you have connected to the WiFi
dbgln("connected to wifi...");
}



void setup() {
debugSerial.begin(115200);
dbgln();
dbgln("[config] load")
prefs.begin("modbusRtuGw");
#if defined(WIFI_RST_BUTTON_PIN)
wifiButton.begin(WIFI_RST_BUTTON_PIN);
wifiButton.setLongClickDetectedHandler( &onLongClick);
wifiButton.setLongClickTime(LONG_PRESS_TIME);
#endif
config.begin(&prefs);
debugSerial.end();
debugSerial.begin(config.getSerialBaudRate(), config.getSerialConfig());
Expand Down Expand Up @@ -55,6 +92,11 @@ void setup() {
dbgln("[setup] finished");
}




void loop() {
// put your main code here, to run repeatedly:
#if defined(WIFI_RST_BUTTON_PIN)
wifiButton.loop();
#endif
}