Bug in SenseBenderDefault sketch


  • Contest Winner

    I was wondering why my SenseBender kept reporting every minute, even though the temperature and humidity didn't change.

    It's a minor one. But in the sendTempHumidityMeasurements(bool force) method, the difference is determined by dividing with 100 and not 100.0 this causes a wrong rounding and always reports a difference higher than the treshhold. Resulting in a temperature report every minute. Even though the temperature hasn't changed much.

    corrected code.

    /*********************************************
     *
     * Sends temperature and humidity from Si7021 sensor
     *
     * Parameters
     * - force : Forces transmission of a value (even if it's the same as previous measurement)
     *
     *********************************************/
    void sendTempHumidityMeasurements(bool force)
    {
      bool tx = force;
      
      si7021_env data = humiditySensor.getHumidityAndTemperature();
      float oldAvgHum = raHum.getAverage();
      
      raHum.addValue(data.humidityPercent);
      
      float diffTemp = abs(lastTemperature - (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths)/100.0); // <-- fixed
      float diffHum = abs(oldAvgHum - raHum.getAverage());
    
      Serial.print(F("TempDiff :"));Serial.println(diffTemp);
      Serial.print(F("HumDiff  :"));Serial.println(diffHum); 
    
      if (isnan(diffHum)) tx = true; 
      if (diffTemp > TEMP_TRANSMIT_THRESHOLD) tx = true;
      if (diffHum >= HUMI_TRANSMIT_THRESHOLD) tx = true;
    
      if (tx) {
        measureCount = 0;
        float temperature = (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths) / 100.0;
         
        int humidity = data.humidityPercent;
        Serial.print("T: ");Serial.println(temperature);
        Serial.print("H: ");Serial.println(humidity);
        
        gw.send(msgTemp.set(temperature,1));
        gw.send(msgHum.set(humidity));
        lastTemperature = temperature;
        lastHumidity = humidity;
      }
    }
    

    ps. I'm sorry I don't have a github account.


  • Mod

    nice catch!


  • Contest Winner

    @mfalkvidd Thanx! It took my a while, but got it.


  • Contest Winner

    Also, do I compile the Sketch for 8Mhz or 1Mhz?


  • Admin


  • Mod

    @hek so the real problem is too long release cycles, and/or not enough backporting?


  • Admin

    Yes! 😧


  • Admin

    @TheoL

    the sensebender is runing on 8Mhz as default. Originally I made so that it could switch to 1Mhz in order to lower the current consumption. But since we are sleeping for 99% of the time, where it's only the watchdog timer that is running, I don't see that much of a power savings running at 1Mhz, compared to 8Mhz.

    In theory if running on 1Mhz the awaken time is also 8 times longer, than when it's running on 8Mhz.. So that can also contribute to a more "equal" power consumption.

    So in short.. Compile for 8Mhz πŸ™‚


Log in to reply
 

Suggested Topics

  • 33
  • 3
  • 5
  • 2
  • 17
  • 11

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts