Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. 2 dallas temp + 4 relays

2 dallas temp + 4 relays

Scheduled Pinned Locked Moved Troubleshooting
39 Posts 6 Posters 3.2k Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • rejoe2R rejoe2

    @theol said in 2 dallas temp + 4 relays:

    You calculate the conversion time, but you don't use it. So it makes sense that you won't get any readings without a wait, because the sensors don't get anytime to read. You should wait for the conversionTime before you read the sensors. Which is I'm guessing shorter than 500 ms, but I don't use Dallas temp sensors. So no expert on that.

    Absolutely right.
    Conversion time depends on resolution, max is 750ms according to data sheet.

    TheoLT Online
    TheoLT Online
    TheoL
    Contest Winner
    wrote on last edited by
    #21

    @rejoe2 changing
    wait(500);

    to

    wait( millisToWaitForConversion );

    Should do the trick.
    But wait has an unsigned long as parameter and your conversionTime is a signed int16_t, you might need to cast it. Best to update the millisWaitForConversion to unsigned long as well.

    // This function helps to avoid a problem with the latest Dallas temperature library.
    unsigned long millisToWaitForConversion(uint8_t bitResolution)
    {
      switch (bitResolution) {
        case 9:
          return 94;
        case 10:
          return 188;
        case 11:
          return 375;
        default:
          return 750;
      }
    }
    

    But it's hard to help with only a fragment of the code. I'm guessing that the resolution doesn't change when your sketch is running. In that case I'd declare a global unsigned long conversionWaitDuration and initialize it in the setup. I honestly would never ever use a wait in a sketchs main loop though. I always use a none blocking wait which uses millis().

    But again hard to help with coding when you can only see a fragment of the code.

    dzjrD 1 Reply Last reply
    0
    • TheoLT TheoL

      @rejoe2 changing
      wait(500);

      to

      wait( millisToWaitForConversion );

      Should do the trick.
      But wait has an unsigned long as parameter and your conversionTime is a signed int16_t, you might need to cast it. Best to update the millisWaitForConversion to unsigned long as well.

      // This function helps to avoid a problem with the latest Dallas temperature library.
      unsigned long millisToWaitForConversion(uint8_t bitResolution)
      {
        switch (bitResolution) {
          case 9:
            return 94;
          case 10:
            return 188;
          case 11:
            return 375;
          default:
            return 750;
        }
      }
      

      But it's hard to help with only a fragment of the code. I'm guessing that the resolution doesn't change when your sketch is running. In that case I'd declare a global unsigned long conversionWaitDuration and initialize it in the setup. I honestly would never ever use a wait in a sketchs main loop though. I always use a none blocking wait which uses millis().

      But again hard to help with coding when you can only see a fragment of the code.

      dzjrD Offline
      dzjrD Offline
      dzjr
      wrote on last edited by
      #22

      @theol

      i have uploaded the complete sketch at Github at here: link url)

      TheoLT 2 Replies Last reply
      0
      • dzjrD dzjr

        @theol

        i have uploaded the complete sketch at Github at here: link url)

        TheoLT Online
        TheoLT Online
        TheoL
        Contest Winner
        wrote on last edited by TheoL
        #23

        @dzjr Would be so much easier to discuss it in Dutch :)

        What is the problem you encounter at the moment?

        I'm looking at the code, and just asking why you use so many unneeded blocks. e.g.

        { if (flow != oldflow) { // Theo <--- Removed the bracelet at the start of the line?
        ...

        That first starting bracelet ({) is not needed because the part that is being executed if the if statement evaluates to true is after the last bracelet. I'll see if I can clean up the code a bit for you. I'll add comments with what I've changed.

        1 Reply Last reply
        0
        • dzjrD dzjr

          @theol

          i have uploaded the complete sketch at Github at here: link url)

          TheoLT Online
          TheoLT Online
          TheoL
          Contest Winner
          wrote on last edited by TheoL
          #24

          @dzjr here is the code with my comments. It compiles but I can't test it I use NRF24L01 and don't have any dallas temp sensors. I'll be cleaning up the code more like removing unused variables. Let's use that one for debugging purposes. Don't add anything else, because there's already a lot in it and it'll be harder to find the bug.

          /******************************************************************
            Created with PROGRAMINO IDE for Arduino - 28.12.2018 12:45:52
            Project     :MySensors Watermeter Node RS485
            Libraries   :MySensors, Dallas temp etc
            Author      :MySensors community & dzjr
            Description :Mysensors Watermeter node & leiding temperatuur
                        met lekkage detectie en optie voor waterdruk
          ******************************************************************/
          
          #define MY_DEBUG
          
          //RS 485 transport zaken
          #define MY_RS485                  //RS-485 transport
          #define MY_RS485_DE_PIN 11        //De DE pin benoemen, normaal is dit PIN-3
          #define MY_RS485_BAUD_RATE 9600
          //#define MY_RS485_MAX_MESSAGE_LENGTH 40
          //#define MY_RS485_SOH_COUNT 3 // gebruiken bij Collision op de bus
          
          //eerst wat administratie en dergelijk
          #define SN "PWN_Node" //Software Naam
          #define SV "1.01"      //Software versie
          #define MY_NODE_ID 20 //Node nummer
          #define MY_TRANSPORT_WAIT_READY_MS 3000    //wachten tot de gateway is opgestart
          
          
          //libaries activeren
          #include <MySensors.h>
          #include <DallasTemperature.h>
          #include <OneWire.h>
          #include <Bounce2.h>
          
          //Dallas settings
          #define COMPARE_TEMP 0 // 1= zenden alleen bij verandering 0= direct zenden
          #define ONE_WIRE_BUS 7
          #define TEMPERATURE_PRECISION 10 // 10 = 0,25°C 
          #define MAX_ATTACHED_DS18B20 4
          unsigned long SLEEP_TIME = 3000; //slaaptijd tussen twee metingen in ms
          OneWire oneWire(ONE_WIRE_BUS); //Een oneWire-exemplaar instellen om te communiceren met alle OneWire-apparaten
          DallasTemperature sensors(&oneWire); //OneWire naar Dallas
          float lastTemperature[MAX_ATTACHED_DS18B20];
          int numSensors = 0;
          bool receivedConfig = false;
          //bool metric = true;
          
          DeviceAddress Probe03 = { 0x28, 0x80, 0x43, 0x77, 0x91, 0x0F, 0x02, 0x5A  }; // leiding temp
          DeviceAddress Probe02 = { 0x28, 0xFF, 0x64, 0x1D, 0xF9, 0x9D, 0xDC, 0x5E  }; // op print1
          DeviceAddress Probe01 = { 0x28, 0xFF, 0x64, 0x1D, 0xF8, 0x4F, 0x3A, 0x08  }; // op print2
          
          
          MyMessage msgTemp(0, V_TEMP);
          
          #define CHILD_ID_PWN 11                 //Child ID Sensor watermeter
          #define CHILD_ID_LEKKAGE 21             //Child ID Lekkage sensor
          #define CHILD_ID_DRUK 22                //Child ID Water druk sensor
          #define PWN_SENSOR 2                    //Pin waar sensor watermeter op is aangesloten
          #define LEKKAGE_PIN A0                  //Pin waarop de lekkage sensor op is aangesloten
          #define WATERDRUK_PIN A1                //Pin waarom de druksensor is aangesloten
          #define SENSOR_INTERRUPT PWN_SENSOR-2   //Usually the interrupt = pin -2 
          #define PULSE_FACTOR 1000               //Pulsen per m³ water 1000=één rotatie per 10 liter
          #define MAX_FLOW 60ul                     //flitert meetfouten eruit (40 van @RBisschops en 100 van @Rejoe) <-- Theo: ul toegevoegd hoef je niet te casten
          #define wachtTime 5000ul              // Theo: added ul which makes it an unsigned long also mixing dutch and english in names is very confusing. At least to me.
          
          MyMessage flowmsg (CHILD_ID_PWN, V_FLOW);
          MyMessage volumemsg (CHILD_ID_PWN, V_VOLUME);
          MyMessage lastcountermsg (CHILD_ID_PWN, V_VAR1);
          MyMessage lekmsg (CHILD_ID_LEKKAGE, V_TEXT);
          MyMessage drukmsg (CHILD_ID_DRUK, V_PRESSURE);
          
          
          //unsigned long SEND_FREQUENCY = 30000; // Minimum time between send (in milliseconds). We don't want to spam the gateway.
          #define SEND_FREQUENCY 30000ul // Theo it's a constant 
          
          double ppl = ((double)PULSE_FACTOR) / 1000;      // Pulses per liter
          volatile unsigned long pulseCount = 0;
          volatile unsigned long lastBlink = 0;
          volatile double flow = 0;
          boolean pcReceived = false;
          unsigned long oldPulseCount = 0;
          unsigned long newBlink = 0;
          double oldflow = 0;
          double volume = 0;
          double oldvolume = 0;
          unsigned long lastSend = 0;
          unsigned long lastPulse = 0;
          #define SLEEP_MODE false        // Watt-value can only be reported when sleep mode is false.
          unsigned long maxTimeDryRun = 30000;
          unsigned long startTimeDryRun = 0;
          volatile unsigned long dryPulseCount = 0;
          
          int lastlekValue = 0;
          int lastdrukValue = 0;
          
          // lowest and highest sensor readings:
          const int sensorMin = 0;     // sensor minimum
          const int sensorMax = 600;  // sensor maximum
          
          
          void before() {
            wait(wachtTime); // Theo: Since this is only used one, a constant is not really needed. You can keep it for better readability
            sensors.begin(); // Theo: I always use meaningfull names. To me sensors is to vague, I'd use dallasSensors or temperatureSensors.
          }
          
          void setup() {
            sensors.setWaitForConversion(false);
            pinMode(PWN_SENSOR, INPUT_PULLUP);
            sensors.setResolution(TEMPERATURE_PRECISION);
            pulseCount = oldPulseCount = 0;
            attachInterrupt(SENSOR_INTERRUPT, onPulse , FALLING );
          }
          
          void presentation() {
            sendSketchInfo(SN, SV);
          
            numSensors = sensors.getDeviceCount();
          
            for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
              //  metric = getControllerConfig().isMetric;
              // Registreer alle sensors naar de Gateway
              present(i + 0, S_TEMP, "temp sensors");
              //present(i+1, S_TEMP, "MK Node temp");
              //present(i+2, S_TEMP, "PWN Leiding temp");
              present(CHILD_ID_PWN, S_WATER, "PWN_Meter");
              request(CHILD_ID_PWN, V_VAR1, "Req PWN data" );
              present(CHILD_ID_LEKKAGE, S_INFO, "Lekkage MK");
              present(CHILD_ID_DRUK, S_BARO, "PWN Waterdruk");
            }
          }
          
          unsigned long currentTime; // Theo: <--- removed declaration from loop. Not necessary but a good practice to make large variables global. That way heap gets less fragmented
          
          void loop() {
            currentTime = millis();
          
            //Watermeter sensor
            //WaterPulse counter
            // Only send values at a maximum frequency or woken up from sleep
            if (currentTime - lastSend > SEND_FREQUENCY) {
              lastSend = currentTime;
          
              if (flow != oldflow) { // Theo <--- Removed the bracelet at the start of the line?
                oldflow = flow;
          #ifdef MY_DEBUG_LOCAL
                Serial.print("l/min:");
                Serial.println(flow);
          #endif
                // Check that we dont get unresonable large flow value.
                // could hapen when long wraps or false interrupt triggered
                if (flow < MAX_FLOW ) { // Theo: <-- cast (unsigned long) removed. No longer needed constant defined is ul (unsigned long) saves a bit of cpu time.
                  send(flowmsg.set(flow, 2 ) ); // Send flow value to gw
                }
              }
          
              // No Pulse count received in 2min
              if (currentTime - lastPulse > 120000) {
                flow = 0;
              }
          
              // Pulse count has changed
              if (pulseCount != oldPulseCount) {
                oldPulseCount = pulseCount;
          #ifdef MY_DEBUG
                Serial.print(F("pulsecnt:"));
                Serial.println(pulseCount);
          #endif
                if (!pcReceived) {
                  request(CHILD_ID_PWN, V_VAR1);
                }
                send(flowmsg.set(pulseCount));                  // Send  pulsecount value to gw in VAR1
          
                double volume = ((double)pulseCount / ((double)PULSE_FACTOR));
                if (volume != oldvolume) {
                  oldvolume = volume;
          #ifdef MY_DEBUG
                  Serial.print(F("vol:"));
                  Serial.println(volume, 3);
          #endif
                  send(volumemsg.set(volume, 3));               // Send volume value to gw
                }
              }
          
          
              //    { Theo
              //Waterdruk meten
              int Waterdruk = (analogRead(WATERDRUK_PIN)) * 10;
              if (Waterdruk != lastdrukValue) {
                send (drukmsg.set(Waterdruk));
                lastdrukValue = Waterdruk;
              }
          
          
              //waterlekkage sensor
              int lekLevel = map(analogRead(LEKKAGE_PIN), sensorMin, sensorMax, 0, 3);
          
              switch (lekLevel) {
                case 0:    // Sensor is droog
                  send(lekmsg.set("Geen lekkage"));
                  break;
                case 1:    // Sensor raakt nat
                  send(lekmsg.set("Vochtig"));
                  break;
                case 2:   // Sensor is volledig bedekt met water
                  send(lekmsg.set("Lekkage"));
                  break;
              }
              //    } Theo
          
              //    } Theo
          
          
          
          
          
          
          
              //    { Theo
              //Dallas temperature sensoren
              // Fetch temperatures from Dallas sensors
              sensors.requestTemperatures();
              // query conversion time and sleep until conversion completed
          //    int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
          
          
          //    wait(500);
          
              wait( sensors.millisToWaitForConversion( sensors.getResolution() ) );
          
              // 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>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
                float temperature;
                // voor geadreseerde sensoren
                switch (i)  {
                  case 0:
                    temperature = sensors.getTempC(Probe01);
                    break;
                  case 1:
                    temperature = sensors.getTempC(Probe02);
                    break;
                  case 2:
                    temperature = sensors.getTempC(Probe03);
                    break;
                  default:
                    temperature = sensors.getTempCByIndex(Probe03);
                    break;
                }
          
          
                // 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) { // Theo: COMPARE_TEMP looks like a constant with value 0 so the #if looks unneeded to me.??
                  //#endif
          
                  // Send in the new temperature
                  send( msgTemp.setSensor( i ).set( temperature, 1 ) );
                  // Save new temperatures for next compare
                  lastTemperature[i] = temperature;
                }
                //      } Theo
              }
            }
          }
          
          void onPulse() {
            if ( !SLEEP_MODE )  {
              unsigned long newBlink = micros();
              unsigned long interval = newBlink - lastBlink;
          
              if (interval != 0) {
                lastPulse = millis();
                if (interval < 1000000L) {
                  // Sometimes we get interrupt on RISING,  1000000 = 1sek debounce ( max 60 l/min)
                  return;
                }
                flow = (60000000.0 / interval) / ppl;
              }
              lastBlink = newBlink;
            }
            pulseCount++;
            dryPulseCount++;
          }
          

          Another MAX_ATTACHED_DS18B20 is 4. You only have 3 probes. This means that the 3rd and 4th will always report the same values.

          1 Reply Last reply
          1
          • dzjrD Offline
            dzjrD Offline
            dzjr
            wrote on last edited by
            #25

            @theol

            Yes, it is easier to discuss in Dutch, but that can not be followed for the rest.

            The only thing that does not work (well) is the reading of the temperature sensors after I turned off the "wait".

            Need to take a look at why the conversionTime does not work properly.

            The use of many blocks is mainly because I am a beginner, my third real arduino sketch.
            And I copied it partly from @rejoe2 his example, and tried to get it working, which also partly succeeded. partly by applying more blocks {} ....

            I can only learn from being very friendly that you help with making the sketch better.

            I would say,

            Neem een oliebol van mij!

            TheoLT 1 Reply Last reply
            0
            • dzjrD dzjr

              @theol

              Yes, it is easier to discuss in Dutch, but that can not be followed for the rest.

              The only thing that does not work (well) is the reading of the temperature sensors after I turned off the "wait".

              Need to take a look at why the conversionTime does not work properly.

              The use of many blocks is mainly because I am a beginner, my third real arduino sketch.
              And I copied it partly from @rejoe2 his example, and tried to get it working, which also partly succeeded. partly by applying more blocks {} ....

              I can only learn from being very friendly that you help with making the sketch better.

              I would say,

              Neem een oliebol van mij!

              TheoLT Online
              TheoLT Online
              TheoL
              Contest Winner
              wrote on last edited by
              #26

              @dzjr If removed all unused variables and stuff. And the use of the bracelets was actually smart of you. Because you combined the different functions between them. The problem with it, is that is makes hard to read the code. So what I've done is I've made new functions of them outside the loop() and give them meaningful names. That way you have the lines of code, need for a specific function together in a method.
              Especially when you start learning how to program, using functions is a good practice. It will help you understand the code better.

              This code should work if it was only because the wait was removed. You need it in this case. It compiles, but I can't test it for you.

              Thanks for the oliebol :-) If you have any questions just ask. I'm glad that I could escape from the oudjaar-ellende :-) so my thanx for that.

              /******************************************************************
                Created with PROGRAMINO IDE for Arduino - 28.12.2018 12:45:52
                Project     :MySensors Watermeter Node RS485
                Libraries   :MySensors, Dallas temp etc
                Author      :MySensors community & dzjr
                Description :Mysensors Watermeter node & leiding temperatuur
                            met lekkage detectie en optie voor waterdruk
              ******************************************************************/
              
              #define MY_DEBUG
              
              //RS 485 transport zaken
              #define MY_RS485                  //RS-485 transport
              #define MY_RS485_DE_PIN 11        //De DE pin benoemen, normaal is dit PIN-3
              #define MY_RS485_BAUD_RATE 9600
              //#define MY_RS485_MAX_MESSAGE_LENGTH 40
              //#define MY_RS485_SOH_COUNT 3 // gebruiken bij Collision op de bus
              
              //eerst wat administratie en dergelijk
              #define SN "PWN_Node" //Software Naam
              #define SV "1.01"      //Software versie
              #define MY_NODE_ID 20 //Node nummer
              #define MY_TRANSPORT_WAIT_READY_MS 3000    //wachten tot de gateway is opgestart
              
              
              //libaries activeren
              #include <MySensors.h>
              #include <DallasTemperature.h>
              #include <OneWire.h>
              #include <Bounce2.h>
              
              //Dallas settings
              #define ONE_WIRE_BUS 7
              
              #define TEMPERATURE_PRECISION 10 // 10 = 0,25°C 
              #define MAX_ATTACHED_DS18B20 4
              
              OneWire oneWire(ONE_WIRE_BUS); //Een oneWire-exemplaar instellen om te communiceren met alle OneWire-apparaten
              DallasTemperature sensors(&oneWire); //OneWire naar Dallas
              
              float lastTemperature[MAX_ATTACHED_DS18B20];
              
              int numSensors = 0;
              bool receivedConfig = false;
              //bool metric = true;
              
              DeviceAddress Probe03 = { 0x28, 0x80, 0x43, 0x77, 0x91, 0x0F, 0x02, 0x5A  }; // leiding temp
              DeviceAddress Probe02 = { 0x28, 0xFF, 0x64, 0x1D, 0xF9, 0x9D, 0xDC, 0x5E  }; // op print1
              DeviceAddress Probe01 = { 0x28, 0xFF, 0x64, 0x1D, 0xF8, 0x4F, 0x3A, 0x08  }; // op print2
              
              
              MyMessage msgTemp(0, V_TEMP);
              
              #define CHILD_ID_PWN 11                 //Child ID Sensor watermeter
              #define CHILD_ID_LEKKAGE 21             //Child ID Lekkage sensor
              #define CHILD_ID_DRUK 22                //Child ID Water druk sensor
              #define PWN_SENSOR 2                    //Pin waar sensor watermeter op is aangesloten
              #define LEKKAGE_PIN A0                  //Pin waarop de lekkage sensor op is aangesloten
              #define WATERDRUK_PIN A1                //Pin waarom de druksensor is aangesloten
              #define SENSOR_INTERRUPT PWN_SENSOR-2   //Usually the interrupt = pin -2 
              #define PULSE_FACTOR 1000               //Pulsen per m³ water 1000=één rotatie per 10 liter
              #define MAX_FLOW 60ul                     //flitert meetfouten eruit (40 van @RBisschops en 100 van @Rejoe) <-- Theo: ul toegevoegd hoef je niet te casten
              #define wachtTime 5000ul              // Theo: added ul which makes it an unsigned long also mixing dutch and english in names is very confusing. At least to me.
              
              MyMessage flowmsg (CHILD_ID_PWN, V_FLOW);
              MyMessage volumemsg (CHILD_ID_PWN, V_VOLUME);
              MyMessage lastcountermsg (CHILD_ID_PWN, V_VAR1);
              MyMessage lekmsg (CHILD_ID_LEKKAGE, V_TEXT);
              MyMessage drukmsg (CHILD_ID_DRUK, V_PRESSURE);
              
              #define SEND_FREQUENCY 30000ul // Theo it's a constant 
              
              double ppl = ((double)PULSE_FACTOR) / 1000;      // Pulses per liter
              volatile unsigned long pulseCount = 0;
              volatile unsigned long lastBlink = 0;
              volatile double flow = 0;
              boolean pcReceived = false; // Theo: This value never changes...???
              unsigned long oldPulseCount = 0;
              
              double oldflow = 0;
              double volume = 0;
              double oldvolume = 0;
              unsigned long lastSend = 0;
              unsigned long lastPulse = 0;
              #define SLEEP_MODE false        // Watt-value can only be reported when sleep mode is false.
              
              volatile unsigned long dryPulseCount = 0;
              int lastdrukValue = 0;
              
              // lowest and highest sensor readings:
              const int sensorMin = 0;     // sensor minimum
              const int sensorMax = 600;  // sensor maximum
              
              
              void before() {
                wait(wachtTime); // Theo: Since this is only used one, a constant is not really needed. You can keep it for better readability
                sensors.begin(); // Theo: I always use meaningfull names. To me sensors is to vague, I'd use dallasSensors or temperatureSensors.
              }
              
              void setup() {
                sensors.setWaitForConversion(false);
                pinMode(PWN_SENSOR, INPUT_PULLUP);
                sensors.setResolution(TEMPERATURE_PRECISION);
                //  pulseCount = oldPulseCount = 0; // Theo not needed they're initialized with 0 in their declaration
                attachInterrupt(SENSOR_INTERRUPT, onPulse , FALLING );
              
                // Theo: initialize the array with 0.0 as a value.
                for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
                  lastTemperature[MAX_ATTACHED_DS18B20] = 0.0;
                };
              }
              
              void presentation() {
                sendSketchInfo(SN, SV);
              
                numSensors = sensors.getDeviceCount();
              
                for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
                  //  metric = getControllerConfig().isMetric;
                  // Registreer alle sensors naar de Gateway
                  present(i + 0, S_TEMP, "temp sensors");
                  //present(i+1, S_TEMP, "MK Node temp");
                  //present(i+2, S_TEMP, "PWN Leiding temp");
                  present(CHILD_ID_PWN, S_WATER, "PWN_Meter");
                  request(CHILD_ID_PWN, V_VAR1, "Req PWN data" );
                  present(CHILD_ID_LEKKAGE, S_INFO, "Lekkage MK");
                  present(CHILD_ID_DRUK, S_BARO, "PWN Waterdruk");
                }
              }
              
              unsigned long currentTime;
              
              void sendPulseValue() {
                if (flow != oldflow) {
                  oldflow = flow;
              
                  // Check that we dont get unresonable large flow value.
                  // could hapen when long wraps or false interrupt triggered
                  if (flow < MAX_FLOW ) { // Theo: <-- cast (unsigned long) removed. No longer needed constant defined is ul (unsigned long) saves a bit of cpu time.
                    send(flowmsg.set(flow, 2 ) ); // Send flow value to gw
                  }
                }
              
                // No Pulse count received in 2min
                if (currentTime - lastPulse > 120000) {
                  flow = 0;
                }
              
                // Pulse count has changed
                if (pulseCount != oldPulseCount) {
                  oldPulseCount = pulseCount;
              #ifdef MY_DEBUG
                  Serial.print(F("pulsecnt:"));
                  Serial.println(pulseCount);
              #endif
                  if (!pcReceived) { // Because this value never changes you're requesting the value from the gateway every other 30 seconds....??
                    request(CHILD_ID_PWN, V_VAR1);
                  }
                  send(flowmsg.set(pulseCount));                  // Send  pulsecount value to gw in VAR1
              
                  double volume = ((double)pulseCount / ((double)PULSE_FACTOR));
                  if (volume != oldvolume) {
                    oldvolume = volume;
              #ifdef MY_DEBUG
                    Serial.print(F("vol:"));
                    Serial.println(volume, 3);
              #endif
                    send(volumemsg.set(volume, 3));               // Send volume value to gw
                  }
                }
              }
              
              void sendWaterPressure() {
                //Waterdruk meten
                int Waterdruk = (analogRead(WATERDRUK_PIN)) * 10;
                if (Waterdruk != lastdrukValue) {
                  send (drukmsg.set(Waterdruk));
                  lastdrukValue = Waterdruk;
                }
              }
              
              void sendWaterLeakageText() {
                //waterlekkage sensor
                int lekLevel = map(analogRead(LEKKAGE_PIN), sensorMin, sensorMax, 0, 3);
              
                switch (lekLevel) {
                  case 0:    // Sensor is droog
                    send(lekmsg.set("Geen lekkage"));
                    break;
                  case 1:    // Sensor raakt nat
                    send(lekmsg.set("Vochtig"));
                    break;
                  case 2:   // Sensor is volledig bedekt met water
                    send(lekmsg.set("Lekkage"));
                    break;
                }
              }
              
              void sendTemperatureValues() {
                //Dallas temperature sensoren
                // Fetch temperatures from Dallas sensors
                sensors.requestTemperatures();
              
                // query conversion time and sleep until conversion completed
                wait( sensors.millisToWaitForConversion( sensors.getResolution() ) );
              
                // 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>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
                  float temperature;
                  // voor geadreseerde sensoren
                  switch (i)  {
                    case 0:
                      temperature = sensors.getTempC(Probe01);
                      break;
                    case 1:
                      temperature = sensors.getTempC(Probe02);
                      break;
                    case 2:
                      temperature = sensors.getTempC(Probe03);
                      break;
                    default:
                      temperature = sensors.getTempCByIndex(Probe03);
                      break;
                  }
              
                  // Only send data if temperature has changed and no error
                  if ( lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
              
                    // Send in the new temperature
                    send( msgTemp.setSensor( i ).set( temperature, 1 ) );
                    // Save new temperatures for next compare
                    lastTemperature[i] = temperature;
                  }
                }
              }
              
              void loop() {
                currentTime = millis();
              
                //Watermeter sensor
                //WaterPulse counter
                // Only send values at a maximum frequency or woken up from sleep
                if (currentTime - lastSend > SEND_FREQUENCY) {
                  lastSend = currentTime;
              
                  sendPulseValue();
                  sendWaterPressure();
                  sendWaterLeakageText();
                  sendTemperatureValues();
                }
              }
              
              // unsigned long newBlink = 0; Theo: <-- removed from top because it's never used since it's a local in your interrupt handler
              void onPulse() {
                if ( !SLEEP_MODE )  { // Theo: since you've declared it as a constant with value false the check is not needed. The evaluation of the if statement will always be true
                  unsigned long newBlink = micros();
                  unsigned long interval = newBlink - lastBlink;
              
                  if (interval != 0) {
                    lastPulse = millis();
                    if (interval < 1000000L) {
                      // Sometimes we get interrupt on RISING,  1000000 = 1sek debounce ( max 60 l/min)
                      return;
                    }
                    flow = (60000000.0 / interval) / ppl;
                  }
                  lastBlink = newBlink;
                }
                pulseCount++;
                dryPulseCount++;
              }
              
              dzjrD 1 Reply Last reply
              0
              • rejoe2R Offline
                rejoe2R Offline
                rejoe2
                wrote on last edited by
                #27

                Good work, @TheoL!
                Some additional remarks intented for @dzjr form my side:

                • Do you really want to start the node also when no communication to the GW is present? Otherwise disable "#define MY_TRANSPORT_WAIT_READY_MS 3000"
                • calculation of the conversion time could also be done once
                • using an array containing all of the sensor addresses makes code even more easy to read.

                For the later two things see https://github.com/rejoe2/MySensors-Dallas-Address-ChildID-Consistency/blob/master/Dallas_Addresses_Array_Solution/Dallas_Addresses_Array_Solution.ino (hope this still works, there had been some changes in the dallas-temp lib since I last used it myself).

                Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                dzjrD 1 Reply Last reply
                0
                • TheoLT TheoL

                  @dzjr If removed all unused variables and stuff. And the use of the bracelets was actually smart of you. Because you combined the different functions between them. The problem with it, is that is makes hard to read the code. So what I've done is I've made new functions of them outside the loop() and give them meaningful names. That way you have the lines of code, need for a specific function together in a method.
                  Especially when you start learning how to program, using functions is a good practice. It will help you understand the code better.

                  This code should work if it was only because the wait was removed. You need it in this case. It compiles, but I can't test it for you.

                  Thanks for the oliebol :-) If you have any questions just ask. I'm glad that I could escape from the oudjaar-ellende :-) so my thanx for that.

                  /******************************************************************
                    Created with PROGRAMINO IDE for Arduino - 28.12.2018 12:45:52
                    Project     :MySensors Watermeter Node RS485
                    Libraries   :MySensors, Dallas temp etc
                    Author      :MySensors community & dzjr
                    Description :Mysensors Watermeter node & leiding temperatuur
                                met lekkage detectie en optie voor waterdruk
                  ******************************************************************/
                  
                  #define MY_DEBUG
                  
                  //RS 485 transport zaken
                  #define MY_RS485                  //RS-485 transport
                  #define MY_RS485_DE_PIN 11        //De DE pin benoemen, normaal is dit PIN-3
                  #define MY_RS485_BAUD_RATE 9600
                  //#define MY_RS485_MAX_MESSAGE_LENGTH 40
                  //#define MY_RS485_SOH_COUNT 3 // gebruiken bij Collision op de bus
                  
                  //eerst wat administratie en dergelijk
                  #define SN "PWN_Node" //Software Naam
                  #define SV "1.01"      //Software versie
                  #define MY_NODE_ID 20 //Node nummer
                  #define MY_TRANSPORT_WAIT_READY_MS 3000    //wachten tot de gateway is opgestart
                  
                  
                  //libaries activeren
                  #include <MySensors.h>
                  #include <DallasTemperature.h>
                  #include <OneWire.h>
                  #include <Bounce2.h>
                  
                  //Dallas settings
                  #define ONE_WIRE_BUS 7
                  
                  #define TEMPERATURE_PRECISION 10 // 10 = 0,25°C 
                  #define MAX_ATTACHED_DS18B20 4
                  
                  OneWire oneWire(ONE_WIRE_BUS); //Een oneWire-exemplaar instellen om te communiceren met alle OneWire-apparaten
                  DallasTemperature sensors(&oneWire); //OneWire naar Dallas
                  
                  float lastTemperature[MAX_ATTACHED_DS18B20];
                  
                  int numSensors = 0;
                  bool receivedConfig = false;
                  //bool metric = true;
                  
                  DeviceAddress Probe03 = { 0x28, 0x80, 0x43, 0x77, 0x91, 0x0F, 0x02, 0x5A  }; // leiding temp
                  DeviceAddress Probe02 = { 0x28, 0xFF, 0x64, 0x1D, 0xF9, 0x9D, 0xDC, 0x5E  }; // op print1
                  DeviceAddress Probe01 = { 0x28, 0xFF, 0x64, 0x1D, 0xF8, 0x4F, 0x3A, 0x08  }; // op print2
                  
                  
                  MyMessage msgTemp(0, V_TEMP);
                  
                  #define CHILD_ID_PWN 11                 //Child ID Sensor watermeter
                  #define CHILD_ID_LEKKAGE 21             //Child ID Lekkage sensor
                  #define CHILD_ID_DRUK 22                //Child ID Water druk sensor
                  #define PWN_SENSOR 2                    //Pin waar sensor watermeter op is aangesloten
                  #define LEKKAGE_PIN A0                  //Pin waarop de lekkage sensor op is aangesloten
                  #define WATERDRUK_PIN A1                //Pin waarom de druksensor is aangesloten
                  #define SENSOR_INTERRUPT PWN_SENSOR-2   //Usually the interrupt = pin -2 
                  #define PULSE_FACTOR 1000               //Pulsen per m³ water 1000=één rotatie per 10 liter
                  #define MAX_FLOW 60ul                     //flitert meetfouten eruit (40 van @RBisschops en 100 van @Rejoe) <-- Theo: ul toegevoegd hoef je niet te casten
                  #define wachtTime 5000ul              // Theo: added ul which makes it an unsigned long also mixing dutch and english in names is very confusing. At least to me.
                  
                  MyMessage flowmsg (CHILD_ID_PWN, V_FLOW);
                  MyMessage volumemsg (CHILD_ID_PWN, V_VOLUME);
                  MyMessage lastcountermsg (CHILD_ID_PWN, V_VAR1);
                  MyMessage lekmsg (CHILD_ID_LEKKAGE, V_TEXT);
                  MyMessage drukmsg (CHILD_ID_DRUK, V_PRESSURE);
                  
                  #define SEND_FREQUENCY 30000ul // Theo it's a constant 
                  
                  double ppl = ((double)PULSE_FACTOR) / 1000;      // Pulses per liter
                  volatile unsigned long pulseCount = 0;
                  volatile unsigned long lastBlink = 0;
                  volatile double flow = 0;
                  boolean pcReceived = false; // Theo: This value never changes...???
                  unsigned long oldPulseCount = 0;
                  
                  double oldflow = 0;
                  double volume = 0;
                  double oldvolume = 0;
                  unsigned long lastSend = 0;
                  unsigned long lastPulse = 0;
                  #define SLEEP_MODE false        // Watt-value can only be reported when sleep mode is false.
                  
                  volatile unsigned long dryPulseCount = 0;
                  int lastdrukValue = 0;
                  
                  // lowest and highest sensor readings:
                  const int sensorMin = 0;     // sensor minimum
                  const int sensorMax = 600;  // sensor maximum
                  
                  
                  void before() {
                    wait(wachtTime); // Theo: Since this is only used one, a constant is not really needed. You can keep it for better readability
                    sensors.begin(); // Theo: I always use meaningfull names. To me sensors is to vague, I'd use dallasSensors or temperatureSensors.
                  }
                  
                  void setup() {
                    sensors.setWaitForConversion(false);
                    pinMode(PWN_SENSOR, INPUT_PULLUP);
                    sensors.setResolution(TEMPERATURE_PRECISION);
                    //  pulseCount = oldPulseCount = 0; // Theo not needed they're initialized with 0 in their declaration
                    attachInterrupt(SENSOR_INTERRUPT, onPulse , FALLING );
                  
                    // Theo: initialize the array with 0.0 as a value.
                    for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
                      lastTemperature[MAX_ATTACHED_DS18B20] = 0.0;
                    };
                  }
                  
                  void presentation() {
                    sendSketchInfo(SN, SV);
                  
                    numSensors = sensors.getDeviceCount();
                  
                    for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
                      //  metric = getControllerConfig().isMetric;
                      // Registreer alle sensors naar de Gateway
                      present(i + 0, S_TEMP, "temp sensors");
                      //present(i+1, S_TEMP, "MK Node temp");
                      //present(i+2, S_TEMP, "PWN Leiding temp");
                      present(CHILD_ID_PWN, S_WATER, "PWN_Meter");
                      request(CHILD_ID_PWN, V_VAR1, "Req PWN data" );
                      present(CHILD_ID_LEKKAGE, S_INFO, "Lekkage MK");
                      present(CHILD_ID_DRUK, S_BARO, "PWN Waterdruk");
                    }
                  }
                  
                  unsigned long currentTime;
                  
                  void sendPulseValue() {
                    if (flow != oldflow) {
                      oldflow = flow;
                  
                      // Check that we dont get unresonable large flow value.
                      // could hapen when long wraps or false interrupt triggered
                      if (flow < MAX_FLOW ) { // Theo: <-- cast (unsigned long) removed. No longer needed constant defined is ul (unsigned long) saves a bit of cpu time.
                        send(flowmsg.set(flow, 2 ) ); // Send flow value to gw
                      }
                    }
                  
                    // No Pulse count received in 2min
                    if (currentTime - lastPulse > 120000) {
                      flow = 0;
                    }
                  
                    // Pulse count has changed
                    if (pulseCount != oldPulseCount) {
                      oldPulseCount = pulseCount;
                  #ifdef MY_DEBUG
                      Serial.print(F("pulsecnt:"));
                      Serial.println(pulseCount);
                  #endif
                      if (!pcReceived) { // Because this value never changes you're requesting the value from the gateway every other 30 seconds....??
                        request(CHILD_ID_PWN, V_VAR1);
                      }
                      send(flowmsg.set(pulseCount));                  // Send  pulsecount value to gw in VAR1
                  
                      double volume = ((double)pulseCount / ((double)PULSE_FACTOR));
                      if (volume != oldvolume) {
                        oldvolume = volume;
                  #ifdef MY_DEBUG
                        Serial.print(F("vol:"));
                        Serial.println(volume, 3);
                  #endif
                        send(volumemsg.set(volume, 3));               // Send volume value to gw
                      }
                    }
                  }
                  
                  void sendWaterPressure() {
                    //Waterdruk meten
                    int Waterdruk = (analogRead(WATERDRUK_PIN)) * 10;
                    if (Waterdruk != lastdrukValue) {
                      send (drukmsg.set(Waterdruk));
                      lastdrukValue = Waterdruk;
                    }
                  }
                  
                  void sendWaterLeakageText() {
                    //waterlekkage sensor
                    int lekLevel = map(analogRead(LEKKAGE_PIN), sensorMin, sensorMax, 0, 3);
                  
                    switch (lekLevel) {
                      case 0:    // Sensor is droog
                        send(lekmsg.set("Geen lekkage"));
                        break;
                      case 1:    // Sensor raakt nat
                        send(lekmsg.set("Vochtig"));
                        break;
                      case 2:   // Sensor is volledig bedekt met water
                        send(lekmsg.set("Lekkage"));
                        break;
                    }
                  }
                  
                  void sendTemperatureValues() {
                    //Dallas temperature sensoren
                    // Fetch temperatures from Dallas sensors
                    sensors.requestTemperatures();
                  
                    // query conversion time and sleep until conversion completed
                    wait( sensors.millisToWaitForConversion( sensors.getResolution() ) );
                  
                    // 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>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
                      float temperature;
                      // voor geadreseerde sensoren
                      switch (i)  {
                        case 0:
                          temperature = sensors.getTempC(Probe01);
                          break;
                        case 1:
                          temperature = sensors.getTempC(Probe02);
                          break;
                        case 2:
                          temperature = sensors.getTempC(Probe03);
                          break;
                        default:
                          temperature = sensors.getTempCByIndex(Probe03);
                          break;
                      }
                  
                      // Only send data if temperature has changed and no error
                      if ( lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
                  
                        // Send in the new temperature
                        send( msgTemp.setSensor( i ).set( temperature, 1 ) );
                        // Save new temperatures for next compare
                        lastTemperature[i] = temperature;
                      }
                    }
                  }
                  
                  void loop() {
                    currentTime = millis();
                  
                    //Watermeter sensor
                    //WaterPulse counter
                    // Only send values at a maximum frequency or woken up from sleep
                    if (currentTime - lastSend > SEND_FREQUENCY) {
                      lastSend = currentTime;
                  
                      sendPulseValue();
                      sendWaterPressure();
                      sendWaterLeakageText();
                      sendTemperatureValues();
                    }
                  }
                  
                  // unsigned long newBlink = 0; Theo: <-- removed from top because it's never used since it's a local in your interrupt handler
                  void onPulse() {
                    if ( !SLEEP_MODE )  { // Theo: since you've declared it as a constant with value false the check is not needed. The evaluation of the if statement will always be true
                      unsigned long newBlink = micros();
                      unsigned long interval = newBlink - lastBlink;
                  
                      if (interval != 0) {
                        lastPulse = millis();
                        if (interval < 1000000L) {
                          // Sometimes we get interrupt on RISING,  1000000 = 1sek debounce ( max 60 l/min)
                          return;
                        }
                        flow = (60000000.0 / interval) / ppl;
                      }
                      lastBlink = newBlink;
                    }
                    pulseCount++;
                    dryPulseCount++;
                  }
                  
                  dzjrD Offline
                  dzjrD Offline
                  dzjr
                  wrote on last edited by
                  #28

                  @theol
                  As a first of course a happy new year for all of you.

                  @TheoL thank you for your work, that reads and programs a lot easier with their own voids, did not know that could work!

                  I just loaded the net, only the temperature sensors do not come through, I'll tell you tonight if I can find it.

                  The sketch is partly based on the MySensor-Garage Sketch from @rejoe2 , I copied the parts I needed (for the water meter), and for the temperature I copied it from another sketch which I had also used for another project. .

                  As I said before, I am a beginner with Arduino, so I am very happy with this help and advice.

                  Thanks again for your help

                  1 Reply Last reply
                  0
                  • rejoe2R rejoe2

                    Good work, @TheoL!
                    Some additional remarks intented for @dzjr form my side:

                    • Do you really want to start the node also when no communication to the GW is present? Otherwise disable "#define MY_TRANSPORT_WAIT_READY_MS 3000"
                    • calculation of the conversion time could also be done once
                    • using an array containing all of the sensor addresses makes code even more easy to read.

                    For the later two things see https://github.com/rejoe2/MySensors-Dallas-Address-ChildID-Consistency/blob/master/Dallas_Addresses_Array_Solution/Dallas_Addresses_Array_Solution.ino (hope this still works, there had been some changes in the dallas-temp lib since I last used it myself).

                    dzjrD Offline
                    dzjrD Offline
                    dzjr
                    wrote on last edited by
                    #29

                    @rejoe2

                    I thought that with #define MY_TRANSPORT_WAIT_READY_MS you could start the gateway first and then the node, I built everything with one 5 volt power supply, which is why I want the node to start later, before I now have a wait in void put down.

                    I will take a look at the DALLAS scketch tonight or I can also use it in this sketch.

                    1 Reply Last reply
                    0
                    • dzjrD Offline
                      dzjrD Offline
                      dzjr
                      wrote on last edited by
                      #30

                      I have it working!

                      In "void setup" I removed the extra lines , and then it worked \ o /

                      // Theo: initialize the array with 0.0 as a value.
                      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
                        lastTemperature[MAX_ATTACHED_DS18B20] = 0.0;
                      };
                      

                      @ rejoe2 i removed the " wait transport" ,
                      I tried your Dallas_Addresses_Array_Solution sketch, I think that maybe there are some library adjustments given, because it did not work directly (I got 00000000 as message).
                      By the way, if I disconnect one sensor, another sensor is set it place at the controller, if it is connected again then it is back to the original ID.

                      I have changed this line (line 114)

                      float temperature = static_cast<float>(static_cast<int>((metric ? sensors.getTempC(dallasAddresses[i]) : sensors.getTempF(dallasAddresses[i])) * 10.)) / 10.;
                      

                      into this: (from the example sketch at the build section)

                      float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
                      
                      zboblamontZ 1 Reply Last reply
                      0
                      • dzjrD dzjr

                        I have it working!

                        In "void setup" I removed the extra lines , and then it worked \ o /

                        // Theo: initialize the array with 0.0 as a value.
                        for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
                          lastTemperature[MAX_ATTACHED_DS18B20] = 0.0;
                        };
                        

                        @ rejoe2 i removed the " wait transport" ,
                        I tried your Dallas_Addresses_Array_Solution sketch, I think that maybe there are some library adjustments given, because it did not work directly (I got 00000000 as message).
                        By the way, if I disconnect one sensor, another sensor is set it place at the controller, if it is connected again then it is back to the original ID.

                        I have changed this line (line 114)

                        float temperature = static_cast<float>(static_cast<int>((metric ? sensors.getTempC(dallasAddresses[i]) : sensors.getTempF(dallasAddresses[i])) * 10.)) / 10.;
                        

                        into this: (from the example sketch at the build section)

                        float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
                        
                        zboblamontZ Offline
                        zboblamontZ Offline
                        zboblamont
                        wrote on last edited by
                        #31

                        @dzjr said in 2 dallas temp + 4 relays:

                        By the way, if I disconnect one sensor, another sensor is set it place at the controller, if it is connected again then it is back to the original ID.

                        This is where the array method is advantageous, the child-IDs of the chip addresses are fixed consecutively in the array, remove the chip from the line and it's place remains vacant until replaced.

                        1 Reply Last reply
                        0
                        • rejoe2R Offline
                          rejoe2R Offline
                          rejoe2
                          wrote on last edited by
                          #32

                          @dzjr said in 2 dallas temp + 4 relays:

                          MY_TRANSPORT_WAIT_READY_MS

                          This flag is - amongst a lot of other stuff - explained here: https://www.mysensors.org/download/sensor_api_20.
                          So putting it to (default) "0" will keep the node looking for an uplink to the GW until that one is really available. As I don't want that (my nodes have some logic of their own, I want to work independently), I added that. But in case, it's just sensors and so on, I'd recommend to stick with the defaults.

                          Wrt. to the "metric"-topic: Please do always have a look at the entire sketch. In my sketches, typically the metric variable is just initialized once in setup(). Eg. in the array-sketch you'll find that in line 97.
                          If you are looking for a "easy" way to replace single sensors and keeping the original order of the others, have a look at this one.

                          Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                          dzjrD 1 Reply Last reply
                          0
                          • rejoe2R rejoe2

                            @dzjr said in 2 dallas temp + 4 relays:

                            MY_TRANSPORT_WAIT_READY_MS

                            This flag is - amongst a lot of other stuff - explained here: https://www.mysensors.org/download/sensor_api_20.
                            So putting it to (default) "0" will keep the node looking for an uplink to the GW until that one is really available. As I don't want that (my nodes have some logic of their own, I want to work independently), I added that. But in case, it's just sensors and so on, I'd recommend to stick with the defaults.

                            Wrt. to the "metric"-topic: Please do always have a look at the entire sketch. In my sketches, typically the metric variable is just initialized once in setup(). Eg. in the array-sketch you'll find that in line 97.
                            If you are looking for a "easy" way to replace single sensors and keeping the original order of the others, have a look at this one.

                            dzjrD Offline
                            dzjrD Offline
                            dzjr
                            wrote on last edited by
                            #33

                            @rejoe2

                            thank you, now I understand how it works, had it tried without a wait and then the transport did not start well, not all nodes were visible in the MySController, with "wait" in the setup all node's are visible in the controller at a complete restart (in case of power failure)

                            The current method with dallas sensors also works well for me, not me to change the sensors, but to always give the sensors a fixed child id in Domoticz.

                            1 Reply Last reply
                            0
                            • rejoe2R Offline
                              rejoe2R Offline
                              rejoe2
                              wrote on last edited by
                              #34

                              @dzjr Did you also try with the default value ("0") instead of 3000?
                              I'm not familiar wir domoticz, but the need for another wait looks like a strange behaviour to me.

                              Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                              dzjrD 1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                kimot
                                wrote on last edited by
                                #35

                                For low number of DS18B20 and if you have got enough free pins,
                                I suggest use separate Arduino pin for each DS18B20.
                                Then your code is absolute universal and you always know, which pin what measure.
                                Do not matter, which DS18B20 you use.
                                With your method, you must read each DS18B20 signature - hardcoded it, compile and flash.
                                When sensor needs replacement due to malfunction - whole process again.

                                rejoe2R dzjrD 2 Replies Last reply
                                0
                                • K kimot

                                  For low number of DS18B20 and if you have got enough free pins,
                                  I suggest use separate Arduino pin for each DS18B20.
                                  Then your code is absolute universal and you always know, which pin what measure.
                                  Do not matter, which DS18B20 you use.
                                  With your method, you must read each DS18B20 signature - hardcoded it, compile and flash.
                                  When sensor needs replacement due to malfunction - whole process again.

                                  rejoe2R Offline
                                  rejoe2R Offline
                                  rejoe2
                                  wrote on last edited by rejoe2
                                  #36

                                  @kimot This consumes a lot of PINs, so it's a question what kind of trade-off you are looking for.
                                  As the 1Wire sensors have the option to address them correctly, I really like the advantage of reducing bus numbers. Just to remark: I also have at least one node running with 3 1Wire PINs - but each with a different timing :grin: . But if you are just worrying about replacement of single sensors, use something like that: https://github.com/rejoe2/MySensors-Dallas-Address-ChildID-Consistency. That only needs a restart between eacht replacement :smirk: .
                                  Or add OTA features to your nodes...

                                  Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                                  1 Reply Last reply
                                  0
                                  • rejoe2R rejoe2

                                    @dzjr Did you also try with the default value ("0") instead of 3000?
                                    I'm not familiar wir domoticz, but the need for another wait looks like a strange behaviour to me.

                                    dzjrD Offline
                                    dzjrD Offline
                                    dzjr
                                    wrote on last edited by
                                    #37

                                    @rejoe2

                                    Yes i tried is, i disable'd it in the sketch, but than the node's are nog presenting good to MYSController, only the update's are coming true but without the name's, only the first node give his client names.
                                    So ik just use wait in void setup.

                                    0_1546544175576_7235d3d6-97e7-4a34-b31e-5c67ac9b9147-image.png

                                    1 Reply Last reply
                                    0
                                    • K kimot

                                      For low number of DS18B20 and if you have got enough free pins,
                                      I suggest use separate Arduino pin for each DS18B20.
                                      Then your code is absolute universal and you always know, which pin what measure.
                                      Do not matter, which DS18B20 you use.
                                      With your method, you must read each DS18B20 signature - hardcoded it, compile and flash.
                                      When sensor needs replacement due to malfunction - whole process again.

                                      dzjrD Offline
                                      dzjrD Offline
                                      dzjr
                                      wrote on last edited by
                                      #38

                                      @kimot
                                      In this node i can do that, i had copied it from another sketch i used 8 dallas sensors and i just copied that to this sketch.

                                      Perhaps i wil adjust the sketch and hardware.

                                      1 Reply Last reply
                                      0
                                      • MGHaffM Offline
                                        MGHaffM Offline
                                        MGHaff
                                        wrote on last edited by
                                        #39

                                        First of all. thank you guys for all the help! here is what i found out. When testing my hardware i found that alone with the MySensors Dallas sensors sketch i would get readings from my Dallas sensors in serial and at controller. With relay sketch alone i would get All 4 relays working in controller and in serial. But combined no Dallas temp in serial or controller. I rewired with new sensors, Arduino nano, radio! Finally digging through my stuff i found a new board from a batch ordered 2 years ago, wired it up on bread board and wallah! Apparently the last batch or boards i ordered must have not passed quality or damaged in shipping!! Thanks again for the support!! On a way brighter note I have address's assigned to my temp sensors now on all my nodes and have learned so much more about the MySensors network!

                                        1 Reply Last reply
                                        3
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        17

                                        Online

                                        11.7k

                                        Users

                                        11.2k

                                        Topics

                                        113.1k

                                        Posts


                                        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                        • Login

                                        • Don't have an account? Register

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • MySensors
                                        • OpenHardware.io
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular