botletics / SIM7000-LTE-Shield

Botletics SIM7000 LTE CAT-M1/NB-IoT Shield for Arduino
https://www.botletics.com/products/sim7000-shield
GNU General Public License v3.0
477 stars 216 forks source link

Failed to enable GPRS #52

Closed ammarqs closed 5 years ago

ammarqs commented 5 years ago

My previous issue was resolved. I was missing a library. After uploading the IoT_example code, and changing the APN to match our providers APN, the system is trying to enable GPRS but fails. Keep so retrying. image

ammarqs commented 5 years ago

Overview: I have customized the program to run with our setup, not using GPS. The controller does not sleep. It loops to checks for any triggers and run functions accordingly. So my program does not include any sleep functions. So the question here is: Does the module have the tendency to log off from network when not active for too long?

ammarqs commented 5 years ago

if so, using this with before every http get funciton will make sure that the modem connects to the network before posting: while (!netStatus()) { Serial.println(F("Failed to connect to cell network, retrying...")); delay(2000); // Retry every 2s } Serial.println(F("Connected to cell network!"));

botletics commented 5 years ago

No, it should stay connected to the network at all times. That bit of code you posted will not ensure it connects, but will only check that it's connected. Because the modem will always want to connect unless you tell it explicitly not to. So I'd recommend that you check for the network status periodically as part of your loop (like every 20s or something).

ammarqs commented 5 years ago

Yea thats what i thought it should be doing. but i left it online yesterday to make sure it stays connected when i come back this morning. I came this morning and the net status light was blinking slowly compared to when connected. Soo i tried to trigger an event but it didnt send out a message. so i had to open my serial port and the connection established and it starting posting messages when function triggered.

So what you say is in my main loop, i check for connection every 20sec or so, if not connected, what should it do to connect back? I guess the request to check for connection will make sure that the modem is communicating at all times and does not go to sleep?

botletics commented 5 years ago

Blinking slowly means it's connected but data isn't enabled. Blinking somewhat rapidly (but not very quickly) means it's not connected.

Per the SIM7000 Hardware Design Document, 64ms ON/800ms OFF indicates no connection, 64ms ON/3000ms OFF indicates registered to network, 64ms ON/300ms OFF indicates transmission of data, and OFF indicates power-off or power-saving mode.

The modem will never go to sleep by itself under normal circumstances where you're supplying proper power to it, and it should also always stay connected to the network.

ammarqs commented 5 years ago

So why do you think this would be happening? Anything that i can do it make sure its connected to the network before it tries to post data?

On Fri, Dec 21, 2018 at 11:51 AM Timothy Woo notifications@github.com wrote:

Blinking slowly means it's connected but data isn't enabled. Blinking somewhat rapidly (but not very quickly) means it's not connected.

Per the SIM7000 Hardware Design Document, 64ms ON/800ms OFF indicates no connection, 64ms ON/3000ms OFF indicates registered to network, 64ms ON/300ms OFF indicates transmission of data, and OFF indicates power-off or power-saving mode.

The modem will never go to sleep by itself under normal circumstances where you're supplying proper power to it, and it should also always stay connected to the network.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/botletics/SIM7000-LTE-Shield/issues/52#issuecomment-449439850, or mute the thread https://github.com/notifications/unsubscribe-auth/AQarX0xDfw-aic1e6vrKCT-3fcMgurPOks5u7RGlgaJpZM4YzlYS .

-- Ammar Quaid Surti, Contact:+1-681-212-9752 Email: ammarqs@gmail.com;

botletics commented 5 years ago

If you check for the network status you could start a timer right when it's NOT connected, then if it remains disconnected for too long then you could pulse the RST pin (pin 7) to restart the module. But I've run long-term tests without problems.

If you are sending a SMS note that Verizon seems to block the Hologram number so you may not get the text if your phone is using Verizon. Please see this wiki page for how to get around that using a Hologram SMS Route.

ammarqs commented 5 years ago

No we arent using any sms.. our package from kore does not allow any sms. Its purely data.

On Fri, Dec 21, 2018 at 11:53 AM Timothy Woo notifications@github.com wrote:

If you check for the network status you could start a timer right when it's NOT connected, then if it remains disconnected for too long then you could pulse the RST pin (pin 7) to restart the module. But I've run long-term tests without problems.

If you are sending a SMS note that Verizon seems to block the Hologram number so you may not get the text if your phone is using Verizon. Please see this wiki page https://github.com/botletics/SIM7000-LTE-Shield/wiki/SMS-Messages#hologram-sms-route for how to get around that using a Hologram SMS Route.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/botletics/SIM7000-LTE-Shield/issues/52#issuecomment-449440359, or mute the thread https://github.com/notifications/unsubscribe-auth/AQarX4qfg8VXtmURqeV_Hhi6Rn2nZ-Eyks5u7RIhgaJpZM4YzlYS .

-- Ammar Quaid Surti, Contact:+1-681-212-9752 Email: ammarqs@gmail.com;

botletics commented 5 years ago

OK, so if you're trying to send something to the cloud then that means it was probably still connected to the network but data wasn't enabled. What exactly did you see from the AT command log when it failed? Did it fail to run a certain command?

ammarqs commented 5 years ago

Thats the thing, it was disconnected from the computer and powered with an actual power source.. before i left, everything worked fine.. i came back it didnt work, so i connected my usb and as soon as i opened my serial port, it did the setup routine and started communicating.. so i didnt get the chhance to check the errors if any..

On Fri, Dec 21, 2018 at 11:57 AM Timothy Woo notifications@github.com wrote:

OK, so if you're trying to send something to the cloud then that means it was probably still connected to the network but data wasn't enabled. What exactly did you see from the AT command log when it failed? Did it fail to run a certain command?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/botletics/SIM7000-LTE-Shield/issues/52#issuecomment-449441217, or mute the thread https://github.com/notifications/unsubscribe-auth/AQarX0go2dj9BpJLgf9KPe1NVJlUV2Puks5u7RLsgaJpZM4YzlYS .

-- Ammar Quaid Surti, Contact:+1-681-212-9752 Email: ammarqs@gmail.com;

botletics commented 5 years ago

By "it did the setup routine" do you mean the microcontroller was reset? The module won't be reset simply by opening the serial monitor. However, opening the serial monitor will restart the Arduino (or microcontroller, depending on what type it is).

botletics commented 5 years ago

Sorry, without getting an AT command log to see exactly what was happening I really can't tell if it's something small in your code that might be tripping it, or something else. It's really hard to say.

ammarqs commented 5 years ago

Yes thats what it did, turning on serial monitor restarted the controller and the modem connected and everything started working as normla

On Fri, Dec 21, 2018 at 12:02 PM Timothy Woo notifications@github.com wrote:

Sorry, without getting an AT command log to see exactly what was happening I really can't tell if it's something small in your code that might be tripping it, or something else. It's really hard to say.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/botletics/SIM7000-LTE-Shield/issues/52#issuecomment-449442475, or mute the thread https://github.com/notifications/unsubscribe-auth/AQarX-MuinToVi9jYIqho9DxDxp0zDfvks5u7RQagaJpZM4YzlYS .

-- Ammar Quaid Surti, Contact:+1-681-212-9752 Email: ammarqs@gmail.com;

ammarqs commented 5 years ago

Yup.. i will do this again today, this time leaving the serial port open.. and leave it for a few hours to check what happened.

On Fri, Dec 21, 2018 at 12:04 PM Ammar Surti ammarqs@gmail.com wrote:

Yes thats what it did, turning on serial monitor restarted the controller and the modem connected and everything started working as normla

On Fri, Dec 21, 2018 at 12:02 PM Timothy Woo notifications@github.com wrote:

Sorry, without getting an AT command log to see exactly what was happening I really can't tell if it's something small in your code that might be tripping it, or something else. It's really hard to say.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/botletics/SIM7000-LTE-Shield/issues/52#issuecomment-449442475, or mute the thread https://github.com/notifications/unsubscribe-auth/AQarX-MuinToVi9jYIqho9DxDxp0zDfvks5u7RQagaJpZM4YzlYS .

-- Ammar Quaid Surti, Contact:+1-681-212-9752 Email: ammarqs@gmail.com;

-- Ammar Quaid Surti, Contact:+1-681-212-9752 Email: ammarqs@gmail.com;

botletics commented 5 years ago

Unfortunately I can't tell you exactly what's wrong. However, you could implement a counter that increments for each unsuccessful attempt to do something (like post data to the cloud) and if it reaches a certain value then you could reset the SIM7000 module and try again.

botletics commented 5 years ago

You can also use the command AT+CFUN=6 to restart the module via software. Just make sure after restarting that you do the entire fona.begin() setup code as well, because it has to find it again.

EDIT: You can use "fona.setFunctionality(6)" to set AT+CFUN=6 in Arduino code.

ammarqs commented 5 years ago

i just doubled checked my code. there is nothing in the loop function to to enable or disable modem. After the setup routine, there is nothing except for the HTTP get requests to do anything with the connection. Here is the Setup: `void setup(){ Serial.begin(9600); Serial.println(F("Hello World!"));

pinMode(ContainerLSW, INPUT);

ifdef LED

pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);

endif

pinMode(FONA_RST, OUTPUT); digitalWrite(FONA_RST, HIGH); // Default state

pinMode(FONA_PWRKEY, OUTPUT); powerOn(); // Power on the module moduleSetup(); // Establishes first-time serial comm and prints IMEI

fona.setFunctionality(1); // AT+CFUN=1 fona.setNetworkSettings(F("c2.korem2m.com")); // For KORE SIM card fona.setPreferredMode(38); // Use LTE only, not 2G fona.setPreferredLTEMode(1); // Use LTE CAT-M only, not NB-IoT fona.setOperatingBand("CAT-M", 12); // AT&T uses band 12

/ // Enable GPS while (!fona.enableGPS(true)) { Serial.println(F("Failed to turn on GPS, retrying...")); delay(2000); // Retry every 2s } Serial.println(F("Turned on GPS!")); /

if (!fona.enableGPRS(false)) Serial.println(F("Failed to disable GPRS!")); // Turn on GPRS while (!fona.enableGPRS(true)) { Serial.println(F("Failed to enable GPRS, retrying...")); delay(2000); // Retry every 2s } Serial.println(F("Enabled GPRS!"));

TotalCycles = EEPROM.read(0); // Total Cycles
CycleSincePickup = EEPROM.read(1); // Cycles Since Return

PowerONMessage(); // RecevieGPSCoordinates(); } ` i am going to try and repeat this tonight. and check what happens.

ammarqs commented 5 years ago

https://mail.google.com/mail/u/0?ui=2&ik=a3785c2d20&attid=0.1&permmsgid=msg-f:1620486063760413180&th=167d1f7d41e911fc&view=att&disp=safe

I suppose this is 64ms OFF/ 300ms OFF Its working right now!

ammarqs commented 5 years ago

Hey, I managed to leave it for 4 hours and it started doing the same thing. looks like the light is blinking for 64ms ON and 3000ms OFF.

This is the error screen once i try to trigger an event. The system was left untouched for a few hours. capture

ammarqs commented 5 years ago

Looks like it leaving it ideal for a few hours disconnects the module from the network.

botletics commented 5 years ago

No, it's connected to the network but data is being disabled. You just have to use "enableGPRS(true)" before posting each time.

ammarqs commented 5 years ago

Thanks. But why do you think it would be doing it? Do i still need to set these: fona.setFunctionality(1); // AT+CFUN=1 fona.setNetworkSettings(F("c2.korem2m.com")); // For KORE SIM card fona.setPreferredMode(38); // Use LTE only, not 2G fona.setPreferredLTEMode(1); // Use LTE CAT-M only, not NB-IoT fona.setOperatingBand("CAT-M", 12); // AT&T uses band 12

On Sat, Dec 22, 2018 at 10:16 PM Timothy Woo notifications@github.com wrote:

No, it's connected to the network but data is being disabled. You just have to use "enableGPRS(true)" before posting each time.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/botletics/SIM7000-LTE-Shield/issues/52#issuecomment-449611497, or mute the thread https://github.com/notifications/unsubscribe-auth/AQarXxzi5WDmfbTPC2lxWdFyeD4IxRAsks5u7vV9gaJpZM4YzlYS .

ammarqs commented 5 years ago

Is there any other way i can check for data connection before tring to connect? If data is not there it does the enablegprs routine, else it just goes through?

botletics commented 5 years ago

It's probably turning off data to save data, but it won't disconnect from the network. You shouldn't have to set those other parameters again. Just run the enableGPRS(true) command to make sure data is enabled. I believe you can also check with AT+CNACT? as well.

ammarqs commented 5 years ago

Hello Timothy, Did you by any chance figure out a way to send an image attachment via POST or GET requests?

ammarqs commented 5 years ago

Or the ftp seTUP?

botletics commented 5 years ago

Basic FTP example is shown in the FTP_Demo sketch

Using FTP with full pictures is a whole different ballgame that I haven't played with yet.

ammarqs commented 5 years ago

The only i see here is that the FTP is not secured. Would this also work with a SFTP protocol or some other secure gateway?

ammarqs commented 5 years ago

Or can we do a simple HTTP GET/POST to post the pictures to the web server?

botletics commented 5 years ago

I don't believe the FTP commands would work over SSL. That would require separate commands. Yes, you can do HTTP GET/POST requests but the AT command manual specifies max data size of 319488 bytes.

ammarqs commented 5 years ago

Yes this should be good enough. The max pic size i will be using is around 80KB. Is there anything special in your library i would have to implement in order to attach a file to the post request?

botletics commented 5 years ago

Should be fine as long as you make sure you don't run out of memory or something.

ammarqs commented 5 years ago

What i meant is: how do i attach a file to a post request within your system?

ammarqs commented 5 years ago

`void setup(){ Serial.begin(9600); Serial.println(F("TEST FUNCTION"));

ifdef LED

pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);

endif

pinMode(FONA_RST, OUTPUT); digitalWrite(FONA_RST, HIGH); // Default state

pinMode(FONA_PWRKEY, OUTPUT); powerOn(); // Power on the module moduleSetup(); // Establishes first-time serial comm and prints IMEI

fona.setFunctionality(1); // AT+CFUN=1 fona.setNetworkSettings(F("c2.korem2m.com")); // For KORE SIM card fona.setPreferredMode(38); // Use LTE only, not 2G fona.setPreferredLTEMode(1); // Use LTE CAT-M only, not NB-IoT fona.setOperatingBand("CAT-M", 12); // AT&T uses band 12

if (!fona.enableGPRS(false)) Serial.println(F("Failed to disable GPRS!")); // Turn on GPRS while (!fona.enableGPRS(true)) { Serial.println(F("Failed to enable GPRS, retrying...")); delay(2000); // Retry every 2s } Serial.println(F("Enabled GPRS!"));

Serial.println("Initializing SD card...");

if (!SD.begin(SD_CS)) { Serial.println(F("initialization failed!")); while (1); } Serial.println(F("initialization done.")); }`

Timothy,

in the above code, nothing works after initializing SD card. I get the initialization done message but after that the system stop communicating with the sim7000 module. It sends AT commands but doesnt receive any replies, none of the GET/POST request work either. If i comment the SD card initialization, everything works normal. What i am missing? Something to do with SPI communication ?

ammarqs commented 5 years ago

never mind. It was the software serial port clashing with the SPI pins. changed the software serial to 8 and 9

ammarqs commented 5 years ago

What i meant is: how do i attach a file to a post request within your system?

botletics commented 5 years ago

Without using FTP you cannot post a file to a directory, or just "attach" the file, but you can only post the contents of that file.

ammarqs commented 5 years ago

I have an image that i need to post. if POST wont work for that, what will? TCP server client connection?

botletics commented 5 years ago

If you just need to send the image data then POST should be just fine. FTP keeps everything as a file system, but the underlying principle is that you still need to send the data.

ammarqs commented 5 years ago

any thing that can help me get started with the post requests? i see examples but adding image data would be something i might get stuck with.

botletics commented 5 years ago

Sorry I am extremely busy. I can't give one-on-one support for everyone :(

ammarqs commented 5 years ago

very well..

ammarqs commented 5 years ago

Timothy, does the library allow me to use flash memory to store data? This will be very helpful to send the images via POST...

botletics commented 5 years ago

Storing data to flash memory has nothing to do with the library itself, although the library does need to be able to handle the data that is sent to it in the postData() function. Storing large amounts of data to flash memory can either be hard-coded in the program using PROGMEM for AVR microcontrollers (which I'm assuming you won't want because you can't change it afterwards) or to use an ESP8266's SPIFFS file system or SD card. However, interfacing it with the library to handle those large amounts of data is a whole different story which I haven't investigated yet.

ammarqs commented 5 years ago

I am probably OK with doing that. Mega has 256 kb of flash that i can use to store the image data while sending it out. Sending out an image as been a pain, tcp client server takes a long time to send data in blocks, somi got mo other way other than doing poststart and postend requests.

On Thu, Jan 17, 2019 at 9:02 PM Timothy Woo notifications@github.com wrote:

Storing data to flash memory has nothing to do with the library itself, although the library does need to be able to handle the data that is sent to it in the postData() function. Storing large amounts of data to flash memory can either be hard-coded in the program using PROGMEM for AVR microcontrollers (which I'm assuming you won't want because you can't change it afterwards) or to use an ESP8266's SPIFFS file system or SD card. However, interfacing it with the library to handle those large amounts of data is a whole different story which I haven't investigated yet.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/botletics/SIM7000-LTE-Shield/issues/52#issuecomment-455400768, or mute the thread https://github.com/notifications/unsubscribe-auth/AQarX6VTVcYh3vAWzA6jAjfF41MdxfMbks5vESs-gaJpZM4YzlYS .

-- Ammar Quaid Surti, Contact:+1-681-212-9752 Email: ammarqs@gmail.com;

ammarqs commented 5 years ago

`void SendPicture(){

if (!fona.enableGPRS(false)) Serial.println(F("Failed to disable GPRS!")); // Turn on GPRS while (!fona.enableGPRS(true)) { Serial.println(F("Failed to enable GPRS, retrying...")); delay(2000); // Retry every 2s } Serial.println(F("Enabled GPRS!"));

uint16_t statuscode; int16_t length; char filename[14] = "1.jpg"; char url[80]; char contenttype[80]; char postdata[20000];

sprintf(url, "xx.xxx.xx.xx/process.php"); sprintf(contenttype, "multipart/form-data; boundary=AaB03x");

String start_request = ""; String end_request = ""; start_request = start_request + "\n" + "--AaB03x" + "\n" + "Content-Disposition: form-data; name=\"fileToUpload\"; filename="+filename+"\n" + "Content-Type: file" + "\n" + "Content-Transfer-Encoding: binary" + "\n" + "\n"; end_request = end_request + "\n" + "--AaB03x--" + "\n";

File myFile = SD.open("1.jpg"); uint16_t jpglen = myFile.size(); uint16_t extra_length; extra_length = start_request.length() + end_request.length(); uint16_t postdatalen = jpglen + extra_length;

if (myFile) { byte clientBuf[20000]; unsigned int clientCount = 0;

while(myFile.available()) { clientBuf[clientCount] = myFile.read(); clientCount++; } if(clientCount > 0) sprintf(postdata, "%s %s %s", start_request, clientBuf ,end_request); }

while (counter < 3 && !fona.HTTP_POST_start(url, F("multipart/form-data; boundary=AaB03x"), (uint8_t )postdata, postdatalen, &statuscode, (uint16_t )&length)); { Serial.println("Couldn't Post Data"); counter ++; } fona.HTTP_POST_end(); Serial.println("Image Sent");

delay(5000); }`

ammarqs commented 5 years ago

Ok now i see what you were saying. Using the flash memory can only be done initially while programming the controller, i cannot write variable to flash memory during live operation, right??

botletics commented 5 years ago

In general, correct.

ammarqs commented 5 years ago

right. appreciate for clearing out the confusion. I saw the update that you made yesterday for including the json script to postdata function. and also providing small hints on how the image can be sent. me and my other developer are still having issues to understanding the concept of sending images. We know for a fact that the usual post script where we can give the path of the location of the image wont work here. Here we have to send the raw format of the image to the server and then merge that on the server side, RIGHT? I am NOT asking you to help me out with the code, but just a walk through on what needs to be done in order to get this going, will help us to try and understand the concept of what needs to be done.

I tried doing your latest code down below, but i am pretty sure we are still missing on how to process the image in the script.

`void SendPicture(){

Serial.println(F("Entering SendPicture"));

if (!fona.enableGPRS(false)) Serial.println(F("Failed to disable GPRS!")); // Turn on GPRS while (!fona.enableGPRS(true)) { Serial.println(F("Failed to enable GPRS, retrying...")); delay(2000); // Retry every 2s } Serial.println(F("Enabled GPRS!"));

uint16_t statuscode; int16_t length; char filename[14] = "1.jpg"; char url[80]; char contenttype[80];

sprintf(url, "xx.xxx.xx.xx/process.php"); sprintf(contenttype, "multipart/form-data; boundary=AaB03x");

File myFile = SD.open("1.jpg"); char body[150] = "{\"Content-Disposition\":\"form-data\",\"name\":\"file_upload\",\"filename\":\"1.jpg\"}";

uint16_t jpglen = myFile.size(); uint16_t postdatalen = jpglen + strlen(body); counter = 0; while (counter < 3 && !fona.postData("POST", url, body,"",postdatalen)); { Serial.println("Didn't Work!! Trying again!"); counter ++; }

Serial.println("File Sent"); } `

botletics commented 5 years ago

Well the problem is that right now the library function doesn't work alongside the SD card library. When you read the contents of a file on the SD card using the SD card library, it reads byte by byte and if you try to pass the data of a file that's too large to the postData() function, it won't work.