I've been trying to use the EventsBoard to monitor several sockets simultaneously, with interrupts associated with these, with RTC alarms (for regular reports/logs) and ACC interrupts.
I've been debugging and have removed all sensor board code, so I have two types of trigger - Accelerometer interrupt, and RTC alarm.
Quote:
#define MAX_TRIES 2
uint8_t timeout = 0;
uint8_t isAlarm = 0;
uint8_t acc_ints = 0;
void setup(){
USB.begin();
USB.println("USB port started...");
USB.println("^^^^^^^^^^^^^^^^^^^START SETUP WINDOW^^^^^^^^^^^^^^^^^^^^^^^");
ACC.ON();
USB.println("ACC ON...");
RTC.ON();
USB.println("RTC ON...");
for(uint8_t i=0;i<10;i++) Utils.blinkLEDs(100);
USB.println("^^^^^^^^^^^^^^^^^^^END SETUP WINDOW^^^^^^^^^^^^^^^^^^^^^^^");
}
void loop(){
USB.println("^^^^^^^^^^^^^^^^^^^START LOOP WINDOW^^^^^^^^^^^^^^^^^^^^^^^");
if( intFlag & ACC_INT )USB.println("FLAG ACC active ");
if( intFlag & RTC_INT )USB.println("FLAG RTC active ");
RTC.setAlarm1("00:00:00:30",RTC_ABSOLUTE,RTC_ALM1_MODE5);
USB.print("Alarm1: ");
USB.println(RTC.getAlarm1());
ACC.setFF();
ACC.setDD();
USB.print("ACC INTERRUPTS SET! ");
PWR.sleep(UART0_OFF | UART1_OFF | BAT_OFF);//sleep, wake if RTC or ACC INT
RTC.ON();
USB.begin();
if( intFlag & ACC_INT )
{
USB.print("\nACC INTERRUPT! >>>>\t");
USB.println(RTC.getTime());
acc_ints++;
USB.print("\tACC ints:\t");
USB.println(acc_ints,DEC);
isAlarm = 1;
//generateSMSBody();
sendSMS();
intFlag &= ~(ACC_INT); // Clear flag
}
if (intFlag & RTC_INT)
{
intFlag &= ~(RTC_INT);
USB.print("\nRTC INTERRUPT! >>>>\t");
USB.println(RTC.getTime());
isAlarm = 0;
//generateSMSBody();
sendSMS();
}
if( intFlag & ACC_INT )USB.println("FLAG ACC active i ");
if( intFlag & RTC_INT )USB.println("FLAG RTC active i ");
if( intFlag & ACC_INT )USB.println("************FLAG ACC ACTIVE***********");
USB.println("^^^^^^^^^^^^^^^^^^^END LOOP WINDOW^^^^^^^^^^^^^^^^^^^^^^^");
}
void sendSMS(){
// setup for GPRS seial port
GPRS.ON();
USB.println("GPRS module ready...");
Utils.setLED(LED1,LED_ON);
// waiting while GPRS connects to the network (for
//while(!GPRS.check());
while((timeout<MAX_TRIES)&&(!GPRS.check())){ //while in time and not connected...
USB.print("timeout = ");
USB.println(timeout,DEC);
timeout++;
USB.print("sendCommand('+CREG')..... ");
if(GPRS.sendCommand("+CREG")) USB.print("sendCommand OK");
else USB.print("sendCommand NOT OK");
//GPRS.sendCommand("+CSQ");
USB.print("answer_command: ");
USB.println(GPRS.answer_command);
//delay(1000);
}
timeout = 0;
if(GPRS.check()){
USB.println("GPRS connected to the network");
Utils.setLED(LED0,LED_ON);
// configure SMS and Incoming Calls
if(GPRS.setInfoIncomingCall()) USB.println("Info Incoming Call OK");
if(GPRS.setInfoIncomingSMS()) USB.println("Info Incoming SMS OK");
if(GPRS.setTextModeSMS()) USB.println("Text Mode SMS OK");
if(isAlarm == 1)
{
if(GPRS.sendSMS("ALARM","08********")) USB.println("SMS Sent OK"); // * should be replaced by the desired tlfn number
else{
USB.println("Error sending Alarm sms");
for(uint8_t i=0;i<10;i++) Utils.blinkLEDs(50);
}
}
else if(isAlarm == 0)
{
if(GPRS.sendSMS("LOG","08********")) USB.println("SMS Sent OK"); // * should be replaced by the desired tlfn number
else{
USB.println("Error sending Log sms");
for(uint8_t i=0;i<10;i++) Utils.blinkLEDs(50);
}
}
else USB.println("isAlarm Error (isAlarm != ( 0 or 1))");
}
else{
USB.println("GPRS connect timed out");
}
delay(50);
GPRS.setMode(GPRS_HIBERNATE);
USB.println("GPRS mode set to HIBERNATE");
Utils.setLED(LED0,LED_OFF);
Utils.setLED(LED1,LED_OFF);
}
This sketch will detect the interrupts as normal, with both ACC interrupts and the Alarm1 interrupts working seemingly independent of one another - as desired.
The GPRS behaviour is thus:
> If I do not cause an ACC interrupt, or disable it's operation, the Reporting / Alarm1, or RTC int, triggered SMS's are sent successfully, with a 95%+ success rate in connecting / sending OK.
> If I disable the RTC ints, The ACC interrupt triggered SMS's are sent successfully with a high success rate.
> If I load the above coded unaltered to the mote, The RTC int triggered (Log) will connect / send as SMS untill the ACC int is generated, then strange behaviour occurs:
-The ACC interrupt will wake the mote up - and sendSMS() is called.
-sendSMS() may connect (but with a less than 50% success rate)
-if a GPRS connection is successfully created the configuration does not succeed - typically configuring 'Incoming calls' but not 'Incoming SMS' or 'Text mode' - It times out and I recieve "Error sending Alarm sms" when the Unconfigured tranmission is attempted.
-if configuration is completed (with a low success rate) the SMS may be sent while "Error sending Alarm sms" is still 'USB.print'ed.
-if the connection fails (times out) the AT ('+CREG') command is typically responded to with a "sendCommand NOT OK" and
Quote:
answer_command:
>
-After the the unsucessful connection all ACC or RTC generated SMS's fail as the GPRS module will not connect, or respond to AT commands after this. It hangs indefinately after
USB.print("sendCommand('+CREG')..... ");The two types of trigger have worked together - but only for one pair of messages, i.e. a Log then an Alarm SMS. The low success rate in the Combined log & alarms is not due to GPRS alone - as each functionality demonstrates the desired performance (reconnect & transmission reliability) on it's own. The interrupts working as long as is GPRS disabled leads me to conclude the issue may not be there either.
I am having real difficulty diagnosing the source of these connection failures,
any advice or help is greatly appreciated.
Thank you.