scheduler.ino 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 (countDisplayInterval < confBas.displayInterval)
  52. countDisplayInterval++;
  53. else
  54. {
  55. countDisplayInterval = 0;
  56. updateDisplay();
  57. }
  58. if (doRestart)
  59. restart();
  60. if (configChangedMqttConnResetRequired && !confCheckUnsaved())
  61. {
  62. configChangedMqttConnResetRequired = false;
  63. mqttResetConnection();
  64. }
  65. if ((millis() - pendingRestart_lastMillis) > 3000)
  66. pendingRestart = false;
  67. // if ( preset != pendingPreset) {
  68. // if ( (millis() - pendingPreset_millis) > pendingPreset_timeout ) {
  69. // preset = pendingPreset;
  70. // }
  71. // }
  72. }
  73. unsigned int outPubInterval_states_count = 0;
  74. unsigned int outPubInterval_sensors_count = 0;
  75. void everyMinute()
  76. {
  77. #ifdef ENABLE_FEATURE_NTP_TIME
  78. if (confTime.ntpEnable)
  79. {
  80. syncClock();
  81. }
  82. #endif
  83. logSysdata();
  84. confChangedLogNote(true);
  85. if (confMqtt.mqtt_enable)
  86. {
  87. if (!confMqtt.mqtt_willRetain)
  88. mqttPublishConnectMsg();
  89. mqttPublishStatus();
  90. if (confMqtt.mqtt_enable_heartbeat)
  91. mqttPublishHeartbeat();
  92. if (confMqtt.mqtt_outPubInterval > 0 && outPubInterval_states_count >= confMqtt.mqtt_outPubInterval)
  93. {
  94. outPubInterval_states_count = 0;
  95. publishCurrentThermostatValues(true); // true forces publishing
  96. }
  97. else
  98. {
  99. outPubInterval_states_count++;
  100. publishCurrentThermostatValues(false); // false publishes only changed values
  101. }
  102. if (confMqtt.mqtt_outPubInterval_sensors > 0 && outPubInterval_sensors_count >= confMqtt.mqtt_outPubInterval_sensors)
  103. {
  104. outPubInterval_sensors_count = 0;
  105. publishCurrentSensorValues(true); // true forces publishing
  106. }
  107. else
  108. {
  109. outPubInterval_sensors_count++;
  110. publishCurrentSensorValues(false); // false publishes only changed values
  111. }
  112. }
  113. }