<SOLVED>Domoticz adds constantly new devices when using manual DeviceAddress for DS18B20



  • Hi,

    after two days testing and trying i give up. BUT i am a programming noob. So i am sure the error is in the code easy to spot for others.

    Situation:
    Arduino Pro Mini has fife DS18B20 sensors attached. Sending data via serial gateway to domoticz which runs on NanoPi (Raspberry compatible). When i use the mysensors temp sketch all works well without problems.
    But i can't use the "standard sketch" because the mysensors code is not assigning DeviceAdreses manually which i need for this project.

    So here is my code:

    #define MY_RADIO_NRF24
    #define MY_DEBUG
    #include <MySensors.h>
    #include <SPI.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    
    // Data wire is plugged into port 2 on the Arduino 
    #define ONE_WIRE_BUS 4 
    #define TEMPERATURE_PRECISION 10 
     
    // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) 
    OneWire oneWire(ONE_WIRE_BUS); 
    
    // Pass our oneWire reference to Dallas Temperature. 
    DallasTemperature sensors(&oneWire); 
    
    #define NODE_ID 1
    #define CHILD_ID_WIND 1
    #define CHILD_ID_TEMP 3
    
    unsigned int val_wspeed;
    unsigned int val_wgust;
    unsigned int val_wdirection;
    
    
    unsigned int last_wspeed;
    unsigned int last_wgust;
    unsigned int last_wdirection;
    
    DeviceAddress  temp1 = { 0x28, 0xEE, 0xB6, 0xB1, 0x27, 0x16, 0x01, 0x1F };
    DeviceAddress  temp2 = { 0x28, 0xEE, 0xE1, 0x20, 0x28, 0x16, 0x01, 0xEA };
    DeviceAddress  temp3 = { 0x28, 0xEE, 0x0D, 0xAA, 0x24, 0x16, 0x02, 0x8A };
    DeviceAddress  temp4 = { 0x28, 0xEE, 0x7D, 0xA8, 0x24, 0x16, 0x02, 0xE0 };
    DeviceAddress  temp5 = { 0x28, 0xFF, 0xF6, 0x8F, 0x62, 0x16, 0x03, 0x7F };
    
    
    MyMessage msgWSpeed(CHILD_ID_WIND, V_WIND);
    MyMessage msgWGust(CHILD_ID_WIND, V_GUST);
    MyMessage msgWDirection(CHILD_ID_WIND, V_DIRECTION);
    MyMessage msg(CHILD_ID_TEMP,V_TEMP);
    
    void setup(void) 
    {
      // start serial port
      Serial.begin(115200);
      Serial.println("Dallas Temperature IC Control Library Demo");
    
      // Start up the library
      sensors.begin();
    
      // report parasite power requirements
      Serial.print("Parasite power is: "); 
      if (sensors.isParasitePowerMode()) Serial.println("ON");
      else Serial.println("OFF");
    
      // set the resolution to 9 bit
      sensors.setResolution(temp1, TEMPERATURE_PRECISION);
      sensors.setResolution(temp2, TEMPERATURE_PRECISION);
      sensors.setResolution(temp3, TEMPERATURE_PRECISION);
      sensors.setResolution(temp4, TEMPERATURE_PRECISION);
      sensors.setResolution(temp5, TEMPERATURE_PRECISION);
    
    }
    
    void presentation()
    {
        present(CHILD_ID_WIND, S_WIND);
        present(CHILD_ID_TEMP, S_WIND);
    }
    
    void loop()
    {  
      // call sensors.requestTemperatures() to issue a global temperature 
      // request to all devices on the bus
      Serial.print("Requesting temperatures...");
      sensors.requestTemperatures();
      Serial.println("DONE");
    
      // print the device information
      float east = sensors.getTempC(temp1);
      Serial.print("East C: ");
      Serial.println(east);
      send(msg.setSensor(temp1).set(east,1));
    
      float north = sensors.getTempC(temp2);
      Serial.print("North  C: ");
      Serial.println(north);
      send(msg.setSensor(temp2).set(north,1));
    
      float west = sensors.getTempC(temp5);
      Serial.print("West  C: ");
      Serial.println(west);
      send(msg.setSensor(temp4).set(west,1));
    
      float south = sensors.getTempC(temp3);
      Serial.print("South C: ");
      Serial.println(south);
      send(msg.setSensor(temp5).set(south,1));
    
      float temp33 = sensors.getTempC(temp4);
      Serial.print("Test  C: ");
      Serial.println(temp33); 
      send(msg.setSensor(temp33).set(temp33,1)); 
      
      // calculating wind direction form temperature differences
        if (north > south && north > west && north > east ) {
        Serial.println("SOUTH");
        unsigned int val_wdirection = 180; 
           send(msgWDirection.set(val_wdirection));
           Serial.print("WD: ");
           Serial.println(val_wdirection);
        }
    
        if (east > north && east > west && east > south ) {
        Serial.println("WEST");
        unsigned int val_wdirection = 280; 
           send(msgWDirection.set(val_wdirection));
           Serial.print("WD: ");
           Serial.println(val_wdirection);
        }
    
         if (south > north && south > west && south > east ) {
        Serial.println("NORTH");
        unsigned int val_wdirection = 0; 
           send(msgWDirection.set(val_wdirection));
           Serial.print("WD: ");
           Serial.println(val_wdirection);
        }
    
        if (west > north && west > south && west > east ) {
        Serial.println("EAST");
        unsigned int val_wdirection = 90; 
           send(msgWDirection.set(val_wdirection));
           Serial.print("WD: ");
           Serial.println(val_wdirection);
        }
    	
    	//domoticz must see speed and gust so i give random numbers for testing
    	unsigned int val_wspeed = 17; 
        if(last_wspeed != val_wspeed)
        { 
           last_wspeed = val_wspeed;
           send(msgWSpeed.set(val_wspeed, 1));
           Serial.print("WS: ");
           Serial.println(val_wspeed);
        }
        
        unsigned int val_wgust = 5; 
        if(last_wgust != val_wgust)
        { 
           last_wgust = val_wgust;
           send(msgWGust.set(val_wgust, 1));
           Serial.print("WG: ");
           Serial.println(val_wgust);
        }
    
          delay (5000);
    }
    

    Problem:
    Domoticz adds more and more temp sensors in the Device List. Randomly i would say. Sometimes fife new devices within 10 minutes. Sometimes none for one hour.
    What is causing that?

    I get this compiling warning from Arduino IDE which i don't know how to solve. Is that the problem?

    C:\Users\ed\Documents\Arduino\Wind-Test\Wind-Test-incl-temp\Wind-Test-incl-temp.ino: In function 'void loop()':
    
    C:\Users\ed\Documents\Arduino\Wind-Test\Wind-Test-incl-temp\Wind-Test-incl-temp.ino:122:27: warning: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'uint8_t {aka unsigned char}' [-fpermissive]
    
       send(msg.setSensor(temp1).set(east,1));
    
                               ^
    
    In file included from C:\Users\ed\Documents\Arduino\libraries\MySensors/MySensors.h:333:0,
    
                     from C:\Users\ed\Documents\Arduino\Wind-Test\Wind-Test-incl-temp\Wind-Test-incl-temp.ino:3:
    
    C:\Users\ed\Documents\Arduino\libraries\MySensors/core/MyMessage.cpp:217:12: note: initializing argument 1 of 'MyMessage& MyMessage::setSensor(uint8_t)'
    
     MyMessage& MyMessage::setSensor(uint8_t _sensor)
    

    What i tried on hardware side:

    • Changed Arduino
    • Changed 4 out of 5 temp sensors
    • Changed Radio

    Here newly added temp-sensors for the last 20 minutes
    alt text

    Any ideas, hints or even solutions?
    15USD for solution. Totally worth it 🙂

    Cheers
    ED


  • Hero Member

    @edsteve said in Domoticz adds constantly new devices when using manual DeviceAddress for DS18B20:

    DeviceAddress temp1 = { 0x28, 0xEE, 0xB6, 0xB1, 0x27, 0x16, 0x01, 0x1F };

    You are using a type DeviceAdress type to indicate a sensor id.
    ie.

    send(msg.setSensor(temp1).set(east,1));
    

    The sensor number should be of a simple int (or uint8_t) type. I suggest to use CHILD_ID_TEMP + tempNo where tempNo is the number of the temp sensor..



  • I understand what you mean. Thanks for your answer.
    But i still have trouble to write your solution into code. If it's not too much work for you. Can you help me out?

    If that solves the problem. Please send me your paypal email.


  • Hero Member

    @edsteve It's no beauty... I have not compiled it so possibly a few syntax errors (and I may have switched some temperature numbers ;)). I like to be awarded with gratitude being a servant to this community... get yourself in the Hall of fame by making a donation to MySensors0_1491829760624_upload-b0b8361b-c269-4f84-8773-b51a788c265c

    #define MY_RADIO_NRF24
    #define MY_DEBUG
    #include <MySensors.h>
    #include <SPI.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    
    // Data wire is plugged into port 2 on the Arduino 
    #define ONE_WIRE_BUS 4 
    #define TEMPERATURE_PRECISION 10 
     
    // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) 
    OneWire oneWire(ONE_WIRE_BUS); 
    
    // Pass our oneWire reference to Dallas Temperature. 
    DallasTemperature sensors(&oneWire); 
    
    #define NODE_ID 1
    #define CHILD_ID_WIND 1
    #define CHILD_ID_TEMP1 3
    #define CHILD_ID_TEMP2 4
    #define CHILD_ID_TEMP3 5
    #define CHILD_ID_TEMP4 6
    #define CHILD_ID_TEMP5 7
    
    unsigned int val_wspeed;
    unsigned int val_wgust;
    unsigned int val_wdirection;
    
    
    unsigned int last_wspeed;
    unsigned int last_wgust;
    unsigned int last_wdirection;
    
    
    DeviceAddress  temp1 = { 0x28, 0xEE, 0xB6, 0xB1, 0x27, 0x16, 0x01, 0x1F };
    DeviceAddress  temp2 = { 0x28, 0xEE, 0xE1, 0x20, 0x28, 0x16, 0x01, 0xEA };
    DeviceAddress  temp3 = { 0x28, 0xEE, 0x0D, 0xAA, 0x24, 0x16, 0x02, 0x8A };
    DeviceAddress  temp4 = { 0x28, 0xEE, 0x7D, 0xA8, 0x24, 0x16, 0x02, 0xE0 };
    DeviceAddress  temp5 = { 0x28, 0xFF, 0xF6, 0x8F, 0x62, 0x16, 0x03, 0x7F };
    
    
    
    MyMessage msgWSpeed(CHILD_ID_WIND, V_WIND);
    MyMessage msgWGust(CHILD_ID_WIND, V_GUST);
    MyMessage msgWDirection(CHILD_ID_WIND, V_DIRECTION);
    MyMessage msg(0,V_TEMP);
    
    void setup(void) 
    {
      // start serial port
      Serial.begin(115200);
      Serial.println("Dallas Temperature IC Control Library Demo");
    
      // Start up the library
      sensors.begin();
    
      // report parasite power requirements
      Serial.print("Parasite power is: "); 
      if (sensors.isParasitePowerMode()) Serial.println("ON");
      else Serial.println("OFF");
    
      // set the resolution to 9 bit
      sensors.setResolution(temp1, TEMPERATURE_PRECISION);
      sensors.setResolution(temp2, TEMPERATURE_PRECISION);
      sensors.setResolution(temp3, TEMPERATURE_PRECISION);
      sensors.setResolution(temp4, TEMPERATURE_PRECISION);
      sensors.setResolution(temp5, TEMPERATURE_PRECISION);
    
    }
    
    void presentation()
    {
        present(CHILD_ID_WIND, S_WIND);
        present(CHILD_ID_TEMP1, S_TEMP);
        present(CHILD_ID_TEMP2, S_TEMP);
        present(CHILD_ID_TEMP3, S_TEMP);
        present(CHILD_ID_TEMP4, S_TEMP);
        present(CHILD_ID_TEMP5, S_TEMP);
    }
    
    void loop()
    {  
      // call sensors.requestTemperatures() to issue a global temperature 
      // request to all devices on the bus
      Serial.print("Requesting temperatures...");
      sensors.requestTemperatures();
      Serial.println("DONE");
    
      // print the device information
      float east = sensors.getTempC(temp1);
      Serial.print("East C: ");
      Serial.println(east);
      send(msg.setSensor(CHILD_ID_TEMP1).set(east,1));
    
      float north = sensors.getTempC(temp2);
      Serial.print("North  C: ");
      Serial.println(north);
      send(msg.setSensor(CHILD_ID_TEMP2).set(north,1));
    
      float west = sensors.getTempC(temp5);
      Serial.print("West  C: ");
      Serial.println(west);
      send(msg.setSensor(CHILD_ID_TEMP5).set(west,1));
    
      float south = sensors.getTempC(temp3);
      Serial.print("South C: ");
      Serial.println(south);
      send(msg.setSensor(CHILD_ID_TEMP3).set(south,1));
    
      float temp33 = sensors.getTempC(temp4);
      Serial.print("Test  C: ");
      Serial.println(temp33); 
      send(msg.setSensor(CHILD_ID_TEMP4).set(temp4,1)); 
      
      // calculating wind direction form temperature differences
        if (north > south && north > west && north > east ) {
        Serial.println("SOUTH");
        unsigned int val_wdirection = 180; 
           send(msgWDirection.set(val_wdirection));
           Serial.print("WD: ");
           Serial.println(val_wdirection);
        }
    
        if (east > north && east > west && east > south ) {
        Serial.println("WEST");
        unsigned int val_wdirection = 280; 
           send(msgWDirection.set(val_wdirection));
           Serial.print("WD: ");
           Serial.println(val_wdirection);
        }
    
         if (south > north && south > west && south > east ) {
        Serial.println("NORTH");
        unsigned int val_wdirection = 0; 
           send(msgWDirection.set(val_wdirection));
           Serial.print("WD: ");
           Serial.println(val_wdirection);
        }
    
        if (west > north && west > south && west > east ) {
        Serial.println("EAST");
        unsigned int val_wdirection = 90; 
           send(msgWDirection.set(val_wdirection));
           Serial.print("WD: ");
           Serial.println(val_wdirection);
        }
    	
    	//domoticz must see speed and gust so i give random numbers for testing
    	unsigned int val_wspeed = 17; 
        if(last_wspeed != val_wspeed)
        { 
           last_wspeed = val_wspeed;
           send(msgWSpeed.set(val_wspeed, 1));
           Serial.print("WS: ");
           Serial.println(val_wspeed);
        }
        
        unsigned int val_wgust = 5; 
        if(last_wgust != val_wgust)
        { 
           last_wgust = val_wgust;
           send(msgWGust.set(val_wgust, 1));
           Serial.print("WG: ");
           Serial.println(val_wgust);
        }
    
          sleep (5000);
    }
    


  • Yeahaa. Thanks so much. I really appreciate it!
    Some small changes with temp4 and works like a charm. If you don't accept my offer. Then the transfer goes to mysensors community 🙂

    Here the working code IF someone need it or i loose mine 😉

    #define MY_RADIO_NRF24
    #define MY_DEBUG
    #include <MySensors.h>
    #include <SPI.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    
    // Data wire is plugged into port 2 on the Arduino 
    #define ONE_WIRE_BUS 4 
    #define TEMPERATURE_PRECISION 10 
     
    // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) 
    OneWire oneWire(ONE_WIRE_BUS); 
    
    // Pass our oneWire reference to Dallas Temperature. 
    DallasTemperature sensors(&oneWire); 
    
    #define NODE_ID 1
    #define CHILD_ID_WIND 1
    #define CHILD_ID_TEMP1 3
    #define CHILD_ID_TEMP2 4
    #define CHILD_ID_TEMP3 5
    #define CHILD_ID_TEMP4 6
    #define CHILD_ID_TEMP5 7
    
    unsigned int val_wspeed;
    unsigned int val_wgust;
    unsigned int val_wdirection;
    
    
    unsigned int last_wspeed;
    unsigned int last_wgust;
    unsigned int last_wdirection;
    
    
    DeviceAddress  temp1 = { 0x28, 0xEE, 0xB6, 0xB1, 0x27, 0x16, 0x01, 0x1F };
    DeviceAddress  temp2 = { 0x28, 0xEE, 0xE1, 0x20, 0x28, 0x16, 0x01, 0xEA };
    DeviceAddress  temp3 = { 0x28, 0xEE, 0x0D, 0xAA, 0x24, 0x16, 0x02, 0x8A };
    DeviceAddress  temp4 = { 0x28, 0xEE, 0x7D, 0xA8, 0x24, 0x16, 0x02, 0xE0 };
    DeviceAddress  temp5 = { 0x28, 0xFF, 0xF6, 0x8F, 0x62, 0x16, 0x03, 0x7F };
    
    
    
    MyMessage msgWSpeed(CHILD_ID_WIND, V_WIND);
    MyMessage msgWGust(CHILD_ID_WIND, V_GUST);
    MyMessage msgWDirection(CHILD_ID_WIND, V_DIRECTION);
    MyMessage msg(0,V_TEMP);
    
    void setup(void) 
    {
      // start serial port
      Serial.begin(115200);
      Serial.println("Dallas Temperature IC Control Library Demo");
    
      // Start up the library
      sensors.begin();
    
      // report parasite power requirements
      Serial.print("Parasite power is: "); 
      if (sensors.isParasitePowerMode()) Serial.println("ON");
      else Serial.println("OFF");
    
      // set the resolution to 9 bit
      sensors.setResolution(temp1, TEMPERATURE_PRECISION);
      sensors.setResolution(temp2, TEMPERATURE_PRECISION);
      sensors.setResolution(temp3, TEMPERATURE_PRECISION);
      sensors.setResolution(temp4, TEMPERATURE_PRECISION);
      sensors.setResolution(temp5, TEMPERATURE_PRECISION);
    
    }
    
    void presentation()
    {
        present(CHILD_ID_WIND, S_WIND);
        present(CHILD_ID_TEMP1, S_TEMP);
        present(CHILD_ID_TEMP2, S_TEMP);
        present(CHILD_ID_TEMP3, S_TEMP);
        present(CHILD_ID_TEMP4, S_TEMP);
        present(CHILD_ID_TEMP5, S_TEMP);
    }
    
    void loop()
    {  
      // call sensors.requestTemperatures() to issue a global temperature 
      // request to all devices on the bus
      Serial.print("Requesting temperatures...");
      sensors.requestTemperatures();
      Serial.println("DONE");
    
      // print the device information
      float east = sensors.getTempC(temp1);
      Serial.print("East C: ");
      Serial.println(east);
      send(msg.setSensor(CHILD_ID_TEMP1).set(east,1));
    
      float north = sensors.getTempC(temp2);
      Serial.print("North  C: ");
      Serial.println(north);
      send(msg.setSensor(CHILD_ID_TEMP2).set(north,1));
    
      float west = sensors.getTempC(temp5);
      Serial.print("West  C: ");
      Serial.println(west);
      send(msg.setSensor(CHILD_ID_TEMP5).set(west,1));
    
      float south = sensors.getTempC(temp3);
      Serial.print("South C: ");
      Serial.println(south);
      send(msg.setSensor(CHILD_ID_TEMP3).set(south,1));
    
      float out = sensors.getTempC(temp4);
      Serial.print("Test  C: ");
      Serial.println(out); 
      send(msg.setSensor(CHILD_ID_TEMP4).set(out,1)); 
      
      // calculating wind direction form temperature differences
        if (north > south && north > west && north > east ) {
        Serial.println("SOUTH");
        unsigned int val_wdirection = 180; 
           send(msgWDirection.set(val_wdirection));
           Serial.print("WD: ");
           Serial.println(val_wdirection);
        }
    
        if (east > north && east > west && east > south ) {
        Serial.println("WEST");
        unsigned int val_wdirection = 280; 
           send(msgWDirection.set(val_wdirection));
           Serial.print("WD: ");
           Serial.println(val_wdirection);
        }
    
         if (south > north && south > west && south > east ) {
        Serial.println("NORTH");
        unsigned int val_wdirection = 0; 
           send(msgWDirection.set(val_wdirection));
           Serial.print("WD: ");
           Serial.println(val_wdirection);
        }
    
        if (west > north && west > south && west > east ) {
        Serial.println("EAST");
        unsigned int val_wdirection = 90; 
           send(msgWDirection.set(val_wdirection));
           Serial.print("WD: ");
           Serial.println(val_wdirection);
        }
      
      //domoticz must see speed and gust so i give random numbers for testing
      unsigned int val_wspeed = 17; 
        if(last_wspeed != val_wspeed)
        { 
           last_wspeed = val_wspeed;
           send(msgWSpeed.set(val_wspeed, 1));
           Serial.print("WS: ");
           Serial.println(val_wspeed);
        }
        
        unsigned int val_wgust = 5; 
        if(last_wgust != val_wgust)
        { 
           last_wgust = val_wgust;
           send(msgWGust.set(val_wgust, 1));
           Serial.print("WG: ");
           Serial.println(val_wgust);
        }
    
          delay (5000);
    }
    

Log in to reply
 

278
Online

6.7k
Users

7.6k
Topics

80.4k
Posts

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.