skorokithakis / A6lib

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

stuck in the blockUntilReady #15

Open GeorgeDLake opened 7 years ago

GeorgeDLake commented 7 years ago

Hi. I have an issue with the dial.ino. it gets stuck in the blockUntilReady function. If I invert the RX and TX lines, then it passes but no data comes to the ESP8266. Signal Strength shows some number like 6845364 and cinfo.number is blank. How can I tell that the A6 is actually working? I tired calling it but the call goes to voice mail. I dont have the module to connect the A6 to the serial port of my PC, so I can only use the ESP to validate.

,

skorokithakis commented 7 years ago

Hmm, I'm not sure, this sounds like one of those weird problems that just goes away if you jiggle enough wires...

GeorgeDLake commented 7 years ago

I have been able to pin it to the function begin. All the factory reset calls return A6_NOTOK

skorokithakis commented 7 years ago

Is it a library problem? Try enabling debugging.

GeorgeDLake commented 7 years ago

I have put some debug code and this part works... A6 reply: AT

+CME ERROR:58 AT+IPR=9600 OK

But from here on..... not working....

skorokithakis commented 7 years ago

Ah, damnit, I thought I had some debug code already there. I'm afraid I haven't used the A6 in a year and I don't remember much :/

GeorgeDLake commented 7 years ago

this is is part of the debug dump ⸮Power-cycling module... Done, waiting for the module to initialize... Done. Autodetecting connection rate... Trying rate 9600... Issuing command: AT Reply in 2000 ms: ⸮⸮ Timed out. Issuing command: AT Reply in 2000 ms: ⸮⸮ Timed out. Trying rate 115200... Issuing command: AT Reply in 154 ms: AT

+CME ERROR:58

Reply OK. Setting baud rate on the module... Issuing command: AT+IPR=9600 Reply in 155 ms: AT+IPR=9600

OK

Reply OK. Switching to the new rate... Rate set. Issuing command: AT&F Reply in 15000 ms: ⸮⸮ Timed out. Issuing command: AT&F Reply in 15000 ms: ⸮⸮ Timed out. Issuing command: ATE0 Reply in 15000 ms: ⸮⸮ Timed out. Issuing command: ATE0

skorokithakis commented 7 years ago

Hmm, looks like maybe your rate isn't being set properly?

GeorgeDLake commented 7 years ago

I used Andreas Spiess code and it works. It was set at 115200, so I change yours to that speed and now it works like a charm. mmmm strange.... I have read that SoftwareSerial does not support that speed... but it works... I will do a 48h test soon..... once I get HTTP request to work. :-)

skorokithakis commented 7 years ago

Hmm, what was that code?

GeorgeDLake commented 7 years ago

https://github.com/SensorsIot/A6-GSM-Module/tree/master/A6_swisscom

skorokithakis commented 7 years ago

I see, thanks. Odd that it works at 115200 and not at 9600, but the ESP can do 115200 no problem, as far as I know.

GeorgeDLake commented 7 years ago

Now I need to get the HTTP request to work... I need to get data and post data to some sites.. :-)

skorokithakis commented 7 years ago

There's already a pull request for that (#5), but it needs a bit of cleaning up and review. You can use that if you want, I'd be grateful if you could shape it up into a more tidy PR.

GeorgeDLake commented 7 years ago

I replaced the lib that I was using and now it stopped working! strange.....

GeorgeDLake commented 7 years ago

It must be something with the local Chilean phone companies. I have tried several libs and code... none connect to the internet.... mmmmmmmm

vanjsy commented 6 years ago

Hi, I'd like to ask for your assistance please if you manage to solve this issue: -qþÿáPower-cycling module... Done, waiting for the module to initialize... Done. Autodetecting connection rate... Trying rate 9600... Issuing command: AT Reply in 2000 ms: ÿÿ Timed out. Issuing command: AT Reply in 2000 ms: ÿÿ Timed out. Trying rate 115200... Issuing command: AT Reply in 2000 ms: AT

Timed out. Issuing command: AT Reply in 2000 ms: AT

Timed out. Couldn't detect the rate. Waiting for module to be ready... Autodetecting connection rate...

Already tried different baudrate, the output still the same. Thanks a lot.

giasone70 commented 6 years ago

Hi, I have a similar problem. I noticed that the library work perfectly with Arduino Uno or Nano (atm328P CPU) but has some strange problem on Arduino ProMini (168 CPU): sometimes (rarely) it gets out from stucking on blockUntilReady function, but nonetheless it doesn't work anyway (it doesn't intercepts calls or SMS). The strangest thing is that the very same hardware works perfectly if I use a simple SoftwareSerial.h sketch! In this case the modems starts regularly and receives and responds without problems to AT commands. I suppose all problems are in begin function and connected ones, but I was not able to understand what is it. Your help would be really appreciated. Alessandro

skorokithakis commented 6 years ago

Hmm, maybe it has something to do with the code pausing for too long and breaking the serial's flow? I'm afraid I don't know very much about interrupts and scheduling so serial reads have higher priority, but this sounds like a likely culprit.

vanjsy commented 6 years ago

Hi, already working on mine. I didn't change anything in the code, except the pin assignment in my ESP8266 which is D7 and D8 (pin 13 and 15). I also didn't include the country code one the mobile number. The only problem im facing right now is that, it wont display the sms received by the GSM into the serial monitor.

giasone70 commented 6 years ago

Since I noticed that the module works perfectly simple starting the softwareserial at 9600 bauds, is there a system to omit all the part of "autosensing" the baud rate and setting it, putting it straight to 9600 (I experimented that is the best speed) and symply waiting for it to reply "OK" to "AT" command? I tried, but I don't know enough your code to put safely my hands on it.

skorokithakis commented 6 years ago

@giasone70 The library starts with 9600 bauds and tries to see if the modem responds, and only tries 115200 if it doesn't. Have you found that it will actually not respond to the sensing but will respond afterwards?

giasone70 commented 6 years ago

unfortunately not... as I said, it usually stucks at blockuntilready. It rarely goes after, but no function actually works... I tried to enable DEBUG, but probably I don't know how to do it, because nothing happens...

skorokithakis commented 6 years ago

Hmm, does it still happen if you add a 30 second delay before blockUntilReady?

giasone70 commented 6 years ago

Yes. It doesn't go further blockUntilReady.:(

skorokithakis commented 6 years ago

Ah, that's too bad. I remember having these problems as well, and then at some point it started working. At that point, I released the library, but I didn't do something specific. It seems to have been the module misbehaving. Try a better power supply, as well.

giasone70 commented 6 years ago

I thought something like that... but, I realized that, in that case, It won't work neither with the simple SoftwareSerial.h routine. It instead works like a charm that way, perfectly receiving AT commands and responding to them.

giasone70 commented 6 years ago

Anyway, how to activate debug mode?

skorokithakis commented 6 years ago

Just define DEBUG.

vanjsy commented 6 years ago

Hi, did you happen to manage to display live message received by the module into the serial monitor? Thanks.

skorokithakis commented 6 years ago

Yeah, that worked for me with the sample code.

vanjsy commented 6 years ago

Sample code works fine, when I run the program the I have this output below. Sending text from the GSM to the number defined is working, the only problem is when im sending a text to the GSM its not displaying below program is just continuing... Reply OK. Extra comma found. Issuing command: AT+CLCC Reply in 165 ms: OK

Reply OK. Extra comma found. Issuing command: AT+CLCC Reply in 165 ms: OK

Reply OK. Extra comma found. Issuing command: AT+CLCC Reply in 165 ms: OK

Reply OK. Extra comma found. Issuing command: AT+CLCC Reply in 165 ms: OK

vanjsy commented 6 years ago

Command doesn't change when text message is received always AT+CLCC OK.

skorokithakis commented 6 years ago

Are you running the example code to detect incoming SMS?

vanjsy commented 6 years ago

YEs Sir, below command from the library was not showing into the serial monitor: // Retrieve the number and locations of unread SMS messages. int A6lib::getUnreadSMSLocs(int* buf, int maxItems) { return getSMSLocsOfType(buf, maxItems, "REC UNREAD"); }

// Retrieve the number and locations of all SMS messages. int A6lib::getSMSLocs(int* buf, int maxItems) { return getSMSLocsOfType(buf, maxItems, "ALL"); }

// Retrieve the number and locations of all SMS messages. int A6lib::getSMSLocsOfType(int* buf, int maxItems, String type) { String seqStart = "+CMGL: "; String response = "";

String command = "AT+CMGL=\"";
command += type;
command += "\"";

// Issue the command and wait for the response.
byte status = A6command(command.c_str(), "\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;

}

// Return the SMS at index. SMSmessage A6lib::readSMS(int index) { String response = ""; char buffer[30];

// Issue the command and wait for the response.
sprintf(buffer, "AT+CMGR=%d", index);
A6command(buffer, "\xff\r\nOK\r\n", "\r\nOK\r\n", A6_CMD_TIMEOUT, 2, &response);

char message[200];
char number[50];
char date[50];
char type[10];
int respStart = 0, matched = 0;
SMSmessage sms = (const struct SMSmessage) {
    "", "", ""
};

// Parse the response if it contains a valid +CLCC.
respStart = response.indexOf("+CMGR");
if (respStart >= 0) {
    // Parse the message header.
    matched = sscanf(response.substring(respStart).c_str(), "+CMGR: \"REC %s\",\"%s\",,\"%s\"\r\n", type, number, date);
    sms.number = String(number);
    sms.date = String(date);
    // The rest is the message, extract it.
    sms.message = response.substring(strlen(type) + strlen(number) + strlen(date) + 24, response.length() - 8);
}
return sms;

}

// Delete the SMS at index. byte A6lib::deleteSMS(int index) { char buffer[20]; sprintf(buffer, "AT+CMGD=%d", index); return A6command(buffer, "OK", "yy", A6_CMD_TIMEOUT, 2, NULL); }

// Set the SMS charset. byte A6lib::setSMScharset(String charset) { char buffer[30];

sprintf(buffer, "AT+CSCS=\"%s\"", charset.c_str());
return A6command(buffer, "OK", "yy", A6_CMD_TIMEOUT, 2, NULL);

}

// Set the volume for the speaker. level should be a number between 5 and // 8 inclusive. void A6lib::setVol(byte level) { char buffer[30];

// level should be between 5 and 8.
level = min(max(level, 5), 8);
sprintf(buffer, "AT+CLVL=%d", level);
A6command(buffer, "OK", "yy", A6_CMD_TIMEOUT, 2, NULL);

}

// Enable the speaker, rather than the headphones. Pass 0 to route audio through // headphones, 1 through speaker. void A6lib::enableSpeaker(byte enable) { char buffer[30];

// enable should be between 0 and 1.
enable = min(max(enable, 0), 1);
sprintf(buffer, "AT+SNFS=%d", enable);
A6command(buffer, "OK", "yy", A6_CMD_TIMEOUT, 2, NULL);

}

vanjsy commented 6 years ago

I'm running your example code from the library you made Sir.

vanjsy commented 6 years ago

Here's the exact code I program into the ESP8266:

include

ifdef ESP8266

define D0 0

define D7 13

define D8 15

endif

// Instantiate the library with TxPin, RxPin. A6lib A6l(D8, D7);

int unreadSMSLocs[30] = {0}; int unreadSMSNum = 0; SMSmessage sms;

void setup() { Serial.begin(115200);

delay(1000);

// Power-cycle the module to reset it.
A6l.powerCycle(D0);
A6l.blockUntilReady(9600);

}

void loop() { String myNumber = "xxxxxxxxx";

callInfo cinfo = A6l.checkCallStatus();
if (cinfo.direction == DIR_INCOMING) {
    if (myNumber.endsWith(cinfo.number)) {
        // If the number that sent the SMS is ours, reply.
        A6l.sendSMS(myNumber, "I can't come to the phone right now, I'm a machine.");
        A6l.hangUp();
    }

    // Get the memory locations of unread SMS messages.
    unreadSMSNum = A6l.getUnreadSMSLocs(unreadSMSLocs, 30);

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

        sms = A6l.readSMS(unreadSMSLocs[i]);
        Serial.println(sms.number);
        Serial.println(sms.date);
        Serial.println(sms.message);
    }
    delay(1000);
}

}

skorokithakis commented 6 years ago

Hmm, very odd. Try enabling debugging to see what's going on, I'm afraid I don't have an A6 ready to debug at the moment...

vanjsy commented 6 years ago

Debug already define into the .h library Sir:

ifndef A6lib_h

define A6lib_h

include

include "SoftwareSerial.h"

define DEBUG

skorokithakis commented 6 years ago

Are you sure myNumber is correct? Try setting it to just the last digit, e.g. myNumber = "6".

vanjsy commented 6 years ago

Yes Sir,. The number that should be define is not the number which is into the GSM right? I'm sure I defines it correctly. Its even sending me text message if I called the GSM, it automatically hangs up.

skorokithakis commented 6 years ago

It's the sender's number.

vanjsy commented 6 years ago

Yes, sender's number. But live sms not displaying :(

skorokithakis commented 6 years ago

Try changing myNumber to just the last digit of the sender's number.

vanjsy commented 6 years ago

Unfortunately still the same Sir, not displaying. Continues looping the CLCC response.

skorokithakis commented 6 years ago

I'm afraid I don't know then, sounds like your command is outputting an extra comma and parsing fails.

vanjsy commented 6 years ago

If it's regarding the Extra Comma Found, do you have any idea where would it be? In the library or into the IDE code?

skorokithakis commented 6 years ago

Probably the library, I guess.

vanjsy commented 6 years ago

But where using the same library right? :)

skorokithakis commented 6 years ago

Indeed we are.

vanjsy commented 6 years ago

What's the use of D0 0? Should it be wired? A6>ESP8266?