Browse Source

relay: clean-up for ota .bin

mcspr-patch-1
Maxim Prokhorov 4 years ago
committed by Max Prokhorov
parent
commit
ee7356b91a
13 changed files with 70 additions and 27 deletions
  1. +3
    -0
      code/espurna/button.ino
  2. +16
    -0
      code/espurna/config/dependencies.h
  3. +4
    -0
      code/espurna/config/general.h
  4. +8
    -6
      code/espurna/config/hardware.h
  5. +7
    -2
      code/espurna/domoticz.ino
  6. +3
    -1
      code/espurna/espurna.ino
  7. +3
    -0
      code/espurna/ir.ino
  8. +4
    -0
      code/espurna/led.ino
  9. +4
    -0
      code/espurna/relay.ino
  10. +0
    -4
      code/espurna/rpc.ino
  11. +15
    -11
      code/espurna/rpnrules.ino
  12. +2
    -2
      code/espurna/sensor.ino
  13. +1
    -1
      code/test/build/core.h

+ 3
- 0
code/espurna/button.ino View File

@ -411,6 +411,8 @@ void buttonEvent(unsigned char id, button_event_t event) {
#endif #endif
switch (action) { switch (action) {
#if RELAY_SUPPORT
case BUTTON_ACTION_TOGGLE: case BUTTON_ACTION_TOGGLE:
relayToggle(button.relayID); relayToggle(button.relayID);
break; break;
@ -422,6 +424,7 @@ void buttonEvent(unsigned char id, button_event_t event) {
case BUTTON_ACTION_OFF: case BUTTON_ACTION_OFF:
relayStatus(button.relayID, false); relayStatus(button.relayID, false);
break; break;
#endif // RELAY_SUPPORT == 1
case BUTTON_ACTION_AP: case BUTTON_ACTION_AP:
if (wifiState() & WIFI_STATE_AP) { if (wifiState() & WIFI_STATE_AP) {


+ 16
- 0
code/espurna/config/dependencies.h View File

@ -38,6 +38,8 @@
#if ALEXA_SUPPORT #if ALEXA_SUPPORT
#undef BROKER_SUPPORT #undef BROKER_SUPPORT
#define BROKER_SUPPORT 1 // If Alexa enabled enable BROKER #define BROKER_SUPPORT 1 // If Alexa enabled enable BROKER
#undef RELAY_SUPPORT
#define RELAY_SUPPORT 1 // and switches
#endif #endif
#if RPN_RULES_SUPPORT #if RPN_RULES_SUPPORT
@ -47,6 +49,11 @@
#define MQTT_SUPPORT 1 #define MQTT_SUPPORT 1
#endif #endif
#if RF_SUPPORT
#undef RELAY_SUPPORT
#define RELAY_SUPPORT 1
#endif
#if LED_SUPPORT #if LED_SUPPORT
#undef BROKER_SUPPORT #undef BROKER_SUPPORT
#define BROKER_SUPPORT 1 // If LED is enabled enable BROKER to supply status changes #define BROKER_SUPPORT 1 // If LED is enabled enable BROKER to supply status changes
@ -74,11 +81,18 @@
#define BROKER_SUPPORT 1 // If Thingspeak enabled enable BROKER #define BROKER_SUPPORT 1 // If Thingspeak enabled enable BROKER
#endif #endif
#if THERMOSTAT_SUPPORT
#undef RELAY_SUPPORT
#define RELAY_SUPPORT 1 // Thermostat depends on switches
#endif
#if SCHEDULER_SUPPORT #if SCHEDULER_SUPPORT
#undef NTP_SUPPORT #undef NTP_SUPPORT
#define NTP_SUPPORT 1 // Scheduler needs NTP to work #define NTP_SUPPORT 1 // Scheduler needs NTP to work
#undef BROKER_SUPPORT #undef BROKER_SUPPORT
#define BROKER_SUPPORT 1 // Scheduler needs Broker to trigger every minute #define BROKER_SUPPORT 1 // Scheduler needs Broker to trigger every minute
#undef RELAY_SUPPORT
#define RELAY_SUPPORT 1 // Scheduler needs relays
#endif #endif
#if LWIP_VERSION_MAJOR != 1 #if LWIP_VERSION_MAJOR != 1
@ -101,6 +115,8 @@
#if TUYA_SUPPORT #if TUYA_SUPPORT
#undef BROKER_SUPPORT #undef BROKER_SUPPORT
#define BROKER_SUPPORT 1 // Broker is required to process relay & lights events #define BROKER_SUPPORT 1 // Broker is required to process relay & lights events
#undef RELAY_SUPPORT
#define RELAY_SUPPORT 1 // Most of the time we require it
#endif #endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------


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

@ -426,6 +426,10 @@
// RELAY // RELAY
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#ifndef RELAY_SUPPORT
#define RELAY_SUPPORT 1
#endif
// Default boot mode: 0 means OFF, 1 ON and 2 whatever was before // Default boot mode: 0 means OFF, 1 ON and 2 whatever was before
#ifndef RELAY_BOOT_MODE #ifndef RELAY_BOOT_MODE
#define RELAY_BOOT_MODE RELAY_BOOT_OFF #define RELAY_BOOT_MODE RELAY_BOOT_OFF


+ 8
- 6
code/espurna/config/hardware.h View File

@ -56,10 +56,10 @@
#define ALEXA_SUPPORT 0 #define ALEXA_SUPPORT 0
#define API_SUPPORT 0 #define API_SUPPORT 0
#define BROKER_SUPPORT 0 #define BROKER_SUPPORT 0
#define DOMOTICZ_SUPPORT 0
#define DEBUG_SERIAL_SUPPORT 0 #define DEBUG_SERIAL_SUPPORT 0
#define DEBUG_TELNET_SUPPORT 0 #define DEBUG_TELNET_SUPPORT 0
#define DEBUG_WEB_SUPPORT 0 #define DEBUG_WEB_SUPPORT 0
#define DOMOTICZ_SUPPORT 0
#define HOMEASSISTANT_SUPPORT 0 #define HOMEASSISTANT_SUPPORT 0
#define I2C_SUPPORT 0 #define I2C_SUPPORT 0
#define MQTT_SUPPORT 0 #define MQTT_SUPPORT 0
@ -71,11 +71,13 @@
#define WEB_SUPPORT 0 #define WEB_SUPPORT 0
// Extra light-weight image // Extra light-weight image
//#define BUTTON_SUPPORT 0
//#define LED_SUPPORT 0
//#define MDNS_SERVER_SUPPORT 0
//#define TELNET_SUPPORT 0
//#define TERMINAL_SUPPORT 0
//#define BUTTON_SUPPORT 0 // don't need / have buttons
//#define LED_SUPPORT 0 // don't need wifi indicator
//#define RELAY_SUPPORT 0 // don't need to preserve pin state between resets
//#define OTA_ARDUINOOTA_SUPPORT 0 // when only using `ota` command
//#define MDNS_SERVER_SUPPORT 0 //
//#define TELNET_SUPPORT 0 // when only using espota.py
//#define TERMINAL_SUPPORT 0 //
#elif defined(ESPURNA_BASE) #elif defined(ESPURNA_BASE)


+ 7
- 2
code/espurna/domoticz.ino View File

@ -128,7 +128,9 @@ void _domoticzMqtt(unsigned int type, const char * topic, char * payload) {
mqttSubscribeRaw(dczTopicOut.c_str()); mqttSubscribeRaw(dczTopicOut.c_str());
// Send relays state on connection // Send relays state on connection
domoticzSendRelays();
#if RELAY_SUPPORT
domoticzSendRelays();
#endif
} }
@ -231,7 +233,10 @@ void _domoticzConfigure() {
const bool enabled = getSetting("dczEnabled", 1 == DOMOTICZ_ENABLED); const bool enabled = getSetting("dczEnabled", 1 == DOMOTICZ_ENABLED);
if (enabled != _dcz_enabled) _domoticzMqttSubscribe(enabled); if (enabled != _dcz_enabled) _domoticzMqttSubscribe(enabled);
_domoticzRelayConfigure(relayCount());
#if RELAY_SUPPORT
_domoticzRelayConfigure(relayCount());
#endif
_dcz_enabled = enabled; _dcz_enabled = enabled;
} }


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

@ -193,7 +193,9 @@ void setup() {
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
lightSetup(); lightSetup();
#endif #endif
relaySetup();
#if RELAY_SUPPORT
relaySetup();
#endif
#if BUTTON_SUPPORT #if BUTTON_SUPPORT
buttonSetup(); buttonSetup();
#endif #endif


+ 3
- 0
code/espurna/ir.ino View File

@ -284,6 +284,8 @@ void _irProcess(unsigned char type, unsigned long code) {
unsigned long button_value = pgm_read_dword(&IR_BUTTON[i][2]); unsigned long button_value = pgm_read_dword(&IR_BUTTON[i][2]);
switch (button_action) { switch (button_action) {
#if RELAY_SUPPORT
case IR_BUTTON_ACTION_STATE: case IR_BUTTON_ACTION_STATE:
relayStatus(0, button_value); relayStatus(0, button_value);
break; break;
@ -291,6 +293,7 @@ void _irProcess(unsigned char type, unsigned long code) {
case IR_BUTTON_ACTION_TOGGLE: case IR_BUTTON_ACTION_TOGGLE:
relayToggle(button_value); relayToggle(button_value);
break; break;
#endif // RELAY_SUPPORT == 1
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE


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

@ -394,6 +394,8 @@ void ledLoop() {
} }
break; break;
#if RELAY_SUPPORT
case LED_MODE_FINDME_WIFI: case LED_MODE_FINDME_WIFI:
if ((wifi_state & WIFI_STATE_WPS) || (wifi_state & WIFI_STATE_SMARTCONFIG)) { if ((wifi_state & WIFI_STATE_WPS) || (wifi_state & WIFI_STATE_SMARTCONFIG)) {
_ledBlink(led, LedMode::NetworkAutoconfig); _ledBlink(led, LedMode::NetworkAutoconfig);
@ -471,6 +473,8 @@ void ledLoop() {
break; break;
} }
#endif // RELAY_SUPPORT == 1
case LED_MODE_ON: case LED_MODE_ON:
if (!_led_update) break; if (!_led_update) break;
_ledStatus(led, true); _ledStatus(led, true);


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

@ -6,6 +6,8 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
*/ */
#if RELAY_SUPPORT
#include <Ticker.h> #include <Ticker.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <vector> #include <vector>
@ -1437,3 +1439,5 @@ void relaySetup() {
DEBUG_MSG_P(PSTR("[RELAY] Number of relays: %d\n"), _relays.size()); DEBUG_MSG_P(PSTR("[RELAY] Number of relays: %d\n"), _relays.size());
} }
#endif // RELAY_SUPPORT == 1

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

@ -6,8 +6,6 @@ Copyright (C) 2020 by Maxim Prokhorov <prokhorov dot max at outlook dot com>
*/ */
#if MQTT_SUPPORT || API_SUPPORT
#include <Schedule.h> #include <Schedule.h>
#include <cstring> #include <cstring>
@ -66,5 +64,3 @@ PayloadStatus rpcParsePayload(const char* payload, const rpc_payload_check_t ext
return PayloadStatus::Unknown; return PayloadStatus::Unknown;
} }
#endif // MQTT_SUPPORT || API_SUPPORT

+ 15
- 11
code/espurna/rpnrules.ino View File

@ -215,17 +215,21 @@ void _rpnInit() {
}); });
// Accept relay number and numeric API status value (0, 1 and 2) // Accept relay number and numeric API status value (0, 1 and 2)
rpn_operator_set(_rpn_ctxt, "relay", 2, [](rpn_context & ctxt) {
float status, id;
rpn_stack_pop(ctxt, id);
rpn_stack_pop(ctxt, status);
if (int(status) == 2) {
relayToggle(int(id));
} else {
relayStatus(int(id), int(status) == 1);
}
return true;
});
#if RELAY_SUPPORT
rpn_operator_set(_rpn_ctxt, "relay", 2, [](rpn_context & ctxt) {
float status, id;
rpn_stack_pop(ctxt, id);
rpn_stack_pop(ctxt, status);
if (int(status) == 2) {
relayToggle(int(id));
} else {
relayStatus(int(id), int(status) == 1);
}
return true;
});
#endif // RELAY_SUPPORT == 1
// Channel operators // Channel operators
#if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT #if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT


+ 2
- 2
code/espurna/sensor.ino View File

@ -2028,7 +2028,7 @@ void sensorLoop() {
_sensorPre(); _sensorPre();
// Get the first relay state // Get the first relay state
#if SENSOR_POWER_CHECK_STATUS
#if RELAY_SUPPORT && SENSOR_POWER_CHECK_STATUS
bool relay_off = (relayCount() == 1) && (relayStatus(0) == 0); bool relay_off = (relayCount() == 1) && (relayStatus(0) == 0);
#endif #endif
@ -2046,7 +2046,7 @@ void sensorLoop() {
value_raw = magnitude.sensor->value(magnitude.local); value_raw = magnitude.sensor->value(magnitude.local);
// Completely remove spurious values if relay is OFF // Completely remove spurious values if relay is OFF
#if SENSOR_POWER_CHECK_STATUS
#if RELAY_SUPPORT && SENSOR_POWER_CHECK_STATUS
if (relay_off) { if (relay_off) {
if (magnitude.type == MAGNITUDE_POWER_ACTIVE || if (magnitude.type == MAGNITUDE_POWER_ACTIVE ||
magnitude.type == MAGNITUDE_POWER_REACTIVE || magnitude.type == MAGNITUDE_POWER_REACTIVE ||


+ 1
- 1
code/test/build/core.h View File

@ -1,10 +1,10 @@
#define ALEXA_SUPPORT 0 #define ALEXA_SUPPORT 0
#define API_SUPPORT 0 #define API_SUPPORT 0
#define BROKER_SUPPORT 0 #define BROKER_SUPPORT 0
#define DOMOTICZ_SUPPORT 0
#define DEBUG_SERIAL_SUPPORT 0 #define DEBUG_SERIAL_SUPPORT 0
#define DEBUG_TELNET_SUPPORT 0 #define DEBUG_TELNET_SUPPORT 0
#define DEBUG_WEB_SUPPORT 0 #define DEBUG_WEB_SUPPORT 0
#define DOMOTICZ_SUPPORT 0
#define HOMEASSISTANT_SUPPORT 0 #define HOMEASSISTANT_SUPPORT 0
#define I2C_SUPPORT 0 #define I2C_SUPPORT 0
#define MQTT_SUPPORT 0 #define MQTT_SUPPORT 0


Loading…
Cancel
Save