Hi All,
I've been playing around with some SIM 900 and SIM 908 shields where I send a get request to a web server. I'm actually having two problems and I might now be thinking its causing this one...
When I connect the Arduino via USB + 12V (2A) supply and open the Serial Monitor, I can see that the code executes "fine" and sends the request to the server.
However when I plug the Arduino only using the 12V supply it doesn't always seem to execute the code - it's like a 2/10 chance and I can't tell where the code hangs.
Using this library: GitHub - MarcoMartines/GSM-GPRS-GPS-Shield: GSM/GPRS & GPS Shield Library for modules using SIM900/SIM908
I've tried the following and have had similar results:
Changing the baud rates to no higher than 9600 and no lower than 2400.
Using a different power supply such as 9V 2A.
Originally using Arduino UNO and then switched to the Arduino MEGA using Serial1.
Any reasons as to why this might be happening?
Going back to beginning I said there is another problem which might be causing this issue, but i'll try and eliminate other possibilities first.
Serial Monitor Output when it works ok...
GSM Shield testing.
ATT: OK
RIC: AT
OK
DB:ELSE
ATT: OK
RIC: AT
OK
DB:ELSE
ATT: OK
RIC: AT
OK
DB:ELSE
ATT: OK
RIC: AT
OK
DB:CORRECT BR
ATT: OK
RIC: AT
OK
ATT: OK
RIC: AT&F
OK
ATT: OK
RIC: ATE0
OK
ATT: OK
RIC:
OK
ATT: OK
RIC:
OK
ATT: OK
RIC:
OK
ATT: OK
RIC:
OK
ATT: +CPMS:
RIC:
+CPMS: 0,25,0,25,0,25
OK
ATT: OK
RIC:
OK
ATT: SHUT OK
RIC:
SHUT OK
status=READY
ATT: OK
RIC:
OK
ATT: OK
RIC:
OK
ATT: ERROR
RIC:
ERROR
DB:STARTING NEW CONNECTION
ATT: SHUT OK
RIC:
SHUT OK
DB:SHUTTED OK
ATT: OK
RIC:
OK
DB:APN OK
ATT: OK
RIC:
OK
DB:CONNECTION OK
ATT: ERROR
RIC:
x.x.x.x (hidden out out the IP)
DB:ASSIGNED AN IP
status=ATTACHED
Temperature: 20.29
ATT: OK
RIC:
OK
DB:RECVD CMD
ATT: CONNECT OK
RIC:
OK
ATT: OK
RIC:
CONNECT OK
DB:OK TCP
ATT: >
RIC:
>
DB:>
ATT: SEND OK
RIC:
SEND OK
DB:SENT
Starting read..
Waiting for Data...HTTP/1.1 200 OK
Date: Fri, 12 Sep 2014 11:12:05
Done..
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "inetGSM.h"
#define gsmPower 9
#define LED 13
#define ThermistorPIN 0 // Analog Pin 0
InetGSM inet;
char msg[50];
int numdata;
char inSerial[50];
int i=0;
boolean started=false;
char request[53];
char strRequest[46] = "/insert.php?formdatahere"; //45 in length
float temp;
char charTemp[6];
String finalRequest;
double res;
double cf;
double mx = 0.0976;
double cx = -0.6764;
int j=0;
double a = 0;
double b = 0;
double c = 0;
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
double k = 0;
double m = 0;
double n = 0;
double o = 0;
double p = 0;
double q = 0;
double u = 0;
double v = 0;
double w = 0;
double s = 0;
double y = 0;
double z = 0;
void setup()
{
pinMode(gsmPower, OUTPUT);
digitalWrite(gsmPower, HIGH);
delay(1000);
digitalWrite(gsmPower, LOW);
Serial.begin(4800);
Serial1.begin(4800);
Serial.println("GSM Shield testing.");
if (gsm.begin(4800)){
Serial.println("\nstatus=READY");
started=true;
gsm.forceON();
}
else Serial.println("\nstatus=IDLE");
if(started){
//GPRS attach, put in order APN, username and password.
started = false;
while(!started)
{
if (inet.attachGPRS("someapn.co.uk", "pass", "pass"))
{
Serial.println("status=ATTACHED");
started = true;
}
else
{
Serial.println("status=ERROR");
}
}
//delay(1000);
//Read IP address.
//gsm.SimpleWriteln("AT+CIFSR");
//delay(5000);
//gsm.WhileSimpleRead();
}
delay(30000);
}
void loop()
{
double tMean1;
double tMean;
double rMean;
int i = 1;
double t = 0;
double r = 0;
request[0] = 0;
for (i=1; i<10; i++) {
int RawADC;
double d;
RawADC = analogRead(ThermistorPIN);
long Resistance; double Temp; // Dual-Purpose variable to save space.
Resistance=((2039808/RawADC) - 1992); // Assuming a 10k Thermistor. Calculation is actually: Resistance = (1024 * BalanceResistor/ADC) - BalanceResistor
Temp = log(Resistance); // Saving the Log(resistance) so not to calculate it 4 times later. // "Temp" means "Temporary" on this line.
Temp = 1 / (0.0014988656 + (0.0002379063 * Temp) + (0.0000001067 * Temp * Temp * Temp)); // Default 2KT Values
Temp = Temp - 273.15; // Convert Kelvin to Celsius // Now it only means "Temperature"
t = Temp + t;
r = Resistance + r;
delay(100);
digitalWrite(LED, HIGH);
}
temp = t/(i);
res = r/(i);
a = b;
b = c;
c = d;
d = e;
e = f;
f = g;
g = h;
h = k;
k = m;
m = temp;
dtostrf(temp,5,2, charTemp);
strcat(request,strRequest);
strcat(request, charTemp);
Serial.print("Temperature: ");
Serial.println(temp);
Serial.println();
numdata=inet.httpGET("somewebsite", 80, request, msg, 50);
Serial.println("\nNumber of data received:");
Serial.println(numdata);
Serial.println("\nData received:");
Serial.println(msg);
serialswread();
delay(45000);
}
void serialswread(){
gsm.SimpleRead();
}