1

I have an Arduino UNO and SIM808 and I'm trying to send my GPS data to the Firebase. I have successfully created a website which I can post data from the website to the Firebase. However I'm trying to send my data from Arduino to the website which failed constantly. I have no idea what is the error.

These are my codes:

 /*
 ### Get GPS data
 1. This example is used to test SIM808 GPS/GPRS/GSM Shield's reading GPS data.
 2. Open the SIM808_GetGPS example or copy these code to your project
 3. Download and dial the function switch to Arduino
 4. open serial helper
 4. Place it outside, waiting for a few minutes and then it will send GPS data to serial
 
 create on 2016年09月23日, version: 1.0
 by jason
 
 */
 #include <DFRobot_sim808.h>
 #include <SoftwareSerial.h>
 
 #define PIN_TX 10
 #define PIN_RX 11
 SoftwareSerial mySerial(PIN_TX, PIN_RX);
 DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,
 
 #define APN "diginet"
 #define USER ""
 #define PASS ""
 unsigned long previousMillis = 0;
 long interval = 60000;
 
 String the_year, the_month, the_day, the_hour, the_minute, the_second, the_time;
 String latitude, longitude;
 
 //DFRobot_SIM808 sim808(&Serial);
 
 void setup() {
 mySerial.begin(9600);
 Serial.begin(9600);
 
 //******** Initialize sim808 module *************
 while (!sim808.init()) {
 delay(1000);
 Serial.print("Sim808 init error\r\n");
 }
 
 //************* Turn on the GPS power************
 if ( sim808.attachGPS())
 Serial.println("Open the GPS power success");
 else
 Serial.println("Open the GPS power failure");
 
 }
 
 void loop() {
 //************** Get GPS data *******************
 getGPS();
 
 unsigned long currentMillis = millis();
 if (currentMillis - previousMillis > interval) {
 previousMillis = currentMillis;
 sendtoFirebase();
 }
 
 }
 
 void getGPS() {
 if (sim808.getGPS()) {
 delay(500);
 the_year = sim808.GPSdata.year;
 the_month = sim808.GPSdata.month;
 the_day = sim808.GPSdata.day;
 the_hour = sim808.GPSdata.hour;
 the_minute = sim808.GPSdata.minute;
 the_second = sim808.GPSdata.second;
 the_time = the_year + " / " + the_month + " / " + the_day + " " + the_hour + ": " + the_minute + ": " + the_second;
 Serial.print(the_time);
 //Serial.print(sim808.GPSdata.year);
 //types(sim808.GPSdata);
 
 
 latitude = String(sim808.GPSdata.lat, 6);
 longitude = String(sim808.GPSdata.lon, 6);
 Serial.println(latitude);
 Serial.println("longitude : ");
 
 Serial.println(longitude);
 
 sim808.latitudeConverToDMS();
 sim808.LongitudeConverToDMS();
 //Serial.print("latitude : ");
 // Serial.print(sim808.latDMS.degrees);
 // Serial.print("\^");
 // Serial.print(sim808.latDMS.minutes);
 // Serial.print("\'");
 // Serial.print(sim808.latDMS.seconeds,6);
 // Serial.println("\"");
 // Serial.print("longitude :");
 // Serial.print("longitude :");
 // Serial.print(sim808.longDMS.degrees);
 // Serial.print("\^");
 // Serial.print(sim808.longDMS.minutes);
 // Serial.print("\'");
 // Serial.print(sim808.longDMS.seconeds, 6);
 // Serial.println("\"");
 
 // Serial.print("speed_kph :");
 // Serial.println(sim808.GPSdata.speed_kph);
 // Serial.print("heading :");
 // Serial.println(sim808.GPSdata.heading);
 
 //************* Turn off the GPS power ************
 //sim808.detachGPS();
 }
 }
 
 void sendtoFirebase() {
 
 boolean newData = false;
 for (unsigned long start = millis(); millis() - start < 2000;) {
 while (sim808.getGPS()) {
 newData = true;
 }
 }
 
 if (newData) {
 newData = false;
 
 String deviceId = "ABC1235";
 
 Serial.print("Device ID:");
 Serial.println(deviceId);
 
 Serial.print("Time:");
 Serial.println(the_time);
 Serial.print("latitude:");
 Serial.println(latitude);
 Serial.print("longitude:");
 Serial.println(longitude);
 
 String temp;
 
 //build the URL to the proxy
 String url = "http://myfypproject.epizy.com/firebase.php?arduino_data=25.00";
 // url += "&deviceid=";
 // url += String(deviceid);
 // url += "&lat=";
 // url += String(latitude);
 // url += "&lon=";
 // url += String(longitude);
 
 Serial.println(url);
 sendATcommand("AT+CFUN=1", "OK", 2000);
 //AT+CGATT = 1 Connect modem is attached to GPRS to a network. AT+CGATT = 0, modem is not attached to GPRS to a network
 sendATcommand("AT+CGATT=1", "OK", 2000);
 //Connection type: GPRS - bearer profile 1
 sendATcommand("AT+SAPBR=3,1,\"Contype\",\"GPRS\"", "OK", 2000);
 //sets the APN settings for your network provider.
 sendATcommand("AT+SAPBR=3,1,\"APN\",\"diginet\"", "OK", 2000);
 //enable the GPRS - enable bearer 1
 sendATcommand("AT+SAPBR=1,1", "OK", 2000);
 //Init HTTP service
 sendATcommand("AT+HTTPINIT", "OK", 2000);
 sendATcommand("AT+HTTPPARA=\"CID\",1", "OK", 1000);
 //Set the HTTP URL sim800.print("AT+HTTPPARA="URL","http://ahmadssd.000webhostapp.com/gpsdata.php?lat=222&lng=222"\r");
 //sendATcommand("AT+HTTPPARA=\"URL\",\"http://myfypproject.epizy.com/firebase.php?arduino_data=25.00\"", "OK", 1000);
 mySerial.print("AT+HTTPPARA=\"URL\",\"");
 mySerial.print(url);
 sendATcommand("\"", "OK", 1000);
 //Set up the HTTP action
 sendATcommand("AT+HTTPACTION=0", "0,200", 1000);
 //Terminate the HTTP service
 sendATcommand("AT+HTTPTERM", "OK", 1000);
 //shuts down the GPRS connection. This returns "SHUT OK".
 //sendATcommand("AT+CIPSHUT", "SHUT OK", 1000);
 
 }
 
 return 1;
 }
 
 int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout) {
 uint8_t x = 0, answer = 0;
 char response[100];
 unsigned long previous;
 
 //Initialize the string
 memset(response, '0円', 100);
 delay(100);
 
 //Clean the input buffer
 while (mySerial.available() > 0) mySerial.read();
 
 if (ATcommand[0] != '0円') {
 //Send the AT command
 mySerial.println(ATcommand);
 }
 
 x = 0;
 previous = millis();
 
 do {
 //if there are data in the UART input buffer, reads it and checks for the asnwer
 if (mySerial.available() != 0) {
 response[x] = mySerial.read();
 //Serial.print(response[x]);
 x++;
 // check if the desired answer (OK) is in the response of the module
 if (strstr(response, expected_answer) != NULL) {
 answer = 1;
 }
 }
 } while ((answer == 0) && ((millis() - previous) < timeout));
 
 Serial.println(response);
 return answer;
 
 }

I keep get the error of 603.

AT+HTTPACTION=0
OK
+HTTPACTION: 0, 603, 0

Below are my PHP, website to firebase codes:

 <?php
require_once 'firebaseLib.php';
// --- This is your Firebase URL
$url = 'https://projectname-default-rtdb.asia-southeast1.firebasedatabase.app/';
// --- Use your token from Firebase here
$token = 'XXXXXXXXXXJYszyqIJxr3UuGl1Zr6qHG03K';
// --- Here is your parameter from the http GET
$arduino_data = $_GET['arduino_data'];
// --- Set up your Firebase url structure here
$firebasePath = '/GPSdata';
/// --- Making calls
$fb = new fireBase($url, $token);
$response = $fb->set($firebasePath, $arduino_data);
echo $url;
sleep(2);

UPDATE:

I can get code 200, but there isn't any result in my firebase or my website.

asked Jun 26, 2021 at 6:09
3
  • the title of your post does not match the content ... the title says post to firebase ... the question says post to intermediate webpage ... why don't you post to firebase directly? Commented Jun 26, 2021 at 19:03
  • because I found out that, SIM808 only can do HTTP request but Firebase required HTTPS request which I need a intermediate webpage. Commented Jun 27, 2021 at 1:31
  • SIM808 HTTPS. Commented Jun 27, 2021 at 11:30

1 Answer 1

1

It is just the server problem. I just changed a website and it works.

answered Jul 1, 2021 at 6:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.