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@open.com.au) 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#undef int 16#undef abs 17#undef double 18#undef float 19#undef round 20void setup() 21{ 22 Serial.begin(9600); // Debugging only 23 Serial.println("setup"); 24 25 // Initialise the IO and ISR 26 vw_set_ptt_inverted(true); // Required for DR3100 27 vw_setup(2000); // Bits per sec 28 vw_rx_start(); // Start the receiver PLL running 29} 30 31void loop() 32{ 33 const char *msg = "hello"; 34 uint8_t buf[VW_MAX_MESSAGE_LEN]; 35 uint8_t buflen = VW_MAX_MESSAGE_LEN; 36 37 // Wait for a message 38 vw_wait_rx(); 39 if (vw_get_message(buf, &buflen)) // Non-blocking 40 { 41 int i; 42 const char *msg = "goodbye"; 43 44 digitalWrite(13, true); // Flash a light to show received good message 45 // Message with a good checksum received, dump it. 46 Serial.print("Got: "); 47 48 for (i = 0; i < buflen; i++) 49 { 50 Serial.print(buf[i], HEX); 51 Serial.print(" "); 52 } 53 Serial.println(""); 54 55 // Send a reply 56 vw_send((uint8_t *)msg, strlen(msg)); 57 digitalWrite(13, false); 58 } 59}