Hi
I have a few basic Shelly H&T to monitor temperature and humidity. they run on a small battery and are very limited in its capabilities.
Its a fixed url option string that it will send along;
?hum=60&temp=25.00&id=shellyht-xxxxxx
You can specify an endpoint, like http://192.168.0.20/sensor.php and it will become
http://192.168.0.20/sensor.php?hum=60&temp=25.00&id=shellyht-xxxxxx
I created the following PHP script(and made it public via apache), to just forward data into emonCMS, but i was wonderring, if there was a build-in way of dealing with devices that cannot add required metadata (like apikey), and where the data is fixed in its format.
<?php
$humidity = isset($_GET['hum']) ? floatval($_GET['hum']) : null;
$temperature = isset($_GET['temp']) ? floatval($_GET['temp']) : null;
$device_id = isset($_GET['id']) ? $_GET['id'] : null;
$humidity = floatval($humidity);
$temperature = floatval($temperature);
$device_id = htmlspecialchars($device_id, ENT_QUOTES, 'UTF-8');
switch ($device_id) {
case 'shellyht-45DF30':
if ($humidity !== null) {
file_get_contents("http://192.168.0.20/feed/post.json?id=9&apikey=APIKEY&value=$humidity");
}
if ($temperature !== null) {
file_get_contents("http://192.168.0.20/feed/post.json?id=8&apikey=APIKEY&value=$temperature");
}
break;
case 'shellyht-yyyyyy':
if ($humidity !== null) {
file_get_contents("http://192.168.0.122/feed/post.json?id=10&value=$humidity");
}
if ($temperature !== null) {
file_get_contents("http://192.168.0.122/feed/post.json?id=11&value=$temperature");
}
break;
default:
// Optional: log unknown device or do nothing
error_log("Unknown device ID: $device_id");
break;
}
?>