Hey
I have a Dragino LHT 65 that sends measurement data to TTN.
The measurement data is sent from TTN to this website.
The measurement data are visible on this website.
To send the data from TTN to the website, I created a WEBHOOK.
Works great.
In the meantime I have created a second WEBHOOK for the same measurement values
to be sent to another website. The settings used are
exactly the same, obviously the login details of the second website are different.
But very strange : the measured values are not written in the table of the
second website, the log file is filled with data, but the MySql table becomes
not completed … What am I doing wrong? Does anyone have a tip? Thanks for your help
The files used :
ttn.php
require ‘config.php’;
$ttn_post = file(‘php://input’);
$data = json_decode($ttn_post[0]);
$sensor_temperature = $data->payload_fields->TempC_SHT;
$sensor_humidity = $data->payload_fields->Hum_SHT;
$sensor_temperature_2 = $data->payload_fields->TempC_DS;
$sensor_battery = $data->payload_fields->BatV;
$sensor_raw_payload = $data->payload_raw;
$gtw_id = $data->metadata->gateways[0]->gtw_id;
$gtw_rssi = $data->metadata->gateways[0]->rssi;
$gtw_snr = $data->metadata->gateways[0]->snr;
$ttn_app_id = $data->app_id;
$ttn_dev_id = $data->dev_id;
$ttn_time = $data->metadata->time;
$db_connect = mysqli_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME) or die(mysql_error());
$server_datetime = date(“Y-m-d H:i:s”);
mysqli_query($db_connect, “INSERT INTO data
(id
, datetime
, app_id
, dev_id
, ttn_timestamp
, gtw_id
, gtw_rssi
,”
. " gtw_snr
, dev_raw_payload
, dev_value_1
, dev_value_2
, dev_value_3
, dev_value_4
) "
. “VALUES (NULL, ‘$server_datetime’, ‘$ttn_app_id’, ‘$ttn_dev_id’, ‘$ttn_time’, ‘$gtw_id’, ‘$gtw_rssi’, ‘$gtw_snr’,”
. " ‘$sensor_raw_payload’, ‘$sensor_temperature’, ‘$sensor_temperature_2’, ‘$sensor_humidity’, ‘$sensor_battery’);
");
if (WRITE_LOG == true) {
file_put_contents(‘log.txt’, $ttn_post[0] . PHP_EOL, FILE_APPEND);
}
?>
config.php
<?php define('DATABASE_USERNAME', 'xxxxxxxx'); define('DATABASE_PASSWORD', 'xxxxxxx'); define('DATABASE_NAME', 'xxxxxxx'); define('DATABASE_HOST', 'localhost'); define('WRITE_LOG', true); //Enable log.txt File ?>