Skip to content

Commit

Permalink
Fix some issues with 2.5 (#1565)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed Mar 29, 2019
1 parent 20269fc commit 51703f6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
23 changes: 13 additions & 10 deletions code/espurna/influxdb.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ Copyright (C) 2017-2019 by Xose Pérez <xose dot perez at gmail dot com>
#if INFLUXDB_SUPPORT

#include "ESPAsyncTCP.h"
#include "SyncClient.h"

#include "libs/SyncClientWrap.h"

bool _idb_enabled = false;
SyncClient _idb_client;
SyncClientWrap * _idb_client;

// -----------------------------------------------------------------------------

Expand Down Expand Up @@ -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());
Expand All @@ -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"));
Expand All @@ -112,6 +113,8 @@ bool idbEnabled() {

void idbSetup() {

_idb_client = new SyncClientWrap();

_idbConfigure();

#if WEB_SUPPORT
Expand Down
21 changes: 21 additions & 0 deletions code/espurna/libs/SyncClientWrap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
SyncClientWrap
Temporary wrap to fix https://github.com/me-no-dev/ESPAsyncTCP/issues/109
*/

#pragma once

#include <SyncClient.h>

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; }

};
6 changes: 5 additions & 1 deletion code/espurna/pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

1 comment on commit 51703f6

@mcspr
Copy link
Collaborator

@mcspr mcspr commented on 51703f6 Mar 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already raised this in the xoseperez/NtpClient#2 , but at what point it is a good idea to import library code and modify it to fix the problems? e.g. hypothetical ESPAsyncTCP TLS using new BearSSL lib, where upstream is kinda slow

Please sign in to comment.