<?php
require_once __DIR__ . '/inc/bootstrap.php';

// Получение данных с Dessmonitor
$anenjBatVoltage = 0;
$anenjPvVoltage  = 0;
$anenjPvCurrent  = 0;
$anenjTemp       = 0;
$dessmonData = @file_get_contents('https://web.dessmonitor.com/public/?sign=6f58bbf6402c97ce614b80876e1cfb5012ca9571&salt=1753542174017&token=3a491f16dfbe8d3e4be66165789fe0536686da0632d6298422992f1bf3af13da&action=querySPDeviceLastData&source=1&devcode=2376&pn=Q0045473081804&devaddr=1&sn=Q0045473081804094801&i18n=en_US');
$dessmonData = json_decode($dessmonData, true);

if (!empty($dessmonData) && $dessmonData['err'] === 0) {
	$anenjBatVoltage  = $dessmonData['dat']['pars']['bt_'][0]['val'];
	$anenjPvVoltage   = $dessmonData['dat']['pars']['pv_'][0]['val'];
	$anenjPvCurrent   = $dessmonData['dat']['pars']['pv_'][1]['val'];
	$anenjTempDC      = $dessmonData['dat']['pars']['sy_'][1]['val'];
	$anenjTempINV     = $dessmonData['dat']['pars']['sy_'][2]['val'];
}


$result = [
	'anenjBatVoltage' => $anenjBatVoltage,
	'anenjPvVoltage'  => $anenjPvVoltage,
	'anenjPvCurrent'  => $anenjPvCurrent,
	'anenjTempDC'     => $anenjTempDC,
	'anenjTempINV'    => $anenjTempINV,

];

file_put_contents(__DIR__ . '/data/anenj.txt', serialize($result));

echo 'Task OK';