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.

218 lines
4.5 KiB

8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 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. */
  15. #include "config/all.h"
  16. // -----------------------------------------------------------------------------
  17. unsigned long _loopDelay = 0;
  18. // -----------------------------------------------------------------------------
  19. // BOOTING
  20. // -----------------------------------------------------------------------------
  21. void setup() {
  22. // Init EEPROM, Serial and SPIFFS
  23. hardwareSetup();
  24. // Question system stability
  25. #if SYSTEM_CHECK_ENABLED
  26. systemCheck(false);
  27. #endif
  28. // Init persistance and terminal features
  29. settingsSetup();
  30. if (getSetting("hostname").length() == 0) {
  31. setSetting("hostname", getIdentifier());
  32. }
  33. setBoardName();
  34. // Cache loop delay value to speed things (recommended max 250ms)
  35. _loopDelay = atol(getSetting("loopDelay", LOOP_DELAY_TIME).c_str());
  36. // Show welcome message and system configuration
  37. info();
  38. // Basic modules, will always run
  39. wifiSetup();
  40. otaSetup();
  41. #if TELNET_SUPPORT
  42. telnetSetup();
  43. #endif
  44. // Do not run the next services if system is flagged stable
  45. #if SYSTEM_CHECK_ENABLED
  46. if (!systemCheck()) return;
  47. #endif
  48. // Init webserver required before any module that uses API
  49. #if WEB_SUPPORT
  50. webSetup();
  51. wsSetup();
  52. apiSetup();
  53. #endif
  54. #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
  55. lightSetup();
  56. #endif
  57. relaySetup();
  58. buttonSetup();
  59. ledSetup();
  60. #if MQTT_SUPPORT
  61. mqttSetup();
  62. #endif
  63. #if MDNS_SERVER_SUPPORT
  64. mdnsServerSetup();
  65. #endif
  66. #if LLMNR_SUPPORT
  67. llmnrSetup();
  68. #endif
  69. #if NETBIOS_SUPPORT
  70. netbiosSetup();
  71. #endif
  72. #if SSDP_SUPPORT
  73. ssdpSetup();
  74. #endif
  75. #if NTP_SUPPORT
  76. ntpSetup();
  77. #endif
  78. #if I2C_SUPPORT
  79. i2cSetup();
  80. #if I2C_CLEAR_BUS
  81. i2cClearBus();
  82. #endif
  83. i2cScan();
  84. #endif
  85. #ifdef ITEAD_SONOFF_RFBRIDGE
  86. rfbSetup();
  87. #endif
  88. #if ALEXA_SUPPORT
  89. alexaSetup();
  90. #endif
  91. #if NOFUSS_SUPPORT
  92. nofussSetup();
  93. #endif
  94. #if INFLUXDB_SUPPORT
  95. idbSetup();
  96. #endif
  97. #if THINGSPEAK_SUPPORT
  98. tspkSetup();
  99. #endif
  100. #if RF_SUPPORT
  101. rfSetup();
  102. #endif
  103. #if IR_SUPPORT
  104. irSetup();
  105. #endif
  106. #if DOMOTICZ_SUPPORT
  107. domoticzSetup();
  108. #endif
  109. #if HOMEASSISTANT_SUPPORT
  110. haSetup();
  111. #endif
  112. #if SENSOR_SUPPORT
  113. sensorSetup();
  114. #endif
  115. #if SCHEDULER_SUPPORT
  116. schSetup();
  117. #endif
  118. // 3rd party code hook
  119. #if USE_EXTRA
  120. extraSetup();
  121. #endif
  122. // Prepare configuration for version 2.0
  123. migrate();
  124. saveSettings();
  125. }
  126. void loop() {
  127. hardwareLoop();
  128. settingsLoop();
  129. wifiLoop();
  130. otaLoop();
  131. #if SYSTEM_CHECK_ENABLED
  132. systemCheckLoop();
  133. // Do not run the next services if system is flagged stable
  134. if (!systemCheck()) return;
  135. #endif
  136. #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
  137. lightLoop();
  138. #endif
  139. relayLoop();
  140. buttonLoop();
  141. ledLoop();
  142. #if MQTT_SUPPORT
  143. mqttLoop();
  144. #endif
  145. #ifdef ITEAD_SONOFF_RFBRIDGE
  146. rfbLoop();
  147. #endif
  148. #if SSDP_SUPPORT
  149. ssdpLoop();
  150. #endif
  151. #if NTP_SUPPORT
  152. ntpLoop();
  153. #endif
  154. #if ALEXA_SUPPORT
  155. alexaLoop();
  156. #endif
  157. #if NOFUSS_SUPPORT
  158. nofussLoop();
  159. #endif
  160. #if RF_SUPPORT
  161. rfLoop();
  162. #endif
  163. #if IR_SUPPORT
  164. irLoop();
  165. #endif
  166. #if SENSOR_SUPPORT
  167. sensorLoop();
  168. #endif
  169. #if THINGSPEAK_SUPPORT
  170. tspkLoop();
  171. #endif
  172. #if SCHEDULER_SUPPORT
  173. schLoop();
  174. #endif
  175. #if MDNS_CLIENT_SUPPORT
  176. mdnsClientLoop();
  177. #endif
  178. // 3rd party code hook
  179. #if USE_EXTRA
  180. extraLoop();
  181. #endif
  182. // Power saving delay
  183. delay(_loopDelay);
  184. }