2017-10-10 14:40:02 +01:00
|
|
|
/*
|
2017-10-18 17:22:34 +01:00
|
|
|
sonoff.h - Master header file for Sonoff-Tasmota
|
2017-10-10 14:40:02 +01:00
|
|
|
|
2017-12-22 13:55:24 +00:00
|
|
|
Copyright (C) 2018 Theo Arends
|
2017-10-10 14:40:02 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
#ifndef _SONOFF_H_
|
|
|
|
#define _SONOFF_H_
|
|
|
|
|
2017-10-10 14:40:02 +01:00
|
|
|
/*********************************************************************************************\
|
|
|
|
* Power Type
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
|
|
|
typedef unsigned long power_t; // Power (Relay) type
|
2017-10-14 10:26:49 +01:00
|
|
|
#define POWER_MASK 0xffffffffUL // Power (Relay) full mask
|
2017-10-10 14:40:02 +01:00
|
|
|
|
|
|
|
/*********************************************************************************************\
|
|
|
|
* Defines
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2017-10-12 10:29:40 +01:00
|
|
|
// Changes to the following MAX_ defines will impact settings layout
|
2018-06-28 13:28:14 +01:00
|
|
|
#define MAX_SWITCHES 8 // Max number of switches
|
2017-10-12 10:29:40 +01:00
|
|
|
#define MAX_RELAYS 8 // Max number of relays
|
2017-10-10 14:40:02 +01:00
|
|
|
#define MAX_LEDS 4 // Max number of leds
|
2017-10-12 10:29:40 +01:00
|
|
|
#define MAX_KEYS 4 // Max number of keys or buttons
|
2017-10-10 14:40:02 +01:00
|
|
|
#define MAX_PWMS 5 // Max number of PWM channels
|
|
|
|
#define MAX_COUNTERS 4 // Max number of counter sensors
|
2018-03-23 16:20:20 +00:00
|
|
|
#define MAX_TIMERS 16 // Max number of Timers
|
2017-10-12 10:29:40 +01:00
|
|
|
#define MAX_PULSETIMERS 8 // Max number of supported pulse timers
|
|
|
|
#define MAX_FRIENDLYNAMES 4 // Max number of Friendly names
|
|
|
|
#define MAX_DOMOTICZ_IDX 4 // Max number of Domoticz device, key and switch indices
|
2017-12-22 13:55:24 +00:00
|
|
|
#define MAX_DOMOTICZ_SNS_IDX 12 // Max number of Domoticz sensors indices
|
2018-04-17 14:34:18 +01:00
|
|
|
#define MAX_KNX_GA 10 // Max number of KNX Group Addresses to read that can be set
|
|
|
|
#define MAX_KNX_CB 10 // Max number of KNX Group Addresses to write that can be set
|
2018-08-23 15:05:51 +01:00
|
|
|
#define MAX_RULE_MEMS 5 // Max number of saved vars
|
2018-05-24 13:25:52 +01:00
|
|
|
#define MAX_RULE_SETS 3 // Max number of rule sets of size 512 characters
|
2018-04-14 13:39:16 +01:00
|
|
|
#define MAX_RULE_SIZE 512 // Max number of characters in rules
|
2017-10-10 14:40:02 +01:00
|
|
|
|
2018-08-23 15:05:51 +01:00
|
|
|
// Changes to the following defines have no impact on settings layout
|
|
|
|
#define MAX_RULE_TIMERS 8 // Max number of rule timers (4 bytes / timer)
|
|
|
|
#define MAX_RULE_VARS 5 // Max number of rule variables (10 bytes / variable)
|
|
|
|
|
2017-10-10 14:40:02 +01:00
|
|
|
#define MQTT_TOKEN_PREFIX "%prefix%" // To be substituted by mqtt_prefix[x]
|
|
|
|
#define MQTT_TOKEN_TOPIC "%topic%" // To be substituted by mqtt_topic, mqtt_grptopic, mqtt_buttontopic, mqtt_switchtopic
|
2018-05-21 16:52:24 +01:00
|
|
|
#define MQTT_TOKEN_ID "%id%" // To be substituted by mqtt_topic, mqtt_grptopic, mqtt_buttontopic, mqtt_switchtopic
|
2017-10-10 14:40:02 +01:00
|
|
|
|
|
|
|
#define WIFI_HOSTNAME "%s-%04d" // Expands to <MQTT_TOPIC>-<last 4 decimal chars of MAC address>
|
|
|
|
|
|
|
|
#define CONFIG_FILE_SIGN 0xA5 // Configuration file signature
|
|
|
|
#define CONFIG_FILE_XOR 0x5A // Configuration file xor (0 = No Xor)
|
|
|
|
|
|
|
|
#define HLW_PREF_PULSE 12530 // was 4975us = 201Hz = 1000W
|
|
|
|
#define HLW_UREF_PULSE 1950 // was 1666us = 600Hz = 220V
|
|
|
|
#define HLW_IREF_PULSE 3500 // was 1666us = 600Hz = 4.545A
|
|
|
|
|
|
|
|
#define MQTT_RETRY_SECS 10 // Minimum seconds to retry MQTT connection
|
2018-07-24 17:41:50 +01:00
|
|
|
#define GLOBAL_VALUES_VALID 300 // Max number of seconds to keep last received values
|
2017-10-10 14:40:02 +01:00
|
|
|
#define APP_POWER 0 // Default saved power state Off
|
|
|
|
#define WS2812_MAX_LEDS 512 // Max number of LEDs
|
|
|
|
|
|
|
|
#define PWM_RANGE 1023 // 255..1023 needs to be devisible by 256
|
|
|
|
//#define PWM_FREQ 1000 // 100..1000 Hz led refresh
|
|
|
|
//#define PWM_FREQ 910 // 100..1000 Hz led refresh (iTead value)
|
|
|
|
#define PWM_FREQ 880 // 100..1000 Hz led refresh (BN-SZ01 value)
|
|
|
|
|
2018-03-14 13:32:51 +00:00
|
|
|
#define DEFAULT_POWER_DELTA 80 // Power change percentage
|
|
|
|
#define MAX_POWER_HOLD 10 // Time in SECONDS to allow max agreed power
|
|
|
|
#define MAX_POWER_WINDOW 30 // Time in SECONDS to disable allow max agreed power
|
|
|
|
#define SAFE_POWER_HOLD 10 // Time in SECONDS to allow max unit safe power
|
|
|
|
#define SAFE_POWER_WINDOW 30 // Time in MINUTES to disable allow max unit safe power
|
|
|
|
#define MAX_POWER_RETRY 5 // Retry count allowing agreed power limit overflow
|
2017-10-10 14:40:02 +01:00
|
|
|
|
2018-08-27 13:53:09 +01:00
|
|
|
#define STATES 20 // Number of states per second using 50 mSec interval
|
2018-03-29 16:21:03 +01:00
|
|
|
#define IMMINENT_RESET_FACTOR 10 // Factor to extent button hold time for imminent Reset to default 40 seconds using KEY_HOLD_TIME of 40
|
2017-10-10 14:40:02 +01:00
|
|
|
#define SYSLOG_TIMER 600 // Seconds to restore syslog_level
|
|
|
|
#define SERIALLOG_TIMER 600 // Seconds to disable SerialLog
|
2018-01-10 13:10:25 +00:00
|
|
|
#define OTA_ATTEMPTS 5 // Number of times to try fetching the new firmware
|
2017-10-10 14:40:02 +01:00
|
|
|
|
2018-05-24 13:25:52 +01:00
|
|
|
#define INPUT_BUFFER_SIZE 520 // Max number of characters in (serial and http) command buffer
|
2017-10-29 17:18:46 +00:00
|
|
|
#define CMDSZ 24 // Max number of characters in command
|
2017-10-10 14:40:02 +01:00
|
|
|
#define TOPSZ 100 // Max number of characters in topic string
|
2018-04-14 13:39:16 +01:00
|
|
|
#define LOGSZ 512 // Max number of characters in log
|
2018-01-20 11:12:39 +00:00
|
|
|
#define MIN_MESSZ 893 // Min number of characters in MQTT message
|
2018-01-30 13:14:55 +00:00
|
|
|
|
2018-07-10 21:12:16 +01:00
|
|
|
#define SENSOR_MAX_MISS 5 // Max number of missed sensor reads before deciding it's offline
|
|
|
|
|
2017-10-10 14:40:02 +01:00
|
|
|
#ifdef USE_MQTT_TLS
|
2018-01-30 13:14:55 +00:00
|
|
|
#define WEB_LOG_SIZE 2000 // Max number of characters in weblog
|
2017-10-10 14:40:02 +01:00
|
|
|
#else
|
2018-01-30 13:14:55 +00:00
|
|
|
#define WEB_LOG_SIZE 4000 // Max number of characters in weblog
|
2017-10-10 14:40:02 +01:00
|
|
|
#endif
|
2018-01-30 13:14:55 +00:00
|
|
|
|
2018-03-31 17:59:37 +01:00
|
|
|
#define MAX_BACKLOG 30 // Max number of commands in backlog
|
2017-10-10 14:40:02 +01:00
|
|
|
#define MIN_BACKLOG_DELAY 2 // Minimal backlog delay in 0.1 seconds
|
|
|
|
|
2018-03-20 13:31:11 +00:00
|
|
|
#define SOFT_BAUDRATE 9600 // Default software serial baudrate
|
2017-10-10 14:40:02 +01:00
|
|
|
#define APP_BAUDRATE 115200 // Default serial baudrate
|
2018-03-18 12:47:30 +00:00
|
|
|
#define SERIAL_POLLING 100 // Serial receive polling in ms
|
2017-10-10 14:40:02 +01:00
|
|
|
#define MAX_STATUS 11 // Max number of status lines
|
|
|
|
|
2018-07-14 14:35:56 +01:00
|
|
|
#define NO_EXTRA_4K_HEAP // Allocate 4k heap for WPS in ESP8166/Arduino core v2.4.2 (was always allocated in previous versions)
|
|
|
|
|
2017-11-17 16:52:31 +00:00
|
|
|
/*
|
|
|
|
// Removed from esp8266 core since 20171105
|
|
|
|
#define min(a,b) ((a)<(b)?(a):(b))
|
|
|
|
#define max(a,b) ((a)>(b)?(a):(b))
|
|
|
|
*/
|
2018-07-14 11:10:13 +01:00
|
|
|
#define tmin(a,b) ((a)<(b)?(a):(b))
|
|
|
|
#define tmax(a,b) ((a)>(b)?(a):(b))
|
2017-11-17 16:52:31 +00:00
|
|
|
|
2018-05-17 14:36:45 +01:00
|
|
|
#define STR_HELPER(x) #x
|
|
|
|
#define STR(x) STR_HELPER(x)
|
|
|
|
|
2018-03-17 14:22:29 +00:00
|
|
|
//enum ws2812NeopixelbusFeature { NEO_RGB, NEO_GRB, NEO_BRG, NEO_RBG, NEO_3LED, NEO_RGBW, NEO_GRBW }; // Doesn't work
|
|
|
|
#define NEO_RGB 0 // Neopixel RGB leds
|
|
|
|
#define NEO_GRB 1 // Neopixel GRB leds
|
|
|
|
#define NEO_BRG 2 // Neopixel BRG leds
|
|
|
|
#define NEO_RBG 3 // Neopixel RBG leds
|
|
|
|
#define NEO_3LED 4 // Placeholder to test for 4 led types
|
|
|
|
#define NEO_RGBW 5 // Neopixel RGBW leds
|
|
|
|
#define NEO_GRBW 6 // Neopixel GRBW leds
|
|
|
|
|
|
|
|
#define MQTT_PUBSUBCLIENT 1 // Mqtt PubSubClient library
|
|
|
|
#define MQTT_TASMOTAMQTT 2 // Mqtt TasmotaMqtt library based on esp-mqtt-arduino
|
|
|
|
#define MQTT_ESPMQTTARDUINO 3 // Mqtt esp-mqtt-arduino library by Ingo Randolf
|
|
|
|
|
2018-04-23 10:37:46 +01:00
|
|
|
// Sunrise and Sunset DawnType
|
|
|
|
#define DAWN_NORMAL -0.8333
|
|
|
|
#define DAWN_CIVIL -6.0
|
|
|
|
#define DAWN_NAUTIC -12.0
|
|
|
|
#define DAWN_ASTRONOMIC -18.0
|
|
|
|
|
2018-05-31 06:46:09 +01:00
|
|
|
// Sensor and Commands definition for KNX Driver
|
2018-05-17 10:55:40 +01:00
|
|
|
#define KNX_TEMPERATURE 17
|
|
|
|
#define KNX_HUMIDITY 18
|
|
|
|
#define KNX_ENERGY_VOLTAGE 19
|
|
|
|
#define KNX_ENERGY_CURRENT 20
|
|
|
|
#define KNX_ENERGY_POWER 21
|
2018-05-17 05:42:51 +01:00
|
|
|
#define KNX_ENERGY_POWERFACTOR 22
|
2018-05-17 10:55:40 +01:00
|
|
|
#define KNX_ENERGY_DAILY 23
|
|
|
|
#define KNX_ENERGY_START 24
|
|
|
|
#define KNX_ENERGY_TOTAL 25
|
2018-05-30 19:19:17 +01:00
|
|
|
#define KNX_SLOT1 26
|
|
|
|
#define KNX_SLOT2 27
|
|
|
|
#define KNX_SLOT3 28
|
|
|
|
#define KNX_SLOT4 29
|
|
|
|
#define KNX_SLOT5 30
|
|
|
|
#define KNX_MAX_device_param 30
|
2018-05-31 06:46:09 +01:00
|
|
|
#define MAX_KNXTX_CMNDS 5
|
2018-05-17 05:42:51 +01:00
|
|
|
|
2017-10-10 14:40:02 +01:00
|
|
|
/*********************************************************************************************\
|
|
|
|
* Enumeration
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
enum WeekInMonthOptions {Last, First, Second, Third, Fourth};
|
|
|
|
enum DayOfTheWeekOptions {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat};
|
|
|
|
enum MonthNamesOptions {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
|
|
|
|
enum HemisphereOptions {North, South};
|
2018-02-17 13:09:39 +00:00
|
|
|
enum GetDateAndTimeOptions { DT_LOCAL, DT_UTC, DT_RESTART, DT_UPTIME };
|
2017-11-08 10:57:16 +00:00
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL};
|
2017-11-08 10:57:16 +00:00
|
|
|
|
2018-07-15 14:21:48 +01:00
|
|
|
enum WifiConfigOptions {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL, MAX_WIFI_OPTION};
|
2017-11-08 10:57:16 +00:00
|
|
|
|
2017-11-22 14:34:07 +00:00
|
|
|
enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, MAX_SWITCH_OPTION};
|
2017-11-08 10:57:16 +00:00
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
enum LedStateOptions {LED_OFF, LED_POWER, LED_MQTTSUB, LED_POWER_MQTTSUB, LED_MQTTPUB, LED_POWER_MQTTPUB, LED_MQTT, LED_POWER_MQTT, MAX_LED_OPTION};
|
2017-11-08 10:57:16 +00:00
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
enum EmulationOptions {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX};
|
2017-11-08 10:57:16 +00:00
|
|
|
|
2018-01-18 15:19:28 +00:00
|
|
|
enum TopicOptions { CMND, STAT, TELE, nu1, RESULT_OR_CMND, RESULT_OR_STAT, RESULT_OR_TELE };
|
|
|
|
|
2018-01-24 16:31:20 +00:00
|
|
|
enum ExecuteCommandPowerOptions { POWER_OFF, POWER_ON, POWER_TOGGLE, POWER_BLINK, POWER_BLINK_STOP, power_nu1, POWER_OFF_NO_STATE, POWER_ON_NO_STATE, power_nu2, POWER_SHOW_STATE };
|
|
|
|
|
|
|
|
enum PowerOnStateOptions { POWER_ALL_OFF, POWER_ALL_ON, POWER_ALL_SAVED_TOGGLE, POWER_ALL_SAVED, POWER_ALL_ALWAYS_ON, POWER_ALL_OFF_PULSETIME_ON };
|
|
|
|
|
2018-08-27 13:53:09 +01:00
|
|
|
enum ButtonStates { PRESSED, NOT_PRESSED };
|
|
|
|
|
|
|
|
enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER };
|
2017-11-08 10:57:16 +00:00
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_MAX_PARAM8};
|
2017-11-08 10:57:16 +00:00
|
|
|
|
2018-01-05 11:26:19 +00:00
|
|
|
enum DomoticzSensors {DZ_TEMP, DZ_TEMP_HUM, DZ_TEMP_HUM_BARO, DZ_POWER_ENERGY, DZ_ILLUMINANCE, DZ_COUNT, DZ_VOLTAGE, DZ_CURRENT, DZ_AIRQUALITY, DZ_MAX_SENSORS};
|
|
|
|
|
2018-03-10 16:58:54 +00:00
|
|
|
enum Ws2812ClockIndex { WS_SECOND, WS_MINUTE, WS_HOUR, WS_MARKER };
|
|
|
|
enum Ws2812Color { WS_RED, WS_GREEN, WS_BLUE };
|
2017-10-25 13:27:30 +01:00
|
|
|
enum LightTypes {LT_BASIC, LT_PWM1, LT_PWM2, LT_PWM3, LT_PWM4, LT_PWM5, LT_PWM6, LT_PWM7, LT_NU8, LT_NU9, LT_NU10, LT_WS2812, LT_RGBW, LT_RGBWC};
|
|
|
|
enum LichtSubtypes {LST_NONE, LST_SINGLE, LST_COLDWARM, LST_RGB, LST_RGBW, LST_RGBWC};
|
|
|
|
enum LichtSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MAX};
|
2017-11-08 10:57:16 +00:00
|
|
|
|
2018-08-26 16:10:18 +01:00
|
|
|
enum XsnsFunctions {FUNC_PRE_INIT, FUNC_INIT, FUNC_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_100_MSECOND, FUNC_EVERY_250_MSECOND, FUNC_EVERY_SECOND, FUNC_PREP_BEFORE_TELEPERIOD,
|
|
|
|
FUNC_JSON_APPEND, FUNC_WEB_APPEND, FUNC_SAVE_BEFORE_RESTART, FUNC_COMMAND, FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, FUNC_SET_POWER, FUNC_SHOW_SENSOR,
|
|
|
|
FUNC_RULES_PROCESS, FUNC_FREE_MEM};
|
2017-10-18 17:22:34 +01:00
|
|
|
|
2017-10-29 17:18:46 +00:00
|
|
|
const uint8_t kDefaultRfCode[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48, 0x2E, 0x1A, 0x00 };
|
|
|
|
|
2018-05-28 14:52:42 +01:00
|
|
|
enum CommandSource { SRC_IGNORE, SRC_MQTT, SRC_RESTART, SRC_BUTTON, SRC_SWITCH, SRC_BACKLOG, SRC_SERIAL, SRC_WEBGUI, SRC_WEBCOMMAND, SRC_WEBCONSOLE, SRC_PULSETIMER,
|
2018-08-20 14:51:46 +01:00
|
|
|
SRC_TIMER, SRC_RULE, SRC_MAXPOWER, SRC_MAXENERGY, SRC_LIGHT, SRC_KNX, SRC_DISPLAY, SRC_WEMO, SRC_HUE, SRC_RETRY, SRC_MAX };
|
|
|
|
const char kCommandSource[] PROGMEM = "I|MQTT|Restart|Button|Switch|Backlog|Serial|WebGui|WebCommand|WebConsole|PulseTimer|Timer|Rule|MaxPower|MaxEnergy|Light|Knx|Display|Wemo|Hue|Retry";
|
2018-05-28 14:52:42 +01:00
|
|
|
|
2018-01-20 11:12:39 +00:00
|
|
|
/*********************************************************************************************\
|
|
|
|
* Extern global variables
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
|
|
|
extern uint8_t light_device; // Light device number
|
|
|
|
|
2018-05-30 19:19:17 +01:00
|
|
|
#endif // _SONOFF_H_
|