add debug output and change data matching
This commit is contained in:
@@ -22,14 +22,16 @@ class EcowittExportCommand extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'export {--user=} {--pass=} {startDate} {endDate}';
|
protected $signature = 'export {--debug} {--user=} {--pass=} {startDate} {endDate}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'Command description';
|
protected $description = 'fetch all data from ecowitt';
|
||||||
|
|
||||||
|
protected $times = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
@@ -59,17 +61,18 @@ class EcowittExportCommand extends Command
|
|||||||
$session_id = $this->getSessionId();
|
$session_id = $this->getSessionId();
|
||||||
$device_ids = $this->getDeviceIds($session_id);
|
$device_ids = $this->getDeviceIds($session_id);
|
||||||
|
|
||||||
$this->startDate = Carbon::parse($this->argument('startDate'))->startOfDay()
|
$this->startDate = Carbon::parse($this->argument('startDate'))->startOfDay();
|
||||||
->format('Y-m-d H:i');
|
|
||||||
|
|
||||||
$this->endDate = Carbon::parse($this->argument('endDate'))->endOfDay()
|
$this->endDate = Carbon::parse($this->argument('endDate'))->endOfDay();
|
||||||
->format('Y-m-d H:i');
|
|
||||||
|
|
||||||
$device_ids->each(function ($deviceId) use ($session_id) {
|
$device_ids->each(function ($deviceId) use ($session_id) {
|
||||||
|
|
||||||
$startDate = $this->startDate;
|
$startDate = $this->startDate->clone();
|
||||||
$endDate = $this->endDate;
|
$endDate = $this->endDate->clone();
|
||||||
|
// declare output variable
|
||||||
|
$outputData = [];
|
||||||
|
|
||||||
|
do {
|
||||||
$response = Http::withCookies(
|
$response = Http::withCookies(
|
||||||
[
|
[
|
||||||
'ousaite_session' => $session_id,
|
'ousaite_session' => $session_id,
|
||||||
@@ -79,59 +82,75 @@ class EcowittExportCommand extends Command
|
|||||||
'device_id' => $deviceId,
|
'device_id' => $deviceId,
|
||||||
'is_list' => 0,
|
'is_list' => 0,
|
||||||
'mode' => 0,
|
'mode' => 0,
|
||||||
'sdate' => $startDate,
|
'sdate' => $startDate->clone()->startOfDay()->format('Y-m-d H:i'),
|
||||||
'edate' => $endDate,
|
'edate' => $startDate->clone()->endOfDay()->format('Y-m-d H:i'),
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->comment("fetching range: {$startDate->clone()->startOfDay()} - {$startDate->clone()->endOfDay()}");
|
||||||
|
|
||||||
$ecowitt = $response->json();
|
$ecowitt = $response->json();
|
||||||
|
|
||||||
// declare output variable
|
$this->times = data_get($ecowitt,'times',[]);
|
||||||
$outputData = [];
|
|
||||||
|
|
||||||
// Temperature in C
|
// Temperature in C
|
||||||
|
$this->debug('fetch outdoor temp');
|
||||||
$outdoorTemp = $this->getData($ecowitt, 'list.tempf.list.tempf');
|
$outdoorTemp = $this->getData($ecowitt, 'list.tempf.list.tempf');
|
||||||
|
|
||||||
// Feels Like in C
|
// Feels Like in C
|
||||||
|
$this->debug('fetch outdoor temp gust');
|
||||||
$outdoorTempGust = $this->getData($ecowitt, 'list.tempf.list.sendible_temp');
|
$outdoorTempGust = $this->getData($ecowitt, 'list.tempf.list.sendible_temp');
|
||||||
|
|
||||||
// Dew Point in C
|
// Dew Point in C
|
||||||
|
$this->debug('collecting: Dew Point in C');
|
||||||
$outdoorDewTemp = $this->getData($ecowitt, 'list.tempf.list.drew_temp');
|
$outdoorDewTemp = $this->getData($ecowitt, 'list.tempf.list.drew_temp');
|
||||||
|
|
||||||
// humidity in %
|
// humidity in %
|
||||||
|
$this->debug('collecting: humidity in %');
|
||||||
$outdoorHumidity = $this->getData($ecowitt, 'list.humidity.list.humidity');
|
$outdoorHumidity = $this->getData($ecowitt, 'list.humidity.list.humidity');
|
||||||
|
|
||||||
// temp indoor in C
|
// temp indoor in C
|
||||||
|
$this->debug('collecting: temp indoor in C');
|
||||||
$indoorTemp = $this->getData($ecowitt, 'list.tempinf.list.tempinf');
|
$indoorTemp = $this->getData($ecowitt, 'list.tempinf.list.tempinf');
|
||||||
|
|
||||||
// humidityin in %
|
// humidityin in %
|
||||||
|
$this->debug('collecting: humidityin in %');
|
||||||
$indoorHumidity = $this->getData($ecowitt, 'list.humidity.list.humidity');
|
$indoorHumidity = $this->getData($ecowitt, 'list.humidity.list.humidity');
|
||||||
|
|
||||||
// solar in lx -- Solar and UVI
|
// solar in lx -- Solar and UVI
|
||||||
|
$this->debug('collecting: solar in lx -- Solar and UVI');
|
||||||
$solarradiation = $this->getData($ecowitt, 'list.solarradiation.list.solarradiation');
|
$solarradiation = $this->getData($ecowitt, 'list.solarradiation.list.solarradiation');
|
||||||
|
|
||||||
// uv
|
// uv
|
||||||
|
$this->debug('collecting: uv');
|
||||||
$uvi = $this->getData($ecowitt, 'list.uv.list.uv');
|
$uvi = $this->getData($ecowitt, 'list.uv.list.uv');
|
||||||
|
|
||||||
// rainrate in mm/hr b
|
// rainrate in mm/hr b
|
||||||
|
$this->debug('collecting: rainrate in mm/hr b');
|
||||||
$rainRateH = $this->getData($ecowitt, 'list.rain.list.rainratein');
|
$rainRateH = $this->getData($ecowitt, 'list.rain.list.rainratein');
|
||||||
|
|
||||||
// daily rainrate total mm/hr
|
// daily rainrate total mm/hr
|
||||||
|
$this->debug('collecting: daily rainrate total mm/hr');
|
||||||
$rainRateDaily = $this->getData($ecowitt, 'list.rain.list.dailyrainin');
|
$rainRateDaily = $this->getData($ecowitt, 'list.rain.list.dailyrainin');
|
||||||
|
|
||||||
// wind_speed in m/s
|
// wind_speed in m/s
|
||||||
|
$this->debug('collecting: wind_speed in m/s');
|
||||||
$windspeed = $this->getData($ecowitt, 'list.wind_speed.list.windspeedmph');
|
$windspeed = $this->getData($ecowitt, 'list.wind_speed.list.windspeedmph');
|
||||||
|
|
||||||
// windGust
|
// windGust
|
||||||
|
$this->debug('collecting: windGust');
|
||||||
$windGust = $this->getData($ecowitt, 'list.wind_speed.list.windgustmph');
|
$windGust = $this->getData($ecowitt, 'list.wind_speed.list.windgustmph');
|
||||||
|
|
||||||
// winddir in degree
|
// winddir in degree
|
||||||
|
$this->debug('collecting: winddir in degree');
|
||||||
$windir = $this->getData($ecowitt, 'list.winddir.list.winddir');
|
$windir = $this->getData($ecowitt, 'list.winddir.list.winddir');
|
||||||
|
|
||||||
// pressure relative in hPa
|
// pressure relative in hPa
|
||||||
|
$this->debug('collecting: pressure relative in hPa');
|
||||||
$pressureRel = $this->getData($ecowitt, 'list.pressure.list.baromrelin');
|
$pressureRel = $this->getData($ecowitt, 'list.pressure.list.baromrelin');
|
||||||
|
|
||||||
// pressure absolute in hPa
|
// pressure absolute in hPa
|
||||||
|
$this->debug('collecting: pressure absolute in hPa');
|
||||||
$pressureAbs = $this->getData($ecowitt, 'list.pressure.list.baromabsin');
|
$pressureAbs = $this->getData($ecowitt, 'list.pressure.list.baromabsin');
|
||||||
|
|
||||||
foreach ($outdoorTemp as $date => $temp) {
|
foreach ($outdoorTemp as $date => $temp) {
|
||||||
@@ -159,6 +178,8 @@ class EcowittExportCommand extends Command
|
|||||||
];
|
];
|
||||||
$outputData[] = $tmp;
|
$outputData[] = $tmp;
|
||||||
}
|
}
|
||||||
|
$startDate = $startDate->addDay()->startOfDay();
|
||||||
|
} while ( $startDate->lte($endDate) );
|
||||||
|
|
||||||
$this->export(getcwd() . "/ecowitt_{$deviceId}.csv", $outputData);
|
$this->export(getcwd() . "/ecowitt_{$deviceId}.csv", $outputData);
|
||||||
|
|
||||||
@@ -168,8 +189,9 @@ class EcowittExportCommand extends Command
|
|||||||
protected function getData($stack, $key)
|
protected function getData($stack, $key)
|
||||||
{
|
{
|
||||||
return collect(data_get($stack, $key))
|
return collect(data_get($stack, $key))
|
||||||
->mapWithKeys(function ($value) {
|
->mapWithKeys(function ($value, $idx) {
|
||||||
return [$value[0] => $value[1] ?: null];
|
$dateTime = data_get($this->times, $idx);
|
||||||
|
return [$dateTime => $value ?: null];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,4 +254,21 @@ class EcowittExportCommand extends Command
|
|||||||
fclose($fp);
|
fclose($fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $msg
|
||||||
|
* @param mixed ...$args
|
||||||
|
*/
|
||||||
|
protected function debug(string $msg, ...$args)
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($this->option('debug')) {
|
||||||
|
$this->info($msg);
|
||||||
|
if (!empty($args)) {
|
||||||
|
dump($args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user