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.

416 lines
17 KiB

8 years ago
8 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. // DEBUG
  7. //------------------------------------------------------------------------------
  8. // Serial debug log
  9. #ifndef ENABLE_SERIAL_DEBUG
  10. #define ENABLE_SERIAL_DEBUG 1 // Enable serial debug log
  11. #endif
  12. #ifndef DEBUG_PORT
  13. #define DEBUG_PORT Serial // Default debugging port
  14. #endif
  15. //------------------------------------------------------------------------------
  16. // UDP debug log
  17. // To receive the message son the destination computer use nc:
  18. // nc -ul 8111
  19. #ifndef ENABLE_UDP_DEBUG
  20. #define ENABLE_UDP_DEBUG 0 // Enable UDP debug log
  21. #endif
  22. #define DEBUG_UDP_IP IPAddress(192, 168, 1, 100)
  23. #define DEBUG_UDP_PORT 8113
  24. //------------------------------------------------------------------------------
  25. // General debug options and macros
  26. #define DEBUG_MESSAGE_MAX_LENGTH 80
  27. #if (ENABLE_SERIAL_DEBUG==1) || (ENABLE_UDP_DEBUG==1)
  28. #define DEBUG_MSG(...) debugSend(__VA_ARGS__)
  29. #define DEBUG_MSG_P(...) debugSend_P(__VA_ARGS__)
  30. #endif
  31. #ifndef DEBUG_MSG
  32. #define DEBUG_MSG(...)
  33. #define DEBUG_MSG_P(...)
  34. #endif
  35. //------------------------------------------------------------------------------
  36. // TERMINAL
  37. //------------------------------------------------------------------------------
  38. #ifndef ENABLE_TERMINAL
  39. #define ENABLE_TERMINAL 1 // Enable terminal commands
  40. #endif
  41. //------------------------------------------------------------------------------
  42. // EEPROM
  43. //------------------------------------------------------------------------------
  44. #define EEPROM_SIZE 4096 // EEPROM size in bytes
  45. #define EEPROM_RELAY_STATUS 0 // Address for the relay status (1 byte)
  46. #define EEPROM_ENERGY_COUNT 1 // Address for the energy counter (4 bytes)
  47. #define EEPROM_CUSTOM_RESET 5 // Address for the reset reason (1 byte)
  48. #define EEPROM_DATA_END 6 // End of custom EEPROM data block
  49. //------------------------------------------------------------------------------
  50. // HEARTBEAT
  51. //------------------------------------------------------------------------------
  52. #define HEARTBEAT_INTERVAL 300000 // Interval between heartbeat messages (in ms)
  53. #define UPTIME_OVERFLOW 4294967295 // Uptime overflow value
  54. // Topics that will be reported in heartbeat
  55. #define HEARTBEAT_REPORT_STATUS 1
  56. #define HEARTBEAT_REPORT_IP 1
  57. #define HEARTBEAT_REPORT_MAC 1
  58. #define HEARTBEAT_REPORT_RSSI 1
  59. #define HEARTBEAT_REPORT_UPTIME 1
  60. #define HEARTBEAT_REPORT_FREEHEAP 1
  61. #define HEARTBEAT_REPORT_VCC 1
  62. #define HEARTBEAT_REPORT_RELAY 1
  63. #define HEARTBEAT_REPORT_LIGHT 1
  64. #define HEARTBEAT_REPORT_HOSTNAME 1
  65. #define HEARTBEAT_REPORT_APP 1
  66. #define HEARTBEAT_REPORT_VERSION 1
  67. #define HEARTBEAT_REPORT_INTERVAL 0
  68. //------------------------------------------------------------------------------
  69. // RESET
  70. //------------------------------------------------------------------------------
  71. #define CUSTOM_RESET_HARDWARE 1 // Reset from hardware button
  72. #define CUSTOM_RESET_WEB 2 // Reset from web interface
  73. #define CUSTOM_RESET_TERMINAL 3 // Reset from terminal
  74. #define CUSTOM_RESET_MQTT 4 // Reset via MQTT
  75. #define CUSTOM_RESET_RPC 5 // Reset via RPC (HTTP)
  76. #define CUSTOM_RESET_OTA 6 // Reset after successful OTA update
  77. #define CUSTOM_RESET_NOFUSS 8 // Reset after successful NOFUSS update
  78. #define CUSTOM_RESET_UPGRADE 9 // Reset after update from web interface
  79. #define CUSTOM_RESET_FACTORY 10 // Factory reset from terminal
  80. #define CUSTOM_RESET_MAX 10
  81. #include <pgmspace.h>
  82. PROGMEM const char custom_reset_hardware[] = "Hardware button";
  83. PROGMEM const char custom_reset_web[] = "Reset from web interface";
  84. PROGMEM const char custom_reset_terminal[] = "Reset from terminal";
  85. PROGMEM const char custom_reset_mqtt[] = "Reset from MQTT";
  86. PROGMEM const char custom_reset_rpc[] = "Reset from RPC";
  87. PROGMEM const char custom_reset_ota[] = "Reset after successful OTA update";
  88. PROGMEM const char custom_reset_nofuss[] = "Reset after successful NoFUSS update";
  89. PROGMEM const char custom_reset_upgrade[] = "Reset after successful web update";
  90. PROGMEM const char custom_reset_factory[] = "Factory reset";
  91. PROGMEM const char* const custom_reset_string[] = {
  92. custom_reset_hardware, custom_reset_web, custom_reset_terminal,
  93. custom_reset_mqtt, custom_reset_rpc, custom_reset_ota,
  94. custom_reset_nofuss, custom_reset_upgrade, custom_reset_factory
  95. };
  96. //------------------------------------------------------------------------------
  97. // BUTTON
  98. //------------------------------------------------------------------------------
  99. #define BUTTON_DEBOUNCE_DELAY 50 // Debounce delay (ms)
  100. #define BUTTON_DBLCLICK_DELAY 500 // Time in ms to wait for a second (or third...) click
  101. #define BUTTON_LNGCLICK_DELAY 1000 // Time in ms holding the button down to get a long click
  102. #define BUTTON_LNGLNGCLICK_DELAY 10000 // Time in ms holding the button down to get a long-long click
  103. #define BUTTON_EVENT_NONE 0
  104. #define BUTTON_EVENT_PRESSED 1
  105. #define BUTTON_EVENT_RELEASED 2
  106. #define BUTTON_EVENT_CLICK 2
  107. #define BUTTON_EVENT_DBLCLICK 3
  108. #define BUTTON_EVENT_LNGCLICK 4
  109. #define BUTTON_EVENT_LNGLNGCLICK 5
  110. #define BUTTON_MODE_NONE 0
  111. #define BUTTON_MODE_TOGGLE 1
  112. #define BUTTON_MODE_ON 2
  113. #define BUTTON_MODE_OFF 3
  114. #define BUTTON_MODE_AP 4
  115. #define BUTTON_MODE_RESET 5
  116. #define BUTTON_MODE_PULSE 6
  117. #define BUTTON_MODE_FACTORY 7
  118. //------------------------------------------------------------------------------
  119. // RELAY
  120. //------------------------------------------------------------------------------
  121. #define RELAY_MODE_OFF 0
  122. #define RELAY_MODE_ON 1
  123. #define RELAY_MODE_SAME 2
  124. #define RELAY_MODE_TOOGLE 3
  125. #define RELAY_TYPE_NORMAL 0
  126. #define RELAY_TYPE_INVERSE 1
  127. #define RELAY_TYPE_LATCHED 2
  128. #define RELAY_SYNC_ANY 0
  129. #define RELAY_SYNC_NONE_OR_ONE 1
  130. #define RELAY_SYNC_ONE 2
  131. #define RELAY_SYNC_SAME 3
  132. #define RELAY_PULSE_NONE 0
  133. #define RELAY_PULSE_OFF 1
  134. #define RELAY_PULSE_ON 2
  135. #define RELAY_PROVIDER_RELAY 0
  136. #define RELAY_PROVIDER_DUAL 1
  137. #define RELAY_PROVIDER_LIGHT 2
  138. #define RELAY_PROVIDER_RFBRIDGE 3
  139. // Pulse time in milliseconds
  140. #define RELAY_PULSE_TIME 1.0
  141. // 0 means OFF, 1 ON and 2 whatever was before
  142. #define RELAY_MODE RELAY_MODE_OFF
  143. // 0 means ANY, 1 zero or one and 2 one and only one
  144. #define RELAY_SYNC RELAY_SYNC_ANY
  145. // 0 means no pulses, 1 means normally off, 2 normally on
  146. #define RELAY_PULSE_MODE RELAY_PULSE_NONE
  147. // Relay requests flood protection window - in seconds
  148. #define RELAY_FLOOD_WINDOW 3
  149. // Allowed actual relay changes inside requests flood protection window
  150. #define RELAY_FLOOD_CHANGES 5
  151. // Pulse with in milliseconds for a latched relay
  152. #define RELAY_LATCHING_PULSE 10
  153. //------------------------------------------------------------------------------
  154. // I18N
  155. //------------------------------------------------------------------------------
  156. #define TMP_CELSIUS 0
  157. #define TMP_FAHRENHEIT 1
  158. #define TMP_UNITS TMP_CELSIUS // Temperature units (TMP_CELSIUS | TMP_FAHRENHEIT)
  159. //------------------------------------------------------------------------------
  160. // LED
  161. //------------------------------------------------------------------------------
  162. // All defined LEDs in the board can be managed through MQTT
  163. // except the first one when LED_AUTO is set to 1.
  164. // If LED_AUTO is set to 1 the board will a defined LED to show wifi status.
  165. #define LED_AUTO 1
  166. // LED # to use as WIFI status indicator
  167. #ifndef WIFI_LED
  168. #define WIFI_LED 1
  169. #endif
  170. // -----------------------------------------------------------------------------
  171. // WIFI & WEB
  172. // -----------------------------------------------------------------------------
  173. #define WIFI_CONNECT_TIMEOUT 30000 // Connecting timeout for WIFI in ms
  174. #define WIFI_RECONNECT_INTERVAL 120000 // If could not connect to WIFI, retry after this time in ms
  175. #define WIFI_MAX_NETWORKS 5 // Max number of WIFI connection configurations
  176. #define HTTP_USERNAME "admin" // HTTP username
  177. #define ADMIN_PASS "fibonacci" // Default password
  178. #define FORCE_CHANGE_PASS 1 // Force the user to change the password if default one
  179. #define WS_BUFFER_SIZE 5 // Max number of secured websocket connections
  180. #define WS_TIMEOUT 1800000 // Timeout for secured websocket
  181. #define WEBSERVER_PORT 80 // HTTP port
  182. #define DNS_PORT 53 // MDNS port
  183. #define ENABLE_MDNS 1 // Enable MDNS by default
  184. #define ENABLE_API 0 // Do not enable API by default
  185. #define API_BUFFER_SIZE 10 // Size of the buffer for HTTP GET API responses
  186. #define WEB_MODE_NORMAL 0
  187. #define WEB_MODE_PASSWORD 1
  188. #define AP_MODE AP_MODE_ALONE
  189. // This option builds the firmware with the web interface embedded.
  190. #ifndef EMBEDDED_WEB
  191. #define EMBEDDED_WEB 1
  192. #endif
  193. // -----------------------------------------------------------------------------
  194. // SPIFFS
  195. // -----------------------------------------------------------------------------
  196. // Do not add support for SPIFFS by default
  197. #ifndef ENABLE_SPIFFS
  198. #define ENABLE_SPIFFS 0
  199. #endif
  200. // -----------------------------------------------------------------------------
  201. // OTA & NOFUSS
  202. // -----------------------------------------------------------------------------
  203. #define OTA_PORT 8266 // OTA port
  204. #define NOFUSS_SERVER "" // Default NoFuss Server
  205. #define NOFUSS_INTERVAL 3600000 // Check for updates every hour
  206. // -----------------------------------------------------------------------------
  207. // MQTT
  208. // -----------------------------------------------------------------------------
  209. #ifndef MQTT_USE_ASYNC
  210. #define MQTT_USE_ASYNC 1 // Use AysncMQTTClient (1) or PubSubClient (0)
  211. #endif
  212. #define MQTT_SERVER "" // Default MQTT broker address
  213. #define MQTT_PORT 1883 // MQTT broker port
  214. #define MQTT_TOPIC "/test/switch/{identifier}" // Default MQTT base topic
  215. #define MQTT_RETAIN true // MQTT retain flag
  216. #define MQTT_QOS 0 // MQTT QoS value for all messages
  217. #define MQTT_KEEPALIVE 30 // MQTT keepalive value
  218. #define MQTT_RECONNECT_DELAY 10000 // Try to reconnect after 10s
  219. #define MQTT_TRY_INTERVAL 30000 // Timeframe for disconnect retries
  220. #define MQTT_MAX_TRIES 12 // After these many retries during the previous MQTT_TRY_INTERVAL the board will reset
  221. #define MQTT_SKIP_RETAINED 1 // Skip retained messages on connection
  222. #define MQTT_SKIP_TIME 1000 // Skip messages for 1 second anter connection
  223. #define MQTT_USE_JSON 0 // Group messages in a JSON body
  224. #define MQTT_USE_JSON_DELAY 100 // Wait this many ms before grouping messages
  225. // These particles will be concatenated to the MQTT_TOPIC base to form the actual topic
  226. #define MQTT_TOPIC_JSON "data"
  227. #define MQTT_TOPIC_ACTION "action"
  228. #define MQTT_TOPIC_RELAY "relay"
  229. #define MQTT_TOPIC_LED "led"
  230. #define MQTT_TOPIC_BUTTON "button"
  231. #define MQTT_TOPIC_IP "ip"
  232. #define MQTT_TOPIC_VERSION "version"
  233. #define MQTT_TOPIC_UPTIME "uptime"
  234. #define MQTT_TOPIC_FREEHEAP "freeheap"
  235. #define MQTT_TOPIC_VCC "vcc"
  236. #define MQTT_TOPIC_STATUS "status"
  237. #define MQTT_TOPIC_MAC "mac"
  238. #define MQTT_TOPIC_RSSI "rssi"
  239. #define MQTT_TOPIC_APP "app"
  240. #define MQTT_TOPIC_INTERVAL "interval"
  241. #define MQTT_TOPIC_HOSTNAME "host"
  242. #define MQTT_TOPIC_TIME "time"
  243. #define MQTT_TOPIC_ANALOG "analog"
  244. #define MQTT_TOPIC_RFOUT "rfout"
  245. #define MQTT_TOPIC_RFIN "rfin"
  246. #define MQTT_TOPIC_RFLEARN "rflearn"
  247. // Lights
  248. #define MQTT_TOPIC_CHANNEL "channel"
  249. #define MQTT_TOPIC_COLOR "color"
  250. #define MQTT_TOPIC_BRIGHTNESS "brightness"
  251. #define MQTT_TOPIC_MIRED "mired"
  252. #define MQTT_TOPIC_KELVIN "kelvin"
  253. #define MQTT_STATUS_ONLINE "1" // Value for the device ON message
  254. #define MQTT_STATUS_OFFLINE "0" // Value for the device OFF message (will)
  255. #define MQTT_ACTION_RESET "reset" // RESET MQTT topic particle
  256. // Internal MQTT events (do not change)
  257. #define MQTT_CONNECT_EVENT 0
  258. #define MQTT_DISCONNECT_EVENT 1
  259. #define MQTT_MESSAGE_EVENT 2
  260. // Custom get and set postfixes
  261. // Use something like "/status" or "/set", with leading slash
  262. #define MQTT_USE_GETTER ""
  263. #define MQTT_USE_SETTER "/set"
  264. // -----------------------------------------------------------------------------
  265. // I2C
  266. // -----------------------------------------------------------------------------
  267. #ifndef ENABLE_I2C
  268. #define ENABLE_I2C 0 // I2C enabled
  269. #endif
  270. #define I2C_SDA_PIN 4 // SDA GPIO
  271. #define I2C_SCL_PIN 14 // SCL GPIO
  272. #define I2C_CLOCK_STRETCH_TIME 200 // BRZO clock stretch time
  273. #define I2C_SCL_FREQUENCY 1000 // BRZO SCL frequency
  274. // -----------------------------------------------------------------------------
  275. // LIGHT
  276. // -----------------------------------------------------------------------------
  277. #define LIGHT_PROVIDER_NONE 0
  278. #define LIGHT_PROVIDER_MY9192 1
  279. #define LIGHT_PROVIDER_DIMMER 2
  280. // LIGHT_PROVIDER_DIMMER can have from 1 to 5 different channels.
  281. // They have to be defined for each device in the hardware.h file.
  282. // If 3 or more channels first 3 will be considered RGB.
  283. // Usual configurations are:
  284. // 1 channels => W
  285. // 2 channels => WW
  286. // 3 channels => RGB
  287. // 4 channels => RGBW
  288. // 5 channels => RGBWW
  289. #define LIGHT_SAVE_DELAY 5 // Persist color after 5 seconds to avoid wearing out
  290. #define LIGHT_PWM_FREQUENCY 1000 // PWM frequency
  291. #define LIGHT_MAX_PWM 4095 // Maximum PWM value
  292. #define LIGHT_MAX_VALUE 255 // Maximum light value
  293. #define LIGHT_MAX_BRIGHTNESS 255 // Maximun brightness value
  294. #define LIGHT_USE_COLOR 1 // Use 3 first channels as RGB
  295. #define LIGHT_USE_WHITE 0 // Use white channel whenever RGB have the same value
  296. #define LIGHT_USE_GAMMA 0 // Use gamma correction for color channels
  297. // -----------------------------------------------------------------------------
  298. // DOMOTICZ
  299. // -----------------------------------------------------------------------------
  300. #ifndef ENABLE_DOMOTICZ
  301. #define ENABLE_DOMOTICZ 1 // Build with domoticz support
  302. #endif
  303. #define DOMOTICZ_ENABLED 1 // Enable domoticz by default
  304. #define DOMOTICZ_IN_TOPIC "domoticz/in" // Default subscription topic
  305. #define DOMOTICZ_OUT_TOPIC "domoticz/out" // Default publication topic
  306. // -----------------------------------------------------------------------------
  307. // INFLUXDB
  308. // -----------------------------------------------------------------------------
  309. #ifndef ENABLE_INFLUXDB
  310. #define ENABLE_INFLUXDB 1 // Enable InfluxDB support by default
  311. #endif
  312. #define INFLUXDB_PORT 8086 // Default InfluxDB port
  313. // -----------------------------------------------------------------------------
  314. // NTP
  315. // -----------------------------------------------------------------------------
  316. #define NTP_SERVER "pool.ntp.org" // Default NTP server
  317. #define NTP_TIME_OFFSET 1 // Default timezone offset (GMT+1)
  318. #define NTP_DAY_LIGHT true // Enable daylight time saving by default
  319. #define NTP_UPDATE_INTERVAL 1800 // NTP check every 30 minutes
  320. // -----------------------------------------------------------------------------
  321. // FAUXMO
  322. // -----------------------------------------------------------------------------
  323. // This setting defines whether Alexa support should be built into the firmware
  324. #ifndef ENABLE_FAUXMO
  325. #define ENABLE_FAUXMO 1
  326. #endif
  327. // This is default value for the fauxmoEnabled setting that defines whether
  328. // this device should be discoberable and respond to Alexa commands.
  329. // Both ENABLE_FAUXMO and fauxmoEnabled should be 1 for Alexa support to work.
  330. #define FAUXMO_ENABLED 1
  331. // -----------------------------------------------------------------------------
  332. // RFBRIDGE
  333. // -----------------------------------------------------------------------------
  334. #define RF_SEND_TIMES 4 // How many times to send the message
  335. #define RF_SEND_DELAY 250 // Interval between sendings in ms