0

I believe a have a question with a simple answer but I'm quite a novice at php and website development in general.

I'm working on a project to send some sensor data to a webpage from an arduino. Most of the website development (php and html code) was done with the assistance of an online tutorial. I have it working well with sending the data (temperature and humidity) and displaying it in a table.

However, I wish to do some testing without the use of the arduino. Specifically using a HTTP request maker like hurl.it to simulate my arduino's POST requests. I know I have all of the information available to do this but being such a novice I'm struggling to post "data" using a request maker.

My add.php file handles the POST and is as follows

<?php

include("connect.php");

$link=Connection();

$temp1=$_POST["temp1"];
$hum1=$_POST["hum1"];

$query = "INSERT INTO `tempLog` (`temperature`, `humidity`) 
    VALUES ('".$temp1."','".$hum1."')"; 

mysqli_query($link, $query);
((is_null($___mysqli_res = mysqli_close($link))) ? false : $___mysqli_res);

header("Location: index.php");

The website is also utilizing an SQL database so that's what the connect.php is referencing.

If needed the portion of the arduino code sending the data is:

h = (int) dht.readHumidity();
t = (int) dht.readTemperature();
}

data = "temp1=";

data.concat(t);

data.concat("&hum1=");

data.concat(h);


if (client.connect("www.******.com",80)) { 
client.println("POST /add.php HTTP/1.1");
client.println("Host: *****.com");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.print(data);
}

Any help on this would be greatly appreciated. I'm eventually looking to add an additional sensor to the arduino but would first like to simulate how the website would handle it with a request maker.

Thanks.

Edit: Don't believe its a duplicate problem. I'm asking how to use a request maker with my specific code. Identifying headers, etc.

Dave
  • 1
  • 1
  • are you saying that `add.php` is not working? –  Apr 20 '17 at 21:23
  • If you're not trying to do things such as automating tests and just want to emulate POST requests for development's sake without actually using Arduino, you could just use something like Postman. It would surely be quicker and more user friendly. – Hissvard Apr 20 '17 at 21:25
  • You are open to SQL injections with this code. You should parameterize that query. – chris85 Apr 20 '17 at 21:29
  • Daves not here man. –  Apr 20 '17 at 21:42
  • @nogad No the code is all working fine with the arduino I'm just trying to make the same request the arduino is with a request maker. for example hurl.it can launch a POST request but I don't know how to set it up with headers, parameters,etc. – Dave Apr 20 '17 at 22:42
  • @Hissvard Yeah I simply want to emulate some POST requests for developmental testing. Postman is exactly what I could use I'm just having trouble getting it to work. I'm not sure if the headers, body, etc is correct. – Dave Apr 20 '17 at 22:49

0 Answers0