mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
fetch devices one by one
This commit is contained in:
@@ -1413,6 +1413,28 @@ void EMSESP::start() {
|
|||||||
webServer.begin(); // start the web server
|
webServer.begin(); // start the web server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fetch devices one by one
|
||||||
|
void EMSESP::scheduled_fetch_values() {
|
||||||
|
static uint8_t no = 0;
|
||||||
|
if (no || (uuid::get_uptime() - last_fetch_ > EMS_FETCH_FREQUENCY)) {
|
||||||
|
if (!no) {
|
||||||
|
last_fetch_ = uuid::get_uptime();
|
||||||
|
no = 1;
|
||||||
|
}
|
||||||
|
if (txservice_.tx_queue_empty()) {
|
||||||
|
uint8_t i = 0;
|
||||||
|
for (const auto & emsdevice : emsdevices) {
|
||||||
|
if (emsdevice && ++i >= no) {
|
||||||
|
emsdevice->fetch_values();
|
||||||
|
no++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
no = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// main loop calling all services
|
// main loop calling all services
|
||||||
void EMSESP::loop() {
|
void EMSESP::loop() {
|
||||||
esp8266React.loop(); // web services
|
esp8266React.loop(); // web services
|
||||||
@@ -1429,10 +1451,7 @@ void EMSESP::loop() {
|
|||||||
mqtt_.loop(); // sends out anything in the MQTT queue
|
mqtt_.loop(); // sends out anything in the MQTT queue
|
||||||
|
|
||||||
// force a query on the EMS devices to fetch latest data at a set interval (1 min)
|
// force a query on the EMS devices to fetch latest data at a set interval (1 min)
|
||||||
if ((uuid::get_uptime() - last_fetch_ > EMS_FETCH_FREQUENCY)) {
|
scheduled_fetch_values();
|
||||||
last_fetch_ = uuid::get_uptime();
|
|
||||||
fetch_device_values();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console_.loop(); // telnet/serial console
|
console_.loop(); // telnet/serial console
|
||||||
|
|||||||
@@ -206,6 +206,7 @@ class EMSESP {
|
|||||||
static void fetch_device_values(const uint8_t device_id = 0);
|
static void fetch_device_values(const uint8_t device_id = 0);
|
||||||
static void fetch_device_values_type(const uint8_t device_type);
|
static void fetch_device_values_type(const uint8_t device_type);
|
||||||
static bool valid_device(const uint8_t device_id);
|
static bool valid_device(const uint8_t device_id);
|
||||||
|
static void scheduled_fetch_values();
|
||||||
|
|
||||||
static bool add_device(const uint8_t device_id, const uint8_t product_id, const char * version, const uint8_t brand);
|
static bool add_device(const uint8_t device_id, const uint8_t product_id, const char * version, const uint8_t brand);
|
||||||
static void scan_devices();
|
static void scan_devices();
|
||||||
|
|||||||
@@ -399,6 +399,10 @@ class TxService : public EMSbus {
|
|||||||
return tx_telegrams_;
|
return tx_telegrams_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool tx_queue_empty() {
|
||||||
|
return tx_telegrams_.size() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_DEBUG)
|
||||||
static constexpr uint8_t MAXIMUM_TX_RETRIES = 0; // when compiled with EMSESP_DEBUG don't retry
|
static constexpr uint8_t MAXIMUM_TX_RETRIES = 0; // when compiled with EMSESP_DEBUG don't retry
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in New Issue
Block a user