Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
0.6.3
Browse files Browse the repository at this point in the history
- Add support for DS18B20 sensor. Works only on TTGO using GPIO 33. Shows in web browser
    and sends via MQTT with AutoDiscovery. Works only when the sensor is connected.

- Number of active socket clients reduced to 5 to avoid hangs. Maybe #10

- Number of active socket clients now sends via MQTT with auto-discovery. Using MQTT Refresh Interval. #9

- Automatically reconnect to a Wi-Fi hotspot after being disconnected, but you still need
    the hotspot to be available during the gateway reboot, otherwise it will start its own hotspot. #8

- Add a checkbox to disable emergency mode in Wi-Fi settings. #11

0.6.2

- Set MQTT reconnect interval same as MQTT update interval to avoid web server freezing,
    while broker is unavailable.

- Added web authentication. Issue #4
    Set to OFF by default, enable on general settings page.

- Blocking saving an empty hostname, login and password to the web interface.
    Replaced with standard values ( ZigStarGM / admin / admin )
  • Loading branch information
xyzroe committed Jan 30, 2022
1 parent 124e9e9 commit 542995c
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 56 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
.gcc-flags.json
.clang_complete
bin
commit
commit
todo
29 changes: 17 additions & 12 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = prod

[env]
framework = arduino

platform = espressif32

lib_deps =
lib_deps =
bblanchon/ArduinoJson@^6.18.3
lorol/LittleFS_esp32@^1.0.6
rlogiacco/CircularBuffer@^1.3.3
plerup/EspSoftwareSerial@^6.13.2
knolleary/PubSubClient@^2.8
marian-craciunescu/ESP32Ping@^1.7

milesburton/DallasTemperature@^3.9.1
robtillaart/DS18B20@^0.1.11
board = esp32dev
board_build.partitions = min_spiffs.csv

monitor_filters = esp32_exception_decoder
monitor_speed = 115200


[env:prod]
build_flags =
${env.build_flags}
-D=${PIOENV}

${env.build_flags}
-D=${PIOENV}
extra_scripts =
pre:tools/version_increment_pre.py
post:tools/build.py

[env:debug]
build_flags =
${env.build_flags}
-D=${PIOENV}
${env.build_flags}
-D=${PIOENV}
-DDEBUG

extra_scripts =
pre:tools/version_increment_pre.py
post:tools/debug_build.py
4 changes: 2 additions & 2 deletions src/Version.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

// AUTO GENERATED FILE, DO NOT EDIT
#ifndef VERSION
#define VERSION "0.6.2"
#define VERSION "0.6.3"
#endif
#ifndef BUILD_TIMESTAMP
#define BUILD_TIMESTAMP "2021-10-31 03:56:11.081030"
#define BUILD_TIMESTAMP "2021-10-31 17:59:39.672556"
#endif

7 changes: 5 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define ETH_MDC_PIN_2 23
#define ETH_MDIO_PIN_2 18
//ZIGBEE
#define RESTART_ZIGBEE_2 12
#define RESTART_ZIGBEE_2 16
#define FLASH_ZIGBEE_2 32
#define ZRXD_2 36
#define ZTXD_2 4
Expand All @@ -51,14 +51,16 @@
#define PRODUCTION 1
#define FLASH 0

#define MAX_SOCKET_CLIENTS 10
#define MAX_SOCKET_CLIENTS 5
#define BAUD_RATE 38400
#define TCP_LISTEN_PORT 9999

#define ETH_ERROR_TIME 30

#define FORMAT_LITTLEFS_IF_FAILED true

#define ONE_WIRE_BUS 33

struct ConfigSettingsStruct
{
bool enableWiFi;
Expand Down Expand Up @@ -104,6 +106,7 @@ struct ConfigSettingsStruct
bool webAuth;
char webUser[50];
char webPass[50];
bool disableEmerg;
};

struct InfosStruct
Expand Down
31 changes: 31 additions & 0 deletions src/etc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,39 @@
#include "mqtt.h"
#include "web.h"

#include <OneWire.h>
#include <DallasTemperature.h>
#include <DS18B20.h>

OneWire oneWire(ONE_WIRE_BUS);

DS18B20 sensor(&oneWire);

extern struct ConfigSettingsStruct ConfigSettings;

void oneWireBegin()
{
DEBUG_PRINTLN(F("oneWire begin"));
sensor.begin();
}

void oneWireRead(String &DStemp)
{
sensor.requestTemperatures();
float tempC = sensor.getTempC();
DEBUG_PRINTLN(tempC);
if(tempC != DEVICE_DISCONNECTED_C)
{
DEBUG_PRINTLN(F("oneWire OK"));
DStemp = tempC;
}
else
{
DEBUG_PRINTLN(F("oneWire error"));
DStemp = 255;
}
}

void getReadableTime(String &readableTime, unsigned long beginTime)
{
unsigned long currentMillis;
Expand Down
3 changes: 3 additions & 0 deletions src/etc.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ uint8_t temprature_sens_read();
#endif
uint8_t temprature_sens_read();

void oneWireBegin();
void oneWireRead(String &DStemp);

void getCPUtemp(String &CPUtemp);
void getBlankCPUtemp(String &CPUtemp);
//void parse_ip_address(IPAddress &ip, const char *str)
Expand Down
13 changes: 10 additions & 3 deletions src/html.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const char HTTP_WIFI[] PROGMEM =
"<div class='form-group'>"
"<div class='form-check'>"
"<input class='form-check-input' id='wifiEnable' type='checkbox' name='wifiEnable' {{checkedWiFi}}>"
"<label class='form-check-label' for='wifiEnable'>Enable</label>"
"<label class='form-check-label' for='wifiEnable'>Enable Wi-Fi client mode</label>"
"</div>"
"</div>"
"<div class='form-group'>"
Expand All @@ -82,7 +82,7 @@ const char HTTP_WIFI[] PROGMEM =
"</div>"
"<div class='form-group'>"
"<div class='form-check'>"
"<input class='form-check-input' id='dhcpWiFi' type='checkbox' name='dhcpWiFi' {{modeWiFi}}>"
"<input class='form-check-input' id='dhcpWiFi' type='checkbox' name='dhcpWiFi' {{dchp}}>"
"<label class='form-check-label' for='dhcpWiFi'>DHCP</label>"
"</div>"
"</div>"
Expand All @@ -98,6 +98,12 @@ const char HTTP_WIFI[] PROGMEM =
"<label for='gateway'>Gateway</label>"
"<input type='text' class='form-control' id='gateway' name='ipGW' value='{{gw}}'>"
"</div>"
"<div class='form-group'>"
"<div class='form-check'>"
"<input class='form-check-input' id='disableEmerg' type='checkbox' name='disableEmerg' {{checkedDisEmerg}}>"
"<label class='form-check-label' for='disableEmerg'><b>Disable</b> emergency mode (AP)</label>"
"</div>"
"</div>"
"<button type='submit' class='btn btn-primary mb-2' name='save'>Save</button>"
"</form>";

Expand Down Expand Up @@ -219,7 +225,8 @@ const char HTTP_ROOT[] PROGMEM =
"<div id='genConfig'>"
"<strong>Socket : </strong>{{connectedSocket}}"
"<br><strong>Uptime : </strong>{{uptime}}"
"<br><strong>Temperature : </strong>{{deviceTemp}} &deg;C"
"<br><strong>ESP temperature : </strong>{{deviceTemp}} &deg;C"
"{{dsTemp}}"
"<br><strong>FW version : </strong>" VERSION
"<br><strong>Hardware : </strong>{{hwRev}}"
"<br><strong>ESP32 model : </strong>{{espModel}}"
Expand Down
20 changes: 15 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
#include "mqtt.h"
#include <ESP32Ping.h>


// application config
unsigned long timeLog;
ConfigSettingsStruct ConfigSettings;
InfosStruct Infos;
bool configOK = false;
String modeWiFi = "STA";
//String modeWiFi = "STA";

// serial end ethernet buffer size
#define BUFFER_SIZE 256
Expand All @@ -39,6 +40,7 @@ String modeWiFi = "STA";
MDNSResponder mdns;

void mDNS_start();
bool setupSTAWifi();

void saveEmergencyWifi(bool state)
{
Expand Down Expand Up @@ -153,6 +155,10 @@ void WiFiEvent(WiFiEvent_t event)
ConfigSettings.connectedEther = false;
ConfigSettings.disconnectEthTime = millis();
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
DEBUG_PRINTLN(F("WIFI STA DISCONNECTED"));
setupSTAWifi();
break;
default:
break;
}
Expand Down Expand Up @@ -253,7 +259,7 @@ bool loadConfigWifi()
File configFile = LITTLEFS.open(path, FILE_READ);
if (!configFile)
{
String StringConfig = "{\"enableWiFi\":0,\"ssid\":\"\",\"pass\":\"\",\"dhcpWiFi\":1,\"ip\":\"\",\"mask\":\"\",\"gw\":\"\"}";
String StringConfig = "{\"enableWiFi\":0,\"ssid\":\"\",\"pass\":\"\",\"dhcpWiFi\":1,\"ip\":\"\",\"mask\":\"\",\"gw\":\"\",\"disableEmerg\":0}";

writeDefultConfig(path, StringConfig);
}
Expand All @@ -279,6 +285,7 @@ bool loadConfigWifi()
strlcpy(ConfigSettings.ipMaskWiFi, doc["mask"] | "", sizeof(ConfigSettings.ipMaskWiFi));
strlcpy(ConfigSettings.ipGWWiFi, doc["gw"] | "", sizeof(ConfigSettings.ipGWWiFi));
ConfigSettings.enableWiFi = (int)doc["enableWiFi"];
ConfigSettings.disableEmerg = (int)doc["disableEmerg"];

configFile.close();
return true;
Expand Down Expand Up @@ -524,7 +531,7 @@ void enableWifi()
if (!setupSTAWifi())
{
setupWifiAP();
modeWiFi = "AP";
//modeWiFi = "AP";
ConfigSettings.radioModeWiFi = true;
DEBUG_PRINTLN(F("AP"));
}
Expand All @@ -538,7 +545,7 @@ void enableWifi()
{
DEBUG_PRINTLN(F("Error SSID & PASS"));
setupWifiAP();
modeWiFi = "AP";
//modeWiFi = "AP";
DEBUG_PRINTLN(F("AP"));
ConfigSettings.radioModeWiFi = true;
}
Expand Down Expand Up @@ -584,6 +591,8 @@ void setupEthernetAndZigbeeSerial()
DEBUG_PRINT(F("Zigbee serial setup @ "));
DEBUG_PRINTLN(ConfigSettings.serialSpeed);
Serial2.begin(ConfigSettings.serialSpeed, SERIAL_8N1, ZRXD_2, ZTXD_2);

oneWireBegin();
}
else
{
Expand Down Expand Up @@ -799,6 +808,7 @@ void setup(void)
{
mqttConnectSetup();
}

}

WiFiClient client[10];
Expand Down Expand Up @@ -922,7 +932,7 @@ void loop(void)
}
}

if (ConfigSettings.connectedEther == false && ConfigSettings.disconnectEthTime != 0 && ConfigSettings.enableWiFi != 1 && ConfigSettings.emergencyWifi != 1)
if (ConfigSettings.connectedEther == 0 && ConfigSettings.disconnectEthTime != 0 && ConfigSettings.enableWiFi != 1 && ConfigSettings.emergencyWifi != 1 && ConfigSettings.disableEmerg == 0)
{
if ((millis() - ConfigSettings.disconnectEthTime) >= (ETH_ERROR_TIME * 1000))
{
Expand Down
Loading

0 comments on commit 542995c

Please sign in to comment.