Beispiel #1
0
void loop()
{
    const char *msg = "hello";
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    // Wait for a message
    vw_wait_rx();
    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
	int i;
	const char *msg = "goodbye";

        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("");

	// Send a reply
	vw_send((uint8_t *)msg, strlen(msg));
        digitalWrite(13, false);
    }
}
void loop2()
{

  vw_wait_rx();
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    int port=parse();
    switchState(port);
    Serial.print(port);
    Serial.println();
  }
}
Beispiel #3
0
String RFEasy::_getMessage() {
  uint8_t buflen = VW_MAX_MESSAGE_LEN; //Set buffer length to maximum for VirtualWire
  uint8_t buf[buflen]; //Initialise char array of size buffer length
  String msg = ""; //Variable for storing the received message (with handshake) in
  vw_wait_rx();
  if(vw_get_message(buf, &buflen)) { //Get message from VirtualWire, scaling buffer length down to message size      
    for(int i = 0; i < buflen; i++) { //Loop through all characters in the buffer
      char c = char(buf[i]); //Get character
      msg = msg + c; //Concatenate to string
    }
  }
  return msg;
}