Unique ID-value DS18B20 Temperature sensors



  • Hi all,

    For a project (water supply line in a protective tube buried in the ground) I need to monitor the temperature during winter time. This tube has a lengt of 25 mtrs. in length and every 2 mtrs. i would like to install a DS18B20 sensor.
    Reading out the temperatures is simple using the sketch for the temperatur sensor, but what happens if one of the installed sensors dies in the future. I personally guess the array is updated once the sensor is being reset and my original info (which sensor at what position) is lost.

    Is it possible to fill an extra array with the Unique ID-value of the sensors at initialisation? Has anyone some experience with this or done it before?
    Any other suggestions are welcome as well of course!

    Thanks!

    BR,

    Boozz


  • Hardware Contributor

    There are several examples on the internet and I have cut and pasted my solution for a similar problem with 4 sensors (serial gateway with dallas sensors):

    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Set LOW transmit power level as default, if you have an amplified NRF-module and
    // power your radio separately with a good regulator you can turn up PA level.
    #define MY_RF24_PA_LEVEL RF24_PA_LOW
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
    #if F_CPU == 8000000L
    #define MY_BAUD_RATE 38400
    #endif
    
    // Flash leds on rx/tx/err
    #define MY_LEDS_BLINKING_FEATURE
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Inverses the behavior of leds
    //#define MY_WITH_LEDS_BLINKING_INVERSE
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    #define MY_INCLUSION_BUTTON_FEATURE
    
    // Inverses behavior of inclusion button (if using external pullup)
    //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
    
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    #define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED
    
    #include <SPI.h>
    #include <MySensors.h>
    
    // Dallas
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    DeviceAddress Probe01 = { 0x28, 0xFF, 0x2E, 0x3E, 0x66, 0x14, 0x01, 0xB2 };
    DeviceAddress Probe02 = { 0x28, 0xFF, 0xB9, 0x40, 0x66, 0x14, 0x01, 0xE9 };
    DeviceAddress Probe03 = { 0x28, 0xFF, 0x47, 0x64, 0x66, 0x14, 0x02, 0x71 };
    DeviceAddress Probe04 = { 0x28, 0xFF, 0x3F, 0x48, 0x66, 0x14, 0x01, 0xA2 };
    
    
    #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
    
    #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
    #define TEMPERATURE_PRECISION 12
    #define MAX_ATTACHED_DS18B20 16
    unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)
    OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
    DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors = 0;
    bool receivedConfig = false;
    bool metric = true;
    // Initialize temperature message
    MyMessage msg(0, V_TEMP);
    
    void before()
    {
      // Startup up the OneWire library
      sensors.begin();
    }
    
    void setup()
    {
      // requestTemperatures() will not block current thread
      sensors.setWaitForConversion(false);
    }
    
    void presentation() {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Temperature Sensor on Gateway Mega2560", "1.2");
    
      // Fetch the number of attached temperature sensors
      numSensors = sensors.getDeviceCount();
      //Serial.print("Numsensors ");
      //Serial.println(numSensors);
    
      // Present all sensors to controller
      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
        present(i, S_TEMP);
      }
    
      DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
    
      for (int i = 0; i < numSensors; i++)
      {
        // Search the wire for address
        if (sensors.getAddress(tempDeviceAddress, i))
        {
          Serial.print("Found device ");
          Serial.print(i, DEC);
          Serial.print(" with address: ");
          printAddress(tempDeviceAddress);
          Serial.println();
    
          Serial.print("Setting resolution to ");
          Serial.println(TEMPERATURE_PRECISION, DEC);
    
          // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
          sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);
    
          Serial.print("Resolution actually set to: ");
          Serial.print(sensors.getResolution(tempDeviceAddress), DEC);
          Serial.println();
        } else {
          Serial.print("Found ghost device at ");
          Serial.print(i, DEC);
          Serial.print(" but could not detect address. Check power and cabling");
        }
      }
    
    }
    
    void loop()
    {
      // Fetch temperatures from Dallas sensors
      //Serial.println("Readung Temperatures....");
      sensors.requestTemperatures();
    
      //Serial.println("Fetched");
    
      // query conversion time and sleep until conversion completed
      int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
      // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
      wait(conversionTime);
    
      // Read temperatures and send them to controller
      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
    
        float temperature;
    
        // Fetch and round temperature to one decimal
        switch (i)  {
          case 0:
            temperature = sensors.getTempC(Probe01);
            break;
          case 1:
            temperature = sensors.getTempC(Probe02);
            break;
          case 2:
            temperature = sensors.getTempC(Probe03);
            break;
          case 3:
            temperature = sensors.getTempC(Probe04);
            break;
          default:
            temperature = sensors.getTempCByIndex(Probe04);
            break;
        }
    
        //Serial.println(temperature);
        // 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
          send(msg.setSensor(i).set(temperature, 1));
          // Save new temperatures for next compare
          lastTemperature[i] = temperature;
        }
      }
      wait(SLEEP_TIME);
    }
    
    
    // function to print a device address
    void printAddress(DeviceAddress deviceAddress)
    {
      for (uint8_t i = 0; i < 8; i++)
      {
        if (deviceAddress[i] < 16) Serial.print("0");
        Serial.print(deviceAddress[i], HEX);
      }
    }
    

    With this I monitor my heat pump boiler.
    0_1473666670976_wp.JPG





  • @FotoFieber and @flopp

    Thank you both for pointing me in the right direction. As far as I can see from here this contains the solutions for my problem. I'm very happy with this info.

    👍

    BR,

    Boozz



  • I have been thinking about another solution for this. As present() supports an optional description, it should be possible to send the 1-wire address in the description. Then the controller can handle things and there's no need to hardcode anything in the sketch - it would also mean that there's no need to update the sketch if a 1-wire device gets replaced.


  • Admin

    The idea was to use V_ID for sensor identifiers when available, like on the DS18B20.

    https://www.mysensors.org/download/serial_api_20#set,-req



  • @hek said:

    The idea was to use V_ID for sensor identifiers when available, like on the DS18B20.

    Too bad this isn't supported for domoticz 😞

    "Error: MySensors: Unknown/Invalid sensor type (42)"

    • Jan


  • @chrille said:

    @hek said:

    The idea was to use V_ID for sensor identifiers when available, like on the DS18B20.

    Too bad this isn't supported for domoticz 😞

    "Error: MySensors: Unknown/Invalid sensor type (42)"

    • Jan

    I have not tried it my self but it should be possible to use. What version of Domoticz do you use?

    See here which type of identifier that is implemented, seems that it was implemented 18 oct 2015
    https://github.com/domoticz/domoticz/blob/master/hardware/MySensorsBase.cpp



  • @flopp said:

    I have not tried it my self but it should be possible to use. What version of Domoticz do you use?

    See here which type of identifier that is implemented, seems that it was implemented 18 oct 2015
    https://github.com/domoticz/domoticz/blob/master/hardware/MySensorsBase.cpp

    I'm using 3.5637 (quite recent beta)

    It would be interesting to hear if someone actually used the V_ID feature (with domoticz, or other controllers), that would share their sketch - just to see if I'm missing something obvious

    • Jan


  • I have now test V_ID, not working in Domoticz. I also get

    Error: MySensors: Unknown/Invalid sensor type (42)
    


  • @chrille
    What version of MySensors are you using?

    I am using 1.5.1





  • @flopp said:

    @chrille
    What version of MySensors are you using?

    I am using 1.5.1

    I am using 2.0.1

    • Jan



Log in to reply
 

Suggested Topics

  • 8
  • 44
  • 1
  • 2
  • 1
  • 3

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts