Hi Felix,
Thanks for the suggestion. Unfortunately that didn't resolve the issue.
I am powering the Moteino from a powered USB hub.
I have attached a diagram of the circuit.
I know it's failing at the sendWithRetry because there are debug statements after the command that never get printed. Also, I have to power cycle the Moteino each time before it will accept code again.
Also, I tried it on a different Moteino. Same result.
Here is the serial o/p. I am tripping the switch during the first sleep cycle.
**************starting MailboxNotifier4_v1.2*************
starting radio
radio started
radio encryption
Transmitting at 915 Mhz...
going to sleep
waking up
Motion detected <<<<<--switch tripped
Before sendWithRetry
I updated the code a little with your suggestions and a little more debugging.
#include <RFM69.h> //get it here:
https://github.com/LowPowerLab/RFM69#include <SPI.h> //get it here:
https://github.com/LowPowerLab/SPIFlash#include <LowPower.h> //get library from:
https://github.com/LowPowerLab/LowPower//writeup here:
http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library///*********************************************************************************************
// *********** IMPORTANT SETTINGS - YOU MUST CHANGE/ONFIGURE TO FIT YOUR HARDWARE *************
//*********************************************************************************************
#define NODEID 55 //unique for each node on same network
#define NETWORKID 100 //the same on all nodes that talk to each other
#define GATEWAYID 1
//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
//#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ
#define FREQUENCY RF69_915MHZ
#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#define SENDEVERYXLOOPS 60 //each loop sleeps 8 seconds, so send status message every this many loops (default "4" = 32 seconds)
//*********************************************************************************************
#define MOTIONPIN 1 //hardware interrupt 1 (D3)
#define BATTERYSENSE A7 //through 1Meg+470Kohm and 0.1uF cap from battery VCC - this ratio divides the voltage to bring it below 3.3V where it is scaled to a readable range
#define LED 9 // Moteinos have LEDs on D9
#define BLINK_EN //uncomment to make LED flash when messages are sent, leave out if you want low power
#define SERIAL_BAUD 115200
#define SERIAL_EN //uncomment this line to enable serial IO debug messages, leave out if you want low power
#ifdef SERIAL_EN
#define DEBUG(input) {Serial.print(input); delay(1);}
#define DEBUGln(input) {Serial.println(input); delay(1);}
#else
#define DEBUG(input);
#define DEBUGln(input);
#endif
RFM69 radio;
volatile boolean motionDetected = false;
void setup() {
#ifdef SERIAL_EN
Serial.begin(SERIAL_BAUD);
#endif
Serial.println("**************starting MailboxNotifier4_v1.2*************");
Serial.println("starting radio");
radio.initialize(FREQUENCY, NODEID, NETWORKID);
Serial.println("radio started");
#ifdef IS_RFM69HW
radio.setHighPower(); //uncomment only for RFM69HW!
#endif
Serial.println("radio encryption");
delay(50);
radio.encrypt(ENCRYPTKEY);
pinMode(MOTIONPIN, INPUT);
attachInterrupt(MOTIONPIN, motionIRQ, RISING);
char buff[50];
sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY == RF69_433MHZ ? 433 : FREQUENCY == RF69_868MHZ ? 868 : 915);
DEBUGln(buff);
radio.sleep();
}
void motionIRQ()
{
motionDetected = true;
//DEBUGln("I");
}
char sendBuf[32];
byte sendLen;
byte sendLoops = 0;
unsigned long MLO = 0; //MailLastOpen (ago, in ms)
unsigned long now = 0, time = 0, lastSend = 0, temp = 0;
char* BATstr = "BAT:5.00v";
void loop() {
now = millis();
if (motionDetected ) //avoid duplicates in 20second intervals
{
DEBUGln("Motion detected");
delay(50);
MLO = time; //save timestamp of event
DEBUGln("Before sendWithRetry");
delay(25);
if (radio.sendWithRetry(GATEWAYID, "MOTION", 6))
{
DEBUGln(" ok!");
}
else DEBUGln(" no response from receiver");
delay(50);
motionDetected = false;
DEBUGln("After sendWithRetry");
}
radio.sleep();
DEBUGln("going to sleep");
delay(25);
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
DEBUGln("waking up");
}