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. Development
  3. Node sending same value multiple times, why?

Node sending same value multiple times, why?

Scheduled Pinned Locked Moved Development
7 Posts 2 Posters 1.3k Views 2 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.
  • Mark SwiftM Offline
    Mark SwiftM Offline
    Mark Swift
    wrote on last edited by Mark Swift
    #1

    Hi guys,

    I'm having an issue with one of my nodes sending the value multiple times (Mostly 3 or 4 times).

    The sketch:

    /*
      REVISION HISTORY
      Created by Mark Swift
      V1.1 - Started code clean up
      V1.2 - Cleaned up
      V1.3 - Changed sleep to smartSleep to allow for future developments // Cancelled for now as doesn't work so well!
    */
    
    #include <SPI.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    //*** MY SENSORS ******************************************
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    #define MY_NODE_ID 2
    // #define MY_PARENT_NODE_ID 1 // AUTO
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    // #define MY_RADIO_RFM69
    
    // Channel furthest away from Wifi
    // #define MY_RF24_CHANNEL 125
    
    // For crappy PA+LNA module
    // #define MY_RF24_PA_LEVEL RF24_PA_LOW
    
    // Enabled repeater feature for this node
    // #define MY_REPEATER_FEATURE
    
    #include <MySensor.h>
    
    //*** CONFIG **********************************************
    
    // Send temperature only if changed? 1 = Yes 0 = No
    #define COMPARE_TEMP 0
    // Pin where dallas sensor is connected
    #define ONE_WIRE_BUS 3
    // The maximum amount of dallas temperatures connected
    #define MAX_ATTACHED_DS18B20 16
    // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
    OneWire oneWire(ONE_WIRE_BUS);
    // Pass the oneWire reference to Dallas Temperature
    DallasTemperature sensors(&oneWire);
    
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors = 0;
    
    // Define loop time
    #define LOOP_TIME 60000 // Sleep time between reads (in milliseconds)
    
    // Define sensor children
    #define CHILD_ID1 1 // Dallas temperature sensor
    
    // Initialise messages
    MyMessage msg(CHILD_ID1, V_TEMP);
    
    //*********************************************************
    
    void setup()
    {
      sensors.begin(); // Startup up the OneWire library
      sensors.setWaitForConversion(false); // RequestTemperatures() will not block current thread
    }
    
    void presentation()
    {
      sendSketchInfo("Garage Freezer", "1.3"); // Send the sketch version information to the gateway and Controller
      numSensors = sensors.getDeviceCount(); // Fetch the number of attached temperature sensors
      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) // Present all sensors to controller
      {
        present(i, S_TEMP);
      }
    }
    
    void loop()
    {
    
      //*** DS18B20 *******************************************
    
      sensors.requestTemperatures(); // Fetch temperatures from Dallas sensors
      int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); // Query conversion time and sleep until conversion completed
      wait(conversionTime); // Sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) // Read temperatures and send them to controller
      {
        float temperature = static_cast<float>(static_cast<int>((getConfig().isMetric ? sensors.getTempCByIndex(i) : sensors.getTempFByIndex(i)) * 10.)) / 10.; // Fetch and round temperature to one decimal
    #if COMPARE_TEMP == 1 // Only send data if temperature has changed and no error
        if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00)
        {
    #else
        if (temperature != -127.00 && temperature != 85.00)
        {
    #endif
          send(msg.setSensor(i).set(temperature, 1)); // Send in the new temperature
          wait(500); // If set to sleeping, will still have time to wait for OTA messages...
          lastTemperature[i] = temperature; // Save new temperatures for next compare
        }
      }
    
      sleep(LOOP_TIME); // Sleep or wait (repeater)
    }
    
    1 Reply Last reply
    0
    • mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      A serial debug output would be useful for troubleshooting.
      How many connected sensors do you have?

      1 Reply Last reply
      0
      • Mark SwiftM Offline
        Mark SwiftM Offline
        Mark Swift
        wrote on last edited by
        #3

        Just one sensor...

        1 Reply Last reply
        0
        • mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by
          #4

          Only one sensor is presented, and the same sensor ID is used for all 3-4 messages?

          1 Reply Last reply
          0
          • Mark SwiftM Offline
            Mark SwiftM Offline
            Mark Swift
            wrote on last edited by
            #5

            Yes, always '0', sometimes it sends twice, sometimes 3, and the odd time 4.

            I've tried clearing the node, uploading a new sketch, it's odd!

            mfalkviddM 1 Reply Last reply
            0
            • Mark SwiftM Mark Swift

              Yes, always '0', sometimes it sends twice, sometimes 3, and the odd time 4.

              I've tried clearing the node, uploading a new sketch, it's odd!

              mfalkviddM Offline
              mfalkviddM Offline
              mfalkvidd
              Mod
              wrote on last edited by mfalkvidd
              #6

              How close in time are the messages sent? If it is >500ms between the messages, there is probably something wrong with the loop or sleep (but they look fine to me).

              If the time between messages is <100ms maybe the ACK doesn't reach the sensor node so it resends the message.

              A serial debug output would show what is happening.

              1 Reply Last reply
              0
              • Mark SwiftM Offline
                Mark SwiftM Offline
                Mark Swift
                wrote on last edited by
                #7

                I'll try a debug when I'm home, but this is a remote node using MYS firmware...

                See MYS screenshots here: http://postimg.org/gallery/8ynl0jw/c4dcd695/

                1 Reply Last reply
                0
                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