Browse Source

Several fixes related to dependencies between modules

pull/463/head
Xose Pérez 6 years ago
parent
commit
18c69f0a1e
7 changed files with 81 additions and 29 deletions
  1. +3
    -1
      code/espurna/config/arduino.h
  2. +10
    -0
      code/espurna/config/general.h
  3. +3
    -14
      code/espurna/espurna.ino
  4. +1
    -1
      code/espurna/influxdb.ino
  5. +4
    -0
      code/espurna/mqtt.ino
  6. +9
    -9
      code/espurna/relay.ino
  7. +51
    -4
      code/espurna/sensors/EmonADC121Sensor.h

+ 3
- 1
code/espurna/config/arduino.h View File

@ -73,7 +73,9 @@
//#define IR_SUPPORT 1
//#define LLMNR_SUPPORT 1 // Only with Arduino Core 2.4.0
//#define MDNS_SUPPORT 0
//#define NOFUSS_SUPPORT 1 // Only with Arduino Core 2.4.0
//#define MQTT_SUPPORT 0
//#define NETBIOS_SUPPORT 1 // Only with Arduino Core 2.4.0
//#define NOFUSS_SUPPORT 1
//#define NTP_SUPPORT 0
//#define RF_SUPPORT 1
//#define SPIFFS_SUPPORT 1


+ 10
- 0
code/espurna/config/general.h View File

@ -66,6 +66,11 @@
#define DEBUG_TELNET_SUPPORT TELNET_SUPPORT // Enable telnet debug log if telnet is enabled too
#endif
#if DEBUG_TELNET_SUPPORT
#undef TELNET_SUPPORT
#define TELNET_SUPPORT 1
#endif
//------------------------------------------------------------------------------
// General debug options and macros
@ -565,6 +570,11 @@ PROGMEM const char* const custom_reset_string[] = {
#define DOMOTICZ_SUPPORT MQTT_SUPPORT // Build with domoticz (if MQTT) support (1.72Kb)
#endif
#if DOMOTICZ_SUPPORT
#undef MQTT_SUPPORT
#define MQTT_SUPPORT 1 // If Domoticz enabled enable MQTT
#endif
#define DOMOTICZ_ENABLED 0 // Disable domoticz by default
#define DOMOTICZ_IN_TOPIC "domoticz/in" // Default subscription topic
#define DOMOTICZ_OUT_TOPIC "domoticz/out" // Default publication topic


+ 3
- 14
code/espurna/espurna.ino View File

@ -56,20 +56,9 @@ void hardwareSetup() {
void hardwareLoop() {
// Heartbeat
static unsigned long last_uptime = 0;
static bool on_connect = true;
bool send = (last_uptime == 0);
send = send || (millis() - last_uptime > HEARTBEAT_INTERVAL);
if (mqttConnected()) {
send = send || on_connect;
} else {
on_connect = true;
}
if (send) {
last_uptime = millis();
if (mqttConnected()) on_connect = false;
static unsigned long last = 0;
if ((last == 0) || (millis() - last > HEARTBEAT_INTERVAL)) {
last = millis();
heartbeat();
}


+ 1
- 1
code/espurna/influxdb.ino View File

@ -78,7 +78,7 @@ template<typename T> bool idbSend(const char * topic, T payload) {
template<typename T> bool idbSend(const char * topic, unsigned char id, T payload) {
char measurement[64];
snprintf_P(measurement, sizeof(measurement), PSTR("%s,id=%d"), topic, id);
snprintf(measurement, sizeof(measurement), "%s,id=%d", topic, id);
return idbSend(topic, payload);
}


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

@ -233,8 +233,12 @@ void _mqttCallback(unsigned int type, const char * topic, const char * payload)
if (type == MQTT_CONNECT_EVENT) {
// Subscribe to internal action topics
mqttSubscribe(MQTT_TOPIC_ACTION);
// Send heartbeat messages
heartbeat();
}
if (type == MQTT_MESSAGE_EVENT) {


+ 9
- 9
code/espurna/relay.ino View File

@ -374,6 +374,15 @@ void _relayBoot() {
}
void _relayConfigure() {
for (unsigned int i=0; i<_relays.size(); i++) {
pinMode(_relays[i].pin, OUTPUT);
if (_relays[i].type == RELAY_TYPE_LATCHED) pinMode(_relays[i].reset_pin, OUTPUT);
_relays[i].pulse = getSetting("relayPulse", i, RELAY_PULSE_MODE).toInt();
_relays[i].pulse_ms = 1000 * getSetting("relayTime", i, RELAY_PULSE_MODE).toFloat();
}
}
//------------------------------------------------------------------------------
// WEBSOCKETS
//------------------------------------------------------------------------------
@ -454,15 +463,6 @@ void _relayWebSocketOnAction(const char * action, JsonObject& data) {
}
void _relayConfigure() {
for (unsigned int i=0; i<_relays.size(); i++) {
pinMode(_relays[i].pin, OUTPUT);
if (_relays[i].type == RELAY_TYPE_LATCHED) pinMode(_relays[i].reset_pin, OUTPUT);
_relays[i].pulse = getSetting("relayPulse", i, RELAY_PULSE_MODE).toInt();
_relays[i].pulse_ms = 1000 * getSetting("relayTime", i, RELAY_PULSE_MODE).toFloat();
}
}
void relaySetupWS() {
wsOnSendRegister(_relayWebSocketOnStart);
wsOnActionRegister(_relayWebSocketOnAction);


+ 51
- 4
code/espurna/sensors/EmonADC121Sensor.h View File

@ -8,7 +8,7 @@
#pragma once
#include "Arduino.h"
#include "EmonAnalogSensor.h"
#include "EmonSensor.h"
#if I2C_USE_BRZO
#include <brzo_i2c.h>
@ -29,7 +29,7 @@
#define ADC121_RESOLUTION 12
#define ADC121_CHANNELS 1
class EmonADC121Sensor : public EmonAnalogSensor {
class EmonADC121Sensor : public EmonSensor {
public:
@ -37,7 +37,7 @@ class EmonADC121Sensor : public EmonAnalogSensor {
// Public
// ---------------------------------------------------------------------
EmonADC121Sensor(): EmonAnalogSensor() {
EmonADC121Sensor(): EmonSensor() {
_channels = ADC121_CHANNELS;
_sensor_id = SENSOR_EMON_ADC121_ID;
init();
@ -102,7 +102,54 @@ class EmonADC121Sensor : public EmonAnalogSensor {
return;
}
EmonAnalogSensor:pre();
_current[0] = read(0);
#if EMON_REPORT_ENERGY
static unsigned long last = 0;
if (last > 0) {
_energy[0] += (_current[0] * _voltage * (millis() - last) / 1000);
}
last = millis();
#endif
}
// Type for slot # index
unsigned char type(unsigned char index) {
_error = SENSOR_ERROR_OK;
unsigned char i=0;
#if EMON_REPORT_CURRENT
if (index == i++) return MAGNITUDE_CURRENT;
#endif
#if EMON_REPORT_POWER
if (index == i++) return MAGNITUDE_POWER_APPARENT;
#endif
#if EMON_REPORT_ENERGY
if (index == i) return MAGNITUDE_ENERGY;
#endif
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
unsigned char channel = index / _magnitudes;
unsigned char i=0;
#if EMON_REPORT_CURRENT
if (index == i++) return _current[channel];
#endif
#if EMON_REPORT_POWER
if (index == i++) return _current[channel] * _voltage;
#endif
#if EMON_REPORT_ENERGY
if (index == i) return _energy[channel];
#endif
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}


Loading…
Cancel
Save