# HTTP integration

**URL:** <https://www.thethingsnetwork.org/forum/t/http-integration/5271>\
**Category:** Uncategorized\
**Created:** [February 7, 2017, 10:17am UTC](https://www.thethingsnetwork.org/forum/t/http-integration/5271 "2017-02-07T10:17:49Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![I-Connect](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/i-connect/32/20484_2.png) [@I-Connect](https://www.thethingsnetwork.org/forum/u/I-Connect)\
**Post date:** [February 9, 2017, 4:53pm UTC](https://www.thethingsnetwork.org/forum/t/http-integration/5271/9 "2017-02-09T16:53:55Z")

</div>

ok, some steps further. On advice of Hylke simulated input via the payload decode function:

```
 var decoded = {"v1":12,"v2":13,"t":22,"h":88,"la":005,"lo":055};
 return decoded;

```

And I trigger a payload to be delivered via ttnctl:

`ttnctl devices simulate 201612001 11111111`

payload is then sent to a ttnpost.php page I made (honoustly looking up most of it via google…):

```php
<?php

//Make sure that it is a POST request.
if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
    throw new Exception('Request method must be POST!');
}
 
//Make sure that the content type of the POST request has been set to application/json
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if(strcasecmp($contentType, 'application/json') != 0){
    throw new Exception('Content type must be: application/json');
}
 
//Receive the RAW post data.
$content = trim(file_get_contents("php://input"));
 
//Attempt to decode the incoming RAW post data from JSON.
$decoded = json_decode($content, true);
 
//If json_decode failed, the JSON is invalid.
if(!is_array($decoded)){
    throw new Exception('Received content contained invalid JSON!');
}

//Process the JSON.

// Create connection
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";

$myConnection= mysqli_connect($servername,$username,$password,$dbname) or die ("could not connect to mysql"); 

$vBattery1 = $decoded['payload_fields']['v1'];
$vBattery2 = $decoded['payload_fields']['v2'];
$temperature= $decoded['payload_fields']['t'];
$humidity= $decoded['payload_fields']['h'];
$locationLat= $decoded['payload_fields']['La'];
$locationLong= $decoded['payload_fields']['lo'];

$sqlCommand="INSERT INTO sensordata(vBattery1, vBattery2, temperature, humidity, locationLat, locationLong) VALUES('$vBattery1','$vBattery2','$temperature','$humidity','$locationLat','$locationLong')";

$query=mysqli_query($myConnection, $sqlCommand) or die(mysql_error()) 

?>

```

(this ttnpost.php works if I call it from another php page with a json in the POST)

~~When I now trigger it with ttnctl a new row is added to the DB but has no values… To be continued (hints are welcome 😉 ).~~

EDIT: Now it works see post below

Jeroen

---

_[View the full topic](https://www.thethingsnetwork.org/forum/t/http-integration/5271)._
