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;
And on the receiver:
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
//ESTADO BOTON
int estadoBoton = 0;
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);
//Pin entrada boton
pinMode(2,INPUT);
}//end setup
void loop()
{
const char *msgNumero = "000456C;";
const char *msgSenyal = "2;";
const char *msgBateria = "5;";
const char *msgEstado = "2";
////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);
strcpy (&msgTotal[ strlen(msgTotal) ], msgEstado);
//capturo estado del boton
estadoBoton = digitalRead(2);
if (estadoBoton == LOW) {
//boton sin apretar.Nada
} else {
//boton apretado. Envio
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);
//estadoBoton = LOW;
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
