Update NODEID and NETWORKID on the fly [SOLUTION]

Started by ColinR, September 01, 2014, 09:28:56 PM

ColinR

Hello,

I would like to update the NODEID and NETWORKID after radio has been instantiated.

If I soft reset, this works fine, but I would ideally like to be able to simply set these properties.

The suggestion so far has been the following:
Quote- to set new nodeID just call radio.setAddress(newNodeID);
- to set new networkID call radio.writeReg(REG_SYNCVALUE2, newNetworkID);

I haven't tested the setAddress call yet, but I found this fine in the RFM69 library. The NETWORKID set errors on compile, however, as REG_SYNCVALUE2 has not been declared. I'm digging farther into the source now, but I'm sure there's an easy solution that a C++ neophyte will take forever to find.

Thanks,
C
CuPID Controls :: Open Source browser-based sensor and device control
Interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

ColinR

Great success.

#include <RFM69registers.h>

// to update NODEID
    radio.setAddress(NEWNODEID);

// to update GATEWAYID
radio.writeReg(REG_SYNCVALUE2, NETWORKID);

I suppose I could just substitude 0x30 for REG_SYNCVALUE2, huh?

C
CuPID Controls :: Open Source browser-based sensor and device control
Interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

TomWS

Quote from: ColinR on September 01, 2014, 09:44:15 PM
Great success.

#include <RFM69registers.h>

// to update NODEID
    radio.setAddress(NEWNODEID);

// to update GATEWAYID
radio.writeReg(REG_SYNCVALUE2, NETWORKID);

I suppose I could just substitude 0x30 for REG_SYNCVALUE2, huh?

C
Looking at the code, I'm not sure that radio.setAddress really does anything useful with the RFM69 registers because I believe this register is not used (no HW address filtering is enabled).  However, the method does update the _address private variable which is used in the SENDER ID field in the transmitted frame, hence does update the 'nodeId'.

I've wanted to update the Network ID dynamically as well to set up my 'area' with multiple independent 'networks', but still have an 'uber' Gateway be able to switch between networks.  The writereg function is ultimately the correct function to use, however, to keep the API at a higher level, it would be best IMO to extend the interface by adding a method to 'setNetwork', rather than mucking around with the RFM69 registers directly.  The prototype for this would be virtually the same as setAddress as in:
   
void setNetwork(byte networkId=1);


And would be trivial to add to the RFM69 library (as I've done in my version) with:
void RFM69::setNetwork(byte networkID)
{
	writeReg(REG_SYNCVALUE2, networkID);
}



I don't think it's necessary to have a private variable to store the Network ID simply because the RFM69 code wouldn't use it any other place and it's simple enough to retrieve using readReg()...

My question to you is whether you've been able to test switching network on the fly and found any 'surprises'?

Tom


Felix

No problem, I will add this function to my next release. Changing the network ID on the fly should not be an issue.