Registered Temperature Sensors on Mysensors, need Help



  • Hi all,

    i need help because i have just finished a node to monitor a heating system.

    Temperature sensors need to be registered to be sure of each sensor shown at the right place.

    So here is my Node program, and all sensors shown in Domoticz, but temperatures stay to 0.

    There is a mistake, but i could not find where, and why !

    Please, if someone is able to "know".

    Thanks

    /**
     * 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
     */
    
    
    // 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 <MySensor.h>  
    #include <DallasTemperature.h>
    #include <OneWire.h>
    #include <Bounce2.h>
    
    #define NODE_ID 01 // or set to AUTO if you want gw to assign a NODE_ID for you.
    #define SKETCH_NAME "Chaudiere"
    #define SKETCH_VERSION "1.01"
    
    #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
    #define CHILD_ID100 100
    #define BUTTON_PIN1  3  // Arduino Digital I/O pin for button/reed switch
    #define CHILD_ID101 101
    #define BUTTON_PIN2  4  // Arduino Digital I/O pin for button/reed switch
    #define CHILD_ID102 102
    #define BUTTON_PIN3  5  // Arduino Digital I/O pin for button/reed switch
    #define CHILD_ID103 103
    #define BUTTON_PIN4  6  // Arduino Digital I/O pin for button/reed switch
    #define CHILD_ID104 104
    #define BUTTON_PIN5  7  // Arduino Digital I/O pin for button/reed switch
    #define CHILD_ID105 105
    #define BUTTON_PIN6  8  // Arduino Digital I/O pin for button/reed switch
    #define PRESSURE_SENSOR_ANALOG_PIN 7
    #define VANNE_SENSOR_ANALOG_PIN 6
    #define CURRENT_PAC_ANALOG_PIN 5
    #define CHILD_C10    10
    #define CHILD_C11    11 // Identification Pressostat Ballon
    #define CHILD_C12    12
    #define CHILD_C13    13
    #define CHILD_C14    14
    #define CHILD_C15    15
    #define CHILD_C16    16 // Identification vanne 3 voies
    #define CHILD_C17    17
    #define CHILD_C18    18
    #define CHILD_C19    19
    #define CHILD_C20    20 // Current P.A.C.
    
    Bounce debouncer = Bounce(); 
    
    int oldValue1=-1;
    int oldValue2=-1;
    int oldValue3=-1;
    int oldValue4=-1;
    int oldValue5=-1;
    int oldValue6=-1;
    
    #define ONE_WIRE_BUS 2 // Pin where dallas sensor is connected 
    #define MAX_ATTACHED_DS18B20 10
    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 Dallas(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
    #define TEMPERATURE_PRECISION 12  //The resolution of the sensor
    float lastTemperature[8];
    
    DeviceAddress dallasAddresses[] = {
     {0x28, 0xEB, 0xBB, 0x58, 0x4, 0x0, 0x0, 0xAA},   // C10 
      {0x28, 0x71, 0x7F, 0x78, 0x4, 0x0, 0x0, 0x99}, // C12
      {0x28, 0xA, 0xC7, 0x77, 0x4, 0x0, 0x0, 0x12},   // C13
      {0x28, 0x23, 0xE, 0x78, 0x4, 0x0, 0x0, 0x79}, // C14
      {0x28, 0x58, 0x16, 0x78, 0x4, 0x0, 0x0, 0x5B},   // C15
      {0x28, 0x6B, 0x1, 0x78, 0x4, 0x0, 0x0, 0xC2}, // C17
      {0x28, 0x91, 0xC9, 0x77, 0x4, 0x0, 0x0, 0xF9},   // C18
      {0x28, 0x2F, 0xE9, 0x77, 0x4, 0x0, 0x0, 0x15}, // C19
    };
    
    int numSensors=0;
    boolean receivedConfig = false;
    boolean metric = true; 
    // Initialize temperature message
    MyMessage msgCirc100(CHILD_ID100,V_TRIPPED), msgCirc101(CHILD_ID101,V_TRIPPED),msgCirc102(CHILD_ID102,V_TRIPPED), msgCirc103(CHILD_ID103,V_TRIPPED), msgCirc104(CHILD_ID104,V_TRIPPED), msgCirc105(CHILD_ID105,V_TRIPPED);
    MyMessage msgTempC10(CHILD_C10,V_TEMP), msgTempC12(CHILD_C12,V_TEMP),msgTempC13(CHILD_C13,V_TEMP), msgTempC14(CHILD_C14,V_TEMP),msgTempC15(CHILD_C15,V_TEMP), msgTempC17(CHILD_C17,V_TEMP),msgTempC18(CHILD_C18,V_TEMP), msgTempC19(CHILD_C19,V_TEMP);
    MyMessage msgPressure(CHILD_C11, V_PRESSURE);
    MyMessage msgVanne(CHILD_C16, V_PERCENTAGE);
    MyMessage msgCurrent(CHILD_C20, V_CURRENT);
    int lastPressureValue;
    int lastPositionValue;
    
    //MyMessage msg(0,V_TEMP);
    
    void setup()  
    { 
      pinMode(BUTTON_PIN1,INPUT);
      pinMode(BUTTON_PIN2,INPUT);
      pinMode(BUTTON_PIN3,INPUT);
      pinMode(BUTTON_PIN4,INPUT);
      pinMode(BUTTON_PIN5,INPUT);
      pinMode(BUTTON_PIN6,INPUT);
       
      // Activate internal pull-Down
      digitalWrite(BUTTON_PIN1,LOW);
      digitalWrite(BUTTON_PIN2,LOW);
      digitalWrite(BUTTON_PIN3,LOW);
      digitalWrite(BUTTON_PIN4,LOW);
      digitalWrite(BUTTON_PIN5,LOW);
      digitalWrite(BUTTON_PIN6,LOW);
        
      // After setting up the button, setup debouncer
      debouncer.attach(BUTTON_PIN1);
      debouncer.interval(50);
      debouncer.attach(BUTTON_PIN2);
      debouncer.interval(50);
      debouncer.attach(BUTTON_PIN3);
      debouncer.interval(50);
      debouncer.attach(BUTTON_PIN4);
      debouncer.interval(50);
      debouncer.attach(BUTTON_PIN5);
      debouncer.interval(50);
      debouncer.attach(BUTTON_PIN6);
      debouncer.interval(50);
      
      // Startup up the OneWire library
      Dallas.begin();
      
      // requestTemperatures() will not block current thread
      Dallas.setWaitForConversion(false);
    
      for (uint8_t i = 0; i < 8; i++) {
        Dallas.setResolution(dallasAddresses[i], TEMPERATURE_PRECISION);
      }
    }
    
    void presentation() {  
      present(CHILD_ID100, S_DOOR);
      present(CHILD_ID101, S_DOOR);
      present(CHILD_ID102, S_DOOR);  
      present(CHILD_ID103, S_DOOR);
      present(CHILD_ID104, S_DOOR);
      present(CHILD_ID105, S_DOOR);
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      // Fetch the number of attached temperature sensors  
      //numSensors = sensors.getDeviceCount();
      //Serial.print ("Capteurs Trouves :");
      //Serial.println (numSensors);
    
      // Present all sensors to controller
      present (CHILD_C10, S_TEMP);
      present (CHILD_C11, S_CUSTOM);
      present (CHILD_C12, S_TEMP);
      present (CHILD_C13, S_TEMP);
      present (CHILD_C14, S_TEMP);
      present (CHILD_C15, S_TEMP);
      present (CHILD_C16, S_CUSTOM);
      present (CHILD_C17, S_TEMP);
      present (CHILD_C18, S_TEMP);
      present (CHILD_C19, S_TEMP);
      present (CHILD_C20, S_CUSTOM);
      
    //  for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
    //     present(i, S_TEMP);
    //     Serial.print("Sensor" );
    //     Serial.print(i);
    //     Serial.print (ADRESSE 18B20);
    //  }
    }
    
    void loop()     
    {     
      // Fetch temperatures from Dallas sensors
      Dallas.requestTemperatures();
    
      // query conversion time and sleep until conversion completed
      // int16_t conversionTime = Dallas.millisToWaitForConversion(Dallas.getResolution());
      // 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 
      // Fetch and round temperature to one decimal
      // Capteur C10
        float temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?Dallas.getTempC(dallasAddresses[0]):Dallas.getTempF(dallasAddresses[0])) * 10.)) / 10.;
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature[0] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
          #endif
          // Send in the new temperature
          send(msgTempC10.set(temperature,1));
          Serial.print("Capteur C10 Present: ");
          Serial.println (temperature);
          // Save new temperatures for next compare
          lastTemperature[0]=temperature;
        }
        // Capteur C12
        temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?Dallas.getTempC(dallasAddresses[1]):Dallas.getTempF(dallasAddresses[1])) * 10.)) / 10.;
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature[1] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
          #endif
          // Send in the new temperature
          send(msgTempC12.set(temperature,1));
          Serial.print("Capteur C12 Present: ");
          Serial.println (temperature);
          // Save new temperatures for next compare
          lastTemperature[1]=temperature;
        }
        // Capteur C13
        temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?Dallas.getTempC(dallasAddresses[2]):Dallas.getTempF(dallasAddresses[2])) * 10.)) / 10.;
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature[2] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
          #endif
          // Send in the new temperature
          send(msgTempC13.set(temperature,1));
          Serial.print("Capteur C13 Present: ");
          Serial.println (temperature);
          // Save new temperatures for next compare
          lastTemperature[2]=temperature;
        }
        // Capteur C14
        temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?Dallas.getTempC(dallasAddresses[3]):Dallas.getTempF(dallasAddresses[3])) * 10.)) / 10.;
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature[3] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
          #endif
          // Send in the new temperature
          send(msgTempC14.set(temperature,1));
          Serial.print("Capteur C14 Present: ");
          Serial.println (temperature);
          // Save new temperatures for next compare
          lastTemperature[3]=temperature;
        }
        // Capteur C15
        temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?Dallas.getTempC(dallasAddresses[4]):Dallas.getTempF(dallasAddresses[4])) * 10.)) / 10.;
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature[4] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
          #endif
          // Send in the new temperature
          send(msgTempC15.set(temperature,1));
          Serial.print("Capteur C15 Present: ");
          Serial.println (temperature);
          // Save new temperatures for next compare
          lastTemperature[4]=temperature;
        }
        // Capteur C17
        temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?Dallas.getTempC(dallasAddresses[5]):Dallas.getTempF(dallasAddresses[5])) * 10.)) / 10.;
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature[5] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
          #endif
          // Send in the new temperature
          send(msgTempC17.set(temperature,1));
          Serial.print("Capteur C17 Present: ");
          Serial.println (temperature);
          // Save new temperatures for next compare
          lastTemperature[5]=temperature;
        }
        // Capteur C18
        temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?Dallas.getTempC(dallasAddresses[6]):Dallas.getTempF(dallasAddresses[6])) * 10.)) / 10.;
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature[6] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
          #endif
          // Send in the new temperature
          send(msgTempC18.set(temperature,1));
          Serial.print("Capteur C18 Present: ");
          Serial.println (temperature);
          // Save new temperatures for next compare
          lastTemperature[6]=temperature;
     }
     // Capteur C19
        temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?Dallas.getTempC(dallasAddresses[7]):Dallas.getTempF(dallasAddresses[7])) * 10.)) / 10.;
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature[7] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
          #endif
          // Send in the new temperature
          send(msgTempC19.set(temperature,1));
          Serial.print("Capteur C19 Present: ");
          Serial.println (temperature);
          // Save new temperatures for next compare
          lastTemperature[7]=temperature;
        }
    
     debouncer.update();
     // Get the update value
     int value1 = debouncer.read();
     int value2 = debouncer.read();
     int value3 = debouncer.read();
     int value4 = debouncer.read();
     int value5 = debouncer.read();
     int value6 = debouncer.read();
     int value7 = debouncer.read();
    
     value1 = digitalRead(BUTTON_PIN1);
     value2 = digitalRead(BUTTON_PIN2);
     value3 = digitalRead(BUTTON_PIN3);
     value4 = digitalRead(BUTTON_PIN4);
     value5 = digitalRead(BUTTON_PIN5);
     value6 = digitalRead(BUTTON_PIN6);
     
     if (value1 != oldValue1) {
         // Send in the new value
         send(msgCirc100.set(value1==HIGH ? 1 : 0));
         oldValue1 = value1;
      }
      if (value2 != oldValue2) {
         // Send in the new value
         send(msgCirc101.set(value2==HIGH ? 1 : 0));
         oldValue2 = value2;
      }
      if (value3 != oldValue3) {
         // Send in the new value
         send(msgCirc102.set(value3==HIGH ? 1 : 0));
         oldValue3 = value3;
      }
        if (value4 != oldValue4) {
         // Send in the new value
         send(msgCirc103.set(value4==HIGH ? 1 : 0));
         oldValue4 = value4;
      }
      if (value5 != oldValue5) {
         // Send in the new value
         send(msgCirc104.set(value5==HIGH ? 1 : 0));
         oldValue5 = value5;
      }
      if (value6 != oldValue6) {
         // Send in the new value
         send(msgCirc105.set(value6==HIGH ? 1 : 0));
         oldValue6 = value6;
      }  
      int PressureValue = (1023-analogRead(PRESSURE_SENSOR_ANALOG_PIN))/10.23; 
      Serial.println(PressureValue);
      if (PressureValue != lastPressureValue) {
          send(msgPressure.set(PressureValue));
          lastPressureValue = PressureValue;
      }
      int PositionValue = (1023-analogRead(VANNE_SENSOR_ANALOG_PIN))/10.23; 
      Serial.println(PositionValue);
      if (PositionValue != lastPositionValue) {
          send(msgVanne.set(PositionValue));
          lastPositionValue = PositionValue;
      }
      int CurrentValue = (1023-analogRead(CURRENT_PAC_ANALOG_PIN))/10.23; 
      Serial.println(CurrentValue);
      if (PositionValue != lastPositionValue) {
          send(msgCurrent.set(CurrentValue));
          lastPositionValue = CurrentValue;
     }
      sleep(SLEEP_TIME);
    }```


  • Another information,

    i am sure of the wiring and sensors connections, i tried with a normal sketch for Arduino, and every sensor is working fine

    Thanks for help


  • Admin

    You could probably simplify this sketch a bit...
    Look in the debug log and check it sends any temp data...
    If not, add debug in some locations until you find the problem. For instance what temp value you actually get when reading it from the dallas sensor.


Log in to reply
 

Suggested Topics

  • 1
  • 1
  • 3
  • 2
  • 5
  • 2

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts