mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 17:29:50 +03:00
support for web server and reset firmware option
This commit is contained in:
@@ -41,7 +41,7 @@ DS18 ds18;
|
||||
Ticker publishValuesTimer;
|
||||
Ticker publishSensorValuesTimer;
|
||||
|
||||
#define SYSTEMCHECK_TIME 10 // every 10 seconds check if EMS can be reached
|
||||
#define SYSTEMCHECK_TIME 30 // every 30 seconds check if EMS can be reached
|
||||
Ticker systemCheckTimer;
|
||||
|
||||
#define REGULARUPDATES_TIME 60 // every minute a call is made to fetch data from EMS devices manually
|
||||
@@ -888,15 +888,15 @@ void do_publishSensorValues() {
|
||||
// call PublishValues without forcing, so using CRC to see if we really need to publish
|
||||
void do_publishValues() {
|
||||
// don't publish if we're not connected to the EMS bus
|
||||
if ((ems_getBusConnected()) && (!myESP.getUseSerial()) && myESP.isMQTTConnected() && EMSESP_Status.publish_time != 0) {
|
||||
if ((ems_getBusConnected()) && myESP.isMQTTConnected() && EMSESP_Status.publish_time != 0) {
|
||||
publishValues(true); // force publish
|
||||
}
|
||||
}
|
||||
|
||||
// callback to light up the LED, called via Ticker every second
|
||||
// fast way is to use WRITE_PERI_REG(PERIPHS_GPIO_BASEADDR + (state ? 4 : 8), (1 << EMSESP_Status.led_gpio)); // 4 is on, 8 is off
|
||||
// when ESP is booting up, ignore this as the LED is being used for something else
|
||||
void do_ledcheck() {
|
||||
if (EMSESP_Status.led) {
|
||||
if ((EMSESP_Status.led) && (myESP.getSystemBootStatus() == MYESP_BOOTSTATUS_BOOTED)) {
|
||||
if (ems_getBusConnected()) {
|
||||
digitalWrite(EMSESP_Status.led_gpio, (EMSESP_Status.led_gpio == LED_BUILTIN) ? LOW : HIGH); // light on. For onboard LED high=off
|
||||
} else {
|
||||
@@ -908,7 +908,7 @@ void do_ledcheck() {
|
||||
|
||||
// Thermostat scan
|
||||
void do_scanThermostat() {
|
||||
if ((ems_getBusConnected()) && (!myESP.getUseSerial())) {
|
||||
if (ems_getBusConnected()) {
|
||||
myDebug_P(PSTR("> Scanning thermostat message type #0x%02X..."), scanThermostat_count);
|
||||
ems_doReadCommand(scanThermostat_count, EMS_Thermostat.device_id);
|
||||
scanThermostat_count++;
|
||||
@@ -917,7 +917,7 @@ void do_scanThermostat() {
|
||||
|
||||
// do a system health check every now and then to see if we all connections
|
||||
void do_systemCheck() {
|
||||
if ((!ems_getBusConnected()) && (!myESP.getUseSerial())) {
|
||||
if (!ems_getBusConnected()) {
|
||||
myDebug_P(PSTR("Error! Unable to read the EMS bus."));
|
||||
}
|
||||
}
|
||||
@@ -925,7 +925,7 @@ void do_systemCheck() {
|
||||
// force calls to get data from EMS for the types that aren't sent as broadcasts
|
||||
// only if we have a EMS connection
|
||||
void do_regularUpdates() {
|
||||
if ((ems_getBusConnected()) && (!myESP.getUseSerial())) {
|
||||
if (ems_getBusConnected()) {
|
||||
myDebugLog("Requesting scheduled EMS device data");
|
||||
ems_getThermostatValues();
|
||||
ems_getBoilerValues();
|
||||
@@ -954,7 +954,7 @@ void do_scanDevices() {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ems_getBusConnected()) && (!myESP.getUseSerial())) {
|
||||
if (ems_getBusConnected()) {
|
||||
ems_doReadCommand(EMS_TYPE_Version, scanDevices_count++); // ask for version
|
||||
}
|
||||
}
|
||||
@@ -1526,6 +1526,40 @@ void MQTTCallback(unsigned int type, const char * topic, const char * message) {
|
||||
}
|
||||
}
|
||||
|
||||
// web information for diagnostics
|
||||
void WebCallback(char * body) {
|
||||
strlcpy(body, "<b>EMS stats:</b><br>", MYESP_MAXCHARBUFFER);
|
||||
|
||||
if (ems_getBusConnected()) {
|
||||
char s[10];
|
||||
strlcat(body, "EMS Bus is connected<br>", MYESP_MAXCHARBUFFER);
|
||||
strlcat(body, "Rx: # successful read requests=", MYESP_MAXCHARBUFFER);
|
||||
strlcat(body, itoa(EMS_Sys_Status.emsRxPgks, s, 10), MYESP_MAXCHARBUFFER);
|
||||
strlcat(body, ", # CRC errors=", MYESP_MAXCHARBUFFER);
|
||||
strlcat(body, itoa(EMS_Sys_Status.emxCrcErr, s, 10), MYESP_MAXCHARBUFFER);
|
||||
if (ems_getTxCapable()) {
|
||||
strlcat(body, "<br>Tx: # successful write requests=", MYESP_MAXCHARBUFFER);
|
||||
strlcat(body, itoa(EMS_Sys_Status.emsTxPkgs, s, 10), MYESP_MAXCHARBUFFER);
|
||||
} else {
|
||||
strlcat(body, "<br>Tx: no signal<br><br>", MYESP_MAXCHARBUFFER);
|
||||
}
|
||||
|
||||
// show device list
|
||||
strlcpy(body, "<b>EMS devices found:</b><br>", MYESP_MAXCHARBUFFER);
|
||||
|
||||
char buffer[MYESP_MAXCHARBUFFER] = {0};
|
||||
uint8_t num_devices = ems_printDevices_s(buffer, MYESP_MAXCHARBUFFER);
|
||||
if (num_devices == 0) {
|
||||
strlcat(body, "no compatible EMS devices detected yet. (wait a few seconds)", MYESP_MAXCHARBUFFER);
|
||||
} else {
|
||||
strlcat(body, buffer, MYESP_MAXCHARBUFFER);
|
||||
}
|
||||
|
||||
} else {
|
||||
strlcat(body, "Unable to establish a connection to the EMS Bus.", MYESP_MAXCHARBUFFER);
|
||||
}
|
||||
}
|
||||
|
||||
// Init callback, which is used to set functions and call methods after a wifi connection has been established
|
||||
void WIFICallback() {
|
||||
// This is where we enable the UART service to scan the incoming serial Tx/Rx bus signals
|
||||
@@ -1641,11 +1675,11 @@ void setup() {
|
||||
// call ems.cpp's init function to set all the internal params
|
||||
ems_init();
|
||||
|
||||
systemCheckTimer.attach(SYSTEMCHECK_TIME, do_systemCheck); // check if Boiler is online
|
||||
systemCheckTimer.attach(SYSTEMCHECK_TIME, do_systemCheck); // check if EMS is reachable
|
||||
|
||||
// set up myESP for Wifi, MQTT, MDNS and Telnet
|
||||
myESP.setTelnet(project_cmds, ArraySize(project_cmds), TelnetCommandCallback, TelnetCallback); // set up Telnet commands
|
||||
myESP.setWIFI(NULL, NULL, WIFICallback);
|
||||
myESP.setWIFI(NULL, NULL, WIFICallback); // empty ssid and password as we take this from the config file
|
||||
|
||||
// MQTT host, username and password taken from the SPIFFS settings
|
||||
myESP.setMQTT(
|
||||
@@ -1657,6 +1691,9 @@ void setup() {
|
||||
// custom settings in SPIFFS
|
||||
myESP.setSettings(FSCallback, SettingsCallback);
|
||||
|
||||
// web custom settings
|
||||
myESP.setWeb(WebCallback);
|
||||
|
||||
// start up all the services
|
||||
myESP.begin(APP_HOSTNAME, APP_NAME, APP_VERSION);
|
||||
|
||||
|
||||
17
src/ems.cpp
17
src/ems.cpp
@@ -2170,6 +2170,23 @@ void ems_printDevices() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* prints the device list to a string for html parsing
|
||||
*/
|
||||
uint8_t ems_printDevices_s(char * buffer, uint16_t len) {
|
||||
if (Devices.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char s[100];
|
||||
for (std::list<_Generic_Type>::iterator it = Devices.begin(); it != Devices.end(); it++) {
|
||||
sprintf(s, "%s (DeviceID:0x%02X ProductID:%d Version:%s)<br>", (it)->model_string, (it)->device_id, (it)->product_id, (it)->version);
|
||||
strlcat(buffer, s, len);
|
||||
}
|
||||
|
||||
return Devices.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a command to UART Tx to Read from another device
|
||||
* Read commands when sent must respond by the destination (target) immediately (or within 10ms)
|
||||
|
||||
25
src/ems.h
25
src/ems.h
@@ -23,9 +23,9 @@
|
||||
|
||||
#define EMS_PRODUCTID_HEATRONICS 95 // ProductID for a Junkers Heatronic3 device
|
||||
|
||||
#define EMS_PRODUCTID_SM10 73 // ProductID for SM10 solar module
|
||||
#define EMS_PRODUCTID_SM10 73 // ProductID for SM10 solar module
|
||||
#define EMS_PRODUCTID_SM100 163 // ProductID for SM10 solar module
|
||||
#define EMS_PRODUCTID_ISM1 101 // ProductID for SM10 solar module
|
||||
#define EMS_PRODUCTID_ISM1 101 // ProductID for SM10 solar module
|
||||
|
||||
|
||||
#define EMS_MIN_TELEGRAM_LENGTH 6 // minimal length for a validation telegram, including CRC
|
||||
@@ -255,12 +255,12 @@ typedef struct { // UBAParameterWW
|
||||
|
||||
// Other ems devices than solar modules, thermostats and boilers
|
||||
typedef struct {
|
||||
bool HP; // set true if there is a Heat Pump available
|
||||
bool HP; // set true if there is a Heat Pump available
|
||||
uint8_t HPModulation; // heatpump modulation in %
|
||||
uint8_t HPSpeed; // speed 0-100 %
|
||||
uint8_t device_id; // the device ID of the Solar Module / Heat Pump (e.g. 0x30)
|
||||
uint8_t model_id; // Solar Module / Heat Pump model (e.g. 3 > EMS_MODEL_OTHER )
|
||||
uint8_t product_id; // (e.g. 101)
|
||||
uint8_t device_id; // the device ID of the Solar Module / Heat Pump (e.g. 0x30)
|
||||
uint8_t model_id; // Solar Module / Heat Pump model (e.g. 3 > EMS_MODEL_OTHER )
|
||||
uint8_t product_id; // (e.g. 101)
|
||||
char version[10];
|
||||
} _EMS_Other;
|
||||
|
||||
@@ -273,8 +273,8 @@ typedef struct {
|
||||
int16_t EnergyLastHour;
|
||||
int16_t EnergyToday;
|
||||
int16_t EnergyTotal;
|
||||
uint8_t device_id; // the device ID of the Solar Module / Heat Pump (e.g. 0x30)
|
||||
uint8_t model_id; // Solar Module / Heat Pump model (e.g. 3 > EMS_MODEL_OTHER )
|
||||
uint8_t device_id; // the device ID of the Solar Module / Heat Pump (e.g. 0x30)
|
||||
uint8_t model_id; // Solar Module / Heat Pump model (e.g. 3 > EMS_MODEL_OTHER )
|
||||
uint8_t product_id; // (e.g. 101)
|
||||
char version[10];
|
||||
} _EMS_SolarModule;
|
||||
@@ -323,6 +323,7 @@ void ems_sendRawTelegram(char * telegram);
|
||||
void ems_scanDevices();
|
||||
void ems_printAllDevices();
|
||||
void ems_printDevices();
|
||||
uint8_t ems_printDevices_s(char * buffer, uint16_t len);
|
||||
void ems_printTxQueue();
|
||||
void ems_testTelegram(uint8_t test_num);
|
||||
void ems_startupTelegrams();
|
||||
@@ -375,8 +376,8 @@ bool _ems_setModel(uint8_t model_id);
|
||||
void _removeTxQueue();
|
||||
|
||||
// global so can referenced in other classes
|
||||
extern _EMS_Sys_Status EMS_Sys_Status;
|
||||
extern _EMS_Boiler EMS_Boiler;
|
||||
extern _EMS_Thermostat EMS_Thermostat;
|
||||
extern _EMS_Sys_Status EMS_Sys_Status;
|
||||
extern _EMS_Boiler EMS_Boiler;
|
||||
extern _EMS_Thermostat EMS_Thermostat;
|
||||
extern _EMS_SolarModule EMS_SolarModule;
|
||||
extern _EMS_Other EMS_Other;
|
||||
extern _EMS_Other EMS_Other;
|
||||
|
||||
@@ -6,5 +6,5 @@
|
||||
#pragma once
|
||||
|
||||
#define APP_NAME "EMS-ESP"
|
||||
#define APP_VERSION "1.8.1b2"
|
||||
#define APP_VERSION "1.8.1b4"
|
||||
#define APP_HOSTNAME "ems-esp"
|
||||
|
||||
Reference in New Issue
Block a user