Skip to content

Instantly share code, notes, and snippets.

@timkeller
Created October 14, 2012 17:44
Show Gist options
  • Save timkeller/3889312 to your computer and use it in GitHub Desktop.
Save timkeller/3889312 to your computer and use it in GitHub Desktop.
Logging the Redbull Stratos API
<?php
/*
Log RedBullStratos Telemetry
Each telemetry data point is in the form:
[AltitudeImperial] => 103477.69028871
[AltitudeIsValid] => 1
[AltitudeMetric] => 31540
[CO2] => 0.16
[CO2IsValid] => 1
[CabinAirPressureBar] => 0.552270058929
[CabinAirPressureIsValid] => 1
[CabinAirPressurePSI] => 8.01
[CabinTemperatureImperial] => 52.25
[CabinTemperatureIsValid] => 1
[CabinTemperatureMetric] => 12.25
[CompassBearing] => 255.8
[CompassDirection] => West
[DirectionIsValid] => 1
[GpsIsValid] => 1
[GroundSpeedImperial] => 24.047017324788
[GroundSpeedIsValid] => 1
[GroundSpeedMetric] => 38.7
[Id] => 1404936
[Latitude] => 33.31489
[Longitude] => -103.797115
[OutsideAirPressureBar] => 0.022752699057
[OutsideAirPressureIsValid] => 1
[OutsideAirPressurePSI] => 0.33
[OutsideTemperatureImperial] => -12.55
[OutsideTemperatureIsValid] => 1
[OutsideTemperatureMetric] => -23.75
[Oxygen] => 23.5
[OxygenIsValid] => 1
[VerticalSpeedImperial] => 1062.9921259843
[VerticalSpeedIsValid] => 1
[VerticalSpeedMetric] => 5.4
*/
$write = fopen("redbull.log", "a+");
$lastId = 0;
for(;;)
{
$fp = fopen("http://services.redbullstratos.com/LiveData/Get?callback=redbullStratos.liveBroadcast.makeRequestCallback","r");
$data = str_replace("redbullStratos.liveBroadcast.makeRequestCallback", "", stream_get_contents($fp));
$data = substr($data, 1,strlen($data)-2);
$object = json_decode($data);
foreach($object->Telemetry as $index => $obj) {
if($obj->Id > $lastId) {
fwrite($write, implode(",", array(time()) + get_object_vars($obj)) . "\n");
$lastId = $obj->Id;
}
}
sleep(5);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment