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.

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