Use Arduino GSM/GPRS SIM900 to send sensor data to my web service

14,118

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

Share:
14,118
Dileep
Author by

Dileep

Updated on June 05, 2022

Comments

  • Dileep
    Dileep almost 2 years

    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());
      }
    }
    
  • Ahh ... It's a programming thi
    Ahh ... It's a programming thi over 8 years
    Great ... if this answered your question don't forget to mark it as the answer ... Thanks
  • Chet
    Chet over 8 years
    Are you sure you can concatenate a string and int like that?
  • Dileep
    Dileep about 8 years
    Hi Someone that matters, Thank you, i sent my dynamic values to MySQL database by using your code. but now the thing is, if i tried to send a string with space its not showing in my database. if i send "AandB" then it is displayed. but if i tried like this, "A and B" (A (space)and(space)B) only A is displayed. Please help me. thank you.