diff --git a/code/espurna/influxdb.ino b/code/espurna/influxdb.ino index d177e448..5a3b1422 100644 --- a/code/espurna/influxdb.ino +++ b/code/espurna/influxdb.ino @@ -9,10 +9,11 @@ Copyright (C) 2017-2019 by Xose PĂ©rez #if INFLUXDB_SUPPORT #include "ESPAsyncTCP.h" -#include "SyncClient.h" + +#include "libs/SyncClientWrap.h" bool _idb_enabled = false; -SyncClient _idb_client; +SyncClientWrap * _idb_client; // ----------------------------------------------------------------------------- @@ -66,8 +67,8 @@ bool idbSend(const char * topic, const char * payload) { bool success = false; - _idb_client.setTimeout(2); - if (_idb_client.connect((const char *) host, port)) { + _idb_client->setTimeout(2); + if (_idb_client->connect((const char *) host, (unsigned int) port)) { char data[128]; snprintf(data, sizeof(data), "%s,device=%s value=%s", topic, getSetting("hostname").c_str(), String(payload).c_str()); @@ -79,17 +80,17 @@ bool idbSend(const char * topic, const char * payload) { getSetting("idbUsername", INFLUXDB_USERNAME).c_str(), getSetting("idbPassword", INFLUXDB_PASSWORD).c_str(), host, port, strlen(data), data); - if (_idb_client.printf(request) > 0) { - while (_idb_client.connected() && _idb_client.available() == 0) delay(1); - while (_idb_client.available()) _idb_client.read(); - if (_idb_client.connected()) _idb_client.stop(); + if (_idb_client->printf(request) > 0) { + while (_idb_client->connected() && _idb_client->available() == 0) delay(1); + while (_idb_client->available()) _idb_client->read(); + if (_idb_client->connected()) _idb_client->stop(); success = true; } else { DEBUG_MSG_P(PSTR("[INFLUXDB] Sent failed\n")); } - _idb_client.stop(); - while (_idb_client.connected()) yield(); + _idb_client->stop(); + while (_idb_client->connected()) yield(); } else { DEBUG_MSG_P(PSTR("[INFLUXDB] Connection failed\n")); @@ -112,6 +113,8 @@ bool idbEnabled() { void idbSetup() { + _idb_client = new SyncClientWrap(); + _idbConfigure(); #if WEB_SUPPORT diff --git a/code/espurna/libs/SyncClientWrap.h b/code/espurna/libs/SyncClientWrap.h new file mode 100644 index 00000000..c22d27f9 --- /dev/null +++ b/code/espurna/libs/SyncClientWrap.h @@ -0,0 +1,21 @@ +/* + +SyncClientWrap + +Temporary wrap to fix https://github.com/me-no-dev/ESPAsyncTCP/issues/109 +*/ + +#pragma once + +#include + +class SyncClientWrap: public SyncClient { + + public: + + int connect(const char *host, uint16_t port); + int connect(CONST IPAddress& ip, uint16_t port) { return connect(ip, port); } + bool flush(unsigned int maxWaitMs = 0) { flush(); return true; } + bool stop(unsigned int maxWaitMs = 0) { stop(); return true; } + +}; diff --git a/code/espurna/pwm.c b/code/espurna/pwm.c index b925da8e..b05df7dc 100644 --- a/code/espurna/pwm.c +++ b/code/espurna/pwm.c @@ -391,7 +391,11 @@ pwm_start(void) pwm_state.current_set = pwm_state.next_set = *pwm; pwm_state.current_phase = phases - 1; ETS_FRC1_INTR_ENABLE(); - RTC_REG_WRITE(FRC1_LOAD_ADDRESS, 0); + #if defined(TIMER_REG_WRITE) + TIMER_REG_WRITE(FRC1_LOAD_ADDRESS, 0); + #else + RTC_REG_WRITE(FRC1_LOAD_ADDRESS, 0); + #endif timer->frc1_ctrl = TIMER1_DIVIDE_BY_16 | TIMER1_ENABLE_TIMER; return; }