Example code - DallasTemperatureSensor.ino



  • below is copied from the example sketch.

    #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
    
    void loop()     
    {     
         // Fetch and round temperature to one decimal
        float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
     
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
        #endif
     
          // Send in the new temperature
          gw.send(msg.setSensor(i).set(temperature,1));
          // Save new temperatures for next compare
          lastTemperature[i]=temperature;
        }
      }
      gw.sleep(SLEEP_TIME);
    }
    
    

    If I have COMPARE_TEMP = 1 it will check if the new value is new and then send it to GW, if not new it will not send to GW.

    I want data even if the temperature is same so I have COMPARE_TEMP = 0.

    With my choose it will not test if the temperature is -127.00 or 85.00, this is something I want to do all the time even if I compare or not.



  • I think you just have to comment out that part of the code (the 5 lines of code)



  • I have done that in my sketch.

    But my request is that the example should always check for -127 and 85, even if the user want to compare old value with new



  • In the 2.0 sketch this is mentioned:

    #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
    So 0 should keep everything working and sens info even when not changed.


  • Mod

    As tlpeter mentioned, the MySensors 2.0 example checks for -127 and 85 even if COMPARE_TEMP is not set to 1. See https://github.com/mysensors/MySensorsArduinoExamples/blob/e31eb10311be071d376d55d0e23133b611a565ef/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino#L96



  • I am sorry, I have low knowledge of the # sign.

    I have read about it and @tlpeter is right.

    Can you confirm that my knowledge is correct.

    #if COMPARE_TEMP == 1
    if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
    #else
    if (temperature != -127.00 && temperature != 85.00) {
    #endif
    

    if I have COMPARE_TEMP = 1, this will be compiled

    if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
    

    otherwise this will be compiled

    if (temperature != -127.00 && temperature != 85.00) {
    

    Sorry once again 😶


  • Mod

    yes @flopp you got it right 🙂




Log in to reply
 

Suggested Topics

  • 90
  • 1
  • 4
  • 3
  • 2
  • 3

10
Online

11.4k
Users

11.1k
Topics

112.7k
Posts