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