Fixed input option via api

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;
}
?>

Welcome, Morten, to the OEM forum.

I’m no expert on the internals of emonCMS, but I’m almost certain the answer is a firm no. I think you probably already have the best solution. A fundamental concept of emonCMS is it can accept data from anywhere worldwide provided your ISP and router/firewall allows (from its origins in the open emoncms.org) and it relies entirely on the APIkey for authority to accept and process the data. It doesn’t have a way to in effect accept “id=shellyht-xxxxxx” as the APIkey.

It might be possible to create an Interfacer for emonHub that does what you need - maybe @TrystanLea, you can confirm?