VirtualWire: How to check a good new message ?

Good Morning,
i've a virtual wire time to time lose some package when I've back the reply.
For example:

a) is the transmitter

b) is the receiver

a) transmit message, b) receive the messagge, then b) transmit back the answer and a) should take the answer and should do something that I've put inside the condition. But happens time to time i didn't receive back the correct message, or the receiver didn't receive the correct message and then didn't transmit back the correct message.

Then I need to put in a place a control for to be sure that each time for sure that each message will be good. Then i think that in someway could be possible check a Crc or CheckSum or some-there else for to be sure that message will be ok. Otherwise the library will be not useful because not stable.

Example Code for Transmit Message:

void TxMsg(byte msg)
   vw_wait_tx(); // Wait until the whole message is gone

Example Code for Receive Message:

void ProcessaMessaggio(byte dev)  // Riceve Msg, calculate dev and write eeprom
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  byte msgrx;
  byte devcalcolata;
  byte stato;  
  int offset2;
  digitalWrite(12, true); 
  vw_wait_rx_max(500); // Wait for a message max 1 second
  // vw_wait_rx();  
  if (vw_get_message(buf, &buflen)) // Non-blocking
         msgrx = buf[i];                  // message received
         devcalcolata = msgrx & 31; // calculate devices
         stato = msgrx & 32;           // calculate the state
  if (devcalcolata == dev && stato == array[dev][12])  // check if the message received is equal to the start message
       // do something
      // do something-else

as you can see is a simply code, just with a check that if the message receive is "good" or "complete" or "correct" then I think will be fine, in this case after I can do a cicle still to transmitt until the message receive will ok or at least for 3-4 times.

could help me please ? otherwise all my project will be a mess because like communication library use virtual wire ... and i need to use ASK library ...


looking the library seems that is this the function where i need to work

vw_get_message(buf, &buflen)

correct ?

The VirtualWire uses a CRC 16-bit checksum.
With noise input, it could be possible that 16-bit is not enough. But that could happen perhaps once a year because of the low bitrate. But I don’t know how to calculate it, it is a guess from what I heard from people developing wireless communication.

If you take a look at the source code, you see that vw_get_message uses the checksum function “vw_crc()” to return ‘true’ or ‘false’.

Messages do get lost, for example if someone turns on something, a pulse might disrupt the message. So you could send a message 3 times or so. If too many messages get lost, the distance could be too far so you could lower the bitrate.

Can you check your code against the examples ?
For example, this ‘msgrx = buf[ i ]’ uses ‘i’, but I can’t see where it comes from. I also don’t know where ‘array’ is declared or how it is used.

Thanks Erdin for the information, so I’ve miss the array definition and a i was declared up in my too long code … :slight_smile: so mainly you can consider buf[0] and array is array of byte …

The fact i send out only one byte, not to much data …

So I’m using Modem that use 1200 bps ASK max then I think that is possible to decrease a little bit …

Right now virtual wire is setup for 1200 bps from the logical stand point you have reason I can try to re-send the message if not correct.

This could be a mess when I use timer … if vw_crc() is inside a vw_get_message I can check directly with it ? what do you think ?

Then if not understood bad could a a bit rate issues ?

Escape way ? Change Modem and Modulation ? which could be an acceptable bit rate ?


The bitrate is fine. I read in the VirtualWire documentation that 1000 or 2000 is a low bitrate.
Is your hardware module maximum 1200 bps ? That is rather low. You could go for 600 bps to see if it makes a difference.

I don't know about a timer. I can't see how that would help.

With one byte at the time, and with a lot over overhead (start conditions, crc) the maximum number of bytes per second is low.
For higher bitrates you could use something like the CC1101 modules. I have them, but I didn't use it yet. So I don't know much about it.

Packages do get lost. That's just how it is. But if the VirtualWire returns valid data, it should be valid. If for example a '3' turns into a '2', then something else is going on. Perhaps the sketch is not correct, or RAM overflow. Do you have a lot of variables or libraries ? Some libraries use a few buffers. That will add up. Or perhaps the VirtualWire buffers and your arrays is too much.

So using the function mentioned before i never loose a package using the software with only 2 arduino ...

I've added to re-transmitt the message 2 times in case of the answer will be different ...

so now i need to do a try with a modem and see what are the "answer" difference with the modem in the middle.