scheduler.ino 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. void checkMillis() {
  2. if ( (millis() - lastRun) > 100 ) {
  3. lastRun = millis();
  4. every100ms();
  5. }
  6. }
  7. void every100ms() {
  8. if (count100ms < 10) count100ms++;
  9. else {
  10. count100ms = 0;
  11. everySecond();
  12. }
  13. //checkSaveConfigTriggered();
  14. }
  15. void everySecond() {
  16. if (countSeconds < 60) countSeconds++;
  17. else {
  18. countSeconds = 0;
  19. everyMinute();
  20. }
  21. //webSocket.sendTXT(num, "Test\n");
  22. // if(confWeb.enableConsole && webSocket.connectedClients() > 0) {
  23. // char buf[40];
  24. // sprintf(buf, "%u\n", millis());
  25. // webSocket.broadcastTXT(buf);
  26. // }
  27. handleDisplayTimeout();
  28. checkValuesChanged();
  29. clearValidSessionId();
  30. if (countMeasureInterval < confBas.measureInterval) countMeasureInterval++;
  31. else {
  32. countMeasureInterval = 0;
  33. measureTempHum();
  34. thermostat();
  35. }
  36. if (countDisplayInterval < confBas.displayInterval) countDisplayInterval++;
  37. else {
  38. countDisplayInterval = 0;
  39. updateDisplay();
  40. }
  41. if (doRestart) restart();
  42. if ( (millis() - pendingRestart_lastMillis) > 3000 ) pendingRestart = false;
  43. // if ( preset != pendingPreset) {
  44. // if ( (millis() - pendingPreset_millis) > pendingPreset_timeout ) {
  45. // preset = pendingPreset;
  46. // }
  47. // }
  48. }
  49. unsigned int outPubInterval_states_count = 0;
  50. unsigned int outPubInterval_sensors_count = 0;
  51. void everyMinute() {
  52. updateUptime();
  53. buildUptimeString();
  54. if(confTime.ntpEnable) {
  55. updateTimeFromNTP();
  56. }
  57. logSysdata();
  58. if(confMqtt.mqtt_enable) {
  59. if(!confMqtt.mqtt_willRetain) mqttPublishConnectMsg();
  60. mqttPublishStatus();
  61. if(confMqtt.mqtt_enable_heartbeat) mqttPublishHeartbeat();
  62. if(confMqtt.mqtt_outPubInterval > 0 && outPubInterval_states_count >= confMqtt.mqtt_outPubInterval) {
  63. outPubInterval_states_count = 0;
  64. publishCurrentThermostatValues(true); // true forces publishing
  65. }
  66. else {
  67. outPubInterval_states_count++;
  68. publishCurrentThermostatValues(false); // false publishes only changed values
  69. }
  70. if(confMqtt.mqtt_outPubInterval_sensors > 0 && outPubInterval_sensors_count >= confMqtt.mqtt_outPubInterval_sensors) {
  71. outPubInterval_sensors_count = 0;
  72. publishCurrentSensorValues(true); // true forces publishing
  73. }
  74. else {
  75. outPubInterval_sensors_count++;
  76. publishCurrentSensorValues(false); // false publishes only changed values
  77. }
  78. }
  79. // if(WifiInApMode) {
  80. // if( (millis() - WifiApModeStartedAt) > WIFI_AP_MODE_TIMEOUT ) {
  81. //
  82. // }
  83. // }
  84. // Serial.print("WiFi Status: ");
  85. // Serial.println(WiFi.status());
  86. }