skorokithakis / A6lib

An ESP8266/Arduino library for communicating with the A6 GSM module. ⛺
MIT License
127 stars 49 forks source link

INVALID_PDU 304 error for int getUnreadSMSLocs(). what problem here? please assist me #7

Closed amit524 closed 7 years ago

amit524 commented 7 years ago

int getUnreadSMSLocs(int* buf, int maxItems) { String seqStart = "+CMGL: "; String response = "";

// Issue the command and wait for the response.
byte status = A6command("AT+CMGL=\"REC UNREAD\"", "\xff\r\nOK\r\n", "\r\nOK\r\n", A6_CMD_TIMEOUT, 2, &response);

int seqStartLen = seqStart.length();
int responseLen = response.length();
int index, occurrences = 0;

// Start looking for the +CMGL string.
for (int i = 0; i < (responseLen - seqStartLen); i++) {
    // If we found a response and it's less than occurrences, add it.
    if (response.substring(i, i + seqStartLen) == seqStart && occurrences < maxItems) {
        // Parse the position out of the reply.
        sscanf(response.substring(i, i + 12).c_str(), "+CMGL: %u,%*s", &index);

        buf[occurrences] = index;
        occurrences++;
    }
}
return occurrences;

}

skorokithakis commented 7 years ago

I don't understand this. Please elaborate on the problem with steps to reproduce.

amit524 commented 7 years ago

when i exucte getUnreadSMSLocs(int* buf, int maxItems) this function i getting time out error or A6command("AT+CMGL=\"REC UNREAD\"", "\xff\r\nOK\r\n", "\r\nOK\r\n", A6_CMD_TIMEOUT, 2, &response); changed function "AT+CMGL=0" inplace of "AT+CMGL=\"REC UNREAD\"" A6command("AT+CMGL=0", "\xff\r\nOK\r\n", "\r\nOK\r\n", A6_CMD_TIMEOUT, 2, &response);

skorokithakis commented 7 years ago

Did that work?

amit524 commented 7 years ago

no

+CMS ERROR: 304 Invalid PDU mode parameter comes

and other all function work properly

skorokithakis commented 7 years ago

So the problem is that you're getting a timeout when trying to read SMS with getUnreadSMSLocs?

amit524 commented 7 years ago

i am using hardware serial inplace of software serial and using mega 2560

amit524 commented 7 years ago

yes if i increase #define A6_CMD_TIMEOUT 2000 then also time out error or +CMS ERROR: 304 comes

skorokithakis commented 7 years ago

Hmm, that's odd. Can you try setting SMS to text mode again?

A6command("AT+CMGF=1", "OK", "yy", A6_CMD_TIMEOUT, 2, NULL);
amit524 commented 7 years ago

this is my cade

callInfo cinfo = checkCallStatus(); if (cinfo.direction == DIR_INCOMING) { Serial.println(cinfo.number); hangUp(); unreadSMSNum =getUnreadSMSLocs(unreadSMSLocs, 30); Serial.println("unreadSMSNum"); Serial.println(unreadSMSNum); for (int i = 0; i < unreadSMSNum; i++) { Serial.print("New message at index: "); Serial.println(unreadSMSLocs[i], DEC);

        sms =readSMS(unreadSMSLocs[i]);
        Serial.println(sms.number);
        Serial.println(sms.date);
        Serial.println(sms.message);
    }
}
amit524 commented 7 years ago

A6command("AT+CMGF=1", "OK", "yy", A6_CMD_TIMEOUT, 2, NULL); this is work and response like this
Reply OK. Issuing command: AT+CMGF=1 Reply in 1056 ms: OK

skorokithakis commented 7 years ago

Does SMS work after that?

amit524 commented 7 years ago

now its work responce like this

Timed out. Issuing command: ATH Reply in 1055 ms: OK

Reply OK. Issuing command: AT+CMGF=1 Reply in 1055 ms: OK

Reply OK. Issuing command: AT+CMGL="REC UNREAD" Reply in 1058 ms: OK

Reply OK. unreadSMSNum 0 Issuing command: AT+CLCC Reply in 1055 ms: OK

amit524 commented 7 years ago

but every time i got the unreadSMSNum is 0

amit524 commented 7 years ago

and not enter in this loop

for (int i = 0; i < unreadSMSNum; i++) { Serial.print("New message at index: "); Serial.println(unreadSMSLocs[i], DEC);

        sms =readSMS(unreadSMSLocs[i]);
        Serial.println(sms.number);
        Serial.println(sms.date);
        Serial.println(sms.message);
    }
amit524 commented 7 years ago

if i send the new message then also reponce like Reply OK. Issuing command: AT+CMGF=1 Reply in 1055 ms: OK

Reply OK. Issuing command: AT+CMGL="REC UNREAD" Reply in 1058 ms: OK

Reply OK. unreadSMSNum 0 Issuing command: AT+CLCC Reply in 1055 ms: OK