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.

192 lines
4.4 KiB

6 years ago
6 years ago
8 years ago
6 years ago
8 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
8 years ago
6 years ago
8 years ago
6 years ago
6 years ago
6 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. // BOOTING
  27. // -----------------------------------------------------------------------------
  28. void setup() {
  29. // -------------------------------------------------------------------------
  30. // Basic modules, will always run
  31. // -------------------------------------------------------------------------
  32. // Init EEPROM
  33. eepromSetup();
  34. // Init persistance and terminal features
  35. settingsSetup();
  36. // Serial debug
  37. // Requires SETTINGS
  38. #if DEBUG_SUPPORT
  39. debugSetup();
  40. #endif
  41. // Load devices data
  42. // Requires SETTINGS
  43. deviceSetup();
  44. // Init Serial, SPIFFS and system check
  45. // Requires EEPROM and DEBUG
  46. systemSetup();
  47. // Show welcome message and system configuration
  48. info();
  49. wifiSetup();
  50. otaSetup();
  51. #if TELNET_SUPPORT
  52. telnetSetup();
  53. #endif
  54. // -------------------------------------------------------------------------
  55. // Check if system is stable
  56. // -------------------------------------------------------------------------
  57. #if SYSTEM_CHECK_ENABLED
  58. if (!systemCheck()) return;
  59. #endif
  60. // -------------------------------------------------------------------------
  61. // Next modules will be only loaded if system is flagged as stable
  62. // -------------------------------------------------------------------------
  63. // Init webserver required before any module that uses API
  64. #if WEB_SUPPORT
  65. webSetup();
  66. wsSetup();
  67. #if DEBUG_WEB_SUPPORT
  68. debugWebSetup();
  69. #endif
  70. #endif
  71. #if API_SUPPORT
  72. apiSetup();
  73. #endif
  74. // lightSetup must be called before relaySetup
  75. #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
  76. lightSetup();
  77. #endif
  78. relaySetup();
  79. #if BUTTON_SUPPORT
  80. buttonSetup();
  81. #endif
  82. #if LED_SUPPORT
  83. ledSetup();
  84. #endif
  85. #if MQTT_SUPPORT
  86. mqttSetup();
  87. #endif
  88. #if MDNS_SERVER_SUPPORT
  89. mdnsServerSetup();
  90. #endif
  91. #if MDNS_CLIENT_SUPPORT
  92. mdnsClientSetup();
  93. #endif
  94. #if LLMNR_SUPPORT
  95. llmnrSetup();
  96. #endif
  97. #if NETBIOS_SUPPORT
  98. netbiosSetup();
  99. #endif
  100. #if SSDP_SUPPORT
  101. ssdpSetup();
  102. #endif
  103. #if NTP_SUPPORT
  104. ntpSetup();
  105. #endif
  106. #if I2C_SUPPORT
  107. i2cSetup();
  108. #endif
  109. #ifdef ITEAD_SONOFF_RFBRIDGE
  110. rfbSetup();
  111. #endif
  112. #if ALEXA_SUPPORT
  113. alexaSetup();
  114. #endif
  115. #if NOFUSS_SUPPORT
  116. nofussSetup();
  117. #endif
  118. #if INFLUXDB_SUPPORT
  119. idbSetup();
  120. #endif
  121. #if THINGSPEAK_SUPPORT
  122. tspkSetup();
  123. #endif
  124. #if RFM69_SUPPORT
  125. rfm69Setup();
  126. #endif
  127. #if RF_SUPPORT
  128. rfSetup();
  129. #endif
  130. #if IR_SUPPORT
  131. irSetup();
  132. #endif
  133. #if DOMOTICZ_SUPPORT
  134. domoticzSetup();
  135. #endif
  136. #if HOMEASSISTANT_SUPPORT
  137. haSetup();
  138. #endif
  139. #if SENSOR_SUPPORT
  140. sensorSetup();
  141. #endif
  142. #if SCHEDULER_SUPPORT
  143. schSetup();
  144. #endif
  145. #if UART_MQTT_SUPPORT
  146. uartmqttSetup();
  147. #endif
  148. // 3rd party code hook
  149. #if USE_EXTRA
  150. extraSetup();
  151. #endif
  152. saveSettings();
  153. }
  154. void loop() {
  155. // Call registered loop callbacks
  156. for (unsigned char i = 0; i < _loop_callbacks.size(); i++) {
  157. (_loop_callbacks[i])();
  158. }
  159. }