There is always the live countdown interface
http://countdown.api.tfl.gov.uk/interfaces/ura/stream_V1?ReturnList=StopCode2,StopPointIndicator,DestinationName,EstimatedTime,ExpireTime,VehicleID,StopID (with your generated LiveBusNNNNNN username and password - it’s an HTTPD digest )
Is the “StopCode2” that it can provide the CALMS ID?#
I know it means watching the live service until you have all the codes you need. It does have a LineID parameter, so you can just poll each service you don’t have all the codes for, rather than having to consume and process every single iBus datapoint.
Brian
(my PHP code to curl to this interface)
namespace xxx\mtrCrossrail\services\tflDigest;
class digestCommon
{
const DEBUGMODE = false;
const LINEID = "UL16,UL51,90";
public $isAlreadyRunning = null;
public function setAlreadyRunning($isAlreadyRunning)
{
$this->isAlreadyRunning = $isAlreadyRunning;
}
public function startDigest($strURL = "http://countdown.api.tfl.gov.uk/interfaces/ura/stream_V1",
$strUsername = "LiveBus<id>",
$strPassword = "<password>",
$arrPostParameters = ["LineID" => self::LINEID,
"ReturnList" => "StopCode2,StopPointIndicator,DestinationName,EstimatedTime,ExpireTime,VehicleID,StopID"], $intAuth = CURLAUTH_DIGEST, $strFunctionName = "on_curl_write")
{
if (self::DEBUGMODE) {
error_reporting(E_ALL);
ini_set('display_errors', '1');
}
if (is_array($arrPostParameters)) {
$arrPostParameters = http_build_query($arrPostParameters);
}
echo PHP_EOL . __FUNCTION__ . " is sending " . strlen(var_export($arrPostParameters, true)) . " bytes to {$strURL}";
echo PHP_EOL . PHP_EOL . PHP_EOL;
$arrOptions = [CURLOPT_URL => $strURL,
CURLOPT_HEADER => false,
CURLOPT_VERBOSE => self::DEBUGMODE,
CURLOPT_RETURNTRANSFER => $strFunctionName !== "",
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => substr($strURL, 0, 5) === "https", // for https
CURLOPT_USERPWD => $strUsername . ":" . $strPassword,
CURLOPT_HTTPAUTH => $intAuth,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $arrPostParameters];
if ($strFunctionName != "") {
$arrOptions = $arrOptions + [CURLOPT_WRITEFUNCTION => array($this, $strFunctionName)];
}
$resCurlHandle = curl_init();
curl_setopt_array($resCurlHandle, $arrOptions);
try {
$RawResponce = curl_exec($resCurlHandle);
// validate CURL status
if (curl_errno($resCurlHandle)) {
throw new \Exception(curl_error($resCurlHandle), 500);
}
// validate HTTP status code (user/strPassword credential issues)
$intStatusCode = curl_getinfo($resCurlHandle, CURLINFO_HTTP_CODE);
if ($intStatusCode != 200) {
throw new \Exception("Response with Status Code [" . $intStatusCode . "].", 500);
}
} catch (\Exception $ex) {
if ($resCurlHandle != null) {
curl_close($resCurlHandle);
}
throw new \Exception($ex);
}
if ($resCurlHandle !== null) curl_close($resCurlHandle);
return $RawResponce;
}
}