Using a custom server API for real time data

Hi everyone,

I would like to set up my own server (a raspberry pi) so that I can have realtime access on my measures. (I plan to write a program that warns me to close my windows when my neighbors start their high-intensity wood-powered air pollution.)

I entered the server address and the path ‘/sensor.php’, the port ‘80’, user and password are empty (since I don’t plan on verifying that for now). The relevant part of the script ‘sensor.php’ looks as follows:

<?php
$log = "test" . time();
foreach($_GET as $key => $value)
{
    $log = 'GET Key = ' . $key . 'Value= ' . $value;
}
foreach($_POST as $key => $value)
{
    $log = 'POST Key = ' . $key . 'Value= ' . $value;
}
$log = $log . PHP_EOL;
file_put_contents('./log_'.date("j.n.Y").'.log', $log, FILE_APPEND);
// input data into mysql database ...
?>

However, the log file contains some lines, but does not show any input, neither GET nor POST. Any idea what I am missing? I assume I’m just using the custom API configuration wrong, but I can’t find it in the documentation.

Thanks for helping! :slight_smile:

Hello,
you should have a look at madavi-api/data_simple.php at master · opendata-stuttgart/madavi-api · GitHub .
Our firmware is sending the data as a binary object/attachment in a POST request.
Right at the top of the script you will find the part on how to ‘extract’ the JSON an decode it to key-value pairs.

2 Likes

Thanks! That solved my problem! :slight_smile:
I didn’t even know that you can transfer data to a php script like this ^^