Arduino + Module SIM900 + PHP + MySQL - Problem POST method

2

Good afternoon everyone!

I'm developing a project that consists of communicating a SIM900 module with an application, and making the interaction of the two will be a WEB server + database.

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

PROBLEM: I am having trouble communicating the SIM900 module by POST method with the page that will "ADD" the information in the MySQL database.

I was able to add the information in 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
But for security reasons I have to use the POST method, and there's the problem ... When I try to send the data in any way by arduino + sim900 (AT + HTTPDATA, AT + CIPSEND or some other), simply "empty" information for me arrives on the site and consequently "empty" values are added in the Database as in the image below:

CurrentPHPpagecodeforADD.phpintheDatabase:

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 ever had this same problem and managed to solve it? do you need any more commands on the add.php page? (it gets the arduino data)

Thank you all right away!

    
asked by anonymous 02.08.2016 / 23:38

2 answers

2

Problem solved!

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

In order to solve the capture problem (POST method in the site) I had to make some modifications in the standard SIM900 module library of the TinySine vendor,

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 do a sort of concatenation with the conversion of variables and only this way I was able to solve my problem in question.

Thank you all for your help!

    
04.08.2016 / 04:08
0

From:

$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 .

    
02.08.2016 / 23:47