scheduler.ino 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. if(sysInfoEverySecond) logSysdata();
  30. #ifdef ENABLE_FEATURE_WEB_CONSOLE_WEBSOCKETS
  31. clearValidSessionId();
  32. #endif
  33. if (countMeasureInterval < confBas.measureInterval) countMeasureInterval++;
  34. else {
  35. countMeasureInterval = 0;
  36. measureTempHum();
  37. thermostat();
  38. }
  39. if (countDisplayInterval < confBas.displayInterval) countDisplayInterval++;
  40. else {
  41. countDisplayInterval = 0;
  42. updateDisplay();
  43. }
  44. if (doRestart) restart();
  45. if ( (millis() - pendingRestart_lastMillis) > 3000 ) pendingRestart = false;
  46. // if ( preset != pendingPreset) {
  47. // if ( (millis() - pendingPreset_millis) > pendingPreset_timeout ) {
  48. // preset = pendingPreset;
  49. // }
  50. // }
  51. }
  52. unsigned int outPubInterval_states_count = 0;
  53. unsigned int outPubInterval_sensors_count = 0;
  54. void everyMinute() {
  55. #ifdef ENABLE_FEATURE_NTP_TIME
  56. if(confTime.ntpEnable) {
  57. syncClock();
  58. }
  59. #endif
  60. logSysdata();
  61. if(confMqtt.mqtt_enable) {
  62. if(!confMqtt.mqtt_willRetain) mqttPublishConnectMsg();
  63. mqttPublishStatus();
  64. if(confMqtt.mqtt_enable_heartbeat) mqttPublishHeartbeat();
  65. if(confMqtt.mqtt_outPubInterval > 0 && outPubInterval_states_count >= confMqtt.mqtt_outPubInterval) {
  66. outPubInterval_states_count = 0;
  67. publishCurrentThermostatValues(true); // true forces publishing
  68. }
  69. else {
  70. outPubInterval_states_count++;
  71. publishCurrentThermostatValues(false); // false publishes only changed values
  72. }
  73. if(confMqtt.mqtt_outPubInterval_sensors > 0 && outPubInterval_sensors_count >= confMqtt.mqtt_outPubInterval_sensors) {
  74. outPubInterval_sensors_count = 0;
  75. publishCurrentSensorValues(true); // true forces publishing
  76. }
  77. else {
  78. outPubInterval_sensors_count++;
  79. publishCurrentSensorValues(false); // false publishes only changed values
  80. }
  81. }
  82. }