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.

234 lines
8.1 KiB

Terminal: change command-line parser (#2247) Change the underlying command line handling: - switch to a custom parser, inspired by redis / sds - update terminalRegisterCommand signature, pass only bare minimum - clean-up `help` & `commands`. update settings `set`, `get` and `del` - allow our custom test suite to run command-line tests - clean-up Stream IO to allow us to print large things into debug stream (for example, `eeprom.dump`) - send parsing errors to the debug log As a proof of concept, introduce `TERMINAL_MQTT_SUPPORT` and `TERMINAL_WEB_API_SUPPORT` - MQTT subscribes to the `<root>/cmd/set` and sends response to the `<root>/cmd`. We can't output too much, as we don't have any large-send API. - Web API listens to the `/api/cmd?apikey=...&line=...` (or PUT, params inside the body). This one is intended as a possible replacement of the `API_SUPPORT`. Internals introduce a 'task' around the AsyncWebServerRequest object that will simulate what WiFiClient does and push data into it continuously, switching between CONT and SYS. Both are experimental. We only accept a single command and not every command is updated to use Print `ctx.output` object. We are also somewhat limited by the Print / Stream overall, perhaps I am overestimating the usefulness of Arduino compatibility to such an extent :) Web API handler can also sometimes show only part of the result, whenever the command tries to yield() by itself waiting for something. Perhaps we would need to create a custom request handler for that specific use-case.
4 years ago
  1. //------------------------------------------------------------------------------
  2. // Do not change this file unless you know what you are doing
  3. // Configuration settings are in the general.h file
  4. //------------------------------------------------------------------------------
  5. #pragma once
  6. //------------------------------------------------------------------------------
  7. // Various modules configuration
  8. #if DEBUG_TELNET_SUPPORT
  9. #undef TELNET_SUPPORT
  10. #define TELNET_SUPPORT 1
  11. #endif
  12. #if not WEB_SUPPORT
  13. #undef DEBUG_WEB_SUPPORT
  14. #define DEBUG_WEB_SUPPORT 0
  15. #endif
  16. #if not WEB_SUPPORT
  17. #undef API_SUPPORT
  18. #define API_SUPPORT 0 // API support requires web support
  19. #endif
  20. #if not WEB_SUPPORT
  21. #undef SSDP_SUPPORT
  22. #define SSDP_SUPPORT 0 // SSDP support requires web support
  23. #endif
  24. #if UART_MQTT_SUPPORT
  25. #undef MQTT_SUPPORT
  26. #define MQTT_SUPPORT 1 // UART<->MQTT requires MQTT and no serial debug
  27. #undef DEBUG_SERIAL_SUPPORT
  28. #define DEBUG_SERIAL_SUPPORT 0 // TODO: compare UART_MQTT_PORT with DEBUG_PORT? (as strings)
  29. #endif
  30. #if ALEXA_SUPPORT
  31. #undef BROKER_SUPPORT
  32. #define BROKER_SUPPORT 1 // If Alexa enabled enable BROKER
  33. #undef RELAY_SUPPORT
  34. #define RELAY_SUPPORT 1 // and switches
  35. #endif
  36. #if RPN_RULES_SUPPORT
  37. #undef BROKER_SUPPORT
  38. #define BROKER_SUPPORT 1 // If RPN Rules enabled enable BROKER
  39. #undef MQTT_SUPPORT
  40. #define MQTT_SUPPORT 1
  41. #endif
  42. #if LED_SUPPORT
  43. #undef BROKER_SUPPORT
  44. #define BROKER_SUPPORT 1 // If LED is enabled enable BROKER to supply status changes
  45. #endif
  46. #if INFLUXDB_SUPPORT
  47. #undef BROKER_SUPPORT
  48. #define BROKER_SUPPORT 1 // If InfluxDB enabled enable BROKER
  49. #endif
  50. #if DOMOTICZ_SUPPORT
  51. #undef BROKER_SUPPORT
  52. #define BROKER_SUPPORT 1 // If Domoticz enabled enable BROKER
  53. #undef MQTT_SUPPORT
  54. #define MQTT_SUPPORT 1 // If Domoticz enabled enable MQTT
  55. #endif
  56. #if HOMEASSISTANT_SUPPORT
  57. #undef MQTT_SUPPORT
  58. #define MQTT_SUPPORT 1 // If Home Assistant enabled enable MQTT
  59. #endif
  60. #if THINGSPEAK_SUPPORT
  61. #undef BROKER_SUPPORT
  62. #define BROKER_SUPPORT 1 // If Thingspeak enabled enable BROKER
  63. #endif
  64. #if THERMOSTAT_SUPPORT
  65. #undef MQTT_USE_JSON
  66. #define MQTT_USE_JSON 1 // Thermostat depends on group messages in a JSON body
  67. #undef RELAY_SUPPORT
  68. #define RELAY_SUPPORT 1 // Thermostat depends on switches
  69. #endif
  70. #if SCHEDULER_SUPPORT
  71. #undef NTP_SUPPORT
  72. #define NTP_SUPPORT 1 // Scheduler needs NTP to work
  73. #undef BROKER_SUPPORT
  74. #define BROKER_SUPPORT 1 // Scheduler needs Broker to trigger every minute
  75. #undef RELAY_SUPPORT
  76. #define RELAY_SUPPORT 1 // Scheduler needs relays
  77. #endif
  78. #if LWIP_VERSION_MAJOR != 1
  79. #undef MDNS_CLIENT_SUPPORT
  80. #define MDNS_CLIENT_SUPPORT 0 // default resolver already handles this
  81. #endif
  82. #if not defined(ARDUINO_ESP8266_RELEASE_2_3_0)
  83. #undef TELNET_SERVER_ASYNC_BUFFERED
  84. #define TELNET_SERVER_ASYNC_BUFFERED 1 // enable buffered telnet by default on latest Cores
  85. #endif
  86. #if LIGHT_PROVIDER == LIGHT_PROVIDER_TUYA
  87. #undef TUYA_SUPPORT
  88. #define TUYA_SUPPORT 1 // Need base Tuya module for this to work
  89. #undef LIGHT_USE_TRANSITIONS
  90. #define LIGHT_USE_TRANSITIONS 0 // TODO: temporary, maybe slower step instead?
  91. #endif
  92. #if TUYA_SUPPORT
  93. #undef BROKER_SUPPORT
  94. #define BROKER_SUPPORT 1 // Broker is required to process relay & lights events
  95. #undef RELAY_SUPPORT
  96. #define RELAY_SUPPORT 1 // Most of the time we require it
  97. #endif
  98. #if TERMINAL_WEB_API_SUPPORT
  99. #undef TERMINAL_SUPPORT
  100. #define TERMINAL_SUPPORT 1 // Need terminal command line parser and commands
  101. #undef WEB_SUPPORT
  102. #define WEB_SUPPORT 1 // Registered as web server request handler
  103. #endif
  104. #if TERMINAL_MQTT_SUPPORT
  105. #undef TERMINAL_SUPPORT
  106. #define TERMINAL_SUPPORT 1 // Need terminal command line parser and commands
  107. #undef MQTT_SUPPORT
  108. #define MQTT_SUPPORT 1 // Subscribe and publish things
  109. #endif
  110. //------------------------------------------------------------------------------
  111. // Hint about ESPAsyncTCP options and our internal one
  112. // TODO: clean-up SSL_ENABLED and USE_SSL settings for 1.15.0
  113. #if ASYNC_TCP_SSL_ENABLED && SECURE_CLIENT == SECURE_CLIENT_NONE
  114. #undef SECURE_CLIENT
  115. #define SECURE_CLIENT SECURE_CLIENT_AXTLS
  116. #endif
  117. #if THINGSPEAK_USE_SSL && THINGSPEAK_USE_ASYNC && (!ASYNC_TCP_SSL_ENABLED)
  118. #warning "Thingspeak in ASYNC mode requires a globally defined ASYNC_TCP_SSL_ENABLED=1"
  119. #undef THINGSPEAK_SUPPORT
  120. #define THINGSPEAK_SUPPORT 0 // Thingspeak in ASYNC mode requires ASYNC_TCP_SSL_ENABLED
  121. #endif
  122. #if WEB_SUPPORT && WEB_SSL_ENABLED && (!ASYNC_TCP_SSL_ENABLED)
  123. #warning "WEB_SUPPORT with SSL requires a globally defined ASYNC_TCP_SSL_ENABLED=1"
  124. #undef WEB_SSL_ENABLED
  125. #define WEB_SSL_ENABLED 0 // WEB_SUPPORT mode th SSL requires ASYNC_TCP_SSL_ENABLED
  126. #endif
  127. #if !DEBUG_SUPPORT
  128. #undef DEBUG_LOG_BUFFER_SUPPORT
  129. #define DEBUG_LOG_BUFFER_SUPPORT 0 // Can't buffer if there is no debugging enabled.
  130. // Helps to avoid checking twice for both DEBUG_SUPPORT and BUFFER_LOG_SUPPORT
  131. #endif
  132. //------------------------------------------------------------------------------
  133. // These depend on newest Core libraries
  134. #if LLMNR_SUPPORT && defined(ARDUINO_ESP8266_RELEASE_2_3_0)
  135. #undef LLMNR_SUPPORT
  136. #define LLMNR_SUPPORT 0
  137. #endif
  138. #if NETBIOS_SUPPORT && defined(ARDUINO_ESP8266_RELEASE_2_3_0)
  139. #undef NETBIOS_SUPPORT
  140. #define NETBIOS_SUPPORT 0
  141. #endif
  142. #if SSDP_SUPPORT && defined(ARDUINO_ESP8266_RELEASE_2_3_0)
  143. #undef SSDP_SUPPORT
  144. #define SSDP_SUPPORT 0
  145. #endif
  146. //------------------------------------------------------------------------------
  147. // Change ntp module depending on Core version
  148. #if NTP_SUPPORT && defined(ARDUINO_ESP8266_RELEASE_2_3_0)
  149. #define NTP_LEGACY_SUPPORT 1
  150. #else
  151. #define NTP_LEGACY_SUPPORT 0
  152. #endif
  153. //------------------------------------------------------------------------------
  154. // When using Dual / Lightfox Dual, notify that Serial should be used
  155. #if (BUTTON_EVENTS_SOURCE == BUTTON_EVENTS_SOURCE_ITEAD_SONOFF_DUAL) || \
  156. (BUTTON_EVENTS_SOURCE == BUTTON_EVENTS_SOURCE_FOXEL_LIGHTFOX_DUAL)
  157. #if DEBUG_SERIAL_SUPPORT
  158. #warning "DEBUG_SERIAL_SUPPORT conflicts with the current BUTTON_EVENTS_SOURCE"
  159. #undef DEBUG_SERIAL_SUPPORT
  160. #define DEBUG_SERIAL_SUPPORT 0
  161. #endif
  162. #endif
  163. //------------------------------------------------------------------------------
  164. // It looks more natural that one click will enable display
  165. // and long click will switch relay
  166. #if THERMOSTAT_DISPLAY_SUPPORT
  167. #undef BUTTON1_CLICK
  168. #define BUTTON1_CLICK BUTTON_ACTION_DISPLAY_ON
  169. #undef BUTTON1_LNGCLICK
  170. #define BUTTON1_LNGCLICK BUTTON_ACTION_TOGGLE
  171. #endif
  172. //------------------------------------------------------------------------------
  173. // We should always set MQTT_MAX_PACKET_SIZE
  174. #if MQTT_LIBRARY == MQTT_LIBRARY_PUBSUBCLIENT
  175. #if not defined(MQTT_MAX_PACKET_SIZE)
  176. #warning "MQTT_MAX_PACKET_SIZE should be set in `build_flags = ...` of the environment! Default value is used instead."
  177. #endif
  178. #endif
  179. //------------------------------------------------------------------------------
  180. // Disable BME680 support if using Core version 2.3.0 due to memory constraints.
  181. #if BME680_SUPPORT && defined(ARDUINO_ESP8266_RELEASE_2_3_0)
  182. #warning "BME680_SUPPORT is not available when using Arduino Core 2.3.0 due to memory constraints. Please use Arduino Core 2.6.3+ instead (or set `platform = ${common.platform_latest}` for the latest version)."
  183. #undef BME680_SUPPORT
  184. #define BME680_SUPPORT 0
  185. #endif
  186. //------------------------------------------------------------------------------
  187. // Prometheus needs web server + request handler API
  188. #if PROMETHEUS_SUPPORT
  189. #undef WEB_SUPPORT
  190. #define WEB_SUPPORT 1
  191. #endif