Netze-Bw will mich nun auch mit einem iMSys beglücken. Da habe ich obigen phyton code mal angeschaut und chatgbt gebeten, diesen in php zu übersetzen. Sieht soweit ganz gut aus.
Sobald das eingebaut ist, probiere ich mal. Sofern Netze-BW den Zugangscode rausrückt, zumindest. Müssen sie ja eigentlich.
Vielleicht mag ja jemand, der schon ein iMSys hat, diese Methode mal probieren?
Grüsse
Ohne Prüfung auf Übersetzngsfehler, hier einmal was chatgbt ausgespuckt hat:
Edit: Scheinbar werden die Zeilenumbrüche beim copy verschluckt, sieht bei mir anders aus
<?php
$user = '12345678';
$password = 'secret';
$url = 'https://192.168.1.200/cgi-bin/hanservice.cgi';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$password");
$response = curl_exec($ch);
curl_close($ch);
preg_match('/name="tkn" value="(.+?)"/', $response, $matches);
$token = $matches[1];
$action = 'meterform';
$post_data = "tkn=" . $token . "&action=" . $action;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIE, 'session=' . $token);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$response = curl_exec($ch);
curl_close($ch);
preg_match('/(.+?)<\/table>/s', $response, $matches);
$table_data = $matches[1];
$dom = new DOMDocument;
$dom->loadHTML($table_data);
$value = $dom->getElementById('table_metervalues_col_wert')->textContent;
$unit = $dom->getElementById('table_metervalues_col_einheit')->textContent;
$timestamp = $dom->getElementById('table_metervalues_col_timestamp')->textContent;
$result_data = [
'value' => trim($value),
'unit' => trim($unit),
'timestamp' => trim($timestamp),
];
echo $result_data['timestamp'] . " " . $result_data['value'] . " " . $result_data['unit'];
?>