Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

874 lines
36 KiB

7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. //------------------------------------------------------------------------------
  2. // Do not change this file unless you know what you are doing
  3. // Configuration settings are in the settings.h file
  4. //------------------------------------------------------------------------------
  5. //------------------------------------------------------------------------------
  6. // GENERAL
  7. //------------------------------------------------------------------------------
  8. #define ADMIN_PASS "fibonacci" // Default password (WEB, OTA, WIFI)
  9. #define DEVICE_NAME MANUFACTURER "_" DEVICE // Concatenate both to get a unique device name
  10. #define LOOP_DELAY_TIME 10 // Delay for this millis in the main loop [0-250]
  11. #define ARRAYINIT(type, name, ...) \
  12. type name[] = {__VA_ARGS__};
  13. //------------------------------------------------------------------------------
  14. // TELNET
  15. //------------------------------------------------------------------------------
  16. #ifndef TELNET_SUPPORT
  17. #define TELNET_SUPPORT 1 // Enable telnet support by default (3.34Kb)
  18. #endif
  19. #ifndef TELNET_STA
  20. #define TELNET_STA 0 // By default, disallow connections via STA interface
  21. #endif
  22. #define TELNET_PORT 23 // Port to listen to telnet clients
  23. #define TELNET_MAX_CLIENTS 1 // Max number of concurrent telnet clients
  24. //------------------------------------------------------------------------------
  25. // DEBUG
  26. //------------------------------------------------------------------------------
  27. // Serial debug log
  28. #ifndef DEBUG_SERIAL_SUPPORT
  29. #define DEBUG_SERIAL_SUPPORT 1 // Enable serial debug log
  30. #endif
  31. #ifndef DEBUG_PORT
  32. #define DEBUG_PORT Serial // Default debugging port
  33. #endif
  34. //------------------------------------------------------------------------------
  35. // UDP debug log
  36. // To receive the message son the destination computer use nc:
  37. // nc -ul 8113
  38. #ifndef DEBUG_UDP_SUPPORT
  39. #define DEBUG_UDP_SUPPORT 0 // Enable UDP debug log
  40. #endif
  41. #define DEBUG_UDP_IP IPAddress(192, 168, 1, 100)
  42. #define DEBUG_UDP_PORT 8113
  43. //------------------------------------------------------------------------------
  44. #ifndef DEBUG_TELNET_SUPPORT
  45. #define DEBUG_TELNET_SUPPORT TELNET_SUPPORT // Enable telnet debug log if telnet is enabled too
  46. #endif
  47. //------------------------------------------------------------------------------
  48. // General debug options and macros
  49. #define DEBUG_FORMAT_MAX_LENGTH 80
  50. #define DEBUG_SUPPORT DEBUG_SERIAL_SUPPORT || DEBUG_UDP_SUPPORT || DEBUG_TELNET_SUPPORT
  51. #if DEBUG_SUPPORT
  52. #define DEBUG_MSG(...) debugSend(__VA_ARGS__)
  53. #define DEBUG_MSG_P(...) debugSend_P(__VA_ARGS__)
  54. #endif
  55. #ifndef DEBUG_MSG
  56. #define DEBUG_MSG(...)
  57. #define DEBUG_MSG_P(...)
  58. #endif
  59. //------------------------------------------------------------------------------
  60. // TERMINAL
  61. //------------------------------------------------------------------------------
  62. #ifndef TERMINAL_SUPPORT
  63. #define TERMINAL_SUPPORT 1 // Enable terminal commands (0.97Kb)
  64. #endif
  65. //------------------------------------------------------------------------------
  66. // SYSTEM CHECK
  67. //------------------------------------------------------------------------------
  68. #ifndef SYSTEM_CHECK_ENABLED
  69. #define SYSTEM_CHECK_ENABLED 1 // Enable crash check by default
  70. #endif
  71. #define SYSTEM_CHECK_TIME 60000 // The system is considered stable after these many millis
  72. #define SYSTEM_CHECK_MAX 5 // After this many crashes on boot
  73. // the system is flagged as unstable
  74. //------------------------------------------------------------------------------
  75. // EEPROM
  76. //------------------------------------------------------------------------------
  77. #define EEPROM_SIZE 4096 // EEPROM size in bytes
  78. #define EEPROM_RELAY_STATUS 0 // Address for the relay status (1 byte)
  79. #define EEPROM_ENERGY_COUNT 1 // Address for the energy counter (4 bytes)
  80. #define EEPROM_CUSTOM_RESET 5 // Address for the reset reason (1 byte)
  81. #define EEPROM_CRASH_COUNTER 6 // Address for the crash counter (1 byte)
  82. #define EEPROM_DATA_END 7 // End of custom EEPROM data block
  83. //------------------------------------------------------------------------------
  84. // HEARTBEAT
  85. //------------------------------------------------------------------------------
  86. #define HEARTBEAT_INTERVAL 300000 // Interval between heartbeat messages (in ms)
  87. #define UPTIME_OVERFLOW 4294967295 // Uptime overflow value
  88. // Topics that will be reported in heartbeat
  89. #define HEARTBEAT_REPORT_STATUS 1
  90. #define HEARTBEAT_REPORT_IP 1
  91. #define HEARTBEAT_REPORT_MAC 1
  92. #define HEARTBEAT_REPORT_RSSI 1
  93. #define HEARTBEAT_REPORT_UPTIME 1
  94. #define HEARTBEAT_REPORT_DATETIME 1
  95. #define HEARTBEAT_REPORT_FREEHEAP 1
  96. #define HEARTBEAT_REPORT_VCC 1
  97. #define HEARTBEAT_REPORT_RELAY 1
  98. #define HEARTBEAT_REPORT_LIGHT 1
  99. #define HEARTBEAT_REPORT_HOSTNAME 1
  100. #define HEARTBEAT_REPORT_APP 1
  101. #define HEARTBEAT_REPORT_VERSION 1
  102. #define HEARTBEAT_REPORT_INTERVAL 0
  103. //------------------------------------------------------------------------------
  104. // RESET
  105. //------------------------------------------------------------------------------
  106. #define CUSTOM_RESET_HARDWARE 1 // Reset from hardware button
  107. #define CUSTOM_RESET_WEB 2 // Reset from web interface
  108. #define CUSTOM_RESET_TERMINAL 3 // Reset from terminal
  109. #define CUSTOM_RESET_MQTT 4 // Reset via MQTT
  110. #define CUSTOM_RESET_RPC 5 // Reset via RPC (HTTP)
  111. #define CUSTOM_RESET_OTA 6 // Reset after successful OTA update
  112. #define CUSTOM_RESET_NOFUSS 8 // Reset after successful NOFUSS update
  113. #define CUSTOM_RESET_UPGRADE 9 // Reset after update from web interface
  114. #define CUSTOM_RESET_FACTORY 10 // Factory reset from terminal
  115. #define CUSTOM_RESET_MAX 10
  116. PROGMEM const char custom_reset_hardware[] = "Hardware button";
  117. PROGMEM const char custom_reset_web[] = "Reboot from web interface";
  118. PROGMEM const char custom_reset_terminal[] = "Reboot from terminal";
  119. PROGMEM const char custom_reset_mqtt[] = "Reboot from MQTT";
  120. PROGMEM const char custom_reset_rpc[] = "Reboot from RPC";
  121. PROGMEM const char custom_reset_ota[] = "Reboot after successful OTA update";
  122. PROGMEM const char custom_reset_nofuss[] = "Reboot after successful NoFUSS update";
  123. PROGMEM const char custom_reset_upgrade[] = "Reboot after successful web update";
  124. PROGMEM const char custom_reset_factory[] = "Factory reset";
  125. PROGMEM const char* const custom_reset_string[] = {
  126. custom_reset_hardware, custom_reset_web, custom_reset_terminal,
  127. custom_reset_mqtt, custom_reset_rpc, custom_reset_ota,
  128. custom_reset_nofuss, custom_reset_upgrade, custom_reset_factory
  129. };
  130. //------------------------------------------------------------------------------
  131. // BUTTON
  132. //------------------------------------------------------------------------------
  133. #define BUTTON_DEBOUNCE_DELAY 50 // Debounce delay (ms)
  134. #define BUTTON_DBLCLICK_DELAY 500 // Time in ms to wait for a second (or third...) click
  135. #define BUTTON_LNGCLICK_DELAY 1000 // Time in ms holding the button down to get a long click
  136. #define BUTTON_LNGLNGCLICK_DELAY 10000 // Time in ms holding the button down to get a long-long click
  137. #define BUTTON_EVENT_NONE 0
  138. #define BUTTON_EVENT_PRESSED 1
  139. #define BUTTON_EVENT_RELEASED 2
  140. #define BUTTON_EVENT_CLICK 2
  141. #define BUTTON_EVENT_DBLCLICK 3
  142. #define BUTTON_EVENT_LNGCLICK 4
  143. #define BUTTON_EVENT_LNGLNGCLICK 5
  144. #define BUTTON_MODE_NONE 0
  145. #define BUTTON_MODE_TOGGLE 1
  146. #define BUTTON_MODE_ON 2
  147. #define BUTTON_MODE_OFF 3
  148. #define BUTTON_MODE_AP 4
  149. #define BUTTON_MODE_RESET 5
  150. #define BUTTON_MODE_PULSE 6
  151. #define BUTTON_MODE_FACTORY 7
  152. //------------------------------------------------------------------------------
  153. // RELAY
  154. //------------------------------------------------------------------------------
  155. #define RELAY_MODE_OFF 0
  156. #define RELAY_MODE_ON 1
  157. #define RELAY_MODE_SAME 2
  158. #define RELAY_MODE_TOOGLE 3
  159. #define RELAY_TYPE_NORMAL 0
  160. #define RELAY_TYPE_INVERSE 1
  161. #define RELAY_TYPE_LATCHED 2
  162. #define RELAY_SYNC_ANY 0
  163. #define RELAY_SYNC_NONE_OR_ONE 1
  164. #define RELAY_SYNC_ONE 2
  165. #define RELAY_SYNC_SAME 3
  166. #define RELAY_PULSE_NONE 0
  167. #define RELAY_PULSE_OFF 1
  168. #define RELAY_PULSE_ON 2
  169. #define RELAY_PROVIDER_RELAY 0
  170. #define RELAY_PROVIDER_DUAL 1
  171. #define RELAY_PROVIDER_LIGHT 2
  172. #define RELAY_PROVIDER_RFBRIDGE 3
  173. // Pulse time in milliseconds
  174. #define RELAY_PULSE_TIME 1.0
  175. // 0 means OFF, 1 ON and 2 whatever was before
  176. #define RELAY_MODE RELAY_MODE_OFF
  177. // 0 means ANY, 1 zero or one and 2 one and only one
  178. #define RELAY_SYNC RELAY_SYNC_ANY
  179. // 0 means no pulses, 1 means normally off, 2 normally on
  180. #define RELAY_PULSE_MODE RELAY_PULSE_NONE
  181. // Relay requests flood protection window - in seconds
  182. #define RELAY_FLOOD_WINDOW 3
  183. // Allowed actual relay changes inside requests flood protection window
  184. #define RELAY_FLOOD_CHANGES 5
  185. // Pulse with in milliseconds for a latched relay
  186. #define RELAY_LATCHING_PULSE 10
  187. // Do not save relay state after these many milliseconds
  188. #define RELAY_SAVE_DELAY 1000
  189. //------------------------------------------------------------------------------
  190. // I18N
  191. //------------------------------------------------------------------------------
  192. #define TMP_CELSIUS 0
  193. #define TMP_FAHRENHEIT 1
  194. //------------------------------------------------------------------------------
  195. // LED
  196. //------------------------------------------------------------------------------
  197. #define LED_MODE_MQTT 0 // LED will be managed from MQTT (OFF by default)
  198. #define LED_MODE_WIFI 1 // LED will blink according to the WIFI status
  199. #define LED_MODE_FOLLOW 2 // LED will follow state of linked relay (check RELAY#_LED)
  200. #define LED_MODE_FOLLOW_INVERSE 3 // LED will follow the opposite state of linked relay (check RELAY#_LED)
  201. #define LED_MODE_FINDME 4 // LED will be ON if all relays are OFF
  202. #define LED_MODE_MIXED 5 // A mixed between WIFI and FINDME
  203. // -----------------------------------------------------------------------------
  204. // WIFI
  205. // -----------------------------------------------------------------------------
  206. #define WIFI_CONNECT_TIMEOUT 60000 // Connecting timeout for WIFI in ms
  207. #define WIFI_RECONNECT_INTERVAL 180000 // If could not connect to WIFI, retry after this time in ms
  208. #define WIFI_MAX_NETWORKS 5 // Max number of WIFI connection configurations
  209. #define WIFI_AP_MODE AP_MODE_ALONE
  210. #define WIFI_SLEEP_ENABLED 1 // Enable WiFi light sleep
  211. // Optional hardcoded configuration (up to 2 different networks)
  212. //#define WIFI1_SSID "..."
  213. //#define WIFI1_PASS "..."
  214. //#define WIFI1_IP "192.168.1.201"
  215. //#define WIFI1_GW "192.168.1.1"
  216. //#define WIFI1_MASK "255.255.255.0"
  217. //#define WIFI1_DNS "8.8.8.8"
  218. //#define WIFI2_SSID "..."
  219. //#define WIFI2_PASS "..."
  220. // -----------------------------------------------------------------------------
  221. // WEB
  222. // -----------------------------------------------------------------------------
  223. #ifndef WEB_SUPPORT
  224. #define WEB_SUPPORT 1 // Enable web support (http, api, 121.65Kb)
  225. #endif
  226. #ifndef WEB_EMBEDDED
  227. #define WEB_EMBEDDED 1 // Build the firmware with the web interface embedded in
  228. #endif
  229. // This is not working at the moment!!
  230. // Requires ASYNC_TCP_SSL_ENABLED to 1 and ESP8266 Arduino Core staging version.
  231. #define WEB_SSL_ENABLED 0 // Use HTTPS web interface
  232. #define WEB_MODE_NORMAL 0
  233. #define WEB_MODE_PASSWORD 1
  234. #define WEB_USERNAME "admin" // HTTP username
  235. #define WEB_FORCE_PASS_CHANGE 1 // Force the user to change the password if default one
  236. #define WEB_PORT 80 // HTTP port
  237. // -----------------------------------------------------------------------------
  238. // WEBSOCKETS
  239. // -----------------------------------------------------------------------------
  240. // This will only be enabled if WEB_SUPPORT is 1 (this is the default value)
  241. #define WS_BUFFER_SIZE 5 // Max number of secured websocket connections
  242. #define WS_TIMEOUT 1800000 // Timeout for secured websocket
  243. // -----------------------------------------------------------------------------
  244. // API
  245. // -----------------------------------------------------------------------------
  246. // This will only be enabled if WEB_SUPPORT is 1 (this is the default value)
  247. #define API_ENABLED 0 // Do not enable API by default
  248. #define API_BUFFER_SIZE 15 // Size of the buffer for HTTP GET API responses
  249. #define API_REAL_TIME_VALUES 0 // Show filtered/median values by default (0 => median, 1 => real time)
  250. // -----------------------------------------------------------------------------
  251. // UI
  252. // -----------------------------------------------------------------------------
  253. #define UI_TAG_INPUT 0
  254. #define UI_TAG_CHECKBOX 1
  255. #define UI_TAG_SELECT 2
  256. // -----------------------------------------------------------------------------
  257. // MDNS & LLMNR
  258. // -----------------------------------------------------------------------------
  259. #ifndef MDNS_SUPPORT
  260. #define MDNS_SUPPORT 1 // Publish services using mDNS by default (1.84Kb)
  261. #endif
  262. #ifndef LLMNR_SUPPORT
  263. #define LLMNR_SUPPORT 0 // Publish device using LLMNR protocol by default (1.95Kb) - requires 2.4.0
  264. #endif
  265. #ifndef NETBIOS_SUPPORT
  266. #define NETBIOS_SUPPORT 0 // Publish device using NetBIOS protocol by default (1.26Kb) - requires 2.4.0
  267. #endif
  268. // -----------------------------------------------------------------------------
  269. // SPIFFS
  270. // -----------------------------------------------------------------------------
  271. #ifndef SPIFFS_SUPPORT
  272. #define SPIFFS_SUPPORT 0 // Do not add support for SPIFFS by default
  273. #endif
  274. // -----------------------------------------------------------------------------
  275. // OTA
  276. // -----------------------------------------------------------------------------
  277. #define OTA_PORT 8266 // OTA port
  278. // -----------------------------------------------------------------------------
  279. // NOFUSS
  280. // -----------------------------------------------------------------------------
  281. #ifndef NOFUSS_SUPPORT
  282. #define NOFUSS_SUPPORT 0 // Do not enable support for NoFuss by default (12.65Kb)
  283. #endif
  284. #define NOFUSS_ENABLED 0 // Do not perform NoFUSS updates by default
  285. #define NOFUSS_SERVER "" // Default NoFuss Server
  286. #define NOFUSS_INTERVAL 3600000 // Check for updates every hour
  287. // -----------------------------------------------------------------------------
  288. // MQTT
  289. // -----------------------------------------------------------------------------
  290. #ifndef MQTT_SUPPORT
  291. #define MQTT_SUPPORT 1 // MQTT support (22.38Kb async, 12.48Kb sync)
  292. #endif
  293. #ifndef MQTT_USE_ASYNC
  294. #define MQTT_USE_ASYNC 1 // Use AysncMQTTClient (1) or PubSubClient
  295. #endif
  296. // MQTT OVER SSL
  297. // Using MQTT over SSL works pretty well but generates problems with the web interface.
  298. // It could be a good idea to use it in conjuntion with WEB_SUPPORT=0.
  299. // Requires ASYNC_TCP_SSL_ENABLED to 1 and ESP8266 Arduino Core staging version.
  300. //
  301. // You can use it with MQTT_USE_ASYNC=1 (AsyncMqttClient library)
  302. // but you might experience hiccups on the web interface, so my recommendation is:
  303. // WEB_SUPPORT=0
  304. //
  305. // If you use it with MQTT_USE_ASYNC=0 (PubSubClient library)
  306. // you will have to disable all the modules that use ESPAsyncTCP, that is:
  307. // ALEXA_SUPPORT=0, INFLUXDB_SUPPORT=0, TELNET_SUPPORT=0 and WEB_SUPPORT=0
  308. //
  309. // You will need the fingerprint for your MQTT server, example for CloudMQTT:
  310. // $ echo -n | openssl s_client -connect m11.cloudmqtt.com:24055 > cloudmqtt.pem
  311. // $ openssl x509 -noout -in cloudmqtt.pem -fingerprint -sha1
  312. #define MQTT_SSL_ENABLED 0 // By default MQTT over SSL will not be enabled
  313. #define MQTT_SSL_FINGERPRINT "" // SSL fingerprint of the server
  314. #define MQTT_ENABLED 0 // Do not enable MQTT connection by default
  315. #define MQTT_AUTOCONNECT 1 // If enabled and MDNS_SUPPORT=1 will perform an autodiscover and
  316. // autoconnect to the first MQTT broker found if none defined
  317. #define MQTT_SERVER "" // Default MQTT broker address
  318. #define MQTT_USER "" // Default MQTT broker usename
  319. #define MQTT_PASS "" // Default MQTT broker password
  320. #define MQTT_PORT 1883 // MQTT broker port
  321. #define MQTT_TOPIC "{identifier}" // Default MQTT base topic
  322. #define MQTT_RETAIN true // MQTT retain flag
  323. #define MQTT_QOS 0 // MQTT QoS value for all messages
  324. #define MQTT_KEEPALIVE 30 // MQTT keepalive value
  325. #define MQTT_RECONNECT_DELAY_MIN 5000 // Try to reconnect in 5 seconds upon disconnection
  326. #define MQTT_RECONNECT_DELAY_STEP 5000 // Increase the reconnect delay in 5 seconds after each failed attempt
  327. #define MQTT_RECONNECT_DELAY_MAX 120000 // Set reconnect time to 2 minutes at most
  328. #define MQTT_SKIP_RETAINED 1 // Skip retained messages on connection
  329. #define MQTT_SKIP_TIME 1000 // Skip messages for 1 second anter connection
  330. #define MQTT_USE_JSON 0 // Group messages in a JSON body
  331. #define MQTT_USE_JSON_DELAY 100 // Wait this many ms before grouping messages
  332. #define MQTT_QUEUE_MAX_SIZE 10 // Size of the MQTT queue when MQTT_USE_JSON is enabled
  333. // These particles will be concatenated to the MQTT_TOPIC base to form the actual topic
  334. #define MQTT_TOPIC_JSON "data"
  335. #define MQTT_TOPIC_ACTION "action"
  336. #define MQTT_TOPIC_RELAY "relay"
  337. #define MQTT_TOPIC_LED "led"
  338. #define MQTT_TOPIC_BUTTON "button"
  339. #define MQTT_TOPIC_IP "ip"
  340. #define MQTT_TOPIC_VERSION "version"
  341. #define MQTT_TOPIC_UPTIME "uptime"
  342. #define MQTT_TOPIC_DATETIME "datetime"
  343. #define MQTT_TOPIC_FREEHEAP "freeheap"
  344. #define MQTT_TOPIC_VCC "vcc"
  345. #define MQTT_TOPIC_STATUS "status"
  346. #define MQTT_TOPIC_MAC "mac"
  347. #define MQTT_TOPIC_RSSI "rssi"
  348. #define MQTT_TOPIC_APP "app"
  349. #define MQTT_TOPIC_INTERVAL "interval"
  350. #define MQTT_TOPIC_HOSTNAME "host"
  351. #define MQTT_TOPIC_TIME "time"
  352. #define MQTT_TOPIC_ANALOG "analog"
  353. #define MQTT_TOPIC_COUNTER "counter"
  354. #define MQTT_TOPIC_RFOUT "rfout"
  355. #define MQTT_TOPIC_RFIN "rfin"
  356. #define MQTT_TOPIC_RFLEARN "rflearn"
  357. // Power module
  358. #define MQTT_TOPIC_CURRENT "current"
  359. #define MQTT_TOPIC_VOLTAGE "voltage"
  360. #define MQTT_TOPIC_POWER_ACTIVE "power"
  361. #define MQTT_TOPIC_POWER_APPARENT "apparent"
  362. #define MQTT_TOPIC_POWER_REACTIVE "reactive"
  363. #define MQTT_TOPIC_MAX_POWER "max_power"
  364. #define MQTT_TOPIC_POWER_FACTOR "factor"
  365. #define MQTT_TOPIC_ENERGY_DELTA "energy_delta"
  366. #define MQTT_TOPIC_ENERGY_TOTAL "energy_total"
  367. // Light module
  368. #define MQTT_TOPIC_CHANNEL "channel"
  369. #define MQTT_TOPIC_COLOR "color" // DEPRECATED, use RGB instead
  370. #define MQTT_TOPIC_COLOR_RGB "rgb"
  371. #define MQTT_TOPIC_COLOR_HSV "hsv"
  372. #define MQTT_TOPIC_ANIM_MODE "anim_mode"
  373. #define MQTT_TOPIC_ANIM_SPEED "anim_speed"
  374. #define MQTT_TOPIC_BRIGHTNESS "brightness"
  375. #define MQTT_TOPIC_MIRED "mired"
  376. #define MQTT_TOPIC_KELVIN "kelvin"
  377. #define MQTT_STATUS_ONLINE "1" // Value for the device ON message
  378. #define MQTT_STATUS_OFFLINE "0" // Value for the device OFF message (will)
  379. #define MQTT_ACTION_RESET "reboot" // RESET MQTT topic particle
  380. // Internal MQTT events (do not change)
  381. #define MQTT_CONNECT_EVENT 0
  382. #define MQTT_DISCONNECT_EVENT 1
  383. #define MQTT_MESSAGE_EVENT 2
  384. // Custom get and set postfixes
  385. // Use something like "/status" or "/set", with leading slash
  386. // Since 1.9.0 the default value is "" for getter and "/set" for setter
  387. #define MQTT_USE_GETTER ""
  388. #define MQTT_USE_SETTER "/set"
  389. // -----------------------------------------------------------------------------
  390. // SETTINGS
  391. // -----------------------------------------------------------------------------
  392. #ifndef SETTINGS_AUTOSAVE
  393. #define SETTINGS_AUTOSAVE 1 // Autosave settings o force manual commit
  394. #endif
  395. // -----------------------------------------------------------------------------
  396. // LIGHT
  397. // -----------------------------------------------------------------------------
  398. // Available light providers (do not change)
  399. #define LIGHT_PROVIDER_NONE 0
  400. #define LIGHT_PROVIDER_MY92XX 1 // works with MY9291 and MY9231
  401. #define LIGHT_PROVIDER_DIMMER 2
  402. // LIGHT_PROVIDER_DIMMER can have from 1 to 5 different channels.
  403. // They have to be defined for each device in the hardware.h file.
  404. // If 3 or more channels first 3 will be considered RGB.
  405. // Usual configurations are:
  406. // 1 channels => W
  407. // 2 channels => WW
  408. // 3 channels => RGB
  409. // 4 channels => RGBW
  410. // 5 channels => RGBWW
  411. #ifndef LIGHT_SAVE_ENABLED
  412. #define LIGHT_SAVE_ENABLED 1 // Light channel values saved by default after each change
  413. #endif
  414. #define LIGHT_SAVE_DELAY 5 // Persist color after 5 seconds to avoid wearing out
  415. #ifndef LIGHT_MAX_PWM
  416. #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
  417. #define LIGHT_MAX_PWM 255
  418. #endif
  419. #if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
  420. #define LIGHT_MAX_PWM 10000 // 5000 * 200ns => 1 kHz
  421. #endif
  422. #endif // LIGHT_MAX_PWM
  423. #ifndef LIGHT_LIMIT_PWM
  424. #define LIGHT_LIMIT_PWM LIGHT_MAX_PWM // Limit PWM to this value (prevent 100% power)
  425. #endif
  426. #ifndef LIGHT_MAX_VALUE
  427. #define LIGHT_MAX_VALUE 255 // Maximum light value
  428. #endif
  429. #define LIGHT_MAX_BRIGHTNESS 255 // Maximun brightness value
  430. #define LIGHT_STEP 32 // Step size
  431. #define LIGHT_USE_COLOR 1 // Use 3 first channels as RGB
  432. #define LIGHT_USE_WHITE 0 // Use white channel whenever RGB have the same value
  433. #define LIGHT_USE_GAMMA 0 // Use gamma correction for color channels
  434. #define LIGHT_USE_CSS 1 // Use CSS style to report colors (1=> "#FF0000", 0=> "255,0,0")
  435. #define LIGHT_USE_RGB 0 // Use RGB color selector (1=> RGB, 0=> HSV)
  436. #define LIGHT_USE_TRANSITIONS 1 // Transitions between colors
  437. #define LIGHT_TRANSITION_STEP 10 // Time in millis between each transtion step
  438. #define LIGHT_TRANSITION_STEPS 50 // Number of steps to acomplish transition
  439. // -----------------------------------------------------------------------------
  440. // POWER METERING
  441. // -----------------------------------------------------------------------------
  442. // Available power-metering providers (do not change this)
  443. #define POWER_PROVIDER_NONE 0x00
  444. #define POWER_PROVIDER_EMON_ANALOG 0x10
  445. #define POWER_PROVIDER_EMON_ADC121 0x11
  446. #define POWER_PROVIDER_HLW8012 0x20
  447. #define POWER_PROVIDER_V9261F 0x30
  448. #define POWER_PROVIDER_ECH1560 0x40
  449. // Available magnitudes (do not change this)
  450. #define POWER_MAGNITUDE_CURRENT 1
  451. #define POWER_MAGNITUDE_VOLTAGE 2
  452. #define POWER_MAGNITUDE_ACTIVE 4
  453. #define POWER_MAGNITUDE_APPARENT 8
  454. #define POWER_MAGNITUDE_REACTIVE 16
  455. #define POWER_MAGNITUDE_POWER_FACTOR 32
  456. #define POWER_MAGNITUDE_ALL 63
  457. // No power provider defined (do not change this)
  458. #ifndef POWER_PROVIDER
  459. #define POWER_PROVIDER POWER_PROVIDER_NONE
  460. #endif
  461. // Identify available magnitudes (do not change this)
  462. #if (POWER_PROVIDER == POWER_PROVIDER_HLW8012) || (POWER_PROVIDER == POWER_PROVIDER_V9261F)
  463. #define POWER_HAS_ACTIVE 1
  464. #else
  465. #define POWER_HAS_ACTIVE 0
  466. #endif
  467. #if (POWER_PROVIDER == POWER_PROVIDER_HLW8012)
  468. #define POWER_HAS_ENERGY 1
  469. #else
  470. #define POWER_HAS_ENERGY 0
  471. #endif
  472. #define POWER_VOLTAGE 230 // Default voltage
  473. #define POWER_MIN_READ_INTERVAL 2000 // Minimum read interval
  474. #define POWER_READ_INTERVAL 6000 // Default reading interval (6 seconds)
  475. #define POWER_REPORT_INTERVAL 60000 // Default report interval (1 minute)
  476. #define POWER_CURRENT_DECIMALS 2 // Decimals for current values
  477. #define POWER_VOLTAGE_DECIMALS 0 // Decimals for voltage values
  478. #define POWER_POWER_DECIMALS 0 // Decimals for power values
  479. #define POWER_ENERGY_DECIMALS 3 // Decimals for energy values
  480. #define POWER_ENERGY_DECIMALS_KWH 6 // Decimals for energy values
  481. #define POWER_ENERGY_FACTOR 1 // Watt * seconds == Joule (Ws == J)
  482. #define POWER_ENERGY_FACTOR_KWH (1. / 1000. / 3600.) // kWh
  483. #if POWER_PROVIDER == POWER_PROVIDER_EMON_ANALOG
  484. #define EMON_CURRENT_RATIO 30 // Current ratio in the clamp (30V/1A)
  485. #define EMON_SAMPLES 1000 // Number of samples to get for each reading
  486. #define EMON_ADC_BITS 10 // ADC depth
  487. #define EMON_REFERENCE_VOLTAGE 1.0 // Reference voltage of the ADC
  488. #define EMON_CURRENT_OFFSET 0.25 // Current offset (error)
  489. #undef ADC_VCC_ENABLED
  490. #define ADC_VCC_ENABLED 0 // Disable internal battery measurement
  491. #endif
  492. #if POWER_PROVIDER == POWER_PROVIDER_EMON_ADC121
  493. #define EMON_CURRENT_RATIO 30 // Current ratio in the clamp (30V/1A)
  494. #define EMON_SAMPLES 1000 // Number of samples to get for each reading
  495. #define EMON_ADC_BITS 12 // ADC depth
  496. #define EMON_REFERENCE_VOLTAGE 3.3 // Reference voltage of the ADC
  497. #define EMON_CURRENT_OFFSET 0.10 // Current offset (error)
  498. #define ADC121_I2C_ADDRESS 0x50 // I2C address of the ADC121
  499. #undef I2C_SUPPORT
  500. #define I2C_SUPPORT 1 // Enabled I2C support
  501. #endif
  502. #if POWER_PROVIDER == POWER_PROVIDER_HLW8012
  503. #define HLW8012_USE_INTERRUPTS 1 // Use interrupts to trap HLW8012 signals
  504. #define HLW8012_SEL_CURRENT HIGH // SEL pin to HIGH to measure current
  505. #define HLW8012_CURRENT_R 0.001 // Current resistor
  506. #define HLW8012_VOLTAGE_R_UP ( 5 * 470000 ) // Upstream voltage resistor
  507. #define HLW8012_VOLTAGE_R_DOWN ( 1000 ) // Downstream voltage resistor
  508. #endif
  509. #if POWER_PROVIDER == POWER_PROVIDER_V9261F
  510. #ifndef V9261F_PIN
  511. #define V9261F_PIN 2 // TX pin from the V9261F
  512. #endif
  513. #ifndef V9261F_PIN_INVERSE
  514. #define V9261F_PIN_INVERSE 1 // Signal is inverted
  515. #endif
  516. #define V9261F_SYNC_INTERVAL 600 // Sync signal length (ms)
  517. #define V9261F_BAUDRATE 4800 // UART baudrate
  518. // Default ratios
  519. #define V9261F_CURRENT_FACTOR 79371434.0
  520. #define V9261F_VOLTAGE_FACTOR 4160651.0
  521. #define V9261F_POWER_FACTOR 153699.0
  522. #define V9261F_RPOWER_FACTOR V9261F_CURRENT_FACTOR
  523. #endif
  524. #if POWER_PROVIDER == POWER_PROVIDER_ECH1560
  525. #ifndef ECH1560_CLK_PIN
  526. #define ECH1560_CLK_PIN 4 // Default CLK pin
  527. #endif
  528. #ifndef ECH1560_MISO_PIN
  529. #define ECH1560_MISO_PIN 5 // Default MISO pin
  530. #endif
  531. #ifndef ECH1560_INVERTED
  532. #define ECH1560_INVERTED 0 // Power signal is inverted
  533. #endif
  534. #endif
  535. // -----------------------------------------------------------------------------
  536. // DOMOTICZ
  537. // -----------------------------------------------------------------------------
  538. #ifndef DOMOTICZ_SUPPORT
  539. #define DOMOTICZ_SUPPORT MQTT_SUPPORT // Build with domoticz (if MQTT) support (1.72Kb)
  540. #endif
  541. #define DOMOTICZ_ENABLED 0 // Disable domoticz by default
  542. #define DOMOTICZ_IN_TOPIC "domoticz/in" // Default subscription topic
  543. #define DOMOTICZ_OUT_TOPIC "domoticz/out" // Default publication topic
  544. #define DOMOTICZ_SKIP_TIME 2 // Avoid recursion skipping messages to same IDX within 2 seconds
  545. // -----------------------------------------------------------------------------
  546. // HOME ASSISTANT
  547. // -----------------------------------------------------------------------------
  548. #ifndef HOMEASSISTANT_SUPPORT
  549. #define HOMEASSISTANT_SUPPORT MQTT_SUPPORT // Build with home assistant support (if MQTT, 1.64Kb)
  550. #endif
  551. #define HOMEASSISTANT_ENABLED 0 // Integration not enabled by default
  552. #define HOMEASSISTANT_PREFIX "homeassistant" // Default MQTT prefix
  553. // -----------------------------------------------------------------------------
  554. // INFLUXDB
  555. // -----------------------------------------------------------------------------
  556. #ifndef INFLUXDB_SUPPORT
  557. #define INFLUXDB_SUPPORT 0 // Enable InfluxDB support by default (4.38Kb)
  558. #endif
  559. #define INFLUXDB_ENABLED 0 // InfluxDB disabled by default
  560. #define INFLUXDB_HOST "" // Default server
  561. #define INFLUXDB_PORT 8086 // Default InfluxDB port
  562. #define INFLUXDB_DATABASE "" // Default database
  563. #define INFLUXDB_USERNAME "" // Default username
  564. #define INFLUXDB_PASSWORD "" // Default password
  565. // -----------------------------------------------------------------------------
  566. // NTP
  567. // -----------------------------------------------------------------------------
  568. #ifndef NTP_SUPPORT
  569. #define NTP_SUPPORT 1 // Build with NTP support by default (6.78Kb)
  570. #endif
  571. #define NTP_SERVER "pool.ntp.org" // Default NTP server
  572. #define NTP_TIME_OFFSET 1 // Default timezone offset (GMT+1)
  573. #define NTP_DAY_LIGHT true // Enable daylight time saving by default
  574. #define NTP_UPDATE_INTERVAL 1800 // NTP check every 30 minutes
  575. // -----------------------------------------------------------------------------
  576. // FAUXMO
  577. // -----------------------------------------------------------------------------
  578. // This setting defines whether Alexa support should be built into the firmware
  579. #ifndef ALEXA_SUPPORT
  580. #define ALEXA_SUPPORT 1 // Enable Alexa support by default (9.5Kb)
  581. #endif
  582. // This is default value for the alexaEnabled setting that defines whether
  583. // this device should be discoberable and respond to Alexa commands.
  584. // Both ALEXA_SUPPORT and alexaEnabled should be 1 for Alexa support to work.
  585. #define ALEXA_ENABLED 1
  586. // -----------------------------------------------------------------------------
  587. // RFBRIDGE
  588. // -----------------------------------------------------------------------------
  589. #define RF_SEND_TIMES 4 // How many times to send the message
  590. #define RF_SEND_DELAY 250 // Interval between sendings in ms
  591. #define RF_RECEIVE_DELAY 500 // Interval between recieving in ms (avoid debouncing)
  592. // -----------------------------------------------------------------------------
  593. // IR
  594. // -----------------------------------------------------------------------------
  595. #ifndef IR_SUPPORT
  596. #define IR_SUPPORT 0 // Do not build with IR support by default (10.25Kb)
  597. #endif
  598. #ifndef IR_PIN
  599. #define IR_PIN 4 // IR LED
  600. #endif
  601. // 24 Buttons Set of the IR Remote
  602. #ifndef IR_BUTTON_SET
  603. #define IR_BUTTON_SET 1 // IR button set to use (see below)
  604. #endif
  605. // IR Button modes
  606. #define IR_BUTTON_MODE_NONE 0
  607. #define IR_BUTTON_MODE_RGB 1
  608. #define IR_BUTTON_MODE_HSV 2
  609. #define IR_BUTTON_MODE_BRIGHTER 3
  610. #define IR_BUTTON_MODE_STATE 4
  611. #define IR_BUTTON_MODE_EFFECT 5
  612. #define LIGHT_EFFECT_SOLID 0
  613. #define LIGHT_EFFECT_FLASH 1
  614. #define LIGHT_EFFECT_STROBE 2
  615. #define LIGHT_EFFECT_FADE 3
  616. #define LIGHT_EFFECT_SMOOTH 4
  617. //Remote Buttons SET 1 (for the original Remote shipped with the controller)
  618. #if IR_SUPPORT
  619. #if IR_BUTTON_SET == 1
  620. #define IR_BUTTON_COUNT 24
  621. const unsigned long IR_BUTTON[IR_BUTTON_COUNT][3] PROGMEM = {
  622. { 0xFF906F, IR_BUTTON_MODE_BRIGHTER, 1 },
  623. { 0xFFB847, IR_BUTTON_MODE_BRIGHTER, 0 },
  624. { 0xFFF807, IR_BUTTON_MODE_STATE, 0 },
  625. { 0xFFB04F, IR_BUTTON_MODE_STATE, 1 },
  626. { 0xFF9867, IR_BUTTON_MODE_RGB, 0xFF0000 },
  627. { 0xFFD827, IR_BUTTON_MODE_RGB, 0x00FF00 },
  628. { 0xFF8877, IR_BUTTON_MODE_RGB, 0x0000FF },
  629. { 0xFFA857, IR_BUTTON_MODE_RGB, 0xFFFFFF },
  630. { 0xFFE817, IR_BUTTON_MODE_RGB, 0xD13A01 },
  631. { 0xFF48B7, IR_BUTTON_MODE_RGB, 0x00E644 },
  632. { 0xFF6897, IR_BUTTON_MODE_RGB, 0x0040A7 },
  633. { 0xFFB24D, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_FLASH },
  634. { 0xFF02FD, IR_BUTTON_MODE_RGB, 0xE96F2A },
  635. { 0xFF32CD, IR_BUTTON_MODE_RGB, 0x00BEBF },
  636. { 0xFF20DF, IR_BUTTON_MODE_RGB, 0x56406F },
  637. { 0xFF00FF, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_STROBE },
  638. { 0xFF50AF, IR_BUTTON_MODE_RGB, 0xEE9819 },
  639. { 0xFF7887, IR_BUTTON_MODE_RGB, 0x00799A },
  640. { 0xFF708F, IR_BUTTON_MODE_RGB, 0x944E80 },
  641. { 0xFF58A7, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_FADE },
  642. { 0xFF38C7, IR_BUTTON_MODE_RGB, 0xFFFF00 },
  643. { 0xFF28D7, IR_BUTTON_MODE_RGB, 0x0060A1 },
  644. { 0xFFF00F, IR_BUTTON_MODE_RGB, 0xEF45AD },
  645. { 0xFF30CF, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_SMOOTH }
  646. };
  647. #endif
  648. //Remote Buttons SET 2 (another identical IR Remote shipped with another controller)
  649. #if IR_BUTTON_SET == 2
  650. #define IR_BUTTON_COUNT 24
  651. const unsigned long IR_BUTTON[IR_BUTTON_COUNT][3] PROGMEM = {
  652. { 0xFF00FF, IR_BUTTON_MODE_BRIGHTER, 1 },
  653. { 0xFF807F, IR_BUTTON_MODE_BRIGHTER, 0 },
  654. { 0xFF40BF, IR_BUTTON_MODE_STATE, 0 },
  655. { 0xFFC03F, IR_BUTTON_MODE_STATE, 1 },
  656. { 0xFF20DF, IR_BUTTON_MODE_RGB, 0xFF0000 },
  657. { 0xFFA05F, IR_BUTTON_MODE_RGB, 0x00FF00 },
  658. { 0xFF609F, IR_BUTTON_MODE_RGB, 0x0000FF },
  659. { 0xFFE01F, IR_BUTTON_MODE_RGB, 0xFFFFFF },
  660. { 0xFF10EF, IR_BUTTON_MODE_RGB, 0xD13A01 },
  661. { 0xFF906F, IR_BUTTON_MODE_RGB, 0x00E644 },
  662. { 0xFF50AF, IR_BUTTON_MODE_RGB, 0x0040A7 },
  663. { 0xFFD02F, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_FLASH },
  664. { 0xFF30CF, IR_BUTTON_MODE_RGB, 0xE96F2A },
  665. { 0xFFB04F, IR_BUTTON_MODE_RGB, 0x00BEBF },
  666. { 0xFF708F, IR_BUTTON_MODE_RGB, 0x56406F },
  667. { 0xFFF00F, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_STROBE },
  668. { 0xFF08F7, IR_BUTTON_MODE_RGB, 0xEE9819 },
  669. { 0xFF8877, IR_BUTTON_MODE_RGB, 0x00799A },
  670. { 0xFF48B7, IR_BUTTON_MODE_RGB, 0x944E80 },
  671. { 0xFFC837, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_FADE },
  672. { 0xFF28D7, IR_BUTTON_MODE_RGB, 0xFFFF00 },
  673. { 0xFFA857, IR_BUTTON_MODE_RGB, 0x0060A1 },
  674. { 0xFF6897, IR_BUTTON_MODE_RGB, 0xEF45AD },
  675. { 0xFFE817, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_SMOOTH }
  676. };
  677. #endif
  678. #endif // IR_SUPPORT
  679. //--------------------------------------------------------------------------------
  680. // Custom RF module
  681. // Check http://tinkerman.cat/adding-rf-to-a-non-rf-itead-sonoff/
  682. // Enable support by passing RF_SUPPORT=1 build flag
  683. //--------------------------------------------------------------------------------
  684. #ifndef RF_SUPPORT
  685. #define RF_SUPPORT 0
  686. #endif
  687. #ifndef RF_PIN
  688. #define RF_PIN 14
  689. #endif
  690. #define RF_CHANNEL 31
  691. #define RF_DEVICE 1