Message logs not consistent

Hello Team,

I am encountering an issue with the message string on my serial monitor. It displays the message logs, but on the Arduino Cloud dashboard, the message appears only once and then no further messages are displayed. Below is the code I have used. Could you please assist me in resolving this problem?

bool alertSent = false; // Track whether the alert has been sent
unsigned long previousMillis = 0; // Store the last time the message was sent
const long interval = 2000; // Interval at which to send the message (2 seconds)
=======================
void onMsgChange() {
  Serial.println(msg); // Print the message log to the Serial Monitor
}
============

// Check if the temperature is between 27°C and 40°C
  if (temperatureValue_C >= 27 && temperatureValue_C <= 40) {
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;
      Serial.println("Temperature is between 27°C and 40°C!");
      msg = "Alert: Temperature is between 27°C and 40°C!";
      alertSent = true; // Set the alert sent flag to true
    }
  } else {
    if (alertSent) {
      Serial.println("Temperature is outside 27°C to 40°C range.");
      msg = ""; // Clear the message
      alertSent = false; // Reset the alert sent flag
    }
  }

  // Wait 2 seconds between readings
  delay(2000);
}


Best regards.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.