Thank you in advance. I am beginner in arduino.
My Question is how to send dynamic sensor data (Continuous Readings) to the web server. I tried the below code to setup the GSM/GPRS connection to the server.
I successfully sent some static data which is in the below code. But when I want to include some dynamic data that comes from sensor, I am unable to insert the same in code.
Present Code:
gprsSerial.println("AT+HTTPPARA=\"URL\",\"xxxx/new.php?sensor1=100\"")
Required Code:
gprsSerial.println("AT+HTTPPARA=\"URL\",\"xxxx/new.php?sensor1=DYNAMIC VALUE\"")
ARDUINO CODE USED & TESTED
#include <SoftwareSerial.h>
SoftwareSerial gprsSerial(7, 8);
void setup()
{
gprsSerial.begin(19200);
Serial.begin(19200);
Serial.println("Config SIM900...");
delay(2000);
Serial.println("Done!...");
gprsSerial.flush();
Serial.flush();
// attach or detach from GPRS service
gprsSerial.println("AT+CGATT?");
delay(100);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"xxxx\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=1,1");
delay(2000);
toSerial();
}
void loop()
{
// initialize http service
gprsSerial.println("AT+HTTPINIT");
delay(2000);
toSerial();
// set http param value
gprsSerial.println("AT+HTTPPARA=\"URL\",\"http://www.oniee.com/new.php?sensor1=100\"");
delay(2000);
toSerial();
// set http action type 0 = GET, 1 = POST, 2 = HEAD
gprsSerial.println("AT+HTTPACTION=0");
delay(6000);
toSerial();
// read server response
gprsSerial.println("AT+HTTPREAD");
delay(1000);
toSerial();
gprsSerial.println("");
gprsSerial.println("AT+HTTPTERM");
toSerial();
delay(300);
gprsSerial.println("");
delay(10000);
}
void toSerial()
{
while(gprsSerial.available()!=0)
{
Serial.write(gprsSerial.read());
}
}
It all depends on where your getting your dynamic data but for this example I'm going to use a digital input on a single pin
int readpin = 4;
byte pinValue;
void loop()
{
// initialize http service
gprsSerial.println("AT+HTTPINIT");
delay(2000);
toSerial();
pinValue = digitalread(readpin);
// set http param value
gprsSerial.println("AT+HTTPPARA=\"URL\",\"http://www.oniee.com/new.php?sensor1="" + pinValue + ""\"");
delay(2000);
toSerial();
...
The number of " might be a little off I don't have a setup to test this on right now, but this basic idea is:
Check the pin (or pins) for value
Store the value
Include the value in your string