# Get signal strength for RF 433 modules (without RSSI). Virtual Wire SOLVED

Hello community!
I am a newbie with Arduino, electricity and programming. I am developing a network of wireless sensors comprise:
-A gateway equipped with Arduino Uno, a GPRS (SIM900) module and an RF receiver 433 Mhz (http://www.bricogeek.com/shop/modulos-radiofrecuencia/370-kit-link-rf-433-mhz.html).
-Several sensors equipped with Arduino Micro, push a button and a transmitter RF 433 Mhz.
The sensors communicate with the gateway through this pair of transmitter / receiver RF433 Mhz low cost, and using Virtual Wire library.
My question is, how can I get the signal quality RF communication? … I need to print a value (eg in%) of this value, so that the farther the receiver is from the transmitter, the lower this value.
I found some (very little) information on this topic online. There is a system called RSSI measurement, but RF modules low cost do not have this feature.
In a google group (https://groups.google.com/forum/#!topic/virtualwire/iWwh-FbCOns), I found a post that suggest several methods:

• "One thought is to try You Might send a counter of the number of times your Transmitted had sent data, and in the receiver, count the number of packets you received You can calculate (# received / sent #) as a rough indicator. of signal strength. "Mr. James Hamilton.
This expert suggested a code like this because “…You’ll need to make sure you put your counter in the tx buffer and extract it from the rx buffer correctly. The buffer stores one byte at a time, but an int is two bytes”:

transmiter:
tx_buf [0] = (counter >> 8) & 0xff;
tx_buf [1] = counter & 0xff;

unsigned int counter = (rx_buf [0] << 8) | rx_buf [1];

but … I am unable to implement it in my code.
Could some kind soul tell me how to fix this? Thank you very much in advance.

Under the code of my sketch in IDE Arduino:

Transmiter code:

``````/#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round
void setup()
{
Serial.begin(9600);	  // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_setup(2000);	 // Bits per sec
vw_set_tx_pin(7);
pinMode(2,INPUT);
}//end setup

void loop()
{
const char *msgNumero = "000456C;";

const char *msgSenyal = "2;";

const char *msgBateria = "5;";

////msgTotal concateno todos los Char con info del sensor para pasarlo al pulsar sensor...
char msgTotal[15];
strcpy (msgTotal, msgNumero);
strcpy (&msgTotal[ strlen(msgTotal) ], msgSenyal);
strcpy (&msgTotal[ strlen(msgTotal) ], msgBateria);

} else {
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msgTotal, strlen(msgTotal));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
delay(5000);//60000ms espero 60 segundos a volver a disponer
}
}//end loop
``````

…and Reciver code (I omit the code relating to GPRS to clarify):

``````#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round
void setup()
{
Serial.begin(9600);	// Debugging only
Serial.println("setup");

// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000);	 // Bits per sec
vw_set_rx_pin(7);
vw_rx_start();       // Start the receiver PLL running
}

void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;

digitalWrite(13, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.
Serial.print("Got: ");

for (i = 0; i < buflen; i++)
{
Serial.print(buf[i], HEX);
Serial.print(" ");
}
Serial.println("");
digitalWrite(13, false);
}
}
``````

Thanks and regards the whole community from Barcelona, and please, be patient whith me, I´m totaly newbie!

Xavi

EDIT: Check solution from Sr. Peter_n

The links don't work, and if I fix the html-address, the bricogeek.com doesn't show a picture. You can add photos and drawing to a post. When you type a post, at the lower left is a "Additional Options...". Use that to attach picture.

Sparkfun has a RF receiver with RSSI signal. https://www.sparkfun.com/products/10533 But most of those receivers don't have it.

You transmit text with the VirtualWire library. I think it is easier to transmit integers and bytes.

In the transmitter you transmit an extra number and increment it with every transmission. For example a number 00...99. Or with integer: a byte 0...255 or an integer. Let's do that 00...99. Make a global integer, and let it count from 0 to 99. Convert it to text of 00 to 99 and add it to the string. In the receiver remember the previous number, and if you receive 62 and the previous number was 43, you have missed 18 transmissions.

Wooow!
Thanks Peter for responding so fast! ok …, i put a image of 433 RF modules that I bought.
I think justly, that this offer is what I’m looking for. Now I’m trying to do some tests by sending some packets to count on arrival, but I can not do it. What you you comment is what I am looking for and the solution to the problem. Could you please give an example or show me a site where you can see a similar example? …or can you explain me who to add an extra number and increment it with every transmission? ¿Can i remeber many numbres for diferents emiters in the reciver?
The tests I’m doing now:
-In transmitter I put a loop that sends 100 packets.
-At the receiver want to count how many of these packages have arrived safely.
It is an approach to your solution, but I think it’s less successful. I have not gotten it to work I explain this. If I can solve the code, I’ll put it in the post.

Thank you very much and greetings!

PD: Sorry for translation! …I´m use google

PD2: I think you’ve explained very well, but from what I read the bad English, and complicated (for me) topic, I find it a bit difficult to implement this solution you offer me. Thanks anyway! I’ll try!

I don't understand Spanish, so you have to use Google Translate :sweat_smile:

Sending 100 packets and counting howmany you received is indeed a simple test. Transmit maybe 2 to 10 packets per second, using a delay.

``````int count = 0;
...
void setup()
{
...
}

void loop()
{
...
if (vw_get_message(buf, &buflen)) // Non-blocking
{
...
count++
Serial.print ("count=");
Serial.println (count);
}
}
``````

Well!, Thank you very much for such a high altruism are pleased to see that there are people who help others. This evening I will try the code you've passed me see if I can implement it. To send 2 to 10 packets per second second I think I must do something like this?

``````...
void setup()
{
...
}

void loop()
{
...
const char *msgChar =  "A";
vw_send((uint8_t *)msgChar, strlen(msgChar));
delay (1000);
}
``````

Again thank you very much and I sent a greetings and a virtual beer! as thanks.

Xavi

Yes, or you could send exactly 100 packages with a delay in between of 15 seconds.

Transmitter:

``````void loop()
{
...
const char msgChar[] =  "A";

for (int i = 0; i < 100; i++)
{
vw_send((uint8_t *)msgChar, strlen(msgChar));
delay (300);
}
delay (15000);
}
``````

I'll try to do a test and expose the results.

Thank you very much for spend your time to help me. You are very helpful and I appreciate it tons.

Now i

Xavi

Wowww! I am impressed! That effectiveness! Mr. Peter_n has found the solution. To simulate RSSI for cheap modules, you can make a system that: -A specific number of packets sent in a specific time from the emiter. -Then are received (in receiver) and the number of packets received is counted. -The number in the counter of the receiver indicates the number of packets received at that time especific in emiter. -The fewer packages (counter value) is received, the sender will be further given that at that specific time were able to send some packages.

Thank you very match Peter_n! Your are great! Your code and rationing are genius! View her code in the post above!

Xavi!