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.

206 lines
4.9 KiB

7 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
7 years ago
8 years ago
6 years ago
6 years ago
7 years ago
  1. /*
  2. ESPurna
  3. Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. Module key prefix: esp (shared with others)
  15. */
  16. #include "config/all.h"
  17. #include <vector>
  18. std::vector<void (*)()> _loop_callbacks;
  19. // -----------------------------------------------------------------------------
  20. // REGISTER
  21. // -----------------------------------------------------------------------------
  22. void espurnaRegisterLoop(void (*callback)()) {
  23. _loop_callbacks.push_back(callback);
  24. }
  25. // -----------------------------------------------------------------------------
  26. // GLOBAL CONFIG KEYS
  27. // -----------------------------------------------------------------------------
  28. #if WEB_SUPPORT
  29. bool _espWebSocketOnReceive(const char * key, JsonVariant& value) {
  30. if (strncmp(key, "admin", 5) == 0) return true;
  31. if (strncmp(key, "hostname", 8) == 0) return true;
  32. if (strncmp(key, "board", 5) == 0) return true;
  33. if (strncmp(key, "loopDelay", 9) == 0) return true;
  34. if (strncmp(key, "wtfHeap", 7) == 0) return true;
  35. return false;
  36. }
  37. #endif
  38. // -----------------------------------------------------------------------------
  39. // BOOTING
  40. // -----------------------------------------------------------------------------
  41. void setup() {
  42. // -------------------------------------------------------------------------
  43. // Basic modules, will always run
  44. // -------------------------------------------------------------------------
  45. // Serial debug
  46. #if DEBUG_SUPPORT
  47. debugSetup();
  48. #endif
  49. // Init EEPROM
  50. eepromSetup();
  51. // Init Serial, SPIFFS and system check
  52. systemSetup();
  53. // Init persistance and terminal features
  54. settingsSetup();
  55. // Board name initialization
  56. setBoardName();
  57. // Show welcome message and system configuration
  58. info();
  59. wifiSetup();
  60. otaSetup();
  61. #if TELNET_SUPPORT
  62. telnetSetup();
  63. #endif
  64. // -------------------------------------------------------------------------
  65. // Check if system is stable
  66. // -------------------------------------------------------------------------
  67. #if SYSTEM_CHECK_ENABLED
  68. if (!systemCheck()) return;
  69. #endif
  70. // -------------------------------------------------------------------------
  71. // Next modules will be only loaded if system is flagged as stable
  72. // -------------------------------------------------------------------------
  73. // Init webserver required before any module that uses API
  74. #if WEB_SUPPORT
  75. webSetup();
  76. wsSetup();
  77. apiSetup();
  78. #if DEBUG_WEB_SUPPORT
  79. debugWebSetup();
  80. #endif
  81. #endif
  82. // lightSetup must be called before relaySetup
  83. #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
  84. lightSetup();
  85. #endif
  86. relaySetup();
  87. buttonSetup();
  88. ledSetup();
  89. #if MQTT_SUPPORT
  90. mqttSetup();
  91. #endif
  92. #if MDNS_SERVER_SUPPORT
  93. mdnsServerSetup();
  94. #endif
  95. #if MDNS_CLIENT_SUPPORT
  96. mdnsClientSetup();
  97. #endif
  98. #if LLMNR_SUPPORT
  99. llmnrSetup();
  100. #endif
  101. #if NETBIOS_SUPPORT
  102. netbiosSetup();
  103. #endif
  104. #if SSDP_SUPPORT
  105. ssdpSetup();
  106. #endif
  107. #if NTP_SUPPORT
  108. ntpSetup();
  109. #endif
  110. #if I2C_SUPPORT
  111. i2cSetup();
  112. #endif
  113. #ifdef ITEAD_SONOFF_RFBRIDGE
  114. rfbSetup();
  115. #endif
  116. #if ALEXA_SUPPORT
  117. alexaSetup();
  118. #endif
  119. #if NOFUSS_SUPPORT
  120. nofussSetup();
  121. #endif
  122. #if INFLUXDB_SUPPORT
  123. idbSetup();
  124. #endif
  125. #if THINGSPEAK_SUPPORT
  126. tspkSetup();
  127. #endif
  128. #if RF_SUPPORT
  129. rfSetup();
  130. #endif
  131. #if IR_SUPPORT
  132. irSetup();
  133. #endif
  134. #if DOMOTICZ_SUPPORT
  135. domoticzSetup();
  136. #endif
  137. #if HOMEASSISTANT_SUPPORT
  138. haSetup();
  139. #endif
  140. #if SENSOR_SUPPORT
  141. sensorSetup();
  142. #endif
  143. #if SCHEDULER_SUPPORT
  144. schSetup();
  145. #endif
  146. #if UART_MQTT_SUPPORT
  147. uartmqttSetup();
  148. #endif
  149. // 3rd party code hook
  150. #if USE_EXTRA
  151. extraSetup();
  152. #endif
  153. // Prepare configuration for version 2.0
  154. migrate();
  155. saveSettings();
  156. // Global configuration settings
  157. #if WEB_SUPPORT
  158. wsOnReceiveRegister(_espWebSocketOnReceive);
  159. #endif
  160. }
  161. void loop() {
  162. // Call registered loop callbacks
  163. for (unsigned char i = 0; i < _loop_callbacks.size(); i++) {
  164. (_loop_callbacks[i])();
  165. }
  166. }