Project

General

Profile

Relay sample from blog is switching on and off with datapackets from other nodes

Added by WilcoE over 6 years ago

Hello,

im using the following script for my relay’s, i found this script on the blog.

#include 
#include 

Port relays (1);

void setup () {
    rf12_initialize(17, RF12_868MHZ, 5);

    relays.digiWrite(0);
    relays.mode(OUTPUT);
    relays.digiWrite2(0);
    relays.mode2(OUTPUT);
}

void loop () {
    if (rf12_recvDone() && rf12_crc == 0 && rf12_len == 2) {
        relays.digiWrite(rf12_data[0]);
        relays.digiWrite2(rf12_data[1]);
    }
}

For some reason the relays are switching on and off when there are other packets broadcasted.
Is it possible to make this code to only accept packets from node 1?


Replies (8)

RE: Relay sample from blog is switching on and off with datapackets from other nodes - Added by WilcoE over 6 years ago

ok, i know what the problem is.
And now i also know why my doorbell is sometime middle of the night playing music.

My AquaNode https://github.com/WilcoE/aquarium\_controller/blob/master/aquarium\_controller.ino
send the following packet in the air: L 20:21:23.257 /dev/ttyUSB0 OK 1 250 0

The relay script above (begin of topic) respond on this packet.

know anyone a solution for this? JCW? LightBulb?

RE: Relay sample from blog is switching on and off with datapackets from other nodes - Added by WilcoE over 6 years ago

ah. i think i solved the problem.

rf12demo sketch on my housemon server is also running on node 1
and my aquaNode also on 1, i think that’s not a good combination.

Need some more testing

RE: Relay sample from blog is switching on and off with datapackets from other nodes - Added by WilcoE over 6 years ago

thats not a solution :(
now running rf12demo sketch on node 31 but still problems

my aquaNode is sending with ID 1
L 10:44:34.093 /dev/ttyUSB0 OK 1 243 0

And my relay node is also getting this packet on node 17

RE: Relay sample from blog is switching on and off with datapackets from other nodes - Added by bgreene over 6 years ago

I had the same problem with nodes misbehaving because they were picking up signals from the heating controllers around the house. Having “things” turn on/off when they shouldn’t was an absolute no, no. I solved the problem by always sending a payload which contains a magicid, a datasize, data and finally another magicid (to be sure, to be sure!). At the receiver, I check the magicid and check the datasize matches rf12_len and check the final byte in the data packet is also my magicid. It means sending a bit more data each time but it has proven rock-solid.

RE: Relay sample from blog is switching on and off with datapackets from other nodes - Added by WilcoE over 6 years ago

bgreene wrote:
> I had the same problem with nodes misbehaving because they were picking up signals from the heating controllers around the house. Having “things” turn on/off when they shouldn’t was an absolute no, no. I solved the problem by always sending a payload which contains a magicid, a datasize, data and finally another magicid (to be sure, to be sure!). At the receiver, I check the magicid and check the datasize matches rf12_len and check the final byte in the data packet is also my magicid. It means sending a bit more data each time but it has proven rock-solid.

ok, glad that im not the only one with this problem.
Strange that nobody else has this problem, JCW has many nodes running in his house.
And i don’t think i got this problem

RE: Relay sample from blog is switching on and off with datapackets from other nodes - Added by jcw over 6 years ago

You’re broadcasting, so everyone will receive and accept the packet.

Try sending to “RF12_HDR_DST | 1” to make sure only node 1 accepts your packet.

RE: Relay sample from blog is switching on and off with datapackets from other nodes - Added by WilcoE over 6 years ago

jcw wrote:
> You’re broadcasting, so everyone will receive and accept the packet.
>
> Try sending to “RF12_HDR_DST | 1” to make sure only node 1 accepts your packet.

thanks, will try that.

RE: Relay sample from blog is switching on and off with datapackets from other nodes - Added by lightbulb over 6 years ago

@WilcoE

You say your AQUA Node output gets picked up by your relay node.

Your relay node listens for 2 byte packets and will respond to any broadcasts “that have 2 byte packets”

As jcw indicated, send a directed packet and only AQUA Node ID will process. Also as you
have done, keep the check for packet length, as that acts as another safeguard to random data.

That being said, you seem to have some conflicting nodes setups. As you indicated, make sure
all your nodes are in the accepted range of 0…31, however 0 and 31 were/are special ID’s, so best for ‘normal’ nodes to sit between 1..30. (jcw will correct if thats wrong)

I was also going to ramble on about using other radio groups to give you more ‘broadcast’ bands but thats a longer post and probably best covered by @jcw.

I keep a little google spreadsheet of Freq/Group/NodeID/other stuff to help me remember.
e.g.

868 212 1 (Running RF12Demo.10 (ACK Mode) connected to ttyAMA0 on helios )
868 212 2 (Running AQUA.1 on tank 1…sends to 868/212/*)
868 212 3 (Running TankRelay.1 on tank 1….sends to 868/212/1)

—lightbulb

    (1-8/8)