Hello.
I want send data to my site using gsm shield. I have code
#include <dht11.h>
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "inetGSM.h"
#include "sms.h"
InetGSM inet;
SMSGSM sms;
dht11 DHT11;
#define DHT11PIN 2
//variables
char msg[50];
int numdata;
char inSerial[50];
int i=0;
boolean started=false;
String url = "";
int totaltemp = 0;
int totalhum = 0;
int totalrain = 0;
int totalphoto = 0;
int OKLED = 12;
int updateled = 13;
int errorled = 11;
void setup(){
Serial.begin(9600);
pinMode(OKLED, OUTPUT);
pinMode(updateled, OUTPUT);
pinMode(errorled, OUTPUT);
digitalWrite(errorled, HIGH);
digitalWrite(OKLED, HIGH);
Serial.println("DHT11 Starting... ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
int chk = DHT11.read(DHT11PIN);
Serial.print("Read DHT11 sensor: ");
switch (chk)
{
case 0: Serial.println("OK"); break;
case -1: Serial.println("Checksum error"); break;
case -2: Serial.println("Time out error"); break;
default: Serial.println("Unknown error"); break;
}
Serial.println("init PHOTORESISTOR");
Serial.println("init RAINDROP_SHIELD");
//init GSM
/* Serial.println("GSM SIM900 Starting...");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(2400)){
Serial.println("status = READY");
started=true;
}
else Serial.println("status=IDLE");
if(started){
//GPRS attach, put in order APN, username and password.
//If no needed auth let them blank.
if (inet.attachGPRS("internet.wind", "", ""))
Serial.println("status = CONNECTED");
else
Serial.println("status=ERROR");
delay(100);
//Read IP address.
gsm.SimpleWriteln("AT+CIFSR");
delay(5000);
//Read until serial buffer is empty.
gsm.WhileSimpleRead();
//if (sms.SendSMS("598555207", "Start Amindi Kutaisi #1.1 (c) www.amindi.com"))
//Serial.println("\nSMS sent OK");
digitalWrite(errorled, LOW);
} else {
Serial.println("Fatal Error!");
digitalWrite(OKLED, LOW);
while(true){}
}
*/
}
void loop(){
totaltemp = 0;
totalhum = 0;
totalrain = 0;
totalphoto = 0;
for (int i=1; i<51; i++){
getTempandHum();
getlight();
checkrain();
delay(200);
}
totaltemp = totaltemp / 50;
totalhum = totalhum / 50;
totalrain = totalrain / 50;
totalphoto = totalphoto / 50;
url = setURL("/amindi/input/updatewrite.php?city=1&weather=&temp=");
delay(100);
Serial.println("||-==-=-=-=-=-=-=-=-=-=-=-=-=-||");
Serial.print("Temperature C: ");
Serial.println(totaltemp);
Serial.print("humidity :");
Serial.print(totalhum);
Serial.println(" %");
Serial.print("Photoresistor: ");
Serial.println(totalphoto);
Serial.print("Rain Drop: ");
Serial.println(totalrain);
Serial.print("New URL: ");
Serial.println(url);
delay(100);
//insertdb();
digitalWrite(updateled, HIGH);
delay(700);
digitalWrite(updateled, LOW);
Serial.println("||-==-=-=-=-=-=-=-=-=-=-=-=-=-||\n\n");
}
void getTempandHum(){
int hum = ((float)DHT11.humidity);
int temp = ((float)DHT11.temperature);
totalhum += hum;
totaltemp +=temp;
}
void getlight(){
int photo = analogRead(A1);
totalphoto += photo / 10;
}
void checkrain(){
int raindrop = analogRead(A0);
totalrain += raindrop / 10;
}
String setURL(String curl){
curl += totaltemp;
curl += "&humidity=";
curl += totalhum;
curl += "&barometer=&photoresistor=";
curl += totalphoto;
curl += "&raindrop=";
curl += totalrain;
curl += "&windspeed=&winddir=&datatime=&submit=Submit";
return curl;
}
void insertdb(){
//TCP Client GET, send a GET request to the server and
//save the reply.
char charurl[url.length()];
url.toCharArray(charurl, url.length());
numdata=inet.httpGET("www.pakura.info", 80, charurl, msg, 50);
//Print the results.
Serial.print("\nNumber of data received:");
Serial.println(numdata);
Serial.println("Database Has been Updated.");
serialhwread();
//Read for new byte on NewSoftSerial.
serialswread();
}
void serialhwread(){
i=0;
if (Serial.available() > 0){
while (Serial.available() > 0) {
inSerial[i]=(Serial.read());
delay(10);
i++;
}
inSerial[i]='\0';
if(!strcmp(inSerial,"/END")){
Serial.println("_");
inSerial[0]=0x1a;
inSerial[1]='\0';
gsm.SimpleWriteln(inSerial);
}
//Send a saved AT command using serial port.
if(!strcmp(inSerial,"TEST")){
Serial.println("SIGNAL QUALITY");
gsm.SimpleWriteln("AT+CSQ");
}
//Read last message saved.
if(!strcmp(inSerial,"MSG")){
Serial.println(msg);
}
else{
Serial.println(inSerial);
gsm.SimpleWriteln(inSerial);
}
inSerial[0]='\0';
}
}
void serialswread(){
gsm.SimpleRead();
}
everything working when dont't use gsm protocol.
output:
||-==-=-=-=-=-=-=-=-=-=-=-=-=-||
Temperature C: 38
humidity :60 %
Photoresistor: 62
Rain Drop: 75
New URL: /amindi/input/updatewrite.php?city=1&weather=&temp=38&humidity=60&barometer=&photoresistor=62&raindrop=75&windspeed=&winddir=&datatime=&submit=Submit
||-==-=-=-=-=-=-=-=-=-=-=-=-=-||
e.g. setURL() function working good. but when I enable GSM protocol code this part:
Serial.println("GSM SIM900 Starting...");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(2400)){
Serial.println("status = READY");
started=true;
}
else Serial.println("status=IDLE");
if(started){
//GPRS attach, put in order APN, username and password.
//If no needed auth let them blank.
if (inet.attachGPRS("internet.wind", "", ""))
Serial.println("status = CONNECTED");
else
Serial.println("status=ERROR");
delay(100);
//Read IP address.
gsm.SimpleWriteln("AT+CIFSR");
delay(5000);
//Read until serial buffer is empty.
gsm.WhileSimpleRead();
//if (sms.SendSMS("598555207", "Start Amindi Kutaisi #1.1 (c) www.amindi.com"))
//Serial.println("\nSMS sent OK");
digitalWrite(errorled, LOW);
} else {
Serial.println("Fatal Error!");
digitalWrite(OKLED, LOW);
while(true){}
}
and this part
insertdb();
setURL() function don't working and outpu:
||-==-=-=-=-=-=-=-=-=-=-=-=-=-||
Temperature C: 25
humidity :56 %
Photoresistor: 66
Rain Drop: 75
New URL:
Number of data received:0
Database Has been Updated.
||-==-=-=-=-=-=-=-=-=-=-=-=-=-||
why don't working this code?
plz help me. how fix this?