Multiple Relays Spanned Across Nodes



  • Hello All -
    I ran in to an interesting issue over the weekend that I'm hoping I can get some help with.

    I have two identical nodes/sensors. Each Arduino has a water pulse meter and a relay (to control an actuator/valve).

    I used the same forloop logic found in the relay example at: http://www.mysensors.org/build/relay

    However, the relay was not discovered/added by Vera on the second node. The only way I could get it to include was if I started the forloop with sensor=2. This will give the first relay on the second node an ID of "2". This seemed like an odd necessity to me as it was coming from a different sensor/node.

    Is this expected behavior?

    for (int sensor=2, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
    // Register all sensors to gw (they will be created as child devices)
    gw.present(sensor, S_LIGHT);
    // Then set relay pins in output mode
    pinMode(pin, OUTPUT);
    // Set relay to last known state (using eeprom storage)
    digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
    }

    All is well and both nodes are up and functioning. It just seemed like an ugly way to handle this situation and could cause trouble down the road as I add relays/sensors.



  • Any thoughts? It's working OK with this hack but will not scale if I start adding more (10+) relays.


  • Admin

    Are you sure you hadn't previously deleted a device with the same id/child id?

    Vera sometimes keeps deleted devices in some hidden cache which is not cleared until you hard-reboot the box. If you try to add a new device with the same id it won't succeed until this cache is cleared.



  • @hek I've rebooted several times over the past few days while working on other sensors. However, your idea sounds valid.

    So you're saying that I should be able to have multiple sensors running the example relay sketch on my network without issue, correct?

    This should be fine because each individual node/arduino gets it's own ID so the relays on each Arduino should not conflict with its neighbors.


Log in to reply
 

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