Author Topic: Communication only works one way regardless of device  (Read 15685 times)

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Communication only works one way regardless of device
« Reply #15 on: April 18, 2016, 02:58:55 PM »
Have you tried changing the RSSI threshold of your receiver when it's supposed to be receiving the ACK? A possible problem is that this is set way too low and is triggering on noise. If that happens the AFC and AGC values latch onto the noise source which may not be at exactly the right frequency and power, and the receiver fails to receive a legitimate packet. Try setting the threshold to something a few 10s of dB below the expected RSSI stength to start with.
Mark.

kolaf

  • NewMember
  • *
  • Posts: 30
  • Country: no
Re: Communication only works one way regardless of device
« Reply #16 on: April 18, 2016, 04:57:51 PM »
I will be happy to try that once I figure out how, but I am not sure how this fits the main observation. The gateway is always able to receive messages from the node, while the node almost never receive anything from the Gateway (either acknowledgements or regular messages). This is the case regardless of which device are used as gateway or node, without physically touching them in between uploading the sketches.

Using a third node as a promiscuous listener I can confirm that the Gateway is actually sending the acknowledgements. I think this rules out any frequency issues and leaves me with a library issue, or a hardware issue (although I have tried this with four different devices). I even tried running two nodes talking to each other without success, and I also added the transmission part of the buffer from the node to a separate gateway to see if this works. I actually got a few more messages through, but this may just be coincidence.

Could it be a memory issue of some sort?

kolaf

  • NewMember
  • *
  • Posts: 30
  • Country: no
Re: Communication only works one way regardless of device
« Reply #17 on: April 19, 2016, 02:57:03 PM »
For what it's worth I tried changing the RSSI sensitivity by changing the value in the following line to 120. I saw no change in behaviour.

Code: [Select]
    /* 0x29 */ { REG_RSSITHRESH, 220 }, // must be set to dBm = (-Sensitivity / 2), default is 0xE4 = 228 so -114dBm

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Communication only works one way regardless of device
« Reply #18 on: April 19, 2016, 04:01:19 PM »
I'm going to throw something out there, I noticed on my setup (my own code, I don't use any libraries) that the receiver would refuse to decode the first packet it sees after transitioning from standby mode to RX mode. It was strange because it saw an RSSI interrupt of the correct value and at the correct time, but did not detect an address match or get a packet received for the first packet. Subsequent packets were fine. I changed my code to go into sleep mode rather than standby and the problem went away.
Somewhere in the library code there's a function that maps idle to either standy or sleep, could you change it to sleep and see what happens? My theory is that transitioning from standy mode to RX mode doesn't fully reset the receiver, but transitioning from sleep to RX mode does. After the first packet has started to be received (which doesn't complete) the receiver is then able to receive subsequent packets. This may be what you're seeing.
Mark.

kolaf

  • NewMember
  • *
  • Posts: 30
  • Country: no
Re: Communication only works one way regardless of device
« Reply #19 on: April 20, 2016, 01:37:11 AM »
I like the theory. I couldn't find the standby versus sleep function you talked about, so as a first attempt I simply sent to acknowledgements right after each other for every received packet. The first time I tried this I got a success rate of about 35% of acks received. Sadly, after playing around with the setMode function to try to map all the standbys to sleep I was not able to reproduce this. Not even after removing all my changes to the library and just going back to the two acknowledgements was I able to get the same results again. I guess this breaks the theory a bit.

Also, for every third packet the Gateway receives from the node, it sends a packet in return waiting for an acknowledgement. If your theory was correct, then the node should always receive this packet since it was sent just after the acknowledgement (with a delay of 4). It almost never receives this packet. Is there an easy way to see whether the radio is receiving anything? It would be nice to see whether it sees the ACK signal at all and is just unable to capture the full packet as you indicate.

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Communication only works one way regardless of device
« Reply #20 on: April 20, 2016, 04:03:01 AM »
If you look in RF_RF69.h you'll see a reference to function
void setIdleMode(uint8_t idleMode);

This function sets the idle state. If you add the following call during intialization you'll set the idle mode to sleep:
setIdleMode(RH_RF69_OPMODE_MODE_SLEEP);

From that point onwards, when the radio is neither transmitting or receiving it'll be in sleep instead of its default state of standy. This is the only change you need to make, I'd recommend going right back to the beginning and reloading a fresh system and make just that change on both the server and the node (it's important to do it on both).

Mark.

kolaf

  • NewMember
  • *
  • Posts: 30
  • Country: no
Re: Communication only works one way regardless of device
« Reply #21 on: April 20, 2016, 06:11:53 AM »
I see no declaration of this function in the file you mention. Does this mean that I have the wrong version of the library? I downloaded it from https://github.com/LowPowerLab/RFM69 only yesterday.

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Communication only works one way regardless of device
« Reply #22 on: April 20, 2016, 09:01:33 AM »
Oh, I've been looking at RadioHead! :-( In that there's an idle mode defined which can be either sleep of standby. Felix's libray has simplified things, actually looks much cleaner.

Can I suggest then that the #define of RF69_MODE_STANDBY be changed to the same value as RF69_MODE_SLEEP as a temporary hack? Whenever it's put into standby it should instead be put into sleep. This may have unforeseen consequences but I'm hoping the sequencer will deal with it properly.

Mark.

kolaf

  • NewMember
  • *
  • Posts: 30
  • Country: no
Re: Communication only works one way regardless of device
« Reply #23 on: April 20, 2016, 10:33:56 AM »
I already tried that, replacing the reference to STANDBY with SLEEP in setMode. It did not have any appreciable effect.

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Communication only works one way regardless of device
« Reply #24 on: April 20, 2016, 10:46:24 AM »
OK, that probably puts that theory to bed then. Pity, because what I saw was very similar to what you are seeing. It could still have been a red herring due to something I was doing wrong, but I had a scope on it and pretty sure it was failing to see an address match even though it got an RSSI interrupt at the right time and right value. Looks like you'll have to dig deeper.
Mark.

kolaf

  • NewMember
  • *
  • Posts: 30
  • Country: no
Re: Communication only works one way regardless of device
« Reply #25 on: April 20, 2016, 01:08:33 PM »
Okay, now just going crazy.

Just for laughs I tried again to change from standby to sleep mode. At the beginning of the setMode function I entered the following code block.

Code: [Select]
if (newMode == RF69_MODE_STANDBY) {
    newMode = RF69_MODE_SLEEP;
  }
 

This time sending messages from the node to the Gateway and receiving acknowledgements seems to work almost every time. The only time it does not work is when the Gateway sends a message in return after every third message it receives from the node. I think this is some kind of race condition were both devices wait for acknowledgement from the other one. This means that the node usually does not receive the message being sent from the gateway.

Still, I call this progress :-)

Edit: I think some of the problems with the messages from the gateway was that I had turned on retries for the message from the gateway to the node. I remove this, and I get more successful messages from the gateway to the node. I also get rid of every third message from the node to the Gateway being unacknowledged. now, if I only could get more reliable messaging from the gateway to the node, everything would be perfect :-)
« Last Edit: April 20, 2016, 01:15:00 PM by kolaf »

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Communication only works one way regardless of device
« Reply #26 on: April 20, 2016, 04:12:15 PM »
OK, that's progress. You have done this hack to both the gateway and the node right? Anyhow, can you confirm that just taking out that hack causes it to fail again, because if you can this represents a significant bug. Two of us will have seen it, and Felix should be made aware of this.

Any change in posting the code that does the sending and receiving on both the gateway and node? I'm curious about the race condition and whether there's any timing issues there.

Mark.

Edit: And just to confirm it's not the little delay that your code added maybe put a small delay in where you put the hack, if that also fixes it we're chasing ghosts.
« Last Edit: April 20, 2016, 04:17:27 PM by perky »

kolaf

  • NewMember
  • *
  • Posts: 30
  • Country: no
Re: Communication only works one way regardless of device
« Reply #27 on: April 21, 2016, 02:45:23 AM »
Okay, I have tested the following combinations:

  • Without the hack to setMode: Acknowledgements are never received, nor any other message from the gateway to the node.
  • With a delay of 1 or 5 in setMode in place of the hack: No change, no acknowledgements are received.
  • With the hack only at the node: Some acknowledgements are received by the node, but still less than half.
  • With the hack on both devices: all messages from the node to the Gateway are acknowledged, but the messages from the gateway to the node are seldom acknowledged.

You can find the sketches for the node and gateway in the examples folder in the RFM69 library. I have not altered the sketches other than setting the correct frequency and high power mode. The fix consists of changing void RFM69::setMode(uint8_t newMode) in RFM69.cpp by inserting

Code: [Select]
if (newMode == RF69_MODE_STANDBY) {
    newMode = RF69_MODE_SLEEP;
  }

at line 144. The resulting full function is included below.

It would be great if you could replicate my results.

I'm a bit confused by why this does not solve the problem with the messages that are sent from the gateway to the node. The message is sent 4 ms after the acknowledgement to the last message, so they should arrive in order at the node, and before the node has time to send a new message to the Gateway.

Code: [Select]
void RFM69::setMode(uint8_t newMode)
{
  if (newMode == RF69_MODE_STANDBY) {
    newMode = RF69_MODE_SLEEP;
  }
//  delay(5);
  if (newMode == _mode)
    return;

  switch (newMode) {
    case RF69_MODE_TX:
      writeReg(REG_OPMODE, (readReg(REG_OPMODE) & 0xE3) | RF_OPMODE_TRANSMITTER);
      if (_isRFM69HW) setHighPowerRegs(true);
      break;
    case RF69_MODE_RX:
      writeReg(REG_OPMODE, (readReg(REG_OPMODE) & 0xE3) | RF_OPMODE_RECEIVER);
      if (_isRFM69HW) setHighPowerRegs(false);
      break;
    case RF69_MODE_SYNTH:
      writeReg(REG_OPMODE, (readReg(REG_OPMODE) & 0xE3) | RF_OPMODE_SYNTHESIZER);
      break;
    case RF69_MODE_STANDBY:
      writeReg(REG_OPMODE, (readReg(REG_OPMODE) & 0xE3) | RF_OPMODE_STANDBY);
      break;
    case RF69_MODE_SLEEP:
      writeReg(REG_OPMODE, (readReg(REG_OPMODE) & 0xE3) | RF_OPMODE_SLEEP);
      break;
    default:
      return;
  }

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Communication only works one way regardless of device
« Reply #28 on: April 21, 2016, 05:48:34 AM »
I'll take a look at the sketch. One difference though is the set mode routine waits for mode ready only when coming out of sleep. Given we're now sleeping now rather than using standby we're going to be waiting for mode ready more often. My code though always waited for mode ready when changing modes regardless of previous mode and I still saw the issue, so I suspect it isn't relevant but worth pointing out.
Mark.

kolaf

  • NewMember
  • *
  • Posts: 30
  • Country: no
Re: Communication only works one way regardless of device
« Reply #29 on: April 22, 2016, 01:40:58 AM »
It seems there are some issues with the going to sleep instead of standby. RSSI at the receiver is always reported at -128, which means that the ATC feature will most probably not work.

I'm also having some problems with range, but I am not yet sure if this is related to the fix. I have the HW versions at 868 MHz, but only get around 100 m of range from a node mounted on the first floor in a wooden house. I use the simple wire antenna with a length of just under 9 cm. It might be that I should switch to some better antennas. I will report when I figure out if the range issue is related to the fix at all.

Is there another way we can "reset" the radio so that it doesn't lose the first packet it receives?
« Last Edit: April 22, 2016, 06:51:59 AM by kolaf »