1. Go to this page and download the library: Download shob01/foxess library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shob01 / foxess example snippets
try {
$startTime = new DateTime();
$foxess = new CloudApi();
$reportVars = [
"gridConsumption",
"loads",
"feedin",
"generation",
"chargeEnergyToTal",
"dischargeEnergyToTal",
];
$now = new DateTime("now", $foxess->getTZ());
// Get production report for current month
$monthlyReport = new ResultDataTable($foxess->getReport("year", $reportVars, $now));
$currentMonthData = ['date' => $now->format('Y-m')] +
$monthlyReport->column($now->format('m') - 1);
// Get production report for today
$dailyReport = new ResultDataTable($foxess->getReport("month", $reportVars, $now));
$todaysData = ['date' => $now->format('Y-m-d')] +
$dailyReport->column($now->format('d') - 1);
// Get production report for current hour
$hourlyReport = new ResultDataTable($foxess->getReport("day", $reportVars, $now));
$hourData = ['date' => $now->format('Y-m-d H')] +
$hourlyReport->column($now->format('H') - 0);
$rawVars = [
"gridConsumptionPower",
"loadsPower",
"invBatPower",
"pv1Power",
"pv2Power",
"pvPower",
"generationPower",
"feedinPower",
"SoC"
];
// Get latest raw (real) data
$latestRaw = new ResultDataTable($foxess->getRaw($rawVars, 'now - 10 minutes'));
$latestData = $latestRaw->column(-1);
if (!empty($latestData)) {
$time = $latestData['time'];
$latestData['time'] = $time->format('Y-m-d H:i:s');
}
// Get real time data
// The real time data will be transformed to the same structure as the
// the getRaw() Method returns to benefit from ResultDataTable
// functionality
$realTimeRaw = new ResultDataTable($foxess->getRealtime($rawVars,true));
$realTimeData = $realTimeRaw->column(0);
if (!empty($realTimeData)) {
$time = $realTimeData['time'];
$realTimeData['time'] = $time->format('Y-m-d H:i:s');
}
// Read SoC (State of charge) Inverter and Battery Temperation data from today
$rawVars = ['SoC', 'invTemperation','batTemperature'];
$todayData = new ResultDataTable($foxess->getRaw($rawVars,'today'));
// Calculate min, max, current and trend values for todays data
$minMax = $todayData->getMinMax();
$dashboardData = [
'month' => $currentMonthData,
'today' => $todaysData,
'hour' => $hourData,
'latest' => $latestData,
'realtime' => $realTimeData,
'minMax' => $minMax
];
$endTime = new DateTime();
$duration = $startTime->diff($endTime);
outputJson('DashboardData', $dashboardData);
echo 'Time used: ' . $duration->format('%s.%f') . ' seconds' . PHP_EOL;
} catch (Exception $fe) {
echo "Exception occured: " . $fe->getMessage() . "<br>";
}
$container = DIContainer::getInstance();
//$container->set(Config::class,fn() => new ConfigFile(__DIR__ . "/../../foxess_config.json"));
$container->set(Config::class,fn() => new ConfigDotEnv());
$container->set(IRequester::class,fn() => new GuzzleHttpRequester());
$container->set('TZ',fn() => new DateTimeZone("Europe/Berlin"));
shell
php -S 127.0.0.1:8000
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.