Arduino to laravel

Morning.
I'm doing a tracking projet and i want to send location data to a laravel api with arduino and sim800.
I try to send data from the arduino but i do not get the 200 from the laravel api
I'm get 307 error.
Someone for help?

Please post your code using code tags </> and be sure to remove your login information.

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <AltSoftSerial.h>
#include <ArduinoJson.h>
#define docSize  200

SoftwareSerial sim800L(10 , 11); 

AltSoftSerial neogps;

TinyGPSPlus gps;


//String apn = "internet.mtn.bj";                   
//String apn_u = "internet";                     
//String apn_p = "internet";     
String apn = "moov";                   
String apn_u = "moov";                     
String apn_p = "moov";                     
                
String url = "http://997f-41-216-47-138.eu.ngrok.io/api/donnees";  //URL of Server

void setup()
{
  Serial.begin(9600);
  
  //Initialisation GSM
  sim800L.begin(9600);

  //Initialisation GPS
  neogps.begin(9600);

  Serial.println("Debut");
  delay(2000);
  //  
  while(sim800L.available()){
    Serial.println(sim800L.readString());
  }
  while(Serial.available())  {
    sim800L.println(Serial.readString());
  }
  delay(2000);
  config_gprs();
  
}


void loop()
{   int Niveau = 5;
    String Latitude, Longitude;
    float altitude;
    int Vitesse;
    int vehicule_id = 1;
    unsigned int val;
    unsigned int Temperature;
    val=analogRead(0); // LM35 connecté A0
    Temperature=(500 * val) /1024;
    
    //Verifier le gps
    boolean newData = false;
    for (unsigned long start = millis(); millis() - start < 2000;){
      while (neogps.available()){
        if (gps.encode(neogps.read())){
          newData = true;
          break;
        }
      }
    }
  
    //Si nouvelle coordonnées GPS
    if(true){
      newData = false;
      //Recuperer les données GPS
      Latitude = String(gps.location.lat(), 6); 
      Longitude = String(gps.location.lng(), 6); 
      altitude = gps.altitude.meters();  
      Vitesse = gps.speed.kmph()+10;
      //int vitessse = vitesse + 10 ;
      }
      Serial.print("Latitude= "); 
      Serial.print(Latitude);
      Serial.print(" Longitude= "); 
      Serial.print(Longitude);
      Serial.print(" Vitesse= "); 
      Serial.print(Vitesse);
      Serial.print(" Temperature= "); 
      Serial.print(Temperature);
      Serial.print("C");
      Serial.println(Temperature);
      //Creation document JSON
      StaticJsonDocument <200> doc;
      doc["Latitude"]=Latitude;
      doc["Longitude"]=Longitude;
      doc["Vitesse"]=Vitesse;
      doc["Temperature"]=Temperature;
      doc["Niveau"]=Niveau;
      doc["vehicule_id"]=vehicule_id;
      //Conversion doc JSON en chaine de caractére 
      char buffer[docSize];
      serializeJson(doc, buffer);
      Serial.println(buffer);
      gsm_http_post(buffer);
      delay(60000);
 }
 void gsm_http_post( String data) {
  Serial.println(" --- Start GPRS & HTTP --- ");
  //gsm_send_serial("AT+SAPBR=0,1");
  gsm_send_serial("AT+SAPBR=1,1");
   delay(4000);
  gsm_send_serial("AT+SAPBR=2,1");
   delay(4000);
  gsm_send_serial("AT+HTTPINIT");
   delay(4000);
  gsm_send_serial("AT+HTTPPARA=\"CID\",1");
   delay(4000);
  //gsm_send_serial("AT+HTTPPARA=\"URL\"," + url);
  gsm_send_serial("AT+HTTPPARA=\"URL\",\"http://997f-41-216-47-138.eu.ngrok.io/api/donnees\"");
   delay(4000);
  gsm_send_serial("AT+HTTPPARA=\"CONTENT\",\"application/json\"");
   delay(6000);
  gsm_send_serial("AT+HTTPDATA=" + String(data.length())+ ",100000");
  gsm_send_serial(data);
   delay(6000);
  gsm_send_serial("AT+HTTPACTION=1  ");
   delay(10000);
  gsm_send_serial("AT+HTTPREAD");
   delay(6000);
  gsm_send_serial("AT+HTTPTERM");
   delay(2000);
  gsm_send_serial("AT+SAPBR=0,1");
}




 void config_gprs() {
  Serial.println(" --- CONFIG GPRS --- ");
  gsm_send_serial("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
   delay(3000);
  gsm_send_serial("AT+SAPBR=3,1,\"APN\",\"moov\"");
   delay(3000);
  if (apn_u != "") {
    gsm_send_serial("AT+SAPBR=3,1,\"USER\"," + apn_u);
  }
  if (apn_p != "") {
    gsm_send_serial("AT+SAPBR=3,1,\"PWD\"," + apn_p);
  }
}


void gsm_send_serial(String command) {
  Serial.println("Send ->: " + command);
  sim800L.println(command);
  long wtimer = millis();
  while (wtimer + 3000 > millis()) {
    while (sim800L.available()) {
      Serial.write(sim800L.read());
    }
  }
  Serial.println();
}

here is my code

The if(true) { will always be true. Why is it there?

What Arduino board? You would be better off using a board with multiple hardware serial ports like a Mega. More than one software serial ports often is troublesome.

I'm using a mega card.
I seet the if true just to get new location data.

You have 3 extra hardware serial ports (Serial 1, Serial2, Serial3) in a Mega. It makes very little sense to use software serial ports.

That is the first time that I have seen that.

for (unsigned long start = millis(); millis() - start < 2000;){
it's an error, i forget to remove it :sweat_smile:

or connect 2 arduino's UART pins as one way like this (Proccessing arduinos tx to External Tasks arduinos rx)
my trick is a little bit easier and better than software serial. also in my trick i didnt thinked but Proccessing arduino can still print something on USB

307 means "Temporary Redirect"

Look in the "Location" reply header for the URL to use and send the request again to the temporary URL. This may just be adding a session cookie to the URL.

Hello everyone.
I was giving the wrong url. i checked it and change it. Know it's giving 603 instead of 200.

"603" is not a valid HTTP error code. Google search indicates it is used by some database systems. To what are you trying to connect?

I want to send data to mysql database through laravel.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.