Wind meter(Direction and Speed) through xively, partially working. on Uno R3.

New to the forum and Arduino platform :grin:

The code has been merged from official Xively library and this projecthttp://www.qsl.net/on7eq/projects/arduino_davis.htm

Wind direction is posting to xively as it should, but when the reed switch code is compiled into it then it seems like the board is freezing up.

Is there any technically limitation on running this merged code together, especially regarding the reed switch interrupt.

Board : Uno R3 w/Wiznet ethernet shield.

Dan.

WindXively.ino (5.29 KB)

 convert:       // Convert to 360°  
  
  if (Direction < 0) {
    Direction = Direction + 360;
    goto convert;
  }
  
  if (Direction > 360) {
    Direction = Direction - 360;
    goto convert;
  }

What useless crap. Learn about while loops.

   sei();         //Enables interrupts
   delay (3000);  //Wait 3 seconds to average
   cli();         //Disable interrupts

Absolute rubbish.

You really can’t expect client/server stuff to work with interrupts disabled.

I wouldn't be so vociferous, but just observe that seeing a "goto" in some code
indicates a complete audit is needed.

Also the best pattern with interrupts is this:

   byte oldSREG = SREG ;  // save status (including whether interrupts are enabled)
   cli();                 // ensure interrupts off
   critical_section () ;  // short critical section runs with interrupts disabled
   SREG = oldSREG ;       // restore interrupt state

This pattern works both inside an interrupt routine and in the main code. See
the source for digitalWrite() for instance.

Critical sections must be as short as possible, just to protect data structures
that are used to communicate with interrupt routines.