XBee wakeup doesn't work from loop()

Okay, the subject is hard to craft, but hopefully you can help.

I have a wireless network using XBees. One coordinator and one end device (there are more but not for this problem). I am using the series 2, which I know how to do, that is not the problem. My problem is one of power consumption.

Summary: On the end device, in the loop, the device first goes into sleep mode 2 times (16 seconds), wakes up, reads sensor data, wakes up the XBee, transmits the value, puts the xbee back to sleep, end of main loop.

To wake up the xbee, I set the pinMode of wake_pin to output and set it low. After I transmit, I set it high.

My problem is the following:

A) If I place the pinMode(wake_pin, OUTPUT) in the setup(), the system doesn't consume power as it should. The arduino is awake for the 16 seconds, RESETS (flash of pin 13), then runs 1 time correctly and transmits my data.

B) If I place the pinMode(wake_pin, OUTPUT) in the loop(), the system consumes power as it should (16 seconds asleep, then wake up, increase in mA for about 1-2 seconds, NO reset, back to sleep). However the xbee does not send data.

So...why is it that the xbee is only going to wake up when I place the pinMode() in the setup()??

Any tips or clues or help will be MUCH appreciated. BTW, in sleep mode, I'm running < mA. During away mode, I'm running at 9 mA.

Thanks,

JEremy

Please post your code.

#include "LowPower.h"
#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include <XBee.h>
#include "Arduino.h"

#define DEVICE_ID "hsi_dev:dendro9:"
#define signal_test_mode 0
#define high_addr 0x0013A200
#define low_addr 0x40A9DCB0
#define delay_sec 2
#define DATA_STORE_LENGTH 30
#define wake_pin 10
#define max_count 2

Adafruit_ADS1115 ads1115(0x48); 
XBee xbee = XBee();
XBeeAddress64 addr64 = XBeeAddress64();



 
void setup()
{
  Serial.begin(9600);
  xbee.setSerial(Serial);
 
}

int csc = 0;

void loop()
{
    pinMode (wake_pin,OUTPUT);    // put XBee to sleep0 

  if(csc < max_count) {
    csc++;
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
    return;
  }

 
  int16_t results;

  char cdata[] = DEVICE_ID;
  int cdata_size = sizeof(cdata);
  int start_pos = cdata_size;
  int total_size = 1;
  if(signal_test_mode == 1) {
     total_size = cdata_size+8;
  } else {
     total_size = cdata_size+6;
  }
  
  uint8_t tdata[total_size];
  uint8_t resultdata[5];


  addr64.setMsb(high_addr);//XXXXX -> Msb address of router/end node
  addr64.setLsb(low_addr);//XXXXX -> Lsb address of router/end nod  

  ads1115.begin();  
  ads1115.setGain(GAIN_ONE); 

 for(int i = 0; i < total_size; i++) {
    tdata[i] = ' ';
  }


  for(int i = 0; i < cdata_size; i++) {
    tdata[i] = cdata[i];
  }    

  results = ads1115.readADC_Differential_0_1();

  for (int k = 4; k >= 0; k--) {
      resultdata[k] = '0'+(results % 10);
    results /= 10;
  }

  if(signal_test_mode == 1) {
    char test_text[] = "SIG_TEST";
    for(int i = 0; i <= 8; i++) {
      tdata[i+start_pos] = test_text[i];
    }
      
  } else {

    for(int i = 0; i <= 4; i++) {
      tdata[i+start_pos] = resultdata[i];
    }
    
    tdata[28] = '\0';
  }



  digitalWrite(wake_pin,LOW);
  
  delay(1000);

  ZBTxRequest zbTx = ZBTxRequest(addr64, tdata, sizeof(tdata));
  xbee.send(zbTx);

  digitalWrite(wake_pin,HIGH);
  

  csc = 0;
  
}