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 20#include"WProgram.h" 21voidsetup(); 22voidloop(); 23voidsetup() 24{ 25 Serial.begin(9600);// Debugging only 26 Serial.println("setup"); 27 28// Initialise the IO and ISR 29vw_set_ptt_inverted(true);// Required for DR3100 30vw_setup(2000);// Bits per sec 31vw_rx_start();// Start the receiver PLL running 32} 33 34voidloop() 35{ 36const char*msg ="hello"; 37uint8_t buf[VW_MAX_MESSAGE_LEN]; 38uint8_t buflen = VW_MAX_MESSAGE_LEN; 39 40// Wait for a message 41vw_wait_rx(); 42if(vw_get_message(buf, &buflen))// Non-blocking 43{ 44int i; 45const char*msg ="goodbye"; 46 47digitalWrite(13,true);// Flash a light to show received good message 48// Message with a good checksum received, dump it. 49 Serial.print("Got: "); 50 51for(i =0; i < buflen; i++) 52{ 53 Serial.print(buf[i], HEX); 54 Serial.print(" "); 55} 56 Serial.println(""); 57 58// Send a reply 59vw_send((uint8_t*)msg,strlen(msg)); 60digitalWrite(13,false); 61} 62} 63 64intmain(void) 65{ 66init(); 67 68setup(); 69 70for(;;) 71loop(); 72 73return0; 74} 75