A6lib icon indicating copy to clipboard operation
A6lib copied to clipboard

stuck in the blockUntilReady

Open GeorgeDLake opened this issue 7 years ago • 57 comments

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.

,

GeorgeDLake avatar May 23 '17 14:05 GeorgeDLake

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

skorokithakis avatar May 23 '17 14:05 skorokithakis

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

GeorgeDLake avatar May 23 '17 16:05 GeorgeDLake

Is it a library problem? Try enabling debugging.

skorokithakis avatar May 23 '17 16:05 skorokithakis

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....

GeorgeDLake avatar May 23 '17 16:05 GeorgeDLake

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 :/

skorokithakis avatar May 23 '17 16:05 skorokithakis

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

GeorgeDLake avatar May 23 '17 16:05 GeorgeDLake

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

skorokithakis avatar May 23 '17 17:05 skorokithakis

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. :-)

GeorgeDLake avatar May 24 '17 15:05 GeorgeDLake

Hmm, what was that code?

skorokithakis avatar May 24 '17 15:05 skorokithakis

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

GeorgeDLake avatar May 24 '17 15:05 GeorgeDLake

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.

skorokithakis avatar May 24 '17 15:05 skorokithakis

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

GeorgeDLake avatar May 24 '17 15:05 GeorgeDLake

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.

skorokithakis avatar May 24 '17 15:05 skorokithakis

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

GeorgeDLake avatar May 24 '17 16:05 GeorgeDLake

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

GeorgeDLake avatar May 25 '17 21:05 GeorgeDLake

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.

vanjsy avatar Jan 03 '18 13:01 vanjsy

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

giasone70 avatar Jan 06 '18 12:01 giasone70

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.

skorokithakis avatar Jan 06 '18 12:01 skorokithakis

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.

vanjsy avatar Jan 06 '18 13:01 vanjsy

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.

giasone70 avatar Jan 06 '18 16:01 giasone70

@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?

skorokithakis avatar Jan 06 '18 16:01 skorokithakis

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...

giasone70 avatar Jan 06 '18 17:01 giasone70

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

skorokithakis avatar Jan 06 '18 17:01 skorokithakis

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

giasone70 avatar Jan 06 '18 18:01 giasone70

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.

skorokithakis avatar Jan 06 '18 18:01 skorokithakis

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 avatar Jan 06 '18 18:01 giasone70

Anyway, how to activate debug mode?

giasone70 avatar Jan 06 '18 18:01 giasone70

Just define DEBUG.

skorokithakis avatar Jan 07 '18 00:01 skorokithakis

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

vanjsy avatar Jan 07 '18 08:01 vanjsy

Yeah, that worked for me with the sample code.

skorokithakis avatar Jan 07 '18 12:01 skorokithakis

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 avatar Jan 07 '18 12:01 vanjsy

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

vanjsy avatar Jan 07 '18 12:01 vanjsy

Are you running the example code to detect incoming SMS?

skorokithakis avatar Jan 07 '18 12:01 skorokithakis

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 avatar Jan 07 '18 12:01 vanjsy

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

vanjsy avatar Jan 07 '18 12:01 vanjsy

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

#include <A6lib.h>

#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);
}

}

vanjsy avatar Jan 07 '18 12:01 vanjsy

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...

skorokithakis avatar Jan 07 '18 12:01 skorokithakis

Debug already define into the .h library Sir:

#ifndef A6lib_h #define A6lib_h

#include <Arduino.h> #include "SoftwareSerial.h"

#define DEBUG

vanjsy avatar Jan 07 '18 12:01 vanjsy

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

skorokithakis avatar Jan 07 '18 12:01 skorokithakis

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.

vanjsy avatar Jan 07 '18 12:01 vanjsy

It's the sender's number.

skorokithakis avatar Jan 07 '18 12:01 skorokithakis

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

vanjsy avatar Jan 07 '18 12:01 vanjsy

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

skorokithakis avatar Jan 07 '18 12:01 skorokithakis

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

vanjsy avatar Jan 07 '18 13:01 vanjsy

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

skorokithakis avatar Jan 07 '18 13:01 skorokithakis

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?

vanjsy avatar Jan 07 '18 13:01 vanjsy

Probably the library, I guess.

skorokithakis avatar Jan 07 '18 13:01 skorokithakis

But where using the same library right? :)

vanjsy avatar Jan 07 '18 13:01 vanjsy

Indeed we are.

skorokithakis avatar Jan 07 '18 13:01 skorokithakis

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

vanjsy avatar Jan 07 '18 13:01 vanjsy

It's wired to a MOSFET that turns the A6 on and off. In my designs, anyway.

skorokithakis avatar Jan 07 '18 13:01 skorokithakis

Im sorry Im new to this, which pin exactly in A6? to ESP8266?

vanjsy avatar Jan 07 '18 13:01 vanjsy

None, I wired its power to a MOSFET in my design.

skorokithakis avatar Jan 07 '18 13:01 skorokithakis

My connection is:

A6(PWR) > A6(VCC) A6(U_TXD) > ESP(TX) D8 A6(U_RXD) > ESP(RX) D7

Is this enough?

vanjsy avatar Jan 07 '18 13:01 vanjsy

Yes, that's fine.

skorokithakis avatar Jan 07 '18 13:01 skorokithakis

Whats the Extra Comma Found means in the code Sir?

vanjsy avatar Jan 07 '18 13:01 vanjsy

I have no idea, and I don't have an A6 to test it, I'm sorry.

skorokithakis avatar Jan 07 '18 13:01 skorokithakis