1// server.pde 2// 3// Simple example of how to use VirtualWire to send and receive messages 4// with a DR3100 module. 5// Wait for a message from another arduino running the 'client' example, 6// and send a reply. 7// You can use this as the basis of a remote control/remote sensing system 8// 9// See VirtualWire.h for detailed API docs 10// Author: Mike McCauley (mikem@airspayce.com) 11// Copyright (C) 2008 Mike McCauley 12// $Id: server.pde,v 1.1 2008/04/20 09:24:17 mikem Exp $ 13 14#include <VirtualWire.h> 15 16void setup() 17{ 18 Serial.begin(9600); // Debugging only 19 Serial.println("setup"); 20 21 // Initialise the IO and ISR 22 vw_set_ptt_inverted(true); // Required for DR3100 23 vw_setup(2000); // Bits per sec 24 vw_rx_start(); // Start the receiver PLL running 25} 26 27void loop() 28{ 29 const char *msg = "hello"; 30 uint8_t buf[VW_MAX_MESSAGE_LEN]; 31 uint8_t buflen = VW_MAX_MESSAGE_LEN; 32 33 // Wait for a message 34 vw_wait_rx(); 35 if (vw_get_message(buf, &buflen)) // Non-blocking 36 { 37 int i; 38 const char *msg = "goodbye"; 39 40 digitalWrite(13, true); // Flash a light to show received good message 41 // Message with a good checksum received, dump it. 42 Serial.print("Got: "); 43 44 for (i = 0; i < buflen; i++) 45 { 46 Serial.print(buf[i], HEX); 47 Serial.print(" "); 48 } 49 Serial.println(""); 50 51 // Send a reply 52 vw_send((uint8_t *)msg, strlen(msg)); 53 digitalWrite(13, false); 54 } 55}