Skip to main content
added 32 characters in body
Source Link
chrisl
  • 16.6k
  • 2
  • 18
  • 27
  1. Although not strictly required, maybe use parentheses around millis() - sendDataPrevMillis for readability;
  2. I guess you will have initialised sendDataPrevMillis to 0 but the first time you assign sendDataPrevMillis to millis() some time will have elapsed since you evaluated. So calling millis() twice will give different results. That makes it less easy to see what is going on.

Suggestion to try:

long HALFHOUR = 30 * 60 * 1000L;

if ( (millis() % HALFHOUR ) == 0L ) {

measure and send ....

}

long HALFHOUR = 30 * 60 * 1000L;

if ( (millis() % HALFHOUR ) == 0L ) {
    //measure and send
    //....
}

Hope this helps.

NB: % is what is called the 'modulo operator' see: https://www.geeksforgeeks.org/modulo-operator-in-c-cpp-with-examples/

  1. Although not strictly required, maybe use parentheses around millis() - sendDataPrevMillis for readability;
  2. I guess you will have initialised sendDataPrevMillis to 0 but the first time you assign sendDataPrevMillis to millis() some time will have elapsed since you evaluated. So calling millis() twice will give different results. That makes it less easy to see what is going on.

Suggestion to try:

long HALFHOUR = 30 * 60 * 1000L;

if ( (millis() % HALFHOUR ) == 0L ) {

measure and send ....

}

Hope this helps.

NB: % is what is called the 'modulo operator' see: https://www.geeksforgeeks.org/modulo-operator-in-c-cpp-with-examples/

  1. Although not strictly required, maybe use parentheses around millis() - sendDataPrevMillis for readability;
  2. I guess you will have initialised sendDataPrevMillis to 0 but the first time you assign sendDataPrevMillis to millis() some time will have elapsed since you evaluated. So calling millis() twice will give different results. That makes it less easy to see what is going on.

Suggestion to try:

long HALFHOUR = 30 * 60 * 1000L;

if ( (millis() % HALFHOUR ) == 0L ) {
    //measure and send
    //....
}

Hope this helps.

NB: % is what is called the 'modulo operator' see: https://www.geeksforgeeks.org/modulo-operator-in-c-cpp-with-examples/

Source Link

  1. Although not strictly required, maybe use parentheses around millis() - sendDataPrevMillis for readability;
  2. I guess you will have initialised sendDataPrevMillis to 0 but the first time you assign sendDataPrevMillis to millis() some time will have elapsed since you evaluated. So calling millis() twice will give different results. That makes it less easy to see what is going on.

Suggestion to try:

long HALFHOUR = 30 * 60 * 1000L;

if ( (millis() % HALFHOUR ) == 0L ) {

measure and send ....

}

Hope this helps.

NB: % is what is called the 'modulo operator' see: https://www.geeksforgeeks.org/modulo-operator-in-c-cpp-with-examples/