Go Down

Topic: Connecting problems with Arduino GSM Shield (Read 9128 times) previous topic - next topic

martinhagreen

Apr 13, 2014, 04:35 pm Last Edit: Apr 15, 2014, 07:40 pm by martinhagreen Reason: 1
Hi all, I´m working on a standalone project with an Arduino Mega 2560 attached to a GSM Shield.
I´m powering it with an swtiching power supply, getting output 12V and 1 amp (I read that It was enough with 1 amp)
I have attached 8 Hall sensors, 1 Led and 1 reed switch.
I´m using it to post the sensors data into a database to show them in a web visualization.

My problem is that sometimes, 3 days later or 2 (this time is variable) since I connect the device, it stops sending data; and the only solution is unplug and plug the power supply again to reset it.
This device is going to be installed on a roof on a corporate building and I can´t go up there to re-plug it, maybe it´s possible to turn off the device once a day (p. example) by code or by hardware (with a Relay?) to avoid this?  Maybe is getting this 2 Amp peak value and because of it its stopping?

Power requirements

It is recommended that the board be powered with an external power supply that can provide between 700mA and 1000mA. Powering an Arduino and the GSM shield from a USB connection is not recommended, as USB cannot provide the required current for when the modem is in heavy use.

The modem can pull up to 2A of current at peak usage, which can occur during data transmission. This current is provided through the large orange capacitor on the board's surface..


The code is the following, the server areas are empty because it´s our client private server:


Code: [Select]

#include <GSM.h>

#define PINNUMBER ""
// APN data
#define GPRS_APN       "bluevia.movistar.es" // replace your GPRS APN
#define GPRS_LOGIN     " "    // replace with your GPRS login
#define GPRS_PASSWORD  " " // replace with your GPRS password

GSMClient client;
GPRS gprs;
GSM gsmAccess;

// URL, path & port
char server[] = "";
char path[] = " ";
int port = 80; // 80 for HTTP

int totalCount = 0;

//Weather variables
long pulseWidth;
float wSpeed;
char params[32];
int velocidad;
int direccion;

int statePin1, statePin2, statePin3, statePin4, statePin5, statePin6, statePin7, statePin8;
//int prevStatePin = 0;


#define delayMillis 60000
//1minuto
//#define delayMillis 60000

unsigned long thisMillis = 0;
unsigned long lastMillis = 0;

int hallPin1 = 12;
int hallPin2 = 11;
int hallPin3 = 9;
int hallPin4 = 8;
int hallPin5 = A0;
int hallPin6 = 6;
int hallPin7 = 5;
int hallPin8 = 4;
int anemoPin = 13;

int ledPin = A5;

void setup()
{
 
 setupExternals();
 
 Serial.begin(9600);

 // connection state
 boolean notConnected = true;
 
 // Start GSM shield
 while(notConnected)
 {
   if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
       (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
        notConnected = false;
   else
   {
     Serial.println("Not connected");
     delay(1000);
   }
 }

 Serial.println("connecting...");
}


void loop()
{
 thisMillis = millis();

 if(thisMillis - lastMillis > delayMillis)
 {
   
   lastMillis = thisMillis;
 
   digitalReads();
   readAnemometer();
   readHalls();
 
   // params must be url encoded.
   sprintf(params,"velocidad=%i&direccion=%i", velocidad,direccion);
   Serial.println(params);    
   if(!postPage(server,port,path,params)) Serial.print(F("Fail "));
   else Serial.print(F("Pass "));
   totalCount++;
   Serial.println(totalCount,DEC);
 }  
 
}

byte postPage(char* domainBuffer,int thisPort,char* page,char* thisData)
{
 int inChar;
 char outBuf[64];

 Serial.print(F("connecting..."));

 if(client.connect(domainBuffer,thisPort))
 {
   Serial.println(F("connected"));
   
   analogWrite(ledPin, 255);
   // send the header
   sprintf(outBuf,"POST %s HTTP/1.1",page);
   client.println(outBuf);
   sprintf(outBuf,"Host: %s",domainBuffer);
   client.println(outBuf);
   client.println(F("Connection: close\r\nContent-Type: application/x-www-form-urlencoded"));
   sprintf(outBuf,"Content-Length: %u\r\n",strlen(thisData));
   client.println(outBuf);

   // send the body (variables)
   client.print(thisData);
 }
 else
 {
   Serial.println(F("failed"));
   analogWrite(ledPin, 0);
   return 0;
 }

 int connectLoop = 0;



 while(client.connected())
 {
   while(client.available())
   {
     inChar = client.read();
     Serial.write(inChar);
     connectLoop = 0;
   }

   delay(1);
   connectLoop++;
 
 }

 Serial.println();
 Serial.println(F("disconnecting."));
 analogWrite(ledPin, 0);
 client.stop();
 return 1;
 
}

void digitalReads(){

 statePin1=digitalRead(hallPin1);
 statePin2=digitalRead(hallPin2);
 statePin3=digitalRead(hallPin3);
 statePin4=digitalRead(hallPin4);
 statePin5=digitalRead(hallPin5);
 statePin6=digitalRead(hallPin6);
 statePin7=digitalRead(hallPin7);
 statePin8=digitalRead(hallPin8);

}

void readHalls(){
 if(statePin1==HIGH)
   {
     direccion = 1;
    }  

   if(statePin2==HIGH)
   {
     direccion = 2;
   }
   
   if(statePin3==HIGH)
   {
   
     direccion = 3;
   }
   
   if(statePin4==HIGH)
   {
     
     direccion = 4;
   }
   
   if(statePin5==HIGH)
   {
     
     direccion = 5;
   }
   
   if(statePin6==HIGH)
   {
     
     direccion = 6;
   }
   
   if(statePin7==HIGH)
   {
     
     direccion = 7;
   }
   
   if(statePin8==HIGH)
   {
     
     direccion = 8;
   }
 
   if (statePin1 == LOW &&
     statePin2 == LOW &&
     statePin3 == LOW &&
     statePin4 == LOW &&
     statePin5 == LOW &&
     statePin6 == LOW &&
     statePin7 == LOW &&
     statePin8 == LOW){
        direccion = direccion;
    }

   return;

}

void setupExternals(){

 
 pinMode(hallPin1,INPUT);
 pinMode(hallPin2,INPUT);
 pinMode(hallPin3,INPUT);
 pinMode(hallPin4,INPUT);
 pinMode(hallPin5,INPUT);
 pinMode(hallPin6,INPUT);
 pinMode(hallPin7,INPUT);
 pinMode(hallPin8,INPUT);
 
 pinMode(anemoPin, INPUT);

}

void readAnemometer(){
 
   //Anemometro
   //=======
   pulseWidth=pulseIn(anemoPin, LOW);
   //Formula for period (in microsec) to mph
   wSpeed=1000000.0/pulseWidth*2.5;
   //convert from mp/h to km/h
   float kmH = wSpeed * 1.609;  
   kmH = constrain(kmH, 1, 200);
   if(kmH == 200){
     kmH = 1.0;
   }
   //========
   velocidad = kmH * 100;
 
   return;

}



Thank you in advance¡

markusdnd

Have you had luck with getting serial debug stream from failure ?

martinhagreen

No, when I had it plugged to the computer and stopped sending data, I get from serial console only this:

connecting...failed
Fail xxx








markusdnd

#3
Apr 14, 2014, 10:36 am Last Edit: Apr 14, 2014, 10:42 am by markusdnd Reason: 1
It seems like a problem I have worked on for past few weeks.

enable the debug mode from the library and try to get debug output when it fails.
GSM gsmAccess(true);

I am of course guessing that you are using the default gsm library for the module.

Edit> of course you are using the standard library. never hurts to ask thou.

martinhagreen

Ofc, Im using the official library, my sketch is based on the GSMwebClient Example

Per example, i went out the weekend, and I noticed than the devide was properly sending data since Wednesday. It might be working for 2 days and disconnect, or 1 month, I couldnt know in advance.

I think the best way to avoid problems is programming a reset of the whole system every XX days, to play it safe.
Maybe I will ned another Arduino board with a relay to interrupt the power supply?  I never used a relay and I don´t know how to start.

How I can enable the debug mode from the library?

Thank you¡

markusdnd

Replace GSM gsmAccess; with GSM gsmAccess(true);

then you will see the data that will be sent to and recieved from gsm module.

What I saw was that at one point (when the hang happens) there is AT command sent but nothing is recieved from module. I guess that the library stays waiting for the reply but nothing happens. for whatever reason

I do not have proper solution yet, but I would love to find out if the symptoms of the problem are the same.

Also I have had 32h of working flawlessly. then it just hangs. no extra info from terminal no nothing.

It seems to me that the library is unable to handle the missing answer from the module. Thou i am not 100 % sure of that.
Also using signal analyzer does not help since I have not figured out the way to log for days in a row.

martinhagreen

#6
Apr 14, 2014, 11:37 am Last Edit: Apr 15, 2014, 07:38 pm by martinhagreen Reason: 1
Ok,  I had my device working more than 32h, but I should try what you are advicing; when it Hangs, i Will post the result

For now, is working, it´s normal to get this extrange/weird encoding?

Starting  Client.
AT%13%
0 9>AT%13%%13%%10%OK%13%%10%
AT+CGREG?%13%
9 40>AT+CGREG?%13%%13%%10%+CGREG: 0,1%13%%10%%13%%10%OK%13%%10%
AT+IFC=1,1%13%
40 57>AT+IFC=1,1%13%%13%%10%OK%13%%10%
AT+CMGF=1%13%
57 75>%19%%17%AT+CMGF=1%13%%13%%10%OK%13%%10%
AT+CLIP=1%13%
75 91>AT+CLIP=1%13%%13%%10%OK%13%%10%
ATE0%13%
91 102>ATE0%13%%13%%10%OK%13%%10%
AT+COLP=1%13%
102 108>%13%%10%OK%13%%10%
AT+CGATT=1%13%
108 114>%13%%10%OK%13%%10%
AT+QIFGCNT=0%13%
114 120>%13%%10%OK%13%%10%
AT+QICSGP=1,"telefonica.es","telefonica","telefonica"%13%
120 126>%13%%10%OK%13%%10%
AT+QIMUX=0%13%
126 4>%13%%10%OK%13%%10%
AT+QIMODE=1%13%
4 10>%13%%10%OK%13%%10%
AT+QINDI=1%13%
10 16>%13%%10%OK%13%%10%
AT+QIREGAPP%13%
16 22>%13%%10%OK%13%%10%
AT+QIACT%13%
22 28>%13%%10%OK%13%%10%
connecting...
velocidad=200&direccion=3
connecting...AT+QIDNSIP=1%13%
28 34>%13%%10%OK%13%%10%
AT+QIOPEN="TCP","labs81.com.es",80%13%
34 40>%13%%10%OK%13%%10%

34 51>%13%%10%OK%13%%10%%13%%10%CONNECT%13%%10%
connected
POST /xxxx/xxx.php HTTP/1.1%13%%10%Host: xxx.com.es%13%%10%Connection: close%13%%10%Content-Type: application/x-www-form-urlencoded%13%%10%Content-Length: 25%13%%10%%13%%10%velocidad=200&direccion=3
51 47>HTTP/1.1 200 OK%13%%10%Date: Mon, 14 Apr 2014 09:44:45 GMT%13%%10%Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8g PHP/5.2.11
HTTP/1.1 200 OK
Date: Mon, 14 Apr 2014 09:44:45 GMT
Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13
20 1> OpenSSL/0.9.8g PHP/5.2.11 with Suhosin-Patch%13%%10%Content-Type: text/html%13%%10%Connection: close%13%%10%%13%%10%OKPOST%13%%10%CLOSED%13%%10%
OpenSSL/0.9.8g PHP/5.2.11 with Suhosin-Patch
Content-Type: text/html
Connection: close

OKPOST

disconnecting.

markusdnd

Yes this is absolutely normal.

another person with the same problem: http://forum.arduino.cc/index.php?topic=233137.new;topicseen#new

It seems to be rather large problem.

PS the % are added by the library so you can find where are the line endings etc.


markusdnd

http://forum.arduino.cc/index.php?topic=233137.0

Seems that the problem has some kind of solution. I will be testing it soon.

martinhagreen

Woah¡ Thank you for the reply, do you think it will work?
I changed the power supply to a 12V & 2amp one, and enabled the output from the library to see the message when it hangs but it is working properly... (I should not complaining about this, but I want to see the error log!)

PierluigiRovere

First: sorry for my bad english  8)

Pay attention of this expression:
Code: [Select]
if(thisMillis - lastMillis > delayMillis)

The Millis() function returns to 0 after 50 days due to the Unsigned LONG type that reaches the maximum value. (Read HERE)

so after this reset, this expression in no longer valid, because "lastMillis" will be bigger then "thisMillis" until the 50th day...





cabbi


First: sorry for my bad english  8)

Pay attention of this expression:
Code: [Select]
if(thisMillis - lastMillis > delayMillis)

The Millis() function returns to 0 after 50 days due to the Unsigned LONG type that reaches the maximum value. (Read HERE)

so after this reset, this expression in no longer valid, because "lastMillis" will be bigger then "thisMillis" until the 50th day...




Because thisMillis & lastMillis are defined as unsigned, the math will keep working after the rollover of 50 days.
(http://stackoverflow.com/questions/727918/what-happens-when-gettickcount-wraps)

gaylepcb01

Here is a great solution from Pipeline PCB's(pipelinepcb.net). A customized version of the Super Link Shield, which we got for our final year project. It has GSM+bluetooth+wifi units, independent controlled by on board AVR's, and simple arduino commands through software serials are there to communicate, thanks to the customized libraries.

Reference : http://www.pipelinepcb.net/projects.html

shimna

hello all......am working on gsm shiled to sent sms. could some one fix the issue asap......

when I load the example "testemodem" shows me this:

Starting modem test...ERROR, no modem answer.
Checking IMEI...Modem's IMEI: 0
Resetting modem...Modem is functoning properly


when I load the example "gsmscannetworks"  or other shows me this:
"GSM networks scanner"
and do not go to the next step


when I load the example "pinmanagement" shows me this:
Change PIN example

PIN & PUK locked. Use PIN2/PUK2 in a mobile phone.

Go Up