Browse Source

Merge branch 'dev' into power

fastled
Xose Pérez 7 years ago
parent
commit
6626e7ff67
6 changed files with 43 additions and 19 deletions
  1. +2
    -1
      code/espurna/debug.ino
  2. +9
    -5
      code/espurna/domoticz.ino
  3. +4
    -0
      code/espurna/espurna.ino
  4. +15
    -12
      code/espurna/influxdb.ino
  5. +3
    -1
      code/espurna/mqtt.ino
  6. +10
    -0
      code/espurna/settings.ino

+ 2
- 1
code/espurna/debug.ino View File

@ -194,7 +194,8 @@ void debugDumpCrashInfo() {
EEPROM.get(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_EPC3, epc3);
EEPROM.get(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_EXCVADDR, excvaddr);
EEPROM.get(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_DEPC, depc);
DEBUG_MSG_P(PSTR("[DEBUG] epc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n"), epc1, epc2, epc3, excvaddr, depc);
DEBUG_MSG_P(PSTR("[DEBUG] epc1=0x%08x epc2=0x%08x epc3=0x%08x\n"), epc1, epc2, epc3);
DEBUG_MSG_P(PSTR("[DEBUG] excvaddr=0x%08x depc=0x%08x\n"), excvaddr, depc);
uint32_t stack_start, stack_end;
EEPROM.get(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_STACK_START, stack_start);


+ 9
- 5
code/espurna/domoticz.ino View File

@ -10,7 +10,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
#include <ArduinoJson.h>
bool _dczEnabled = false;
bool _dcz_enabled = false;
//------------------------------------------------------------------------------
// Private methods
@ -35,7 +35,7 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload)
if (type == MQTT_MESSAGE_EVENT) {
if (!_dczEnabled) return;
if (!_dcz_enabled) return;
// Check topic
if (dczTopicOut.equals(topic)) {
@ -68,7 +68,7 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload)
//------------------------------------------------------------------------------
template<typename T> void domoticzSend(const char * key, T nvalue, const char * svalue) {
if (!_dczEnabled) return;
if (!_dcz_enabled) return;
unsigned int idx = getSetting(key).toInt();
if (idx > 0) {
char payload[128];
@ -82,7 +82,7 @@ template<typename T> void domoticzSend(const char * key, T nvalue) {
}
void domoticzSendRelay(unsigned int relayID) {
if (!_dczEnabled) return;
if (!_dcz_enabled) return;
char buffer[15];
snprintf_P(buffer, sizeof(buffer), PSTR("dczRelayIdx%d"), relayID);
domoticzSend(buffer, relayStatus(relayID) ? "1" : "0");
@ -95,7 +95,7 @@ int domoticzIdx(unsigned int relayID) {
}
void domoticzConfigure() {
_dczEnabled = getSetting("dczEnabled", DOMOTICZ_ENABLED).toInt() == 1;
_dcz_enabled = getSetting("dczEnabled", DOMOTICZ_ENABLED).toInt() == 1;
}
void domoticzSetup() {
@ -103,4 +103,8 @@ void domoticzSetup() {
mqttRegister(_domoticzMqtt);
}
bool domoticzEnabled() {
return _dcz_enabled;
}
#endif

+ 4
- 0
code/espurna/espurna.ino View File

@ -198,7 +198,11 @@ void welcome() {
} else {
DEBUG_MSG_P(PSTR("[INIT] Last reset reason: %s\n"), (char *) ESP.getResetReason().c_str());
}
DEBUG_MSG_P(PSTR("[INIT] Free heap: %u bytes\n"), ESP.getFreeHeap());
#if ADC_VCC_ENABLED
DEBUG_MSG_P(PSTR("[INIT] Power: %d mV\n"), ESP.getVcc());
#endif
DEBUG_MSG_P(PSTR("\n"));
}


+ 15
- 12
code/espurna/influxdb.ino View File

@ -11,18 +11,18 @@ Copyright (C) 2017 by Xose Pérez <xose dot perez at gmail dot com>
#include "ESPAsyncTCP.h"
#include "SyncClient.h"
bool influxDBEnabled = false;
SyncClient _influxClient;
bool _influxdb_enabled = false;
SyncClient _influx_client;
template<typename T> bool influxDBSend(const char * topic, T payload) {
if (!influxDBEnabled) return true;
if (!_influxdb_enabled) return true;
if (!wifiConnected() || (WiFi.getMode() != WIFI_STA)) return true;
DEBUG_MSG("[INFLUXDB] Sending\n");
_influxClient.setTimeout(2);
if (!_influxClient.connect(getSetting("idbHost").c_str(), getSetting("idbPort", INFLUXDB_PORT).toInt())) {
_influx_client.setTimeout(2);
if (!_influx_client.connect(getSetting("idbHost").c_str(), getSetting("idbPort", INFLUXDB_PORT).toInt())) {
DEBUG_MSG("[INFLUXDB] Connection failed\n");
return false;
}
@ -37,22 +37,25 @@ template<typename T> bool influxDBSend(const char * topic, T payload) {
getSetting("idbHost").c_str(), getSetting("idbPort", INFLUXDB_PORT).toInt(),
strlen(data), data);
if (_influxClient.printf(request) > 0) {
while (_influxClient.connected() && _influxClient.available() == 0) delay(1);
while (_influxClient.available()) _influxClient.read();
if (_influxClient.connected()) _influxClient.stop();
if (_influx_client.printf(request) > 0) {
while (_influx_client.connected() && _influx_client.available() == 0) delay(1);
while (_influx_client.available()) _influx_client.read();
if (_influx_client.connected()) _influx_client.stop();
return true;
}
_influxClient.stop();
_influx_client.stop();
DEBUG_MSG("[INFLUXDB] Sent failed\n");
while (_influxClient.connected()) delay(0);
while (_influx_client.connected()) delay(0);
return false;
}
bool influxdbEnabled() {
return _influxdb_enabled;
}
void influxDBConfigure() {
influxDBEnabled = getSetting("idbHost").length() > 0;
_influxdb_enabled = getSetting("idbHost").length() > 0;
}
void influxDBSetup() {


+ 3
- 1
code/espurna/mqtt.ino View File

@ -31,6 +31,7 @@ WiFiClientSecure _mqtt_client_secure;
#endif // MQTT_USE_ASYNC
bool _mqtt_enabled = MQTT_ENABLED;
bool _mqtt_use_json = false;
unsigned long _mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MIN;
String _mqtt_topic;
String _mqtt_setter;
@ -135,7 +136,7 @@ void _mqttFlush() {
}
void mqttSend(const char * topic, const char * message, bool force) {
bool useJson = force ? false : getSetting("mqttUseJson", MQTT_USE_JSON).toInt() == 1;
bool useJson = force ? false : _mqtt_use_json;
if (useJson) {
mqtt_message_t element;
element.topic = strdup(topic);
@ -466,6 +467,7 @@ void mqttConfigure() {
} else {
_mqtt_enabled = getSetting("mqttEnabled", MQTT_ENABLED).toInt() == 1;
}
_mqtt_use_json = (getSetting("mqttUseJson", MQTT_USE_JSON).toInt() == 1);
}


+ 10
- 0
code/espurna/settings.ino View File

@ -135,6 +135,16 @@ void settingsSetup() {
e->response(Embedis::OK);
});
Embedis::command( F("INFO"), [](Embedis* e) {
welcome();
e->response(Embedis::OK);
});
Embedis::command( F("UPTIME"), [](Embedis* e) {
e->stream->printf("Uptime: %d seconds\n", getUptime());
e->response(Embedis::OK);
});
Embedis::command( F("RESET"), [](Embedis* e) {
e->response(Embedis::OK);
customReset(CUSTOM_RESET_TERMINAL);


Loading…
Cancel
Save