💬 Temperature Sensor


  • Mod

    @Patrik-Söderström according to http://www.esp8266.com/viewtopic.php?f=12&t=9430 you need a newer version of the onewire library.



  • Can anyone tell me what these errors say?

    DallasTemperature.cpp:433: error: no 'int16_t DallasTemperature::calculateTemperature(const uint8_t*, uint8_t*)' member function declared in class 'DallasTemperature'
    int16_t DallasTemperature::calculateTemperature(const uint8_t* deviceAddress, uint8_t* scratchPad){

                                                                                                  ^
    

    sketch/DallasTemperature.cpp: In member function 'int16_t DallasTemperature::getTemp(const uint8_t*)':
    DallasTemperature.cpp:484: error: 'calculateTemperature' was not declared in this scope
    if (isConnected(deviceAddress, scratchPad)) return calculateTemperature(deviceAddress, scratchPad);

                                                                                                      ^
    

    sketch/DallasTemperature.cpp: In member function 'bool DallasTemperature::hasAlarm(const uint8_t*)':
    DallasTemperature.cpp:764: error: 'calculateTemperature' was not declared in this scope
    char temp = calculateTemperature(deviceAddress, scratchPad) >> 7;

                                                                   ^
    

    exit status 1
    no 'int16_t DallasTemperature::calculateTemperature(const uint8_t*, uint8_t*)' member function declared in class 'DallasTemperature'



  • @remis

    I confirm that i can suppress the compilation error but nothing append on serial port...

    Could somebody write here the typical serial port output with debug available?

    This example is not working. What is the good solution to use this temperature sensor ?

    thanks



  • Why don't we use an internal pull-up resistor available within an arduino board? Why additional external one?

    pinMode(pin, INPUT); // set pin to input
    digitalWrite(pin, HIGH); // turn on pullup resistors


  • Mod

    @Alex-B-Goode the datasheet says "The 1-Wire bus requires an external pullup resistor of approximately 5kΩ"
    The internal pull-up of most Arduinos are 20-50kΩ

    So my guess is that the reason is that the person who created the instructions read the datasheet and chose to follow its recommendation. But accounding to http://electronics.stackexchange.com/a/62096/107155 the exact size might not be important, so it might be possible to use the internal pull up. Try it and let us know if it works.



  • Does this example compile for anyone??? I get this error:

    In file included from /Users/Documents/Arduino/tas_temp/tas_temp.ino:37:0:
    /Users/Documents/Arduino/libraries/DallasTemperature/DallasTemperature.h: In function 'void loop()':
    /Users/Documents/Arduino/libraries/DallasTemperature/DallasTemperature.h:252:13: error: 'int16_t DallasTemperature::millisToWaitForConversion(uint8_t)' is private
    int16_t millisToWaitForConversion(uint8_t);

             ^
    

    tas_temp:85: error: within this context
    int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
    ^
    exit status 1
    within this context


  • Mod

    @toddsantoro see post 2 and 3 in this thread or read the instructions on the build page, just under the "Example" heading.



  • @mfalkvidd said:

    @toddsantoro see post 2 and 3 in this thread or read the instructions on the build page, just under the "Example" heading.

    ^ What he said 😁



  • @mfalkvidd OK. I have it compiling and uploaded to the nano. My config file looks like this now:

    sensor 6:
      -platform: onewire
        names:
          some_id: outside
          mount_dir: "/mnt/1wire"
    

    I get an error when I restart HASS on the Pi.

    ERROR (Thread-6) [homeassistant.components.sensor.onewire] No onewire sensor found. Check if dtoverlay=w1-gpio is in your /boot/config.txt. Check the mount_dir parameter if it's defined.
    

    I guess my question is do I need to define the mount_dir variable and if so is the one I have correct? And if it is correct do I need to create that directory on my Pi?

    I also do not get any output in the Arduino Serial Monitor window. Not sure if I even should...

    Thanks in advance for any help...


  • Mod

    @toddsantoro I am not familiar with homeassistant so I have no clue unfortunately.

    About debug output on the serial monitor: Debug needs to be enabled first. See instructions at https://forum.mysensors.org/topic/666/debug-faq-and-how-ask-for-help and https://www.mysensors.org/build/debug

    Debug output is often essential when troubleshooting.



  • @mfalkvidd Thank you!!! I get this output in the serial monitor

    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=2)
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-2 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=2)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 2-2-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:READ 0-0-2 s=255,c=3,t=25,pt=1,l=1,sg=0:1
    TSP:MSG:PONG RECV (hops=1)
    TSP:CHKUPL:OK
    TSM:UPL:OK
    TSM:READY
    TSP:MSG:SEND 2-2-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
    TSP:MSG:SEND 2-2-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=ok:2.0.0
    TSP:MSG:SEND 2-2-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=ok:0
    TSP:MSG:READ 0-0-2 s=255,c=3,t=6,pt=0,l=1,sg=0:I
    TSP:MSG:SEND 2-2-0-0 s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=ok:Temperature Sensor
    TSP:MSG:SEND 2-2-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:1.1
    Request registration...
    TSP:MSG:SEND 2-2-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
    TSP:MSG:READ 0-0-2 s=255,c=3,t=27,pt=1,l=1,sg=0:1
    Node registration=1
    Init complete, id=2, parent=0, distance=1, registration=1
    

    Does this look OK? If so I will ask my previous question on the Home Assistant forum. You have been a great help and once I get one of these things down I will be able to help others:)


  • Mod

    @toddsantoro yes that looks good.

    The "st=ok:xyz" means message xyz was acknowledged by the destination node (in your case by the gateway)



  • No compile error but i cant see anything on the serial monitor. also the temp sensor burend out with a 4k7 resistor :S



  • @stingone
    Hi. The same issue for me . I solve it with : 38400 bauds configuration serial port ( instead of 115200 default value)
    and i lowering the RF power output with low_pa enable: it confirms that I have some issues with power suppply.

    good luck



  • It seems the DallasTempereture library is not a part of the default Library setup from Mysensors as of version 2.0? I tried to compile the above code, but I had to manually download DallasTemperature from GitHub first. Then OneWire was also missing. Adding these two libraries brought me a bit further, but I get a long list of errors connected to OneWire. What libraries should be used?


  • Mod

    @bentrik the library is part of the MySensorsArduinoExamples, which can be downloaded at https://github.com/mysensors/MySensorsArduinoExamples/archive/master.zip



  • Hi All, i'm also new here and into this. Like others i also ran into problems compiling this sketch, i tried al libraries mentioned in the posts in this thread, but no go. keep getting this error message:

    In file included from C:\Users\Gebruiker\Desktop\My Sensors\MySensors-master\MySensorsArduinoExamples-master\examples\DallasTemperatureSensor\DallasTemperatureSensor.ino:37:0:

    C:\Users\Gebruiker\Documents\Arduino\libraries\DallasTemperature/DallasTemperature.h: In function 'void loop()':

    C:\Users\Gebruiker\Documents\Arduino\libraries\DallasTemperature/DallasTemperature.h:252:13: error: 'int16_t DallasTemperature::millisToWaitForConversion(uint8_t)' is private

     int16_t millisToWaitForConversion(uint8_t);
             ^
    

    DallasTemperatureSensor:85: error: within this context

    int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());

          exit status 1
    

    within this context

    Can someone help me with this problem? i have no clue at all and woud really like to build me a working sensor so i can hook it up to my Domoticz setup. thanks

    hin this context



  • @Sealander

    see solution above. Delete your dallas library and replace with the one above in the master zip file. That was the solution for me.



  • @mfalkvidd Thanks for the feedback, It got me a bit further.
    I have a fresh Windows Arduino 1.6.12 install, and I have download the MySensors Library 2.0 through the Library manager, and I've found MySensors.h and MyConfig.h under \Documents\Arduino\libraries\MySensors

    I'm able to compile and upload the RelayActuator but quite a few of the library files seem to be missing in 2.0. DallasTemperature seem to be one of them.-But I struggled with DallasTemperature and some others.

    I copied all the whole MySensors-1.5.4.zip library files to to C:\Program Files (x86)\Arduino\libraries, and I managed to compile, but I got an error message saying Invalid version found: 1.04
    Then I tried to only copy the DallasTemperature and OneWire folder, and I had no errors.

    -So I assume all library files the entire MySensors Examples catalouge are not ready in Libraries 2.0.

    Anyways: The solution to get this sensor to work with Arduino 1.6.12, following the Download and API guide, adding MySensors 2.0 through the Library Manager, is to manually add:
    \Arduino\libraries\DallasTemperature
    \Arduino\libraries\OneWire\

    -from https://github.com/mysensors/MySensorsArduinoExamples/archive/master.zip
    -And not adding the whole structure.

    Now I just have to find out how to make it speak to my serial gateway 😆



  • I get the feeling it is possible to use more then one sensor parallel on port 3. I wonder if each sensor is being monitored? Am I right and do I need to alter or change something?



  • my feeling was right.... i just connected 5 temp censors it is working great



  • I am getting the error:

    DallasTemperatureSensor.ino: In function 'void loop()':
    DallasTemperatureSensor:93: error: 'getConfig' was not declared in this scope
         float temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
    

    Does anyone have any suggestions?


  • Mod



  • @mfalkvidd That worked. Thanks.



  • Hello,
    I'm a beginner in home automation and I'm trying MySensor for the first time. My acctual configaration is a Domoticz on a Raspberry Pi 2B and a RFLink GW with a NRF24L01 module to try to measure with a MySensor probe.
    I've building a temperature sensor with a DS18B20 sensor on a Official Arduino nano board and I can not run the sensor correctly.
    The arduino serial monitor show these:

    0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1
    3 TSM:INIT
    4 TSF:WUR:MS=0
    11 TSM:INIT:TSP OK
    12 TSM:FPAR
    15 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2022 !TSM:FPAR:NO REPLY
    2024 TSM:FPAR
    2026 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    4034 !TSM:FPAR:NO REPLY
    4036 TSM:FPAR
    4038 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    6046 !TSM:FPAR:NO REPLY
    6048 TSM:FPAR
    6050 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    8058 !TSM:FPAR:FAIL
    8059 TSM:FAIL:CNT=1
    8061 TSM:FAIL:PDT

    Someone could help me?


  • Mod

    Did you set node ID?



  • Where should I put it? In arduino sensor code?


  • Mod

    Yes, it's like #define MY_NODE_ID 2 and put it at beginning of the code



  • Ok , with Node ID, I have this:

    0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1
    3 MCO:BGN:BFR
    63 TSM:INIT
    64 TSF:WUR:MS=0
    71 TSM:INIT:TSP OK
    73 TSM:INIT:STATID=2
    75 TSF:SID:OK,ID=2
    76 TSM:FPAR
    113 TSF:MSG:SEND,2-2-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2120 !TSM:FPAR:NO REPLY
    2122 TSM:FPAR
    2158 TSF:MSG:SEND,2-2-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    4166 !TSM:FPAR:NO REPLY
    4168 TSM:FPAR
    4204 TSF:MSG:SEND,2-2-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    6212 !TSM:FPAR:NO REPLY
    6214 TSM:FPAR
    6250 TSF:MSG:SEND,2-2-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    8258 !TSM:FPAR:FAIL
    8259 TSM:FAIL:CNT=1


  • Mod

    ok, but we are going off topic since now your problem seems to be the radios can't talk to each other, so if you take a look in troubleshooting section you will see others having this error that usually if bad wiring, missing capacitor on vcc of the nrf24, range/interference problem. How far are the 2 radio modules? Try putting them 2-3 meters apart.



  • Thanks, my radio modules are very close, they are on the same table for test. On of them may be damaged, I must receive others. I'm going in the troubleshooting section to avoid polluting this article.
    Thanks for your help


  • Mod

    Put them at least 2 meters apart, just to play safe.



  • It's the same, I've even reversed the radio modules



  • @gohan , I'm in the same situation as @Vincent-Lgrd. I'm powering my arduino UNO from usb (to test). Is that a possible problem?


  • Mod

    I use USB pretty much all the time and never had any issue. I had many problems in the beginning with radio modules that had the black blob instead of the ic and once I got the new ones everything started to work. I'm still working on increasing the range, probably because they are clones and not good quality.



  • @gohan I changed my getaway to an old good rpi model b, and the temperature node started to work, so I think that the problem was on de getaway wiring or in the getaway code itsef. Thanks



  • Is it also possible to upload the example code to a Arduino Nano, and connect it via USB to a Windows PC with Domoticz?

    Or will it only work with the radio modules (and extra gateway?)


  • Mod

    I think you can use the serial gateway sketch and the sensor code in setup and loop



  • Thank you for posting this project!

    Could like to suggest a small change to the sketch. There are several posts out there about this not running with the latest DallasTemperature library. The call to sensors.millisToWaitForConversion won't compile because the method is not public. From another post I learned that this method is very simple and could be included in the sketch. I would suggest changing the line

    int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());

    to read

    int16_t conversionTime = millisToWaitForConversion(sensors.getResolution());

    and add this function to the sketch:

    int16_t millisToWaitForConversion(uint8_t bitResolution)
    {
    switch (bitResolution)
    {
    case 9:
    return 94;
    case 10:
    return 188;
    case 11:
    return 375;
    default:
    return 750;
    }
    }

    In any case, this might help the next person using this project.



  • I had some problems with Domoticz triggering an event based on a certain temperature. When using multiple DS18B20 it is a good idea to use the ID of the sensors to always get the same order of sensors. If one is not read, for example B of A, B, C then C becomes B. See: https://forum.mysensors.org/topic/4143/about-ds18b20-onewire for more info. You maybe need to adjust the sketch a bit for your number of sensors.



  • @CurtisMack

    could you explain how to solve this ?
    I'm no pro, and wanted to use 1 single DS1820 in a sketch and also got same message about :
    int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());

    Mysensors is hard hard nut to learn, specially because of a lot of changes in the newer version 2.1.0 ...(and im still learning to work with arduino software , i keep running often against old sketches i like to try as sample to use them in other sketches , (my way of learning) but than they dont work with latest version. because something changed.
    but i love the mysensors functions.

    p.s sorry for my bad english....





  • I sofar got the sketch running and giving good data on serial and into domoticz

    i only could use some help with how to sent my Temperature in Celsius to domoticz to
    i tried to use:
    send(msgTemp.set(insideThermometer ,2));
    and
    send(msgTemp.set(tempC,2));

    both without luck, the first did transmit some data but wrong numbers
    second did nothing think because with this i done i does not know what address the DS1820 is on.

    Im learning every day something new....

    Maybe someone could help,



  • forgot the sketch

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <BH1750.h>
    #include <Wire.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    
    // Data wire is plugged into port 3 on the Arduino
    #define ONE_WIRE_BUS 3
    
    // 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);
    
    // arrays to hold device address
    DeviceAddress insideThermometer;
    
    
    unsigned long SLEEP_TIME = 180000; // Sleep time between reads (in milliseconds)
    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
    int SOLAR_SENSE_PIN = A1;  // select the input pin for the solar sense point
    #define CHILD_ID_BATTERY 4
    #define CHILD_ID_SOLAR 6
    #define CHILD_ID_LIGHT 1
    #define CHILD_ID_TEMP1 2
    
    BH1750 lightSensor;
    
    int oldBatteryPcnt = 0;
    MyMessage msgTemp(CHILD_ID_TEMP1,V_TEMP);
    MyMessage msgbatt(CHILD_ID_BATTERY, V_VOLTAGE);
    MyMessage msgsolar(CHILD_ID_SOLAR, V_VOLTAGE);
    MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    uint16_t lastlux;  //lux
    
    void setup(void)
    {
    // use the 1.1 V internal reference
      #if defined(__AVR_ATmega2560__)
      analogReference(INTERNAL1V1);
      #else
      analogReference(INTERNAL);
      #endif
    
      
    // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Battery Meter", "2.0");
      present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
     
      //Serial.begin(9600); // start serial port
      Serial.print("Locating devices..."); // locate devices on the bus
      sensors.begin(); // start reading sensor
      Serial.print("Found ");
      Serial.print(sensors.getDeviceCount(), DEC);
      Serial.println(" devices.");
      Serial.print("Parasite power is: "); // report parasite power requirements
      
      if (sensors.isParasitePowerMode()) Serial.println("ON");
      else Serial.println("OFF"); 
    // assign address manually.  the addresses below will beed to be changed
      // to valid device addresses on your bus.  device address can be retrieved
      // by using either oneWire.search(deviceAddress) or individually via
      // sensors.getAddress(deviceAddress, index)
      //insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
    
      // Method 1:
      // search for devices on the bus and assign based on an index.  ideally,
      // you would do this to initially discover addresses on the bus and then 
      // use those addresses and manually assign them (see above) once you know 
      // the devices on your bus (and assuming they don't change).
      if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
      
      // method 2: search()
      // search() looks for the next device. Returns 1 if a new address has been
      // returned. A zero might mean that the bus is shorted, there are no devices, 
      // or you have already retrieved all of them.  It might be a good idea to 
      // check the CRC to make sure you didn't get garbage.  The order is 
      // deterministic. You will always get the same devices in the same order
      //
      // Must be called before search()
      //oneWire.reset_search();
      // assigns the first address found to insideThermometer
      //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");
    
      // show the addresses we found on the bus
      Serial.print("Device 0 Address: ");
      printAddress(insideThermometer);
      Serial.println();
    
      // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
      sensors.setResolution(insideThermometer, 9);
     
      Serial.print("Device 0 Resolution: ");
      Serial.print(sensors.getResolution(insideThermometer), DEC); 
      Serial.println();  
    }
    
    // function to print the temperature for a device
    void printTemperature(DeviceAddress deviceAddress)
    {
      // method 1 - slower
      //Serial.print("Temp C: ");
      //Serial.print(sensors.getTempC(deviceAddress));
      //Serial.print(" Temp F: ");
      //Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit
    
      // method 2 - faster
      float tempC = sensors.getTempC(deviceAddress);
      Serial.print("Temp C: ");
      Serial.print(tempC);
      Serial.print(" Temp F: ");
      Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit
    }
    
    
    
    void loop(void)
    {
      // call sensors.requestTemperatures() to issue a global temperature 
      // request to all devices on the bus
      Serial.print("Requesting temperatures...");
      sensors.requestTemperatures(); // Send the command to get temperatures
      Serial.println("DONE");
      
      
      // It responds almost immediately. Let's print out the data
      printTemperature(insideThermometer); // Use a simple function to print out the data
    {
    
     // get the battery Voltage
      int sensorValue2 = analogRead(BATTERY_SENSE_PIN);
      delay(1000);   
      
      int sensorValue1 = analogRead(BATTERY_SENSE_PIN);
      delay(100);
      
      int sensorValue = analogRead(BATTERY_SENSE_PIN);
      delay(1000);
        
      int sensorValueS = analogRead(SOLAR_SENSE_PIN);
      delay(1000);
     
    #ifdef MY_DEBUG
      Serial.print("Battery Voltage2: ");
      Serial.println(sensorValue2);
      Serial.print("Battery Voltage1: ");
      Serial.println(sensorValue1);
      Serial.print("Battery Voltage: ");
      Serial.println(sensorValue);
      Serial.print("Solar Voltage: ");
      Serial.println(sensorValueS);
    #endif
    
      // 1M, 470K divider across battery and using internal ADC ref of 1.1V
      // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
      // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
      // 3.44/1023 = Volts per bit = 0.003363075
      const float vRef = 4.200/ 1.05/ 1023 ;  
      int batteryPcnt = sensorValue / 10;
      float batteryV  = sensorValue * 0.0042598 ; // 0.0038952294568380753114792412093 max 4,2 volt
      float batteryS  = sensorValueS * 0.0102459 ; // 0.0038952294568380753114792412093 max 10 volt
      
    #ifdef MY_DEBUG
      Serial.print("Battery Voltage: ");
      Serial.print(batteryV);
      Serial.println(" V");
    send(msgbatt.set(batteryV ,2));
    
      Serial.print("Solar Voltage: ");
      Serial.print(batteryS);
      Serial.println(" V");
    send(msgsolar.set(batteryS ,2));
    
      Serial.print("Battery percent: ");
      Serial.print(batteryPcnt);
      Serial.println(" %");
    #endif
    
       if (oldBatteryPcnt != batteryPcnt) {
        // Power up radio after sleep
        sendBatteryLevel(batteryPcnt);
        oldBatteryPcnt = batteryPcnt;
      }
          
      uint16_t lux = lightSensor.readLightLevel();// Get Lux value
      Serial.println(lux);
      if (lux != lastlux) {
          send(msg.set(lux));
          lastlux = lux;
      }
      sleep(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);
      }
    }
      
    
    
    
    


  • @Rene046 Your sketch doesn't show either of the send commands you say you are attempting. This makes it difficult to determine why it wouldn't be working. I am relative new to all of this as well, and use Vera not a Domoticz. On the first version that is sending a message, what data is getting through? I would try putting the "send" command someplace in the code where msgTemp has already been set. Then just call send(msgTemp).



  • hi

    Then i would have placed this in the loop>
    The error i get then is :'TempC' was not declared in this scope

    #ifdef MY_DEBUG
    Serial.print("DS1820 Temperature: ");
      Serial.print(tempC);
      Serial.println(" C");
    send(msgTemp.set(tempC ,2));
      
      Serial.print("Battery Voltage: ");
      Serial.print(batteryV);
      Serial.println(" V");
    send(msgbatt.set(batteryV ,2));```


  • so far my result.

    had to use float TempC = 50.5 at the start
    but in my serial i get the right temperature,
    but using it in the loop gives me still wrong number 50.5 so gets not updated.

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <BH1750.h>
    #include <Wire.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    
    // Data wire is plugged into port 3 on the Arduino
    #define ONE_WIRE_BUS 3
    
    // 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);
    
    // arrays to hold device address
    DeviceAddress insideThermometer;
    
    
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
    int SOLAR_SENSE_PIN = A1;  // select the input pin for the solar sense point
    #define CHILD_ID_BATTERY 4
    #define CHILD_ID_SOLAR 6
    #define CHILD_ID_LIGHT 1
    #define CHILD_ID_TEMP1 2
    
    BH1750 lightSensor;
    float TempC = 50.5;
    int oldBatteryPcnt = 0;
    MyMessage msgTemp(CHILD_ID_TEMP1,V_TEMP);
    MyMessage msgbatt(CHILD_ID_BATTERY, V_VOLTAGE);
    MyMessage msgsolar(CHILD_ID_SOLAR, V_VOLTAGE);
    MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    uint16_t lastlux;  //lux
    
    void setup(void)
    {
    // use the 1.1 V internal reference
      #if defined(__AVR_ATmega2560__)
      analogReference(INTERNAL1V1);
      #else
      analogReference(INTERNAL);
      #endif
    
      
    // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Battery Meter", "2.0");
      present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
     
      //Serial.begin(9600); // start serial port
      Serial.print("Locating devices..."); // locate devices on the bus
      sensors.begin(); // start reading sensor
      Serial.print("Found ");
      Serial.print(sensors.getDeviceCount(), DEC);
      Serial.println(" devices.");
      Serial.print("Parasite power is: "); // report parasite power requirements
      
      if (sensors.isParasitePowerMode()) Serial.println("ON");
      else Serial.println("OFF"); 
    // assign address manually.  the addresses below will beed to be changed
      // to valid device addresses on your bus.  device address can be retrieved
      // by using either oneWire.search(deviceAddress) or individually via
      // sensors.getAddress(deviceAddress, index)
      //insideThermometer = { 0x10, 0x9C, 0x04, 0x26, 0x01, 0x08, 0x0, 0x8C };
    
    
      // Method 1:
      // search for devices on the bus and assign based on an index.  ideally,
      // you would do this to initially discover addresses on the bus and then 
      // use those addresses and manually assign them (see above) once you know 
      // the devices on your bus (and assuming they don't change).
      if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
      
      // method 2: search()
      // search() looks for the next device. Returns 1 if a new address has been
      // returned. A zero might mean that the bus is shorted, there are no devices, 
      // or you have already retrieved all of them.  It might be a good idea to 
      // check the CRC to make sure you didn't get garbage.  The order is 
      // deterministic. You will always get the same devices in the same order
      //
      // Must be called before search()
      //oneWire.reset_search();
      // assigns the first address found to insideThermometer
      //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");
    
      // show the addresses we found on the bus
      Serial.print("Device 0 Address: ");
      printAddress(insideThermometer);
      Serial.println();
    
      // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
      sensors.setResolution(insideThermometer, 9);
     
      Serial.print("Device 0 Resolution: ");
      Serial.print(sensors.getResolution(insideThermometer), DEC); 
      Serial.println();  
    }
    
    // function to print the temperature for a device
    void printTemperature(DeviceAddress deviceAddress)
    {
      // method 1 - slower
      //Serial.print("Temp C: ");
      //Serial.print(sensors.getTempC(deviceAddress));
      //Serial.print(" Temp F: ");
      //Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit
    
      // method 2 - faster
      float TempC = sensors.getTempC(deviceAddress);
      Serial.print("Temp C: ");
      Serial.print(TempC);
      Serial.print(" Temp F: ");
      Serial.println(DallasTemperature::toFahrenheit(TempC)); // Converts tempC to Fahrenheit
    }
    
    
    
    void loop(void)
    {
      // call sensors.requestTemperatures() to issue a global temperature 
      // request to all devices on the bus
      Serial.print("Requesting temperatures...");
      sensors.requestTemperatures(); // Send the command to get temperatures
      Serial.println("DONE");
      
      
      // It responds almost immediately. Let's print out the data
      printTemperature(insideThermometer); // Use a simple function to print out the data
    {
    
     // get the battery Voltage
      int sensorValue2 = analogRead(BATTERY_SENSE_PIN);
      delay(1000);   
      
      int sensorValue1 = analogRead(BATTERY_SENSE_PIN);
      delay(100);
      
      int sensorValue = analogRead(BATTERY_SENSE_PIN);
      delay(1000);
        
      int sensorValueS = analogRead(SOLAR_SENSE_PIN);
      delay(1000);
     
    #ifdef MY_DEBUG
      Serial.print("Battery Voltage2: ");
      Serial.println(sensorValue2);
      Serial.print("Battery Voltage1: ");
      Serial.println(sensorValue1);
      Serial.print("Battery Voltage: ");
      Serial.println(sensorValue);
      Serial.print("Solar Voltage: ");
      Serial.println(sensorValueS);
    #endif
    
      // 1M, 470K divider across battery and using internal ADC ref of 1.1V
      // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
      // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
      // 3.44/1023 = Volts per bit = 0.003363075
      const float vRef = 4.200/ 1.05/ 1023 ;  
      int batteryPcnt = sensorValue / 10;
      float batteryV  = sensorValue * 0.0042598 ; // 0.0038952294568380753114792412093 max 4,2 volt
      float batteryS  = sensorValueS * 0.0102459 ; // 0.0038952294568380753114792412093 max 10 volt
    
    
    #ifdef MY_DEBUG
    Serial.print("DS1820 Temperature: ");
      Serial.print(TempC);
      Serial.println(" C");
    send(msgTemp.set(TempC ,2));
    
      
      Serial.print("Battery Voltage: ");
      Serial.print(batteryV);
      Serial.println(" V");
    send(msgbatt.set(batteryV ,2));
    
      Serial.print("Solar Voltage: ");
      Serial.print(batteryS);
      Serial.println(" V");
    send(msgsolar.set(batteryS ,2));
    
      Serial.print("Battery percent: ");
      Serial.print(batteryPcnt);
      Serial.println(" %");
    #endif
    
       if (oldBatteryPcnt != batteryPcnt) {
        // Power up radio after sleep
        sendBatteryLevel(batteryPcnt);
        oldBatteryPcnt = batteryPcnt;
      }
          
      uint16_t lux = lightSensor.readLightLevel();// Get Lux value
      Serial.println(lux);
      if (lux != lastlux) {
          send(msg.set(lux));
          lastlux = lux;
      }
      sleep(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);
      }
    }
      
    
    
    


  • here is my serial result.

    45651 MCO:SLP:WUP=-1
    Requesting temperatures...DONE
    Temp 😄 17.87 Temp F: 64.18
    Battery Voltage2: 931
    Battery Voltage1: 926
    Battery Voltage: 927
    Solar Voltage: 393
    DS1820 Temperature: 50.50 C
    49545 TSF:MSG:SEND,2-2-0-0,s=2,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:50.50
    Battery Voltage: 3.95 V
    49557 TSF:MSG:SEND,2-2-0-0,s=4,c=1,t=38,pt=7,l=5,sg=0,ft=0,st=OK:3.95
    Solar Voltage: 4.03 V
    49569 TSF:MSG:SEND,2-2-0-0,s=6,c=1,t=38,pt=7,l=5,sg=0,ft=0,st=OK:4.03
    Battery percent: 92 %
    1
    49577 MCO:SLP:MS=30000,SMS=0,I1=255,M1=255,I2=255,M2=255
    49584 MCO:SLP:TPD



  • i dont know how but i got it now running perfect, and cleaned up a bid.
    for if anyone could use ....

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <BH1750.h>
    #include <Wire.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    
    // Data wire is plugged into port 3 on the Arduino
    #define ONE_WIRE_BUS 3
    
    // 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);
    
    // arrays to hold device address
    DeviceAddress insideThermometer;
    
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
    int SOLAR_SENSE_PIN = A1;  // select the input pin for the solar sense point
    #define CHILD_ID_BATTERY 4
    #define CHILD_ID_SOLAR 6
    #define CHILD_ID_LIGHT 1
    #define CHILD_ID_TEMP1 2
    
    BH1750 lightSensor;
    float TempC = 50.5;
    int oldBatteryPcnt = 0;
    MyMessage msgTempC(CHILD_ID_TEMP1,V_TEMP);
    MyMessage msgbatt(CHILD_ID_BATTERY, V_VOLTAGE);
    MyMessage msgsolar(CHILD_ID_SOLAR, V_VOLTAGE);
    MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    uint16_t lastlux;  //lux
    
    void setup(void)
    {
    // use the 1.1 V internal reference
      #if defined(__AVR_ATmega2560__)
      analogReference(INTERNAL1V1);
      #else
      analogReference(INTERNAL);
      #endif
      
    // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Battery Meter", "2.0");
      present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
       
      sensors.begin(); // start reading sensor
      
      // search for devices on the bus and assign based on an index.  ideally,
      if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
      
      // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
      //sensors.setResolution(insideThermometer, 9);
    }
    
    void loop(void)
    {
      
     // get the battery Voltage
      int sensorValue2 = analogRead(BATTERY_SENSE_PIN);
      delay(1000);   
      
      int sensorValue1 = analogRead(BATTERY_SENSE_PIN);
      delay(100);
      
      int sensorValue = analogRead(BATTERY_SENSE_PIN);
      delay(1000);
        
      int sensorValueS = analogRead(SOLAR_SENSE_PIN);
      delay(1000);
     
    #ifdef MY_DEBUG
      Serial.print("Battery Voltage2: ");
      Serial.println(sensorValue2);
      Serial.print("Battery Voltage1: ");
      Serial.println(sensorValue1);
      Serial.print("Battery Voltage: ");
      Serial.println(sensorValue);
      Serial.print("Solar Voltage: ");
      Serial.println(sensorValueS);
    #endif
    
      // 1M, 470K divider across battery and using internal ADC ref of 1.1V
      // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
      // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
      // 3.44/1023 = Volts per bit = 0.003363075
      const float vRef = 4.200/ 1.05/ 1023 ;  
      int batteryPcnt = sensorValue / 10;
      float batteryV  = sensorValue * 0.0042598 ; // 0.0038952294568380753114792412093 max 4,2 volt
      float batteryS  = sensorValueS * 0.0102459 ; // 0.0038952294568380753114792412093 max 10 volt
      float TempC = sensors.getTempC(insideThermometer);
    
    #ifdef MY_DEBUG
      Serial.print("DS1820 Temperature: ");
      Serial.print(TempC);
      Serial.println(" C");
    send(msgTempC.set(TempC ,2));
      
      Serial.print("Battery Voltage: ");
      Serial.print(batteryV);
      Serial.println(" V");
    send(msgbatt.set(batteryV ,2));
    
      Serial.print("Solar Voltage: ");
      Serial.print(batteryS);
      Serial.println(" V");
    send(msgsolar.set(batteryS ,2));
    
      Serial.print("Battery percent: ");
      Serial.print(batteryPcnt);
      Serial.println(" %");
    #endif
    
       if (oldBatteryPcnt != batteryPcnt) {
        // Power up radio after sleep
        sendBatteryLevel(batteryPcnt);
        oldBatteryPcnt = batteryPcnt;
      }
          
      uint16_t lux = lightSensor.readLightLevel();// Get Lux value
      Serial.println(lux);
      if (lux != lastlux) {
          send(msg.set(lux));
          lastlux = lux;
      }
      sleep(SLEEP_TIME);
    }
    
    
    
    


  • Hi,

    Can someone push me into the right direction.
    I followed the "tutorial" and setup a Serial Gateway. This seems to be running just fine.

    Now i want to add a node with a temperature sensor.

    Both are using the NRF24L radio.

    On my node i get an errors in the serial monitor.
    What did i do wrong?

    0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1
    3 MCO:BGN:BFR
    63 TSM:INIT
    64 TSF:WUR:MS=0
    71 !TSM:INIT:TSP FAIL
    72 TSM:FAIL:CNT=1
    74 TSM:FAIL:PDT
    10077 TSM:FAIL:RE-INIT
    10079 TSM:INIT
    10085 !TSM:INIT:TSP FAIL
    10088 TSM:FAIL:CNT=2
    10089 TSM:FAIL:PDT
    

  • Mod



  • Hi Gohan,

    I did not know that page. Thanks for the push 👍

    I think i have crappy radio tho, because i switched it with anotherone i have and it started working....
    Thanks!


  • Mod

    don't tell me about crappy nrf24... I got a bunch of really bad ones that work but only for 5 meters max.



  • I just tried this today but get an error. Here's the output.....

    Arduino: 1.8.3 (Windows 10), Board: "Arduino Pro or Pro Mini, ATmega328 (3.3V, 8 MHz)"

    In file included from C:\Users\captain\Documents\Arduino\MYS-HW-CH\MYS-HW-CH.ino:37:0:

    C:\Users\captain\Documents\Arduino\libraries\DallasTemperature/DallasTemperature.h: In function 'void loop()':

    C:\Users\captain\Documents\Arduino\libraries\DallasTemperature/DallasTemperature.h:252:13: error: 'int16_t DallasTemperature::millisToWaitForConversion(uint8_t)' is private

     int16_t millisToWaitForConversion(uint8_t);
    
             ^
    

    MYS-HW-CH:85: error: within this context

    int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());

                                                                                     ^
    

    exit status 1
    within this context

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

    THis is MYS 2.1.1 installed so a bit baffled as to what is causing the problem, it should just work, right?

    Anyone with any insight please let me know! 🙂


  • Mod

    @skywatch just follow the instructions on the build page:

    This example uses a modified version of the external DTH library, which is included in the MySensors external examples. Please install it and restart the Arduino IDE before trying to compile.



  • Thank you - that did it.

    But it would be good to have that info in the file header too, just to call attention to it. Either that or a structured step-by-step tutorial so that things like this don't get left out.

    At least it works now though, kul!



  • really silly question.....so does create multiple sensors? so i would have temp1 temp2 or does it combine the value of both for an averaged temprature?
    the way i read it it would present mutiple sensors i think?


  • Mod

    It creates the sensors that you present during the presentation.



  • appologies for the badly worded questions...the code in its example format....
    am i reading it correctly that it presents sensors based on the variable for number of temp sensors?


  • Mod

    It will present different sensros according to the #define MAX_ATTACHED_DS18B20 16



  • Hi,
    I have only one sensor on the mini pro and I have this in the logs:
    2017-07-30 14:41:28.492 (Mysensor) Temp (Congélateur)
    2017-07-30 14:41:28.497 (Mysensor) Temp (Congélateur)
    2017-07-30 14:41:28.501 (Mysensor) Temp (Congélateur)
    2017-07-30 14:41:28.506 (Mysensor) Temp (Congélateur)
    2017-07-30 14:41:28.510 (Mysensor) Temp (Congélateur)
    2017-07-30 14:41:28.515 (Mysensor) Temp (Congélateur)
    2017-07-30 14:41:28.521 (Mysensor) Temp (Congélateur)
    2017-07-30 14:41:28.526 (Mysensor) Temp (Congélateur)

    Sleep time is set to 60000ms, why the time between 2 messages is around 5ms???


  • Mod

    @Digdogger it can depend on a lot of things. The best way to know is to look at the debug logs from the node and the gateway from the time when it happened. There could be a problem with the communication, with the radios, with the power supply, with the sketch, etc.

    It could also be that you're using a microcontroller that doesn't support MySensors sleep, such as the esp8266. But it is just a guess. The information that's usually needed to troubleshoot is listed in https://forum.mysensors.org/topic/666/debug-faq-and-how-ask-for-help/



  • OK thanks mfalkvidd



  • Slightly off-topic here... but related to this particular sketch

    If you look close enough (and copy-paste the sketch into your IDE) you'll witness that one curly-bracket is technically missing at the end of loop()...

    But as I added it to the sketch I got error

    Sketch compiles fine "with" the missing curly-bracket... ???

    Any comment to that (in my sense) funny behavior ?


  • Mod

    @ben999 the simple answer is probably that the backet isn't missing 🙂

    Can you show why you think it is missing?



  • @mfalkvidd

    I must have gone mad then 👻

    Check the loop()
    The last closing curly--bracket is for

    for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
    

    So which one closes

    void loop()     {  
    

    If i add one more to "make it right" then hell brakes loose...

    sketch_jul31a:110: error: expected declaration before '}' token
     }
     ^
    exit status 1
    expected declaration before '}' token
    

    1-That's the only sketch behaving this way
    2-Even the "IDE-automatic-opening-bracket-finder" (shows which bracket is open when placing cursor on closing bracket) can NOT find the right bracket for loop()...

    😱


  • Mod

    Interesting observation @ben999

    This is caused by the preprocessing directives.

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

    Only one of these if statements will be active. The Arduino IDE probably doesn't evaluate preprocessing directives, so it sees two if statements and therefore thinks it should see two end braces. A way to "fix" this could be to move the starting curly brace to after the preprocessing directives:

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

    This allows the Arduino IDE to parse the code correctly, and correctly match the braces.


  • Mod

    It's time to move to a better IDE 😁



  • @mfalkvidd
    Gosh you're a genius ! And you share your knowledge with style and simple explanation ! But i can only upvote you once 😄

    @gohan
    No way 😄 IDE is nice and simple for nice and simple people like me 🐰



  • I just upgraded to the MYS 2.1.1 version.

    My OneWire temperature sensors were not detected!

    I moved the sensors.begin() from setup() to before(), and that seems to have fixed things, and my temp sensors are being detected and read now.

    Anyone know why the OneWire library has to be initialized before MySensors setup?

    Thanks!



  • @chaeron I assume, you used an old version of the sketch.

    Your question most likely is related to a change in the order of the initialisation. This has changed in Version 2.2: from
    setup()=>presentation()
    to
    before()=>presentation()=>setup().

    So also the initialisation of sensors had to be reviewed accordingly (eg. to get the number of devices).



  • @rejoe2 said in 💬 Temperature Sensor:

    @chaeron I assume, you used an old version of the sketch.

    That is correct....the original code was written over a year ago. Trying to run it under 2.1.1 caused it to fail.

    Your question most likely is related to a change in the order of the initialisation. This has changed in Version 2.2: from
    setup()=>presentation()
    to
    before()=>presentation()=>setup().

    So where was this rather major change documented? It would probably have broken any 1-Wire examples, including the temperature one.

    So also the initialisation of sensors had to be reviewed accordingly (eg. to get the number of devices).

    So I figured out....I went looking for documentation on this rather significant change and was not able to find it noted anywhere.



  • There was a rather small note in the 2.0.0 changelog about the introduction of before().

    Btw: Another functional routine (preHwInit() (?)) may have been introduced also with 2.1.1 (?). But until now, all of my sketches and tests got along without this preHwInit() functionality. But imo the new structure is pretty good: before() is helpfull to initialise SPI devices on same bus as nRF24 and to collect relevant info like the number of DS18x20, setup() is now also good to send info you only need once (e.g. the Dallas-Chip-ID).

    The rest is - at least afaik - not really documented well, but most examples (if you use the updated ones) will work (apart from the DS18x20 example, where other - external - code changes made some parts tricky to use.

    I made some working sketches for the Dallas Sensors some time ago based on some ideas I found here in the MySensors forum; they mostly should still work (exept for the change of getConfig() to getControllerConfig()). If you are interested: here .

    Kind regards



  • If anyone is interested:

    The sketches in my repo have been updated yesterday for complete compability with the new structure and syntax. They compile fine and should work, but I didn't have the time to make functional tests also.
    If anyone is interested, I could also add a multibus example with several Sensors at each bus and different timings for each bus. One of my nodes is working on this concept for several days now (Heizung, RS485 version), so I'm pretty confident this will reliably work for longer periods. But it's rather special😀 .



  • @rejoe2
    Where do we find your repo then?



  • @chaeron
    Thx for asking.

    Repo-link was mentioned above, @rejoe2 said in 💬 Temperature Sensor:

    If you are interested: here .

    Btw: the sketches have been updated and compile now also with MySensors 2.2.0-beta. But to be honest, I didn't test them with hardware until now. So feedback is appreciated :simple_smile:.



  • Additionally: There is also a multibus version included that uses different timings for reading each of the buses.
    For using this sketch, I'm not sure wheter some changes in the DallasTemperature-lib also is required (it is based on an very recent example of the maintainer's guthub version; should be linked in the Arduino Library Manager; I myself applied some changes wrt. this in my local libs).
    I may aslo post this in case anyone's interested (and these mods are necessary).



  • @rejoe2 Any idea why the DallasTemperatureSimple from your GitHub not presenting in Domoticz?

    /**
       The MySensors Arduino library handles the wireless radio link and protocol
       between your home built sensors/actuators and HA controller of choice.
       The sensors forms a self healing radio network with optional repeaters. Each
       repeater and gateway builds a routing tables in EEPROM which keeps track of the
       network topology allowing messages to be routed to nodes.
    
       Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       Copyright (C) 2013-2015 Sensnology AB
       Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
    
       Documentation: http://www.mysensors.org
       Support Forum: http://forum.mysensors.org
    
       This program is free software; you can redistribute it and/or
       modify it under the terms of the GNU General Public License
       version 2 as published by the Free Software Foundation.
    
     *******************************
    
       DESCRIPTION
    
       Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller
       http://www.mysensors.org/build/temp
       Enhanced Version also sending the Dallas-ROM-ID, MySensors Version >=2.1.0
    */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #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 MAX_ATTACHED_DS18B20 16
    uint8_t DS_First_Child_ID = 7; //First Child-ID to be used by Dallas Bus; set this to be higher than other Child-ID's who need EEPROM storage to avoid conflicts
    unsigned long SLEEP_TIME = 30000; // 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;
    DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
    int resolution = 12; // precision: 12 bits = 0.0625°C, 11 bits = 0.125°C, 10 bits = 0.25°C, 9 bits = 0.5°C
    int conversionTime = 0;
    // Initialize temperature message
    MyMessage msgTemp(0, V_TEMP);
    MyMessage msgId(0, V_ID);
    
    char* charAddr = "Check for faults";
    #define SEND_ID
    
    void before()
    {
      // 12 bits = 750 ms, 11 bits = 375ms, 10 bits = 187.5ms, 9 bits = 93.75ms
      conversionTime = 750 / (1 << (12 - resolution));
      // Startup up the OneWire library
      sensors.begin();
    }
    
    void presentation() {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Temperature Sensor", "1.2");
    
      // Fetch the number of attached temperature sensors
      numSensors = sensors.getDeviceCount();
    
      // Present all sensors to controller
      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
        sensors.getAddress(tempDeviceAddress, i);
        charAddr = addrToChar(tempDeviceAddress);
        present(i + DS_First_Child_ID, S_TEMP, charAddr);
    #ifdef MY_DEBUG
        Serial.println(charAddr);
    #endif
      }
    }
    
    void setup()
    {
      // requestTemperatures() will not block current thread
      sensors.setWaitForConversion(false);
    
      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
        sensors.getAddress(tempDeviceAddress, i);
    #ifdef SEND_ID
        // 8 will assure a length of 16 of the sent ROM-ID
        send(msgId.setSensor(i + DS_First_Child_ID).set(tempDeviceAddress, 8));
    #endif
        sensors.setResolution(tempDeviceAddress, resolution);
        metric = getControllerConfig().isMetric;
      }
    }
    
    
    void loop()
    {
      // Fetch temperatures from Dallas sensors
      sensors.requestTemperatures();
    
      // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
      sleep(conversionTime);
    
      // Read temperatures and send them to controller
      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
    
        // Fetch and round temperature to one decimal
        float temperature = static_cast<float>(static_cast<int>((metric ? 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
          send(msgTemp.setSensor(i + DS_First_Child_ID).set(temperature, 1));
          wait(20);
          // Save new temperatures for next compare
          lastTemperature[i] = temperature;
        }
      }
    
      // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
      sleep(SLEEP_TIME);
    }
    
    char* addrToChar(uint8_t* data) {
      String strAddr = String(data[0], HEX); //Chip Version; should be higher than 16
      byte first ;
      int j = 0;
      for (uint8_t i = 1; i < 8; i++) {
        if (data[i] < 16) strAddr = strAddr + 0;
        strAddr = strAddr + String(data[i], HEX);
        strAddr.toUpperCase();
      }
      for (int j = 0; j < 16; j++) {
        charAddr[j] = strAddr[j];
      }
      return charAddr;
    }
    
    

  • Mod

    @Dick you are missing

    #define MY_NODE_ID x

    where x is the unique sensor ID you want to assign to node. If look in the gateway or node log you will see the node asking for an ID


  • Mod

    @gohan Domticz is capable of handing out node ids so using the default auto setting is perfectly fine.

    But yes, the debug log from node and gateway will help a lot in determining what the problem is.



  • @mfalkvidd I already tried a fixed node ID but that was not the solution so I checked the log of domoticz and this is the result:

    2017-08-19 11:59:30.260 MySensors: Node: 48, Sketch Name: Temperature Sensor
    2017-08-19 11:59:30.261 MySensors: Node: 48, Sketch Version: 1.2
    2017-08-19 11:59:38.480 MySensors: Node: 48, Sketch Name: Temperature Sensor
    2017-08-19 11:59:38.481 MySensors: Node: 48, Sketch Version: 1.2

    So it see the node but it does not pop up as a new device.
    The Arduino log shows this:

    0 MCO:BGN:INIT REPEATER,CP=RNNRA--,VER=2.1.1
    3 MCO:BGN:BFR
    6 TSM:INIT
    7 TSF:WUR:MS=0
    14 TSM:INIT:TSP OK
    16 TSF:SID:OK,ID=48
    17 TSM:FPAR
    59 TSF:MSG:SEND,48-48-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    360 TSF:MSG:READ,0-0-48,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    365 TSF:MSG:FPAR OK,ID=0,D=1
    408 TSF:MSG:READ,20-20-48,s=255,c=3,t=8,pt=1,l=1,sg=0:1
    2066 TSM:FPAR:OK
    2067 TSM:ID
    2068 TSM:ID:OK
    2070 TSM:UPL
    2074 TSF:MSG:SEND,48-48-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    2086 TSF:MSG:READ,0-0-48,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    2092 TSF:MSG:PONG RECV,HP=1
    2094 TSM:UPL:OK
    2096 TSM:READY:ID=48,PAR=0,DIS=1
    2101 TSF:MSG:SEND,48-48-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    2110 TSF:MSG:READ,0-0-48,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    2118 TSF:MSG:SEND,48-48-0-0,s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
    2127 TSF:MSG:SEND,48-48-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    2143 TSF:MSG:READ,0-0-48,s=255,c=3,t=6,pt=0,l=1,sg=0:M
    2152 TSF:MSG:SEND,48-48-0-0,s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=OK:Temperature Sensor
    2162 TSF:MSG:SEND,48-48-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.2
    2169 MCO:REG:REQ
    2173 TSF:MSG:SEND,48-48-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
    2183 TSF:MSG:READ,0-0-48,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2188 MCO:PIM:NODE REG=1
    2190 MCO:BGN:STP
    2191 MCO:BGN:INIT OK,TSP=1
    2196 MCO:SLP:MS=750,SMS=0,I1=255,M1=255,I2=255,M2=255
    2201 !MCO:SLP:REP
    2952 MCO:SLP:MS=30000,SMS=0,I1=255,M1=255,I2=255,M2=255
    2957 !MCO:SLP:REP
    32960 MCO:SLP:MS=750,SMS=0,I1=255,M1=255,I2=255,M2=255


  • Mod

    @Dick that output doesn't seem to match the sketch you posted. The output says the node is a repeater, but I don't see any repeater activation in the sketch.



  • @mfalkvidd Thx for your observation, I didn't realise that. Did you try to use this sketch also?
    As FHEM is the controller sw I use, I am not able to really test this kind of behaviour, that more seemed to be related to domoticz (or other trouble wrt. to this individual MySensors-installation).

    @Dick Imo, the node at least when trying to register behaves as necessary: it presents itself to the controller (but the chosen ID seems to be already bound to a different node). In FHEM - not for the node itself but for individual readings - it is necessary to reload the page to see updated readings, if it's the very first time they are sent from node's side (hope, you can follow my thoughts). Maybe domoticz shows a similar behaviour?


  • Mod

    @rejoe2 could you clarify which observation you are referring to?



  • @mfalkvidd I was reffering to this part of the serial output:

    0 MCO:BGN:INIT REPEATER,CP=RNNRA--,VER=2.1.1
    

    Imo, the only thing that is not standard is to also use a comment when presenting the individual temp-sensors:

    present(i + DS_First_Child_ID, S_TEMP, charAddr);
    

    FHEM doesn't care about that (just ignores this comment), but maybe other controllers don't like that at all. (I added this as it is a possible feature and may be helpful for others), but @Dick , you could try to delete the last argument.


  • Mod

    @rejoe2 the repeater feature is disabled by default, so Dick must have activated it by a define.



  • @Dick Besides the inclusion mode, in FHEM one also has to activate a feature called "autocreate". Is there a comparable routine, and in case if: did you turn it on?
    If you have a look in your domoticz log, there most likely appear further trials to register, or not?



  • @mfalkvidd For your info, I started the sketch cleareeprom to clear my Nano, loaded the script mentioned already and the log I posted is the same so the log must fit the sketch for the DallasTemperatureSimple. The repeater is activated or is it better to turn it off?


  • Mod

    @Dick the repeater feature is turned off by default so there is something very fishy going on.
    Have you modified any of the MySensors library files?



  • @rejoe2 What I see in the Log of Domoticz is that all the nodes are registered and are visible in Black the only blue one is only the Dalles node
    2017-08-19 12:44:48.339 MySensors: Node: 3, Sketch Name: Relay
    2017-08-19 12:44:48.340 MySensors: Node: 3, Sketch Version: 1.0
    2017-08-19 12:47:28.520 MySensors: Node: 48, Sketch Name: Temperature Sensor
    2017-08-19 12:47:28.530 MySensors: Node: 48, Sketch Version: 1.2
    2017-08-19 12:48:00.005 (GW Mysensors) Light/Switch (Voor Gor Pir)
    2017-08-19 12:48:39.405 MySensors: Node: 48, Sketch Name: Temperature Sensor
    2017-08-19 12:48:39.405 MySensors: Node: 48, Sketch Version: 1.2
    2017-08-19 12:49:36.059 MySensors: Node: 48, Sketch Name: Temperature Sensor
    2017-08-19 12:49:36.060 MySensors: Node: 48, Sketch Version: 1.2
    2017-08-19 12:51:47.939 MySensors: Node: 12, Sketch Name: Temperature Sensor
    2017-08-19 12:51:47.939 MySensors: Node: 12, Sketch Version: 1.2
    2017-08-19 12:51:54.329 MySensors: Node: 12, Sketch Name: Temperature Sensor
    2017-08-19 12:51:54.330 MySensors: Node: 12, Sketch Version: 1.2
    2017-08-19 12:54:56.992 (GW Mysensors) Light/Switch (Serre IRbui)
    2017-08-19 12:55:44.429 MySensors: Node: 12, Sketch Name: Temperature Sensor
    2017-08-19 12:55:44.440 MySensors: Node: 12, Sketch Version: 1.2



  • @mfalkvidd I changed the dalles lib with an older one, because in a disussion a wile ago it was advised to get it working. Now this modified Sketch is available I replaced the dalles lib again the latest one. For the rest nothing.


  • Mod

    @Dick this part

    2201 !MCO:SLP:REP
    

    of the initial log you posted says that the node cannot sleep because it is a repeater.

    This part of the sketch:

      // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
      sleep(conversionTime);
    

    explains that if the node is a repeater, the sleep call must be replaced by wait. If it is not replaced, the temperature sensors will not be ready when getTemp... is called, so the node will not send any values. Domoticz only lists sensors that have sent a value.



  • @mfalkvidd I chaned the Sleep into Wait but the same log in both Domoticz and on my Arduino. I thought it was an easy go but it appear not to be.



  • @Dick Did you change it at both places ( sleep(conversionTime);)?



  • @rejoe2 Yes on both location I replaced the sleep into a wait



  • @mfalkvidd In the Arduino log he Sleep error is not i anymore so that is solved but still no new device in Domoticz


  • Mod

    @Dick if you get the same log on the Arduino as before changing to wait, the sketch upload must have failed. Perhaps your Arduino is broken?
    Edit: Sorry, didn't see your last reply.

    What does the node log say now?



  • @mfalkvidd Ths is what the log says
    0 MCO:BGN:INIT REPEATER,CP=RNNRA--,VER=2.1.1
    3 MCO:BGN:BFR
    6 TSM:INIT
    7 TSF:WUR:MS=0
    14 TSM:INIT:TSP OK
    16 TSF:SID:OK,ID=12
    18 TSM:FPAR
    59 TSF:MSG:SEND,12-12-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    1016 TSF:MSG:READ,0-0-12,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    1021 TSF:MSG:FPAR OK,ID=0,D=1
    1804 TSF:MSG:READ,20-20-12,s=255,c=3,t=8,pt=1,l=1,sg=0:1
    1851 TSF:MSG:READ,4-4-12,s=255,c=3,t=8,pt=1,l=1,sg=0:1
    2067 TSM:FPAR:OK
    2068 TSM:ID
    2069 TSM:ID:OK
    2071 TSM:UPL
    2075 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    2087 TSF:MSG:READ,0-0-12,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    2093 TSF:MSG:PONG RECV,HP=1
    2095 TSM:UPL:OK
    2097 TSM:READY:ID=12,PAR=0,DIS=1
    2102 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    2111 TSF:MSG:READ,0-0-12,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    2119 TSF:MSG:SEND,12-12-0-0,s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
    2128 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    2144 TSF:MSG:READ,0-0-12,s=255,c=3,t=6,pt=0,l=1,sg=0:M
    2152 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=OK:Temperature Sensor
    2163 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.2
    2169 MCO:REG:REQ
    2173 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
    2183 TSF:MSG:READ,0-0-12,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2188 MCO:PIM:NODE REG=1
    2190 MCO:BGN:STP
    2192 MCO:BGN:INIT OK,TSP=1


  • Mod

    @Dick thanks. The node still doesn't send any values so that's why it does not show up in Domoticz.

    My next step would be to manually add serial debug prints at end of setup(), presentation(), and almost everywhere in loop(), to see why it doesn't attempt to send.



  • Very strange.
    I just mad the test and copied the code (out of your post above) to my IDE, compiled and uploaded: No problem, worked fine. Node gets registered by FHEM, sends ID once and Temp regularly as expected. For testing, I used just one DS18B20, but that shouldn't make any difference. (And MySensors lib version 2.2-beta, but that also shouldn't be an issue).

    Btw: what kind of a GW you are using?
    Recently, I came across a situation with a WiFi-GW that absolutely refused to accept new nodes. Using a serial one, everything was fine... Strange thing, too. (The GW itself was ok, there were several other nodes working without any communication problems. the new HW was also ok. Last, the channel was also correct, as all the existing nodes just switched over to the serial GW.... Reflashing that nasty thing also was no solution.)


Log in to reply
 

Suggested Topics

  • 3
  • 10
  • 2
  • 110
  • 2
  • 109

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts