SCENARIO: SERVER AND ONE OR MORE CLIENT CONNECTED USE VIRTUAL WIRE
SCOPE: SYNCRONIZE TRASMISSION AND RECEPTION BETWEEN SERVER & CLIENT/S
SO, DUE THE FACT SEND OUT A CHAR FOR EXAPLE "A" THEN THE CLIENT THAT IS LISTENING MODE RECEIVED "A" IF THE MESSAGE IS FOR THE CLIENT REPLY "CLIENT A OK" TURN CLIENT A LED
THE FOR THE FIRST PART CHECK IF THE MESSAGE IS FOR THE CLIENT AND THEN SEND OUT ANSWER IS SIMPLY ... BUT THE SERVER SEEMS DOESN'T RECEIVED NOTHING,
IS THERE SOMEONE THAT USE VIRTUAL WIRE IN BOTH RECEPTION AND TRASMISSION MODE WITHOUT ISSUES ?
here you are the code for trasmitt, so at home I've send out the data "a" using a key pad but is the same the logical:
#include <VirtualWire.h>
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_setup(1200); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
const char *msg = "a";
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
// Wait at most 200ms for a reply
if (vw_wait_rx_max(200))
{
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
// 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("");
}
}
else
Serial.println("Timout");
}
and here the code of the receiver without check if the char if the char "a" is for the client but it is the same ... just for semplify to you ... is there sometiming to wait for syncronize both ?
#include <VirtualWire.h>
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_setup(12000); // Bits per sec
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);
}
const char *msg = "Client 1 arrived";
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
}