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.

1148 lines
38 KiB

8 years ago
8 years ago
6 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
6 years ago
8 years ago
8 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
8 years ago
6 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 DEVICE_NAME MANUFACTURER "_" DEVICE // Concatenate both to get a unique device name
  9. #ifndef ADMIN_PASS
  10. #define ADMIN_PASS "fibonacci" // Default password (WEB, OTA, WIFI)
  11. #endif
  12. #ifndef USE_PASSWORD
  13. #define USE_PASSWORD 1 // Insecurity caution! Disabling this will disable password querying completely.
  14. #endif
  15. #ifndef LOOP_DELAY_TIME
  16. #define LOOP_DELAY_TIME 10 // Delay for this millis in the main loop [0-250]
  17. #endif
  18. //------------------------------------------------------------------------------
  19. // DEBUG
  20. //------------------------------------------------------------------------------
  21. // Serial debug log
  22. #ifndef DEBUG_SERIAL_SUPPORT
  23. #define DEBUG_SERIAL_SUPPORT 1 // Enable serial debug log
  24. #endif
  25. #ifndef DEBUG_PORT
  26. #define DEBUG_PORT Serial // Default debugging port
  27. #endif
  28. #ifndef SERIAL_BAUDRATE
  29. #define SERIAL_BAUDRATE 115200 // Default baudrate
  30. #endif
  31. #ifndef DEBUG_ADD_TIMESTAMP
  32. #define DEBUG_ADD_TIMESTAMP 1 // Add timestamp to debug messages
  33. // (in millis overflowing every 1000 seconds)
  34. #endif
  35. // Second serial port (used for RX)
  36. #ifndef SERIAL_RX_ENABLED
  37. #define SERIAL_RX_ENABLED 0 // Secondary serial port for RX
  38. #endif
  39. #ifndef SERIAL_RX_PORT
  40. #define SERIAL_RX_PORT Serial // This setting is usually defined
  41. // in the hardware.h file for those
  42. // boards that require it
  43. #endif
  44. #ifndef SERIAL_RX_BAUDRATE
  45. #define SERIAL_RX_BAUDRATE 115200 // Default baudrate
  46. #endif
  47. //------------------------------------------------------------------------------
  48. // UDP debug log
  49. // To receive the message son the destination computer use nc:
  50. // nc -ul 8113
  51. #ifndef DEBUG_UDP_SUPPORT
  52. #define DEBUG_UDP_SUPPORT 0 // Enable UDP debug log
  53. #endif
  54. #ifndef DEBUG_UDP_IP
  55. #define DEBUG_UDP_IP IPAddress(192, 168, 1, 100)
  56. #endif
  57. #ifndef DEBUG_UDP_PORT
  58. #define DEBUG_UDP_PORT 8113
  59. #endif
  60. //------------------------------------------------------------------------------
  61. #ifndef DEBUG_TELNET_SUPPORT
  62. #define DEBUG_TELNET_SUPPORT 1 // Enable telnet debug log (will only work if TELNET_SUPPORT is also 1)
  63. #endif
  64. //------------------------------------------------------------------------------
  65. #ifndef DEBUG_WEB_SUPPORT
  66. #define DEBUG_WEB_SUPPORT 1 // Enable web debug log (will only work if WEB_SUPPORT is also 1)
  67. #endif
  68. //------------------------------------------------------------------------------
  69. // TELNET
  70. //------------------------------------------------------------------------------
  71. #ifndef TELNET_SUPPORT
  72. #define TELNET_SUPPORT 1 // Enable telnet support by default (3.34Kb)
  73. #endif
  74. #ifndef TELNET_STA
  75. #define TELNET_STA 0 // By default, disallow connections via STA interface
  76. #endif
  77. #define TELNET_PORT 23 // Port to listen to telnet clients
  78. #define TELNET_MAX_CLIENTS 1 // Max number of concurrent telnet clients
  79. //------------------------------------------------------------------------------
  80. // TERMINAL
  81. //------------------------------------------------------------------------------
  82. #ifndef TERMINAL_SUPPORT
  83. #define TERMINAL_SUPPORT 1 // Enable terminal commands (0.97Kb)
  84. #endif
  85. #define TERMINAL_BUFFER_SIZE 128 // Max size for commands commands
  86. //------------------------------------------------------------------------------
  87. // SYSTEM CHECK
  88. //------------------------------------------------------------------------------
  89. #ifndef SYSTEM_CHECK_ENABLED
  90. #define SYSTEM_CHECK_ENABLED 1 // Enable crash check by default
  91. #endif
  92. #ifndef SYSTEM_CHECK_MAX
  93. #define SYSTEM_CHECK_TIME 60000 // The system is considered stable after these many millis
  94. #endif
  95. #ifndef SYSTEM_CHECK_MAX
  96. #define SYSTEM_CHECK_MAX 5 // After this many crashes on boot
  97. // the system is flagged as unstable
  98. #endif
  99. //------------------------------------------------------------------------------
  100. // EEPROM
  101. //------------------------------------------------------------------------------
  102. #define EEPROM_SIZE 4096 // EEPROM size in bytes
  103. #define EEPROM_RELAY_STATUS 0 // Address for the relay status (1 byte)
  104. #define EEPROM_ENERGY_COUNT 1 // Address for the energy counter (4 bytes)
  105. #define EEPROM_CUSTOM_RESET 5 // Address for the reset reason (1 byte)
  106. #define EEPROM_CRASH_COUNTER 6 // Address for the crash counter (1 byte)
  107. #define EEPROM_MESSAGE_ID 7 // Address for the MQTT message id (4 bytes)
  108. #define EEPROM_DATA_END 11 // End of custom EEPROM data block
  109. //------------------------------------------------------------------------------
  110. // HEARTBEAT
  111. //------------------------------------------------------------------------------
  112. #ifndef HEARTBEAT_ENABLED
  113. #define HEARTBEAT_ENABLED 1
  114. #endif
  115. #ifndef HEARTBEAT_INTERVAL
  116. #define HEARTBEAT_INTERVAL 300000 // Interval between heartbeat messages (in ms)
  117. #endif
  118. #define UPTIME_OVERFLOW 4294967295 // Uptime overflow value
  119. // Topics that will be reported in heartbeat
  120. #define HEARTBEAT_REPORT_STATUS 1
  121. #define HEARTBEAT_REPORT_IP 1
  122. #define HEARTBEAT_REPORT_MAC 1
  123. #define HEARTBEAT_REPORT_RSSI 1
  124. #define HEARTBEAT_REPORT_UPTIME 1
  125. #define HEARTBEAT_REPORT_DATETIME 1
  126. #define HEARTBEAT_REPORT_FREEHEAP 1
  127. #define HEARTBEAT_REPORT_VCC 1
  128. #define HEARTBEAT_REPORT_RELAY 1
  129. #define HEARTBEAT_REPORT_LIGHT 1
  130. #define HEARTBEAT_REPORT_HOSTNAME 1
  131. #define HEARTBEAT_REPORT_APP 1
  132. #define HEARTBEAT_REPORT_VERSION 1
  133. #define HEARTBEAT_REPORT_BOARD 1
  134. #define HEARTBEAT_REPORT_INTERVAL 0
  135. //------------------------------------------------------------------------------
  136. // Load average
  137. //------------------------------------------------------------------------------
  138. #ifndef LOADAVG_INTERVAL
  139. #define LOADAVG_INTERVAL 30000 // Interval between calculating load average (in ms)
  140. #endif
  141. #ifndef LOADAVG_REPORT
  142. #define LOADAVG_REPORT 1 // Should we report Load average over MQTT?
  143. #endif
  144. //------------------------------------------------------------------------------
  145. // BUTTON
  146. //------------------------------------------------------------------------------
  147. #ifndef BUTTON_DEBOUNCE_DELAY
  148. #define BUTTON_DEBOUNCE_DELAY 50 // Debounce delay (ms)
  149. #endif
  150. #ifndef BUTTON_DBLCLICK_DELAY
  151. #define BUTTON_DBLCLICK_DELAY 500 // Time in ms to wait for a second (or third...) click
  152. #endif
  153. #ifndef BUTTON_LNGCLICK_DELAY
  154. #define BUTTON_LNGCLICK_DELAY 1000 // Time in ms holding the button down to get a long click
  155. #endif
  156. #ifndef BUTTON_LNGLNGCLICK_DELAY
  157. #define BUTTON_LNGLNGCLICK_DELAY 10000 // Time in ms holding the button down to get a long-long click
  158. #endif
  159. //------------------------------------------------------------------------------
  160. // RELAY
  161. //------------------------------------------------------------------------------
  162. // Default boot mode: 0 means OFF, 1 ON and 2 whatever was before
  163. #ifndef RELAY_BOOT_MODE
  164. #define RELAY_BOOT_MODE RELAY_BOOT_OFF
  165. #endif
  166. // 0 means ANY, 1 zero or one and 2 one and only one
  167. #ifndef RELAY_SYNC
  168. #define RELAY_SYNC RELAY_SYNC_ANY
  169. #endif
  170. // Default pulse mode: 0 means no pulses, 1 means normally off, 2 normally on
  171. #ifndef RELAY_PULSE_MODE
  172. #define RELAY_PULSE_MODE RELAY_PULSE_NONE
  173. #endif
  174. // Default pulse time in seconds
  175. #ifndef RELAY_PULSE_TIME
  176. #define RELAY_PULSE_TIME 1.0
  177. #endif
  178. // Relay requests flood protection window - in seconds
  179. #ifndef RELAY_FLOOD_WINDOW
  180. #define RELAY_FLOOD_WINDOW 3
  181. #endif
  182. // Allowed actual relay changes inside requests flood protection window
  183. #ifndef RELAY_FLOOD_CHANGES
  184. #define RELAY_FLOOD_CHANGES 5
  185. #endif
  186. // Pulse with in milliseconds for a latched relay
  187. #ifndef RELAY_LATCHING_PULSE
  188. #define RELAY_LATCHING_PULSE 10
  189. #endif
  190. // Do not save relay state after these many milliseconds
  191. #ifndef RELAY_SAVE_DELAY
  192. #define RELAY_SAVE_DELAY 1000
  193. #endif
  194. // -----------------------------------------------------------------------------
  195. // WIFI
  196. // -----------------------------------------------------------------------------
  197. #ifndef WIFI_CONNECT_TIMEOUT
  198. #define WIFI_CONNECT_TIMEOUT 60000 // Connecting timeout for WIFI in ms
  199. #endif
  200. #ifndef WIFI_RECONNECT_INTERVAL
  201. #define WIFI_RECONNECT_INTERVAL 180000 // If could not connect to WIFI, retry after this time in ms
  202. #endif
  203. #define WIFI_MAX_NETWORKS 5 // Max number of WIFI connection configurations
  204. #ifndef WIFI_AP_MODE
  205. #define WIFI_AP_MODE AP_MODE_ALONE
  206. #endif
  207. #ifndef WIFI_SLEEP_MODE
  208. #define WIFI_SLEEP_MODE WIFI_NONE_SLEEP // WIFI_NONE_SLEEP, WIFI_LIGHT_SLEEP or WIFI_MODEM_SLEEP
  209. #endif
  210. #ifndef WIFI_SCAN_NETWORKS
  211. #define WIFI_SCAN_NETWORKS 1 // Perform a network scan before connecting
  212. #endif
  213. // Optional hardcoded configuration (up to 2 networks)
  214. #ifndef WIFI1_SSID
  215. #define WIFI1_SSID ""
  216. #endif
  217. #ifndef WIFI1_PASS
  218. #define WIFI1_PASS ""
  219. #endif
  220. #ifndef WIFI1_IP
  221. #define WIFI1_IP ""
  222. #endif
  223. #ifndef WIFI1_GW
  224. #define WIFI1_GW ""
  225. #endif
  226. #ifndef WIFI1_MASK
  227. #define WIFI1_MASK ""
  228. #endif
  229. #ifndef WIFI1_DNS
  230. #define WIFI1_DNS ""
  231. #endif
  232. #ifndef WIFI2_SSID
  233. #define WIFI2_SSID ""
  234. #endif
  235. #ifndef WIFI2_PASS
  236. #define WIFI2_PASS ""
  237. #endif
  238. #ifndef WIFI2_IP
  239. #define WIFI2_IP ""
  240. #endif
  241. #ifndef WIFI2_GW
  242. #define WIFI2_GW ""
  243. #endif
  244. #ifndef WIFI2_MASK
  245. #define WIFI2_MASK ""
  246. #endif
  247. #ifndef WIFI2_DNS
  248. #define WIFI2_DNS ""
  249. #endif
  250. #ifndef WIFI_RSSI_1M
  251. #define WIFI_RSSI_1M -30 // Calibrate it with your router reading the RSSI at 1m
  252. #endif
  253. #ifndef WIFI_PROPAGATION_CONST
  254. #define WIFI_PROPAGATION_CONST 4 // This is typically something between 2.7 to 4.3 (free space is 2)
  255. #endif
  256. // -----------------------------------------------------------------------------
  257. // WEB
  258. // -----------------------------------------------------------------------------
  259. #ifndef WEB_SUPPORT
  260. #define WEB_SUPPORT 1 // Enable web support (http, api, 121.65Kb)
  261. #endif
  262. #ifndef WEB_EMBEDDED
  263. #define WEB_EMBEDDED 1 // Build the firmware with the web interface embedded in
  264. #endif
  265. // This is not working at the moment!!
  266. // Requires ASYNC_TCP_SSL_ENABLED to 1 and ESP8266 Arduino Core 2.4.0
  267. #ifndef WEB_SSL_ENABLED
  268. #define WEB_SSL_ENABLED 0 // Use HTTPS web interface
  269. #endif
  270. #ifndef WEB_USERNAME
  271. #define WEB_USERNAME "admin" // HTTP username
  272. #endif
  273. #ifndef WEB_FORCE_PASS_CHANGE
  274. #define WEB_FORCE_PASS_CHANGE 1 // Force the user to change the password if default one
  275. #endif
  276. #ifndef WEB_PORT
  277. #define WEB_PORT 80 // HTTP port
  278. #endif
  279. // -----------------------------------------------------------------------------
  280. // WEBSOCKETS
  281. // -----------------------------------------------------------------------------
  282. // This will only be enabled if WEB_SUPPORT is 1 (this is the default value)
  283. #ifndef WS_AUTHENTICATION
  284. #define WS_AUTHENTICATION 1 // WS authentication ON by default (see #507)
  285. #endif
  286. #ifndef WS_BUFFER_SIZE
  287. #define WS_BUFFER_SIZE 5 // Max number of secured websocket connections
  288. #endif
  289. #ifndef WS_TIMEOUT
  290. #define WS_TIMEOUT 1800000 // Timeout for secured websocket
  291. #endif
  292. #ifndef WS_UPDATE_INTERVAL
  293. #define WS_UPDATE_INTERVAL 30000 // Update clients every 30 seconds
  294. #endif
  295. // -----------------------------------------------------------------------------
  296. // API
  297. // -----------------------------------------------------------------------------
  298. // This will only be enabled if WEB_SUPPORT is 1 (this is the default value)
  299. #ifndef API_ENABLED
  300. #define API_ENABLED 0 // Do not enable API by default
  301. #endif
  302. #ifndef API_BUFFER_SIZE
  303. #define API_BUFFER_SIZE 15 // Size of the buffer for HTTP GET API responses
  304. #endif
  305. #ifndef API_REAL_TIME_VALUES
  306. #define API_REAL_TIME_VALUES 0 // Show filtered/median values by default (0 => median, 1 => real time)
  307. #endif
  308. // -----------------------------------------------------------------------------
  309. // MDNS / LLMNR / NETBIOS / SSDP
  310. // -----------------------------------------------------------------------------
  311. #ifndef MDNS_SERVER_SUPPORT
  312. #define MDNS_SERVER_SUPPORT 1 // Publish services using mDNS by default (1.48Kb)
  313. #endif
  314. #ifndef MDNS_CLIENT_SUPPORT
  315. #define MDNS_CLIENT_SUPPORT 0 // Resolve mDNS names (3.44Kb)
  316. #endif
  317. #ifndef LLMNR_SUPPORT
  318. #define LLMNR_SUPPORT 0 // Publish device using LLMNR protocol by default (1.95Kb) - requires 2.4.0
  319. #endif
  320. #ifndef NETBIOS_SUPPORT
  321. #define NETBIOS_SUPPORT 0 // Publish device using NetBIOS protocol by default (1.26Kb) - requires 2.4.0
  322. #endif
  323. #ifndef SSDP_SUPPORT
  324. #define SSDP_SUPPORT 0 // Publish device using SSDP protocol by default (4.59Kb)
  325. // Not compatible with ALEXA_SUPPORT at the moment
  326. #endif
  327. #ifndef SSDP_DEVICE_TYPE
  328. #define SSDP_DEVICE_TYPE "upnp:rootdevice"
  329. //#define SSDP_DEVICE_TYPE "urn:schemas-upnp-org:device:BinaryLight:1"
  330. #endif
  331. // -----------------------------------------------------------------------------
  332. // SPIFFS
  333. // -----------------------------------------------------------------------------
  334. #ifndef SPIFFS_SUPPORT
  335. #define SPIFFS_SUPPORT 0 // Do not add support for SPIFFS by default
  336. #endif
  337. // -----------------------------------------------------------------------------
  338. // OTA
  339. // -----------------------------------------------------------------------------
  340. #ifndef OTA_PORT
  341. #define OTA_PORT 8266 // OTA port
  342. #endif
  343. #define OTA_GITHUB_FP "D7:9F:07:61:10:B3:92:93:E3:49:AC:89:84:5B:03:80:C1:9E:2F:8B"
  344. // -----------------------------------------------------------------------------
  345. // NOFUSS
  346. // -----------------------------------------------------------------------------
  347. #ifndef NOFUSS_SUPPORT
  348. #define NOFUSS_SUPPORT 0 // Do not enable support for NoFuss by default (12.65Kb)
  349. #endif
  350. #ifndef NOFUSS_ENABLED
  351. #define NOFUSS_ENABLED 0 // Do not perform NoFUSS updates by default
  352. #endif
  353. #ifndef NOFUSS_SERVER
  354. #define NOFUSS_SERVER "" // Default NoFuss Server
  355. #endif
  356. #ifndef NOFUSS_INTERVAL
  357. #define NOFUSS_INTERVAL 3600000 // Check for updates every hour
  358. #endif
  359. // -----------------------------------------------------------------------------
  360. // UART <-> MQTT
  361. // -----------------------------------------------------------------------------
  362. #ifndef UART_MQTT_SUPPORT
  363. #define UART_MQTT_SUPPORT 0 // No support by default
  364. #endif
  365. #ifndef UART_MQTT_USE_SOFT
  366. #define UART_MQTT_USE_SOFT 0 // Use SoftwareSerial
  367. #endif
  368. #ifndef UART_MQTT_HW_PORT
  369. #define UART_MQTT_HW_PORT Serial // Hardware serial port (if UART_MQTT_USE_SOFT == 0)
  370. #endif
  371. #ifndef UART_MQTT_RX_PIN
  372. #define UART_MQTT_RX_PIN 4 // RX PIN (if UART_MQTT_USE_SOFT == 1)
  373. #endif
  374. #ifndef UART_MQTT_TX_PIN
  375. #define UART_MQTT_TX_PIN 5 // TX PIN (if UART_MQTT_USE_SOFT == 1)
  376. #endif
  377. #ifndef UART_MQTT_BAUDRATE
  378. #define UART_MQTT_BAUDRATE 115200 // Serial speed
  379. #endif
  380. #define UART_MQTT_BUFFER_SIZE 100 // UART buffer size
  381. // -----------------------------------------------------------------------------
  382. // MQTT
  383. // -----------------------------------------------------------------------------
  384. #ifndef MQTT_SUPPORT
  385. #define MQTT_SUPPORT 1 // MQTT support (22.38Kb async, 12.48Kb sync)
  386. #endif
  387. #ifndef MQTT_USE_ASYNC
  388. #define MQTT_USE_ASYNC 1 // Use AysncMQTTClient (1) or PubSubClient (0)
  389. #endif
  390. // MQTT OVER SSL
  391. // Using MQTT over SSL works pretty well but generates problems with the web interface.
  392. // It could be a good idea to use it in conjuntion with WEB_SUPPORT=0.
  393. // Requires ASYNC_TCP_SSL_ENABLED to 1 and ESP8266 Arduino Core 2.4.0.
  394. //
  395. // You can use SSL with MQTT_USE_ASYNC=1 (AsyncMqttClient library)
  396. // but you might experience hiccups on the web interface, so my recommendation is:
  397. // WEB_SUPPORT=0
  398. //
  399. // If you use SSL with MQTT_USE_ASYNC=0 (PubSubClient library)
  400. // you will have to disable all the modules that use ESPAsyncTCP, that is:
  401. // ALEXA_SUPPORT=0, INFLUXDB_SUPPORT=0, TELNET_SUPPORT=0, THINGSPEAK_SUPPORT=0 and WEB_SUPPORT=0
  402. //
  403. // You will need the fingerprint for your MQTT server, example for CloudMQTT:
  404. // $ echo -n | openssl s_client -connect m11.cloudmqtt.com:24055 > cloudmqtt.pem
  405. // $ openssl x509 -noout -in cloudmqtt.pem -fingerprint -sha1
  406. #ifndef MQTT_SSL_ENABLED
  407. #define MQTT_SSL_ENABLED 0 // By default MQTT over SSL will not be enabled
  408. #endif
  409. #ifndef MQTT_SSL_FINGERPRINT
  410. #define MQTT_SSL_FINGERPRINT "" // SSL fingerprint of the server
  411. #endif
  412. #ifndef MQTT_ENABLED
  413. #define MQTT_ENABLED 0 // Do not enable MQTT connection by default
  414. #endif
  415. #ifndef MQTT_AUTOCONNECT
  416. #define MQTT_AUTOCONNECT 1 // If enabled and MDNS_SERVER_SUPPORT=1 will perform an autodiscover and
  417. #endif
  418. // autoconnect to the first MQTT broker found if none defined
  419. #ifndef MQTT_SERVER
  420. #define MQTT_SERVER "" // Default MQTT broker address
  421. #endif
  422. #ifndef MQTT_USER
  423. #define MQTT_USER "" // Default MQTT broker usename
  424. #endif
  425. #ifndef MQTT_PASS
  426. #define MQTT_PASS "" // Default MQTT broker password
  427. #endif
  428. #ifndef MQTT_PORT
  429. #define MQTT_PORT 1883 // MQTT broker port
  430. #endif
  431. #ifndef MQTT_TOPIC
  432. #define MQTT_TOPIC "{hostname}" // Default MQTT base topic
  433. #endif
  434. #ifndef MQTT_RETAIN
  435. #define MQTT_RETAIN true // MQTT retain flag
  436. #endif
  437. #ifndef MQTT_QOS
  438. #define MQTT_QOS 0 // MQTT QoS value for all messages
  439. #endif
  440. #ifndef MQTT_KEEPALIVE
  441. #define MQTT_KEEPALIVE 30 // MQTT keepalive value
  442. #endif
  443. #ifndef MQTT_RECONNECT_DELAY_MIN
  444. #define MQTT_RECONNECT_DELAY_MIN 5000 // Try to reconnect in 5 seconds upon disconnection
  445. #endif
  446. #ifndef MQTT_RECONNECT_DELAY_STEP
  447. #define MQTT_RECONNECT_DELAY_STEP 5000 // Increase the reconnect delay in 5 seconds after each failed attempt
  448. #endif
  449. #ifndef MQTT_RECONNECT_DELAY_MAX
  450. #define MQTT_RECONNECT_DELAY_MAX 120000 // Set reconnect time to 2 minutes at most
  451. #endif
  452. #ifndef MQTT_SKIP_RETAINED
  453. #define MQTT_SKIP_RETAINED 1 // Skip retained messages on connection
  454. #endif
  455. #ifndef MQTT_SKIP_TIME
  456. #define MQTT_SKIP_TIME 1000 // Skip messages for 1 second anter connection
  457. #endif
  458. #ifndef MQTT_USE_JSON
  459. #define MQTT_USE_JSON 0 // Group messages in a JSON body
  460. #endif
  461. #ifndef MQTT_USE_JSON_DELAY
  462. #define MQTT_USE_JSON_DELAY 100 // Wait this many ms before grouping messages
  463. #endif
  464. #ifndef MQTT_QUEUE_MAX_SIZE
  465. #define MQTT_QUEUE_MAX_SIZE 20 // Size of the MQTT queue when MQTT_USE_JSON is enabled
  466. #endif
  467. // These are the properties that will be sent when useJson is true
  468. #ifndef MQTT_ENQUEUE_IP
  469. #define MQTT_ENQUEUE_IP 1
  470. #endif
  471. #ifndef MQTT_ENQUEUE_MAC
  472. #define MQTT_ENQUEUE_MAC 1
  473. #endif
  474. #ifndef MQTT_ENQUEUE_HOSTNAME
  475. #define MQTT_ENQUEUE_HOSTNAME 1
  476. #endif
  477. #ifndef MQTT_ENQUEUE_DATETIME
  478. #define MQTT_ENQUEUE_DATETIME 1
  479. #endif
  480. #ifndef MQTT_ENQUEUE_MESSAGE_ID
  481. #define MQTT_ENQUEUE_MESSAGE_ID 1
  482. #endif
  483. // These particles will be concatenated to the MQTT_TOPIC base to form the actual topic
  484. #define MQTT_TOPIC_JSON "data"
  485. #define MQTT_TOPIC_ACTION "action"
  486. #define MQTT_TOPIC_RELAY "relay"
  487. #define MQTT_TOPIC_LED "led"
  488. #define MQTT_TOPIC_BUTTON "button"
  489. #define MQTT_TOPIC_IP "ip"
  490. #define MQTT_TOPIC_VERSION "version"
  491. #define MQTT_TOPIC_UPTIME "uptime"
  492. #define MQTT_TOPIC_DATETIME "datetime"
  493. #define MQTT_TOPIC_FREEHEAP "freeheap"
  494. #define MQTT_TOPIC_VCC "vcc"
  495. #define MQTT_TOPIC_STATUS "status"
  496. #define MQTT_TOPIC_MAC "mac"
  497. #define MQTT_TOPIC_RSSI "rssi"
  498. #define MQTT_TOPIC_MESSAGE_ID "id"
  499. #define MQTT_TOPIC_APP "app"
  500. #define MQTT_TOPIC_INTERVAL "interval"
  501. #define MQTT_TOPIC_HOSTNAME "host"
  502. #define MQTT_TOPIC_TIME "time"
  503. #define MQTT_TOPIC_RFOUT "rfout"
  504. #define MQTT_TOPIC_RFIN "rfin"
  505. #define MQTT_TOPIC_RFLEARN "rflearn"
  506. #define MQTT_TOPIC_RFRAW "rfraw"
  507. #define MQTT_TOPIC_UARTIN "uartin"
  508. #define MQTT_TOPIC_UARTOUT "uartout"
  509. #define MQTT_TOPIC_LOADAVG "loadavg"
  510. #define MQTT_TOPIC_BOARD "board"
  511. // Light module
  512. #define MQTT_TOPIC_CHANNEL "channel"
  513. #define MQTT_TOPIC_COLOR_RGB "rgb"
  514. #define MQTT_TOPIC_COLOR_HSV "hsv"
  515. #define MQTT_TOPIC_ANIM_MODE "anim_mode"
  516. #define MQTT_TOPIC_ANIM_SPEED "anim_speed"
  517. #define MQTT_TOPIC_BRIGHTNESS "brightness"
  518. #define MQTT_TOPIC_MIRED "mired"
  519. #define MQTT_TOPIC_KELVIN "kelvin"
  520. #define MQTT_STATUS_ONLINE "1" // Value for the device ON message
  521. #define MQTT_STATUS_OFFLINE "0" // Value for the device OFF message (will)
  522. #define MQTT_ACTION_RESET "reboot" // RESET MQTT topic particle
  523. #define MQTT_MESSAGE_ID_SHIFT 1000 // Store MQTT message id into EEPROM every these many
  524. // Custom get and set postfixes
  525. // Use something like "/status" or "/set", with leading slash
  526. // Since 1.9.0 the default value is "" for getter and "/set" for setter
  527. #ifndef MQTT_GETTER
  528. #define MQTT_GETTER ""
  529. #endif
  530. #ifndef MQTT_SETTER
  531. #define MQTT_SETTER "/set"
  532. #endif
  533. // -----------------------------------------------------------------------------
  534. // BROKER
  535. // -----------------------------------------------------------------------------
  536. #ifndef BROKER_SUPPORT
  537. #define BROKER_SUPPORT 1 // The broker is a poor-man's pubsub manager
  538. #endif
  539. // -----------------------------------------------------------------------------
  540. // SETTINGS
  541. // -----------------------------------------------------------------------------
  542. #ifndef SETTINGS_AUTOSAVE
  543. #define SETTINGS_AUTOSAVE 1 // Autosave settings o force manual commit
  544. #endif
  545. #define SETTINGS_MAX_LIST_COUNT 10 // Maximum index for settings lists
  546. // -----------------------------------------------------------------------------
  547. // LIGHT
  548. // -----------------------------------------------------------------------------
  549. // LIGHT_PROVIDER_DIMMER can have from 1 to 5 different channels.
  550. // They have to be defined for each device in the hardware.h file.
  551. // If 3 or more channels first 3 will be considered RGB.
  552. // Usual configurations are:
  553. // 1 channels => W
  554. // 2 channels => WW
  555. // 3 channels => RGB
  556. // 4 channels => RGBW
  557. // 5 channels => RGBWW
  558. #ifndef LIGHT_SAVE_ENABLED
  559. #define LIGHT_SAVE_ENABLED 1 // Light channel values saved by default after each change
  560. #endif
  561. #ifndef LIGHT_SAVE_DELAY
  562. #define LIGHT_SAVE_DELAY 5 // Persist color after 5 seconds to avoid wearing out
  563. #endif
  564. #ifndef LIGHT_MAX_PWM
  565. #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
  566. #define LIGHT_MAX_PWM 255
  567. #endif
  568. #if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
  569. #define LIGHT_MAX_PWM 10000 // 5000 * 200ns => 1 kHz
  570. #endif
  571. #endif // LIGHT_MAX_PWM
  572. #ifndef LIGHT_LIMIT_PWM
  573. #define LIGHT_LIMIT_PWM LIGHT_MAX_PWM // Limit PWM to this value (prevent 100% power)
  574. #endif
  575. #ifndef LIGHT_MAX_VALUE
  576. #define LIGHT_MAX_VALUE 255 // Maximum light value
  577. #endif
  578. #ifndef LIGHT_MAX_BRIGHTNESS
  579. #define LIGHT_MAX_BRIGHTNESS 255 // Maximun brightness value
  580. #endif
  581. //#define LIGHT_MIN_MIREDS 153 // NOT USED (yet)! // Default to the Philips Hue value that HA has always assumed
  582. //#define LIGHT_MAX_MIREDS 500 // NOT USED (yet)! // https://developers.meethue.com/documentation/core-concepts
  583. #ifndef LIGHT_DEFAULT_MIREDS
  584. #define LIGHT_DEFAULT_MIREDS 153 // Default value used by MQTT. This value is __NEVRER__ applied!
  585. #endif
  586. #ifndef LIGHT_STEP
  587. #define LIGHT_STEP 32 // Step size
  588. #endif
  589. #ifndef LIGHT_USE_COLOR
  590. #define LIGHT_USE_COLOR 1 // Use 3 first channels as RGB
  591. #endif
  592. #ifndef LIGHT_USE_WHITE
  593. #define LIGHT_USE_WHITE 0 // Use white channel whenever RGB have the same value
  594. #endif
  595. #ifndef LIGHT_USE_GAMMA
  596. #define LIGHT_USE_GAMMA 0 // Use gamma correction for color channels
  597. #endif
  598. #ifndef LIGHT_USE_CSS
  599. #define LIGHT_USE_CSS 1 // Use CSS style to report colors (1=> "#FF0000", 0=> "255,0,0")
  600. #endif
  601. #ifndef LIGHT_USE_RGB
  602. #define LIGHT_USE_RGB 0 // Use RGB color selector (1=> RGB, 0=> HSV)
  603. #endif
  604. #ifndef LIGHT_WHITE_FACTOR
  605. #define LIGHT_WHITE_FACTOR 1 // When using LIGHT_USE_WHITE with uneven brightness LEDs,
  606. // this factor is used to scale the white channel to match brightness
  607. #endif
  608. #ifndef LIGHT_USE_TRANSITIONS
  609. #define LIGHT_USE_TRANSITIONS 1 // Transitions between colors
  610. #endif
  611. #ifndef LIGHT_TRANSITION_STEP
  612. #define LIGHT_TRANSITION_STEP 10 // Time in millis between each transtion step
  613. #endif
  614. #ifndef LIGHT_TRANSITION_TIME
  615. #define LIGHT_TRANSITION_TIME 500 // Time in millis from color to color
  616. #endif
  617. // -----------------------------------------------------------------------------
  618. // DOMOTICZ
  619. // -----------------------------------------------------------------------------
  620. #ifndef DOMOTICZ_SUPPORT
  621. #define DOMOTICZ_SUPPORT MQTT_SUPPORT // Build with domoticz (if MQTT) support (1.72Kb)
  622. #endif
  623. #define DOMOTICZ_ENABLED 0 // Disable domoticz by default
  624. #define DOMOTICZ_IN_TOPIC "domoticz/in" // Default subscription topic
  625. #define DOMOTICZ_OUT_TOPIC "domoticz/out" // Default publication topic
  626. // -----------------------------------------------------------------------------
  627. // HOME ASSISTANT
  628. // -----------------------------------------------------------------------------
  629. #ifndef HOMEASSISTANT_SUPPORT
  630. #define HOMEASSISTANT_SUPPORT MQTT_SUPPORT // Build with home assistant support (if MQTT, 1.64Kb)
  631. #endif
  632. #define HOMEASSISTANT_ENABLED 0 // Integration not enabled by default
  633. #define HOMEASSISTANT_PREFIX "homeassistant" // Default MQTT prefix
  634. // -----------------------------------------------------------------------------
  635. // INFLUXDB
  636. // -----------------------------------------------------------------------------
  637. #ifndef INFLUXDB_SUPPORT
  638. #define INFLUXDB_SUPPORT 0 // Disable InfluxDB support by default (4.38Kb)
  639. #endif
  640. #ifndef INFLUXDB_ENABLED
  641. #define INFLUXDB_ENABLED 0 // InfluxDB disabled by default
  642. #endif
  643. #ifndef INFLUXDB_HOST
  644. #define INFLUXDB_HOST "" // Default server
  645. #endif
  646. #ifndef INFLUXDB_PORT
  647. #define INFLUXDB_PORT 8086 // Default InfluxDB port
  648. #endif
  649. #ifndef INFLUXDB_DATABASE
  650. #define INFLUXDB_DATABASE "" // Default database
  651. #endif
  652. #ifndef INFLUXDB_USERNAME
  653. #define INFLUXDB_USERNAME "" // Default username
  654. #endif
  655. #ifndef INFLUXDB_PASSWORD
  656. #define INFLUXDB_PASSWORD "" // Default password
  657. #endif
  658. // -----------------------------------------------------------------------------
  659. // THINGSPEAK
  660. // -----------------------------------------------------------------------------
  661. #ifndef THINGSPEAK_SUPPORT
  662. #define THINGSPEAK_SUPPORT 1 // Enable Thingspeak support by default (2.56Kb)
  663. #endif
  664. #ifndef THINGSPEAK_ENABLED
  665. #define THINGSPEAK_ENABLED 0 // Thingspeak disabled by default
  666. #endif
  667. #ifndef THINGSPEAK_APIKEY
  668. #define THINGSPEAK_APIKEY "" // Default API KEY
  669. #endif
  670. #define THINGSPEAK_USE_ASYNC 1 // Use AsyncClient instead of WiFiClientSecure
  671. // THINGSPEAK OVER SSL
  672. // Using THINGSPEAK over SSL works well but generates problems with the web interface,
  673. // so you should compile it with WEB_SUPPORT to 0.
  674. // When THINGSPEAK_USE_ASYNC is 1, requires ASYNC_TCP_SSL_ENABLED to 1 and ESP8266 Arduino Core 2.4.0.
  675. #define THINGSPEAK_USE_SSL 0 // Use secure connection
  676. #define THINGSPEAK_FINGERPRINT "78 60 18 44 81 35 BF DF 77 84 D4 0A 22 0D 9B 4E 6C DC 57 2C"
  677. #define THINGSPEAK_HOST "api.thingspeak.com"
  678. #if THINGSPEAK_USE_SSL
  679. #define THINGSPEAK_PORT 443
  680. #else
  681. #define THINGSPEAK_PORT 80
  682. #endif
  683. #define THINGSPEAK_URL "/update"
  684. #define THINGSPEAK_MIN_INTERVAL 15000 // Minimum interval between POSTs (in millis)
  685. // -----------------------------------------------------------------------------
  686. // SCHEDULER
  687. // -----------------------------------------------------------------------------
  688. #ifndef SCHEDULER_SUPPORT
  689. #define SCHEDULER_SUPPORT 1 // Enable scheduler (1.77Kb)
  690. #endif
  691. #ifndef SCHEDULER_MAX_SCHEDULES
  692. #define SCHEDULER_MAX_SCHEDULES 10 // Max schedules alowed
  693. #endif
  694. // -----------------------------------------------------------------------------
  695. // NTP
  696. // -----------------------------------------------------------------------------
  697. #ifndef NTP_SUPPORT
  698. #define NTP_SUPPORT 1 // Build with NTP support by default (6.78Kb)
  699. #endif
  700. #ifndef NTP_SERVER
  701. #define NTP_SERVER "pool.ntp.org" // Default NTP server
  702. #endif
  703. #ifndef NTP_TIMEOUT
  704. #define NTP_TIMEOUT 1000 // Set NTP request timeout to 2 seconds (issue #452)
  705. #endif
  706. #ifndef NTP_TIME_OFFSET
  707. #define NTP_TIME_OFFSET 60 // Default timezone offset (GMT+1)
  708. #endif
  709. #ifndef NTP_DAY_LIGHT
  710. #define NTP_DAY_LIGHT 1 // Enable daylight time saving by default
  711. #endif
  712. #ifndef NTP_SYNC_INTERVAL
  713. #define NTP_SYNC_INTERVAL 60 // NTP initial check every minute
  714. #endif
  715. #ifndef NTP_UPDATE_INTERVAL
  716. #define NTP_UPDATE_INTERVAL 1800 // NTP check every 30 minutes
  717. #endif
  718. #ifndef NTP_START_DELAY
  719. #define NTP_START_DELAY 1000 // Delay NTP start 1 second
  720. #endif
  721. #ifndef NTP_DST_REGION
  722. #define NTP_DST_REGION 0 // 0 for Europe, 1 for USA (defined in NtpClientLib)
  723. #endif
  724. // -----------------------------------------------------------------------------
  725. // ALEXA
  726. // -----------------------------------------------------------------------------
  727. // This setting defines whether Alexa support should be built into the firmware
  728. #ifndef ALEXA_SUPPORT
  729. #define ALEXA_SUPPORT 1 // Enable Alexa support by default (10.84Kb)
  730. #endif
  731. // This is default value for the alexaEnabled setting that defines whether
  732. // this device should be discoberable and respond to Alexa commands.
  733. // Both ALEXA_SUPPORT and alexaEnabled should be 1 for Alexa support to work.
  734. #ifndef ALEXA_ENABLED
  735. #define ALEXA_ENABLED 1
  736. #endif
  737. // -----------------------------------------------------------------------------
  738. // RFBRIDGE
  739. // This module is not compatible with RF_SUPPORT=1
  740. // -----------------------------------------------------------------------------
  741. #ifndef RF_SEND_TIMES
  742. #define RF_SEND_TIMES 4 // How many times to send the message
  743. #endif
  744. #ifndef RF_SEND_DELAY
  745. #define RF_SEND_DELAY 500 // Interval between sendings in ms
  746. #endif
  747. #ifndef RF_RECEIVE_DELAY
  748. #define RF_RECEIVE_DELAY 500 // Interval between recieving in ms (avoid debouncing)
  749. #endif
  750. #ifndef RF_RAW_SUPPORT
  751. #define RF_RAW_SUPPORT 0 // RF raw codes require a specific firmware for the EFM8BB1
  752. // https://github.com/rhx/RF-Bridge-EFM8BB1
  753. #endif
  754. // -----------------------------------------------------------------------------
  755. // IR
  756. // -----------------------------------------------------------------------------
  757. #ifndef IR_SUPPORT
  758. #define IR_SUPPORT 0 // Do not build with IR support by default (10.25Kb)
  759. #endif
  760. #ifndef IR_PIN
  761. #define IR_PIN 4 // IR LED
  762. #endif
  763. // 24 Buttons Set of the IR Remote
  764. #ifndef IR_BUTTON_SET
  765. #define IR_BUTTON_SET 1 // IR button set to use (see below)
  766. #endif
  767. //Remote Buttons SET 1 (for the original Remote shipped with the controller)
  768. #if IR_SUPPORT
  769. #if IR_BUTTON_SET == 1
  770. /*
  771. +------+------+------+------+
  772. | UP | Down | OFF | ON |
  773. +------+------+------+------+
  774. | R | G | B | W |
  775. +------+------+------+------+
  776. | 1 | 2 | 3 |FLASH |
  777. +------+------+------+------+
  778. | 4 | 5 | 6 |STROBE|
  779. +------+------+------+------+
  780. | 7 | 8 | 9 | FADE |
  781. +------+------+------+------+
  782. | 10 | 11 | 12 |SMOOTH|
  783. +------+------+------+------+
  784. */
  785. #define IR_BUTTON_COUNT 24
  786. const unsigned long IR_BUTTON[IR_BUTTON_COUNT][3] PROGMEM = {
  787. { 0xFF906F, IR_BUTTON_MODE_BRIGHTER, 1 },
  788. { 0xFFB847, IR_BUTTON_MODE_BRIGHTER, 0 },
  789. { 0xFFF807, IR_BUTTON_MODE_STATE, 0 },
  790. { 0xFFB04F, IR_BUTTON_MODE_STATE, 1 },
  791. { 0xFF9867, IR_BUTTON_MODE_RGB, 0xFF0000 },
  792. { 0xFFD827, IR_BUTTON_MODE_RGB, 0x00FF00 },
  793. { 0xFF8877, IR_BUTTON_MODE_RGB, 0x0000FF },
  794. { 0xFFA857, IR_BUTTON_MODE_RGB, 0xFFFFFF },
  795. { 0xFFE817, IR_BUTTON_MODE_RGB, 0xD13A01 },
  796. { 0xFF48B7, IR_BUTTON_MODE_RGB, 0x00E644 },
  797. { 0xFF6897, IR_BUTTON_MODE_RGB, 0x0040A7 },
  798. { 0xFFB24D, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_FLASH },
  799. { 0xFF02FD, IR_BUTTON_MODE_RGB, 0xE96F2A },
  800. { 0xFF32CD, IR_BUTTON_MODE_RGB, 0x00BEBF },
  801. { 0xFF20DF, IR_BUTTON_MODE_RGB, 0x56406F },
  802. { 0xFF00FF, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_STROBE },
  803. { 0xFF50AF, IR_BUTTON_MODE_RGB, 0xEE9819 },
  804. { 0xFF7887, IR_BUTTON_MODE_RGB, 0x00799A },
  805. { 0xFF708F, IR_BUTTON_MODE_RGB, 0x944E80 },
  806. { 0xFF58A7, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_FADE },
  807. { 0xFF38C7, IR_BUTTON_MODE_RGB, 0xFFFF00 },
  808. { 0xFF28D7, IR_BUTTON_MODE_RGB, 0x0060A1 },
  809. { 0xFFF00F, IR_BUTTON_MODE_RGB, 0xEF45AD },
  810. { 0xFF30CF, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_SMOOTH }
  811. };
  812. #endif
  813. //Remote Buttons SET 2 (another identical IR Remote shipped with another controller)
  814. #if IR_BUTTON_SET == 2
  815. /*
  816. +------+------+------+------+
  817. | UP | Down | OFF | ON |
  818. +------+------+------+------+
  819. | R | G | B | W |
  820. +------+------+------+------+
  821. | 1 | 2 | 3 |FLASH |
  822. +------+------+------+------+
  823. | 4 | 5 | 6 |STROBE|
  824. +------+------+------+------+
  825. | 7 | 8 | 9 | FADE |
  826. +------+------+------+------+
  827. | 10 | 11 | 12 |SMOOTH|
  828. +------+------+------+------+
  829. */
  830. #define IR_BUTTON_COUNT 24
  831. const unsigned long IR_BUTTON[IR_BUTTON_COUNT][3] PROGMEM = {
  832. { 0xFF00FF, IR_BUTTON_MODE_BRIGHTER, 1 },
  833. { 0xFF807F, IR_BUTTON_MODE_BRIGHTER, 0 },
  834. { 0xFF40BF, IR_BUTTON_MODE_STATE, 0 },
  835. { 0xFFC03F, IR_BUTTON_MODE_STATE, 1 },
  836. { 0xFF20DF, IR_BUTTON_MODE_RGB, 0xFF0000 },
  837. { 0xFFA05F, IR_BUTTON_MODE_RGB, 0x00FF00 },
  838. { 0xFF609F, IR_BUTTON_MODE_RGB, 0x0000FF },
  839. { 0xFFE01F, IR_BUTTON_MODE_RGB, 0xFFFFFF },
  840. { 0xFF10EF, IR_BUTTON_MODE_RGB, 0xD13A01 },
  841. { 0xFF906F, IR_BUTTON_MODE_RGB, 0x00E644 },
  842. { 0xFF50AF, IR_BUTTON_MODE_RGB, 0x0040A7 },
  843. { 0xFFD02F, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_FLASH },
  844. { 0xFF30CF, IR_BUTTON_MODE_RGB, 0xE96F2A },
  845. { 0xFFB04F, IR_BUTTON_MODE_RGB, 0x00BEBF },
  846. { 0xFF708F, IR_BUTTON_MODE_RGB, 0x56406F },
  847. { 0xFFF00F, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_STROBE },
  848. { 0xFF08F7, IR_BUTTON_MODE_RGB, 0xEE9819 },
  849. { 0xFF8877, IR_BUTTON_MODE_RGB, 0x00799A },
  850. { 0xFF48B7, IR_BUTTON_MODE_RGB, 0x944E80 },
  851. { 0xFFC837, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_FADE },
  852. { 0xFF28D7, IR_BUTTON_MODE_RGB, 0xFFFF00 },
  853. { 0xFFA857, IR_BUTTON_MODE_RGB, 0x0060A1 },
  854. { 0xFF6897, IR_BUTTON_MODE_RGB, 0xEF45AD },
  855. { 0xFFE817, IR_BUTTON_MODE_EFFECT, LIGHT_EFFECT_SMOOTH }
  856. };
  857. #endif
  858. #endif // IR_SUPPORT
  859. //--------------------------------------------------------------------------------
  860. // Custom RF module
  861. // Check http://tinkerman.cat/adding-rf-to-a-non-rf-itead-sonoff/
  862. // Enable support by passing RF_SUPPORT=1 build flag
  863. // This module is not compatible with RFBRIDGE or SONOFF RF
  864. //--------------------------------------------------------------------------------
  865. #ifndef RF_SUPPORT
  866. #define RF_SUPPORT 0
  867. #endif
  868. #ifndef RF_PIN
  869. #define RF_PIN 14
  870. #endif
  871. #define RF_DEBOUNCE 500
  872. #define RF_LEARN_TIMEOUT 60000