RF Link Module Acknowledge Message

Hi everybody.
I’m trying to work with these RF modules:

And so far everything is great, I’ve been using the VirtualWire library and it works like a charm.

The thing is, I’m trying to develop an algorithm that would allow me to have an Acknowledge message. Of course, I’m using a TX and RX module for both sides of the communications.
Basically, what I mean is:
Equip 1 sends a message to Equip2
Equip 2 receives
Equip 2 sends an ACK message to Equip1
Equip1 receives.

So, if initially, Equip1 sends a message and doesn’t get the response, it would treat it as a Lost Package.

I have this code in Equip1 (the transmit and recieved functions are the default examples of the VirtuaWire library)

void loop()
{
  while(_txCount != 5) // in the transmit() function, I have a counter that increases each time it sends the message, I want it to send it 5 times
  {
    transmit();
  }
  
//After transmitting, I wait for a response message in the following 0.362 seconds (which is the time it takes to send 5 messages):
  unsigned long varT= millis();
   unsigned long varInit=0;
  while(varInit< varT+362){      
     received();  //enter receiver mode
     varInit=millis();
  }

In the other side I have:

void loop()
{
   if(received() == 1){   //If I got a package
     delay(292); //wait for this time to send a message
  unsigned long varT= millis();
   unsigned long varInit=0;
  while(varInit< varT+362){       //will transmit for 0.362 seconds
     transmit();
     varInit=millis();
  }

The thing is, it works, but I’m not very good at coding, and I was wondering if there was a better approach to do this?

I presume you a transmitter and receiver at both ends?

If it works, in what way do you think it could be improved?

I don't understand why you transmit more than once at any one time. Surely it is only necessary to re-transmit if there was a problem with the first attempt. Doing it one step at a time should eliminate a lot of the waiting if the first transmission is OK.

I have something similar working with a pair of 2.4GHz transceivers and they seem to communicate (over a very short distance) with no problems.

You don't seem to be doing any check to ensure that what is received is sensible. Adding a checksum byte may be useful.

...R

Yep, as I stated I have a transmitter/receiver pair at both ends.

I had not thought of sending it only once and check everytime if the message was received. But, woudln't I loose more time like that?
Send it once, waits...not received
Send it another time, waits...not received
Send it a third time, waits...received

As for the CRC, the VirtualWire library already does that, doesn't it?

By the way, thanks for answering.

I don't follow your reasoning about losing more time by acknowledging each transmit. That may happen if there is a need for a lot of retries but it will be much quicker if it is right first time, which is what I would expect.

I haven't used VirtualWire so I didn't realize it included a CRC.

And (though it's of little consequence) your OP does not state "I have a transmitter/receiver pair at both ends" :slight_smile:

...R

[quote author=Rainier9 link=topic=175953.msg1305858#msg1305858 date=1373127018]

The thing is, I'm trying to develop an algorithm that would allow me to have an Acknowledge message. Of course, I'm using a TX and RX module for both sides of the communications.
}

That's the OP. I'll try to deliver the ACK as soon as the first message arrives and see how that will go.

Thanks.

Oops - I hadn't seen that in spite of reading it two or three times looking for it ...

I ran into a problem with the system I'm developing and the experience may be useful to you. My original sketch started listening for the ack more-or-less immediately after the message was transmitted.

When I modified the sketch towards the final version I want I kept getting timeouts rather than receiving the acknowledge message (I'm not using auto acknowledge as it doesn't suit my application which will have several listeners). Eventually I realized the problem was that in the new version there was sufficient delay before the receiver was switched on for the acknowledge message to be missed. Then it was easy to reorganize the sketch to start listening for the acknowledge message earlier. It's also essential to listen long enough before deciding the acknowledge won't ever come.

...R

Thanks for answering!

Given the fact that the response comes varies with the distance, the last part of what you said is the hardest one of the process. Right now I have 1 Second to decide to consider the package lost. Although it may vary after some testing.

The distance won't affect the time for the radio signals to propagate unless it is measured in miles - 300 million metres per second.

...R