Merge branch 'v2_web' of https://github.com/proddy/EMS-ESP into web

This commit is contained in:
MichaelDvP
2020-07-07 06:18:48 +02:00
19 changed files with 402 additions and 48 deletions

View File

@@ -0,0 +1,36 @@
#include "EMSESPDevicesService.h"
#include "emsesp.h"
#include "mqtt.h"
namespace emsesp {
EMSESPDevicesService::EMSESPDevicesService(AsyncWebServer * server, SecurityManager * securityManager) {
server->on(EMSESP_DEVICES_SERVICE_PATH,
HTTP_GET,
securityManager->wrapRequest(std::bind(&EMSESPDevicesService::emsespDevicesService, this, std::placeholders::_1),
AuthenticationPredicates::IS_AUTHENTICATED));
}
void EMSESPDevicesService::emsespDevicesService(AsyncWebServerRequest * request) {
AsyncJsonResponse * response = new AsyncJsonResponse(false, MAX_EMSESP_STATUS_SIZE);
JsonObject root = response->getRoot();
JsonArray devices = root.createNestedArray("devices");
for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice) {
JsonObject deviceRoot = devices.createNestedObject();
deviceRoot["type"] = emsdevice->device_type_name();
deviceRoot["brand"] = emsdevice->brand_to_string();
deviceRoot["name"] = emsdevice->name();
deviceRoot["deviceid"] = emsdevice->device_id();
deviceRoot["productid"] = emsdevice->product_id();
deviceRoot["version"] = emsdevice->version();
}
response->setLength();
request->send(response);
}
}
} // namespace emsesp

View File

@@ -0,0 +1,30 @@
#ifndef EMSESPDevicesService_h
#define EMSESPDevicesService_h
#include <ArduinoJson.h>
#include <AsyncJson.h>
#include <ESPAsyncWebServer.h>
#include <SecurityManager.h>
// #include <HttpEndpoint.h>
// #include <MqttPubSub.h>
// #include <WebSocketTxRx.h>
#include "version.h"
#define MAX_EMSESP_STATUS_SIZE 1024
#define EMSESP_DEVICES_SERVICE_PATH "/rest/emsespDevices"
namespace emsesp {
class EMSESPDevicesService {
public:
EMSESPDevicesService(AsyncWebServer * server, SecurityManager * securityManager);
private:
void emsespDevicesService(AsyncWebServerRequest * request);
};
} // namespace emsesp
#endif

View File

@@ -0,0 +1,20 @@
#include <EMSESPScanDevicesService.h>
#include "emsesp.h"
namespace emsesp {
EMSESPScanDevicesService::EMSESPScanDevicesService(AsyncWebServer * server, SecurityManager * securityManager) {
server->on(SCAN_DEVICES_SERVICE_PATH,
HTTP_POST,
securityManager->wrapRequest(std::bind(&EMSESPScanDevicesService::scan_devices, this, std::placeholders::_1), AuthenticationPredicates::IS_ADMIN));
}
void EMSESPScanDevicesService::scan_devices(AsyncWebServerRequest * request) {
request->onDisconnect([]() {
EMSESP::send_read_request(EMSdevice::EMS_TYPE_UBADevices, EMSdevice::EMS_DEVICE_ID_BOILER);
});
request->send(200);
}
} // namespace emsesp

View File

@@ -0,0 +1,21 @@
#ifndef EMSESPScanDevicesService_h
#define EMSESPScanDevicesService_h
#include <ESPAsyncWebServer.h>
#include <SecurityManager.h>
#define SCAN_DEVICES_SERVICE_PATH "/rest/scanDevices"
namespace emsesp {
class EMSESPScanDevicesService {
public:
EMSESPScanDevicesService(AsyncWebServer * server, SecurityManager * securityManager);
private:
void scan_devices(AsyncWebServerRequest * request);
};
} // namespace emsesp
#endif

View File

@@ -1,6 +1,7 @@
#include "EMSESPStatusService.h"
#include "emsesp.h"
#include "mqtt.h"
#include "version.h"
namespace emsesp {

View File

@@ -5,14 +5,7 @@
#include <AsyncJson.h>
#include <ESPAsyncWebServer.h>
#include <SecurityManager.h>
#include <HttpEndpoint.h>
#include <MqttPubSub.h>
#include <WebSocketTxRx.h>
#include "EMSESPSettingsService.h"
#include "version.h"
#include <AsyncMqttClient.h>
#define MAX_EMSESP_STATUS_SIZE 1024
#define EMSESP_STATUS_SERVICE_PATH "/rest/emsespStatus"
@@ -24,9 +17,8 @@ class EMSESPStatusService {
EMSESPStatusService(AsyncWebServer * server, SecurityManager * securityManager, AsyncMqttClient * mqttClient);
private:
EMSESPSettingsService * _emsespSettingsService;
void emsespStatusService(AsyncWebServerRequest * request);
AsyncMqttClient * _mqttClient;
void emsespStatusService(AsyncWebServerRequest * request);
AsyncMqttClient * _mqttClient;
void init_mqtt();
};

View File

@@ -47,20 +47,6 @@ EMSESPShell::EMSESPShell()
void EMSESPShell::started() {
logger().log(LogLevel::INFO, LogFacility::CONSOLE, F("User session opened on console %s"), console_name().c_str());
// set console name
EMSESP::esp8266React.getWiFiSettingsService()->read([&](WiFiSettings & wifiSettings) { console_hostname_ = wifiSettings.hostname.c_str(); });
if (console_hostname_.empty()) {
console_hostname_.resize(16, '\0');
#if defined(ESP8266)
snprintf_P(&console_hostname_[0], console_hostname_.capacity() + 1, PSTR("esp8266"));
#else
snprintf_P(&console_hostname_[0], console_hostname_.capacity() + 1, PSTR("esp32"));
#endif
}
}
void EMSESPShell::stopped() {
@@ -76,6 +62,7 @@ void EMSESPShell::stopped() {
}
// show welcome banner
// this is one of the first functions called when the shell is started
void EMSESPShell::display_banner() {
println();
printfln(F("┌──────────────────────────────────────────┐"));
@@ -86,6 +73,18 @@ void EMSESPShell::display_banner() {
printfln(F("└──────────────────────────────────────────┘"));
println();
// set console name
EMSESP::esp8266React.getWiFiSettingsService()->read([&](WiFiSettings & wifiSettings) { console_hostname_ = wifiSettings.hostname.c_str(); });
if (console_hostname_.empty()) {
console_hostname_.resize(16, '\0');
#if defined(ESP8266)
snprintf_P(&console_hostname_[0], console_hostname_.capacity() + 1, PSTR("esp8266"));
#else
snprintf_P(&console_hostname_[0], console_hostname_.capacity() + 1, PSTR("esp32"));
#endif
}
// load the list of commands
add_console_commands();
@@ -197,7 +196,7 @@ void EMSESPShell::add_console_commands() {
if (arguments.size() == 0) {
EMSESP::send_read_request(EMSdevice::EMS_TYPE_UBADevices, EMSdevice::EMS_DEVICE_ID_BOILER);
} else {
shell.printfln(F("Performing a deep scan by pinging our device library..."));
shell.printfln(F("Performing a deep scan..."));
std::vector<uint8_t> Device_Ids;
Device_Ids.push_back(0x08); // Boilers - 0x08

View File

@@ -239,16 +239,18 @@ void Solar::process_SM100Energy(std::shared_ptr<const Telegram> telegram) {
void Solar::process_ISM1StatusMessage(std::shared_ptr<const Telegram> telegram) {
telegram->read_value(collectorTemp_, 4); // Collector Temperature
telegram->read_value(bottomTemp_, 6); // Temperature Bottom of Solar Boiler
uint16_t Wh = 0xFFFF;
telegram->read_value(Wh, 2); // Solar Energy produced in last hour only ushort, is not * 10
if (Wh != 0xFFFF) {
energyLastHour_ = Wh * 10; // set to *10
}
telegram->read_bitvalue(pump_, 8, 0); // Solar pump on (1) or off (0)
telegram->read_value(pumpWorkMin_, 10, 3); // force to 3 bytes
telegram->read_bitvalue(tankHeated_, 9, 2); // issue #422
telegram->read_bitvalue(collectorOnOff_, 9, 0);
telegram->read_bitvalue(collectorOnOff_, 9, 0); // collector on/off
telegram->read_bitvalue(tankHeated_, 9, 2); // tank full
}
/*

View File

@@ -82,6 +82,10 @@ class EMSdevice {
version_ = version;
}
inline std::string version() const {
return version_;
}
inline void brand(uint8_t brand) {
brand_ = brand;
}
@@ -94,6 +98,10 @@ class EMSdevice {
name_ = name;
}
inline std::string name() const {
return name_;
}
std::string brand_to_string() const;
static uint8_t decode_brand(uint8_t value);

View File

@@ -38,6 +38,10 @@ EMSESPSettingsService EMSESP::emsespSettingsService = EMSESPSettingsService(&web
EMSESPStatusService EMSESP::emsespStatusService =
EMSESPStatusService(&webServer, EMSESP::esp8266React.getSecurityManager(), EMSESP::esp8266React.getMqttClient());
EMSESPDevicesService EMSESP::emsespDevicesService = EMSESPDevicesService(&webServer, EMSESP::esp8266React.getSecurityManager());
EMSESPScanDevicesService EMSESP::emsespScanDevicesService = EMSESPScanDevicesService(&webServer, EMSESP::esp8266React.getSecurityManager());
std::vector<std::unique_ptr<EMSdevice>> EMSESP::emsdevices; // array of all the detected EMS devices
std::vector<emsesp::EMSESP::Device_record> EMSESP::device_library_; // libary of all our known EMS devices so far
@@ -60,7 +64,7 @@ bool EMSESP::tap_water_active_ = false; /
uint32_t EMSESP::last_fetch_ = 0;
// for a specific EMS device go and request data values
// or if device_id is 0 it will fetch from all known devices
// or if device_id is 0 it will fetch from all our known and active devices
void EMSESP::fetch_device_values(const uint8_t device_id) {
for (const auto & emsdevice : emsdevices) {
if (emsdevice) {
@@ -103,13 +107,16 @@ void EMSESP::watch_id(uint16_t watch_id) {
}
}
// change the tx_mode
// resets all counters and bumps the UART
void EMSESP::reset_tx(uint8_t const tx_mode) {
txservice_.telegram_read_count(0);
txservice_.telegram_write_count(0);
txservice_.telegram_fail_count(0);
if (tx_mode) {
EMSuart::stop();
EMSuart::start(tx_mode); // reset the UART
EMSuart::start(tx_mode);
EMSESP::fetch_device_values();
}
}

View File

@@ -35,7 +35,9 @@
#include <ESP8266React.h>
#include "EMSESPStatusService.h"
#include "EMSESPDevicesService.h"
#include "EMSESPSettingsService.h"
#include "EMSESPScanDevicesService.h"
#include "emsdevice.h"
#include "emsfactory.h"
@@ -133,6 +135,9 @@ class EMSESP {
static bool add_device(const uint8_t device_id, const uint8_t product_id, std::string & version, const uint8_t brand);
static std::vector<std::unique_ptr<EMSdevice>> emsdevices;
// services
static Mqtt mqtt_;
static System system_;
static Sensors sensors_;
@@ -141,9 +146,12 @@ class EMSESP {
static RxService rxservice_;
static TxService txservice_;
static ESP8266React esp8266React;
static EMSESPSettingsService emsespSettingsService;
static EMSESPStatusService emsespStatusService;
// web controllers
static ESP8266React esp8266React;
static EMSESPSettingsService emsespSettingsService;
static EMSESPStatusService emsespStatusService;
static EMSESPDevicesService emsespDevicesService;
static EMSESPScanDevicesService emsespScanDevicesService;
private:
EMSESP() = delete;
@@ -165,8 +173,7 @@ class EMSESP {
uint8_t flags;
};
static std::vector<std::unique_ptr<EMSdevice>> emsdevices;
static std::vector<Device_record> device_library_;
static std::vector<Device_record> device_library_;
static uint8_t actual_master_thermostat_;
static uint16_t watch_id_;

View File

@@ -1 +1 @@
#define EMSESP_APP_VERSION "2.0.0_b1" // based off b32
#define EMSESP_APP_VERSION "2.0.0_b2" // based off a32