Arduino Forum

Products => Arduino GSM Shield => Topic started by: moshehab on Sep 15, 2019, 10:47 pm

Title: sending GPS Coordinates and data to HTTP website with GPRS/GPS module Sim808
Post by: moshehab on Sep 15, 2019, 10:47 pm
hi guys
Am using Arduino Uno , ultrasonic sensor & GPRS/GPS Sim808 module . i didn't test the module yet , but i donno if this code will send the data to the website or no as the module didn't deliver yet
if anyone can check this code and am waiting for your comments
<code>
#include "functionofUS.h"
#include "gprstest.h"
void setup() {
 sim808.begin(9600);
 Serial.begin(9600);
 testdistance();
 delay(50);
 sendData("AT+CGNSPWR=1",1000,DEBUG);
 delay(50);
 sendData("AT+CGNSSEQ=RMC",1000,DEBUG);
 delay(150);
}
void loop(){
gsm_connect_gprs();
gsm_send_data();
gsm_disConnect_gprs(); 
}
#include <SoftwareSerial.h>
SoftwareSerial sim808(2,3);

//char phone_no[] = "xxxxxxx"; // replace with your phone no.
String data[5];
#define DEBUG true
String state,timegps,latitude,longitude;
void sendTabData(String command , const int timeout , boolean debug){
  sim808.println(command);
  long int time = millis();
  int i = 0;

  while((time+timeout) > millis()){
    while(sim808.available()){
      char c = sim808.read();
      if (c != ',') {
         data +=c;
         delay(100);
      } else {
        i++; 
      }
      if (i == 5) {
        delay(100);
        goto exitL;
      }
    }
  }exitL:
  if (debug) {
    state = data[1];
    timegps = data[2];
    latitude = data[3];
    longitude =data[4]; 
  }
}
String sendData (String command , const int timeout ,boolean debug){
 
  String response = "";
  sim808.println(command);
  long int time = millis();
  int i = 0;

  while ( (time+timeout ) > millis()){
    while (sim808.available()){
      char c = sim808.read();
      response +=c;
    }
  }
  if (debug) {
     Serial.print(response);
     }
     return response;
}

void offgps(void){
  sendData( "AT+CGNSPWR=0",1000,true);
}
void getgps(void){
   sendData( "AT+CGNSPWR=1",1000,true);
   sendData( "AT+CGPSINF=0",1000,true);
  sendTabData("AT+CGNSINF",1000,DEBUG);
  if (state !=0) {
    Serial.println("State  :"+state);
    Serial.println("Time  :"+timegps);
    Serial.println("Latitude  :"+latitude);
    Serial.println("Longitude  :"+longitude);
  } else {
    Serial.println("GPS Initialising...");
  }}
void gsm_send_data()
{
 
  getgps();
    Serial.println("Sending data.");   
    sim808.write("AT+HTTPINIT\r\n");  // Initialize HTTP
    //Serial.print("AT+HTTPINIT\r\n");
    delay(1000);
    sim808.write("AT+HTTPPARA=\"URL\",\"http://shehanshaman.000webhostapp.com/?readingsensor=");
    //URL/?readingsensor=98%&location=location=maps.google.com/maps?q=loc:longitude,latitude
    delay(50);
    //sim808.print("");
    sim808.print(runussensor());   // Add percentage to the url
    delay(150);
    sim808.write("%");
    delay(50);
    sim808.write("&location=maps.google.com/maps?q=loc:");
    //Serial.print("&location=");
    delay(50);
    sim808.print(longitude);   // Add location to url
    //Serial.print(location);
  delay(50);
  sim808.write(",");
  delay(50);
  latitude+='0';
 sim808.print(latitude);   // close url
    delay(50);
    sim808.write("\"\r\n");   // close url
   
    //Serial.print("\"\r\n");
    delay(2000);
    sim808.write("AT+HTTPPARA=\"CID\",1\r\n");    // End the PARA
    //Serial.print("AT+HTTPPARA=\"CID\",1\r\n");
    delay(2000);
    sim808.write("AT+HTTPACTION=0\r\n");
    //Serial.print("AT+HTTPACTION=0\r\n");
    delay(3000);   
    sim808.write("AT+HTTPTERM\r\n");
    delay(3000);   
    Serial.print("data sent complete : ");
    offgps();
}

void gsm_disConnect_gprs(){
  sim808.write("AT+CGATT=0\r\n"); // Attach to GPRS
  delay(2000);
  Serial.println("GPRS off");
}
 
void gsm_connect_gprs(){
 
  sim808.write("AT+CGATT=1\r\n"); // Attach to GPRS
  delay(2000);
  sim808.write("AT+SAPBR=1,1\r\n"); // Open a GPRS context
  delay(2000);
  //serialSIM808.write("AT+SAPBER=2,1\r\n");  // To query the GPRS context
  //delay(2000);
  Serial.println("GPRS on");
}
</code>

am sorry if there is anything not clear :)
Title: Re: sending GPS Coordinates and data to HTTP website with GPRS/GPS module Sim808
Post by: moshehab on Sep 16, 2019, 01:49 pm
Edit : i wanna to send the coordinates and the reading sensor to the website