Arduino + Module SIM900 + PHP + Mysql - POST method problem

Asked

Viewed 542 times

3

Good afternoon to all!,

I am developing a project that consists in the communication of a module SIM900 with an application, and doing the interaction of the two will be a server WEB + Database.

The APP, Database and PHP page items are already working perfectly.

PROBLEM: I am having problem in the communication of module SIM900 by the POST method with the page that will make the "ADD" of the information in the Mysql database.

I was able to add the information to the database using the GET method (via URL)

AT+SAPBR=1,1

AT+HTTPINIT

AT+HTTPPARA="URL","site/add.php?variável1=xx&Variavel2=xx&Variavel3=xx"

AT+HTTPACTION=0

However for security reasons I have to use the POST method, and there is the problem... When I try to send the data anyway by Arduino+sim900 (AT+HTTPDATA,AT+CIPSEND or some other), simply "empty" information arrives to me on the site and consequently "empty" values are added in the database as in the image below:

Bando de Dados MySQL Current code of the ADD.php page in the Database:

include("connect.php");

$link=Connection();

$Bateria=$_POST["Bateria"];
$Odometro=$_POST["Odometro"];
$Consumo=$_POST["Consumo"];
$Carro_Padrao=$_POST["Carro_Padrao"];

$query = "INSERT INTO `u984057597_app`.`SMS_Recebidos`(`timeStamp`,`Bateria`,`Odometro`,`Consumo`,`Carro_Padrao`) VALUES (DATE_SUB(now(), INTERVAL 3 HOUR),'".$Bateria."','".$Odometro."','".$Consumo."','".$Carro_Padrao."')"; 

mysql_query($query,$link);
mysql_close($link);

Has anyone had this same problem and managed to solve it? , is it necessary to have an extra command on the add.php page? (it receives the data from Arduino)

Thank you all from now on!

  • Thiago, welcome. Edit your question and add the code, without using the image as this makes it difficult to verify it. I recommend reading the Tour

  • Thanks @Marcelodeandrade, I’ve edited the same and I’m checking the Tour.

2 answers

2


Problem solved!

The configuration that had entered the question was OK and did not require modifications (ADD.php page).

To solve the capture problem (POST method on the website) I had to make some modifications in the standard library of the module SIM900 of the supplier Tinysine, being them:

1- Modificar a linha 37 do arquivo GSM.cpp para o BaudRate 4800 (antigo era 9600).

2- Modificar a linha 4 do arquivo HWSerial.cpp para o BaudRate 4800(antigo era 9600).

3- Adicionar as seguintes sintaxes na programação do arduino:

ORIGINAL

numdata=inet.httpPOST("site", 80, "/arduino/add.php", "variavel=valor&variavel2=valor2",msg, 50);

MODIFIED

char temp_string[64];
char msg[100];
int numdata;
String valor = "Bateria=13.2V&Odometro=10250Km&Consumo=12.3Km/L&Carro_Padrao=A4";
valor.toCharArray(temp_string, 64);
numdata = inet.httpPOST("site", 80, "/arduino/add.php", temp_string, msg, 50);
delay(5000);

In this last step I had to make a kind of concatenation with conversion of variables and only in this way I could solve my problem in question.

Thanks for all your help!

  • Welcome to Sopt, as your answer solved your own problem, you can mark it as an accepted answer in 2 days, remember this :) In that time you can make one (http://answall.com/tour)[Tour] through the site, and explore all that is good about Sopt.

0

Of:

$variavel1=$_GET["variavel1"];
$variavel2=$_GET["variavel2"];
$variavel3=$_GET["variavel3"];
$variavel4=$_GET["variavel4"];

To:

$variavel1=$_POST["variavel1"];
$variavel2=$_POST["variavel2"];
$variavel3=$_POST["variavel3"];
$variavel4=$_POST["variavel4"];

Also remember to change the method in the form: method=post.

  • Thanks for the prompt reply, this modification (POST) had already done I ended up putting the old image of the code... already the form method would be for me to use in the page I am sending correct? The page I posted there is the page that "receives" the data so I don’t think it applies in this case... @Lipespry

  • On the page of the formulated, you should put the method as POST and on the page that treats the data, use $_POST['var'].

  • His comment ended up helping me to find the solution, I had to research on how Uino did this "formulated", and I ended up finding some defects in the manufacturer’s standard library and I ended up having to make some modifications! I answered with the solution above so that anyone who needs help in the future has this other way that I found, thank you.. @Lipespry

Browser other questions tagged

You are not signed in. Login or sign up in order to post.