scheduler.ino 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. void scheduler_checkMillis()
  2. {
  3. if ((millis() - lastMillis_100ms) >= 100)
  4. {
  5. lastMillis_100ms = millis();
  6. scheduler_every100ms();
  7. }
  8. if ((millis() - lastMillis_1s) >= 1000)
  9. {
  10. lastMillis_1s = millis();
  11. scheduler_everySecond();
  12. }
  13. if ((millis() - lastMillis_1m) >= 60000)
  14. {
  15. lastMillis_1m = millis();
  16. scheduler_everyMinute();
  17. }
  18. }
  19. void scheduler_every100ms()
  20. {
  21. //checkSaveConfigTriggered();
  22. }
  23. void scheduler_everySecond()
  24. {
  25. conf_confChangedLogNote(false); // only outputs once if false and only if config is not saved
  26. //webSocket.sendTXT(num, "Test\n");
  27. // if(confWeb.enableConsole && webSocket.connectedClients() > 0) {
  28. // char buf[40];
  29. // sprintf(buf, "%u\n", millis());
  30. // webSocket.broadcastTXT(buf);
  31. // }
  32. #ifdef ENABLE_LCD_I2C
  33. display_handleTimeout();
  34. #endif
  35. #ifdef FIRMWARE_VARIANT_THERMOSTAT
  36. thermostat_checkValuesChanged();
  37. #endif
  38. if (sysInfoEverySecond) log_sysdata();
  39. #ifdef ENABLE_FEATURE_WSCONSOLE
  40. clearValidSessionId();
  41. #endif
  42. if ( countMeasureInterval < confSens.measureInterval || (confSens.measureInterval == 0 && countMeasureInterval < 15) ) {
  43. // default of 15s if confSens.measureInterval was set to 0
  44. countMeasureInterval++;
  45. }
  46. else
  47. {
  48. countMeasureInterval = 0;
  49. #ifdef ENABLE_SENSORS_ONEWIRE
  50. oneWireSensors_getData();
  51. #endif
  52. #ifdef ENABLE_SENSOR_DHT22
  53. if (confSens.DHT_enable) DHT_measureTempHum();
  54. #endif
  55. #ifdef FIRMWARE_VARIANT_THERMOSTAT
  56. thermostat_mainFunction();
  57. #endif
  58. }
  59. #ifdef FIRMWARE_VARIANT_THERMOSTAT
  60. if(thermostat_heatingPause > 0) {
  61. thermostat_heatingPause--;
  62. thermostat_publish_heatingPauseTime();
  63. }
  64. if(thermostat_heatingLockTime > 0) {
  65. thermostat_heatingLockTime--;
  66. thermostat_publish_heatingLockTime();
  67. }
  68. #endif // FIRMWARE_VARIANT_THERMOSTAT
  69. #ifdef ENABLE_LCD_I2C
  70. if (display_overrideInterval > 0) {
  71. if (display_countInterval < display_overrideInterval)
  72. display_countInterval++;
  73. else
  74. {
  75. display_countInterval = 0;
  76. display_overrideInterval = 0;
  77. display_update();
  78. }
  79. }
  80. else {
  81. if (display_countInterval < confDisplay.displayInterval)
  82. display_countInterval++;
  83. else
  84. {
  85. display_countInterval = 0;
  86. display_update();
  87. }
  88. }
  89. #endif // ENABLE_LCD_I2C
  90. if (system_doRestart) {
  91. restart();
  92. }
  93. if(system_restartAtMillis > 0 && millis() > system_restartAtMillis) {
  94. restart();
  95. }
  96. if (configChangedMqttConnResetRequired && !confCheckUnsaved()) {
  97. configChangedMqttConnResetRequired = false;
  98. mqttResetConnection();
  99. }
  100. if ((millis() - system_pendingRestart_lastMillis) > 3000) {
  101. system_pendingRestart = false;
  102. }
  103. // if ( preset != pendingPreset) {
  104. // if ( (millis() - pendingPreset_millis) > pendingPreset_timeout ) {
  105. // preset = pendingPreset;
  106. // }
  107. // }
  108. #ifdef ENABLE_I2C_PORTEXPANDER
  109. portexpander_readInputs();
  110. //portexpander_toggleOutputs();
  111. #endif
  112. #ifdef FIRMWARE_VARIANT_HEATCONTROL
  113. heatcontrol_mainFunction();
  114. #endif
  115. } // scheduler_everySecond()
  116. void scheduler_everyMinute()
  117. {
  118. #ifdef ENABLE_FEATURE_NTP_TIME
  119. if (confTime.ntpEnable) {
  120. syncClock();
  121. }
  122. #endif
  123. log_sysdata();
  124. conf_confChangedLogNote(true);
  125. if (confMqtt.mqtt_enable) {
  126. if (!confMqtt.mqtt_willRetain) {
  127. mqtt_publishConnectMsg();
  128. }
  129. mqtt_publishStatus();
  130. if (confMqtt.mqtt_enable_heartbeat) {
  131. mqttPublishHeartbeat();
  132. }
  133. if (confMqtt.mqtt_outPubInterval > 0 && outPubInterval_states_count >= confMqtt.mqtt_outPubInterval) {
  134. outPubInterval_states_count = 0;
  135. #ifdef FIRMWARE_VARIANT_THERMOSTAT
  136. thermostat_publishCurrentValues(true); // true forces publishing
  137. #endif
  138. #ifdef FIRMWARE_VARIANT_HEATCONTROL
  139. heatcontrol_publish_sw_disableControl_heating();
  140. heatcontrol_publish_sw_disableControl_pump();
  141. heatcontrol_publish_in_heat_active();
  142. heatcontrol_publish_in_heat_request();
  143. heatcontrol_publish_out_heat();
  144. heatcontrol_publish_out_pump();
  145. heatcontrol_publish_lockTime();
  146. heatcontrol_publish_pumpBacklash();
  147. heatcontrol_publish_testMode();
  148. heatcontrol_publish_heatCurve_current();
  149. heatcontrol_publish_lockActive();
  150. heatcontrol_pump_forceRunAfterTimeout();
  151. #endif
  152. }
  153. else {
  154. outPubInterval_states_count++;
  155. #ifdef FIRMWARE_VARIANT_THERMOSTAT
  156. thermostat_publishCurrentValues(false); // false publishes only changed values
  157. #endif
  158. }
  159. if (confMqtt.mqtt_outPubInterval_sensors > 0 && outPubInterval_sensors_count >= confMqtt.mqtt_outPubInterval_sensors) {
  160. outPubInterval_sensors_count = 0;
  161. publishCurrentSensorValues(true); // true forces publishing
  162. }
  163. else {
  164. outPubInterval_sensors_count++;
  165. publishCurrentSensorValues(false); // false publishes only changed values
  166. }
  167. if (confSens.DHT_enable) DHT_logCurrentData();
  168. }
  169. } // scheduler_everyMinute()