scheduler.ino 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. void checkMillis()
  2. {
  3. if ((millis() - lastRun) >= 100)
  4. {
  5. lastRun = millis();
  6. every100ms();
  7. }
  8. }
  9. void every100ms()
  10. {
  11. if (count100ms < 10)
  12. count100ms++;
  13. else
  14. {
  15. count100ms = 0;
  16. everySecond();
  17. }
  18. //checkSaveConfigTriggered();
  19. }
  20. void everySecond()
  21. {
  22. if (countSeconds < 60)
  23. countSeconds++;
  24. else
  25. {
  26. countSeconds = 0;
  27. everyMinute();
  28. }
  29. confChangedLogNote(false); // only outputs once if false and only if config is not saved
  30. //webSocket.sendTXT(num, "Test\n");
  31. // if(confWeb.enableConsole && webSocket.connectedClients() > 0) {
  32. // char buf[40];
  33. // sprintf(buf, "%u\n", millis());
  34. // webSocket.broadcastTXT(buf);
  35. // }
  36. handleDisplayTimeout();
  37. checkValuesChanged();
  38. if (sysInfoEverySecond)
  39. logSysdata();
  40. #ifdef ENABLE_FEATURE_WEB_CONSOLE_WEBSOCKETS
  41. clearValidSessionId();
  42. #endif
  43. if (countMeasureInterval < confBas.measureInterval)
  44. countMeasureInterval++;
  45. else
  46. {
  47. countMeasureInterval = 0;
  48. measureTempHum();
  49. thermostat();
  50. }
  51. if(heatingPause > 0) {
  52. heatingPause--;
  53. publish_heatingPauseTime();
  54. }
  55. if(heatingLockTime > 0) {
  56. heatingLockTime--;
  57. publish_heatingLockTime();
  58. }
  59. if (countDisplayInterval < confBas.displayInterval)
  60. countDisplayInterval++;
  61. else
  62. {
  63. countDisplayInterval = 0;
  64. updateDisplay();
  65. }
  66. if (doRestart)
  67. restart();
  68. if (configChangedMqttConnResetRequired && !confCheckUnsaved())
  69. {
  70. configChangedMqttConnResetRequired = false;
  71. mqttResetConnection();
  72. }
  73. if ((millis() - pendingRestart_lastMillis) > 3000)
  74. pendingRestart = false;
  75. // if ( preset != pendingPreset) {
  76. // if ( (millis() - pendingPreset_millis) > pendingPreset_timeout ) {
  77. // preset = pendingPreset;
  78. // }
  79. // }
  80. }
  81. unsigned int outPubInterval_states_count = 0;
  82. unsigned int outPubInterval_sensors_count = 0;
  83. void everyMinute()
  84. {
  85. #ifdef ENABLE_FEATURE_NTP_TIME
  86. if (confTime.ntpEnable)
  87. {
  88. syncClock();
  89. }
  90. #endif
  91. logSysdata();
  92. confChangedLogNote(true);
  93. if (confMqtt.mqtt_enable)
  94. {
  95. if (!confMqtt.mqtt_willRetain)
  96. mqttPublishConnectMsg();
  97. mqttPublishStatus();
  98. if (confMqtt.mqtt_enable_heartbeat)
  99. mqttPublishHeartbeat();
  100. if (confMqtt.mqtt_outPubInterval > 0 && outPubInterval_states_count >= confMqtt.mqtt_outPubInterval)
  101. {
  102. outPubInterval_states_count = 0;
  103. publishCurrentThermostatValues(true); // true forces publishing
  104. }
  105. else
  106. {
  107. outPubInterval_states_count++;
  108. publishCurrentThermostatValues(false); // false publishes only changed values
  109. }
  110. if (confMqtt.mqtt_outPubInterval_sensors > 0 && outPubInterval_sensors_count >= confMqtt.mqtt_outPubInterval_sensors)
  111. {
  112. outPubInterval_sensors_count = 0;
  113. publishCurrentSensorValues(true); // true forces publishing
  114. }
  115. else
  116. {
  117. outPubInterval_sensors_count++;
  118. publishCurrentSensorValues(false); // false publishes only changed values
  119. }
  120. }
  121. }