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


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

@ -38,6 +38,8 @@
#if ALEXA_SUPPORT
#undef BROKER_SUPPORT
#define BROKER_SUPPORT 1 // If Alexa enabled enable BROKER
#undef RELAY_SUPPORT
#define RELAY_SUPPORT 1 // and switches
#endif
#if RPN_RULES_SUPPORT
@ -47,6 +49,11 @@
#define MQTT_SUPPORT 1
#endif
#if RF_SUPPORT
#undef RELAY_SUPPORT
#define RELAY_SUPPORT 1
#endif
#if LED_SUPPORT
#undef BROKER_SUPPORT
#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
#endif
#if THERMOSTAT_SUPPORT
#undef RELAY_SUPPORT
#define RELAY_SUPPORT 1 // Thermostat depends on switches
#endif
#if SCHEDULER_SUPPORT
#undef NTP_SUPPORT
#define NTP_SUPPORT 1 // Scheduler needs NTP to work
#undef BROKER_SUPPORT
#define BROKER_SUPPORT 1 // Scheduler needs Broker to trigger every minute
#undef RELAY_SUPPORT
#define RELAY_SUPPORT 1 // Scheduler needs relays
#endif
#if LWIP_VERSION_MAJOR != 1
@ -101,6 +115,8 @@
#if TUYA_SUPPORT
#undef BROKER_SUPPORT
#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
//------------------------------------------------------------------------------


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

@ -426,6 +426,10 @@
// RELAY
//------------------------------------------------------------------------------
#ifndef RELAY_SUPPORT
#define RELAY_SUPPORT 1
#endif
// Default boot mode: 0 means OFF, 1 ON and 2 whatever was before
#ifndef RELAY_BOOT_MODE
#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 API_SUPPORT 0
#define BROKER_SUPPORT 0
#define DOMOTICZ_SUPPORT 0
#define DEBUG_SERIAL_SUPPORT 0
#define DEBUG_TELNET_SUPPORT 0
#define DEBUG_WEB_SUPPORT 0
#define DOMOTICZ_SUPPORT 0
#define HOMEASSISTANT_SUPPORT 0
#define I2C_SUPPORT 0
#define MQTT_SUPPORT 0
@ -71,11 +71,13 @@
#define WEB_SUPPORT 0
// 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)


+ 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());
// 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);
if (enabled != _dcz_enabled) _domoticzMqttSubscribe(enabled);
_domoticzRelayConfigure(relayCount());
#if RELAY_SUPPORT
_domoticzRelayConfigure(relayCount());
#endif
_dcz_enabled = enabled;
}


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

@ -193,7 +193,9 @@ void setup() {
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
lightSetup();
#endif
relaySetup();
#if RELAY_SUPPORT
relaySetup();
#endif
#if BUTTON_SUPPORT
buttonSetup();
#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]);
switch (button_action) {
#if RELAY_SUPPORT
case IR_BUTTON_ACTION_STATE:
relayStatus(0, button_value);
break;
@ -291,6 +293,7 @@ void _irProcess(unsigned char type, unsigned long code) {
case IR_BUTTON_ACTION_TOGGLE:
relayToggle(button_value);
break;
#endif // RELAY_SUPPORT == 1
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE


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

@ -394,6 +394,8 @@ void ledLoop() {
}
break;
#if RELAY_SUPPORT
case LED_MODE_FINDME_WIFI:
if ((wifi_state & WIFI_STATE_WPS) || (wifi_state & WIFI_STATE_SMARTCONFIG)) {
_ledBlink(led, LedMode::NetworkAutoconfig);
@ -471,6 +473,8 @@ void ledLoop() {
break;
}
#endif // RELAY_SUPPORT == 1
case LED_MODE_ON:
if (!_led_update) break;
_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 <ArduinoJson.h>
#include <vector>
@ -1437,3 +1439,5 @@ void relaySetup() {
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 <cstring>
@ -66,5 +64,3 @@ PayloadStatus rpcParsePayload(const char* payload, const rpc_payload_check_t ext
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)
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
#if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT


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

@ -2028,7 +2028,7 @@ void sensorLoop() {
_sensorPre();
// 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);
#endif
@ -2046,7 +2046,7 @@ void sensorLoop() {
value_raw = magnitude.sensor->value(magnitude.local);
// Completely remove spurious values if relay is OFF
#if SENSOR_POWER_CHECK_STATUS
#if RELAY_SUPPORT && SENSOR_POWER_CHECK_STATUS
if (relay_off) {
if (magnitude.type == MAGNITUDE_POWER_ACTIVE ||
magnitude.type == MAGNITUDE_POWER_REACTIVE ||


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

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


Loading…
Cancel
Save