Hello again,
Thanks for the advice, I've already made SMS & lost call tests successfully,
both with the example code and my own "sendSMS(char*)" functions.
Below is the sketch I'm using to combine ZB and GPRS, on a waspmote with a Coordinator ZB module, which when it recieves a packet sends the contents as an SMS (using a function I have previously tested).
I'm using the LED patterns to observe the flow of control - So far I have found the packets (ZB) are sent / recieved reliably, however when the sendSMS(char*) function is called the GPRS module times out and does not associate with the network.
I originally tested code similar to this (minus the SMS components) successfully, then added the aforementioned SMS function. This new code (Identical to that posted below) associated with the network and transmitted SMS successfully as soon as I uploaded it. When I tested slightly different versions of the code the now all too familiar timeouts returned, and switching back to the original sketch hasn't fixed this.
I have had successful GPRS associations and SMS transmissions with a sendSMS(char*) function call in the setup part of the sketch - however this is not the functionality I need to achieve.
Quote:
#define MAX_TRIES 2
packetXBee* paq_sent;
int8_t state=0;
long previous=0;
char aux[200];
char recievedBody[100];
char* macHigh=" ";
char* macLow=" ";
int aux_1 = 0;
int aux_2 = 0;
uint8_t timeout = 0;
#define key_access "LIBELIUM"
uint8_t direccion[8]={0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF};
uint8_t macA[8]={0x00,0x13,0xA2,0x00,0x40,0x65,0x02,0xAA};
//0013A200406502AA
void setup(){
// Store key access in EEPROM
for(int i=0;i<8;i++){
Utils.writeEEPROM(i+107,key_access[i]);
}
RTC.ON();
ACC.ON();
XBee.setMode(XBEE_ON);
XBee.begin(9600);
delay(1000);
XBee.print("+++");
delay(2000);
XBee.println("ATBD5,AP2,WR,CN");
delay(150);
XBee.setMode(XBEE_OFF);
XBee.close();
Utils.setLED(LED0, LED_ON);
Utils.setLED(LED1, LED_ON);
delay(5000);
Utils.setLED(LED0, LED_OFF);
Utils.setLED(LED1, LED_OFF);
for (int i=0;i<24;i++){
Utils.blinkLEDs(125);
}
// Inits the XBee XSC library
xbeeZB.init(ZIGBEE,FREQ2_4G,NORMAL);
// Powers XBee
xbeeZB.ON();
// Get the XBee MAC address
delay(500);
int counter = 0;
while(xbeeZB.getOwnMac()==1&&counter<4){
xbeeZB.getOwnMac();
counter++;
}
Utils.hex2str(xbeeZB.sourceMacHigh,macHigh,4);
Utils.hex2str(xbeeZB.sourceMacLow,macLow,4);
}
void loop(){
for(uint8_t i = 0;i<2;i++){
Utils.blinkLEDs(100);
}
//previous=millis();
//while( (millis()-previous) < 20000 )
//{
if( XBee.available() )
{
xbeeZB.treatData();
if( !xbeeZB.error_RX )
{
while(xbeeZB.pos>0)
{
//xbeeZB.packet_finished[xbeeZB.pos-1]->data;
sprintf(aux,"B(%u)[[[%s]]]\n",PWR.getBatteryLevel(),xbeeZB.packet_finished[xbeeZB.pos-1]->data);
//sendSMS(aux);
paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee));
paq_sent->mode=UNICAST;
paq_sent->MY_known=0;
paq_sent->packetID=0x52;
paq_sent->opt=0;
xbeeZB.hops=0;
xbeeZB.setOriginParams(paq_sent,MAC_TYPE);
//xbeeZB.setDestinationParams(paq_sent, direccion, aux, MAC_TYPE, DATA_ABSOLUTE);
xbeeZB.setDestinationParams(paq_sent, macA, aux, MAC_TYPE, DATA_ABSOLUTE);
xbeeZB.sendXBee(paq_sent);
free(paq_sent);
paq_sent = NULL;
free(xbeeZB.packet_finished[xbeeZB.pos-1]);
xbeeZB.packet_finished[xbeeZB.pos-1]=NULL;
xbeeZB.pos--;
sendSMS(aux);
}
}
}
//}
//delay(500);
}
void sendSMS(char*){ //subfn to send SMS with message body as argument
GPRS.begin();
GPRS.setMode(GPRS_ON);
//waiting while GPRS connects to the network
while((timeout<MAX_TRIES)&&(!GPRS.check())){ //while in time and not connected...
USB.print("timeout = ");
USB.println(timeout,DEC);
timeout++;
}
timeout = 0;
if(GPRS.check()){
//configure SMS and Incoming calls
GPRS.setInfoIncomingCall();
GPRS.setInfoIncomingSMS();
GPRS.setTextModeSMS();
// Sending test SMS
GPRS.sendSMS(aux,"087*******"); //phone no.
GPRS.setMode(GPRS_HIBERNATE);
}
else{
GPRS.setMode(GPRS_HIBERNATE);
for(uint8_t i = 0;i<10;i++){
Utils.blinkLEDs(1000);
}
}
}
As always your help and advice in resolving this issue would be very welcome.
Thanks.
PS. I am using the same SIM, APN & GPRS module + antenna for the combined GPRS & ZB and the GPRS standalone tests.