RailUK Forums
RailUK Forums > UK Railway Forums > UK Railway Discussion


Reply
Thread Tools
Unread 29th June 2012, 21:16   #16
jamesjefferies
Member
 
Join Date: 29 Jun 2012
Location: Sheffield, South Yorkshire
Posts: 8
Default

Thanks B0b for posting your java, I was attempting to get it working using the Stomp rubygem with the ruby example, but it seemed to keep dropping the connection... (and thanks to poggs for clearing up to use /topic and not /queue)

however, all works well with Gozirra, so I'm making progress.

Typical timing though, off to North Wales for hols for a couple of weeks, just when I want to do some JSON parsing!
jamesjefferies is offline   Reply With Quote
Sponsored links - Registered users do not see these banners - join today!
Unread 30th June 2012, 19:07   #17
ralphchadkirk
Does not work for the BBC
Established Member
 
ralphchadkirk's Avatar
 
Join Date: 20 Oct 2008
Location: Hatfield or Surrey
Posts: 5,065
Default

Still having trouble with it - though I suspect it is me, not Stomp this time.

Basically trying to get the TSRs on the LNE(S) route, the script connects, subscribes with no Stomp errors but stalls when running the readFrame() method, sending the CPU usage up to 100% and crashing out when reaching the maximum time.
__________________
All posts are my opinion and should not be taken as an authoritative source
ralphchadkirk is online now   Reply With Quote
Unread 30th June 2012, 20:12   #18
DynamicSpirit
Member
 
DynamicSpirit's Avatar
 
Join Date: 12 Apr 2012
Posts: 225
Default

Thanks for posting that, metroland - and so quickly after the announcement too! I've got my subscription in.

Has anyone had any luck downloading the train schedules? I don't seem to be able to. For example, the developer pack gives the example of using the URL https://datafeeds.networkrail.co.uk/...Y&day=toc-full to download the Northern Rail daily full schedule (Actually the PDF had an extra space after 'ntrod' which I've removed). But whenever I try that URL in the browser, I just get back the error User not subscribed to CIF_ED_FULL_DAILY. But a quick look at my account shows that's rubbish - it's clearly showing my account as active and subscribed to that schedule. Same thing with all the other schedules I've tried.
--- old post above --- --- new post below ---
Quote:
Originally Posted by dooton View Post
Working on a Java implementation. There documentation could be a little more helpful I do agree!
Agreed. And it's even worse for people like me who inhabit the .NET world, since they don't even provide samples in those languages!

Last edited by DynamicSpirit; 30th June 2012 at 20:12. Reason: Double post prevention system
DynamicSpirit is offline   Reply With Quote
Unread 30th June 2012, 21:50   #19
robh
Sofware Devloper
Member
 
Join Date: 30 Jun 2012
Posts: 7
Default

Quote:
Originally Posted by DynamicSpirit View Post
Has anyone had any luck downloading the train schedules? I don't seem to be able to.
I have just tried: https://datafeeds.networkrail.co.uk/...Y&day=toc-full

It works for me, I am subscribed to the schedule "All Full Daily"

Quote:
Originally Posted by dooton View Post
Working on a Java implementation. There documentation could be a little more helpful I do agree!
I agree, the network rail doc is just a copy of the "Java API" section of the ActiveMQ documentation: https://activemq.apache.org/stomp.html with the key sentence "Note that this API is provided purely for testing purposes and you should always consider using standard JMS API from Java instead of this one." removed.

Can anyone tell me the port that their stomp service is running on? It's something like ***16 if I remember correctly. I was playing around with it at work on Friday and had it working but I can't seem to download the developer PDF here at home as it's asking me for a login and the one for the datafeeds isn't being accepted.

EDIT: Found a cached version (slightly older revision than I was reading on Friday though): https://docs.google.com/viewer?a=v&q...6ST6CMetUZeMKQ

It's port 61618

Last edited by robh; 30th June 2012 at 21:52. Reason: Additional info
robh is offline   Reply With Quote
Unread 1st July 2012, 20:16   #20
DAH
Member
 
Join Date: 17 Apr 2008
Posts: 12
Default

Quote:
Originally Posted by ralphchadkirk View Post
Just got access to the live feeds. Unfortunately the documentation for PHP just seems to be a copy and paste from the extension producers website. And it's flatly refusing my username and password despite saying that the security token isn't needed yet...
Having the same problem, just will not connect even though my status is 'Active'.

Getting:

Code:
Fatal error: Uncaught exception 'StompException' with message 'Could not connect to datafeeds.networkrail.co.uk:61618 (10/10)' in /<path>/Stomp.php:168
Stack trace: 
#0 <path>/Stomp.php(190): Stomp->_makeConnection() 
#1 <path>/stomp_test.php(7): Stomp->connect() 
#2 {main} thrown in <path>/Stomp.php on line 168
stomp_test.php is using what is suggested in the Developer Pack V4.0.
DAH is offline   Reply With Quote
Unread 1st July 2012, 20:16   #21
Poggs
Open Data Geek
Member
 
Poggs's Avatar
 
Join Date: 28 Aug 2008
Location: London
Posts: 251
Default

Quote:
Originally Posted by DynamicSpirit View Post
Agreed. And it's even worse for people like me who inhabit the .NET world, since they don't even provide samples in those languages!
I deliberately steered the platform down the Stomp route because it's a simple, neutral standard.

Have you looked at http://activemq.apache.org/nms/ for your .NET requirements?
Poggs is offline   Reply With Quote
Unread 1st July 2012, 20:51   #22
ralphchadkirk
Does not work for the BBC
Established Member
 
ralphchadkirk's Avatar
 
Join Date: 20 Oct 2008
Location: Hatfield or Surrey
Posts: 5,065
Default

Still haven't got to actually parsing a JSON message yet! This is my first experience of ActiveMQ and Stomp, but I'm having more trouble than I expected. Still got the crashing problem...
--- old post above --- --- new post below ---
Quote:
Originally Posted by DAH View Post
Having the same problem, just will not connect even though my status is 'Active'.

Getting:

Code:
Fatal error: Uncaught exception 'StompException' with message 'Could not connect to datafeeds.networkrail.co.uk:61618 (10/10)' in /<path>/Stomp.php:168
Stack trace: 
#0 <path>/Stomp.php(190): Stomp->_makeConnection() 
#1 <path>/stomp_test.php(7): Stomp->connect() 
#2 {main} thrown in <path>/Stomp.php on line 168
stomp_test.php is using what is suggested in the Developer Pack V4.0.
Are you adding the tcp:// prefix to datafeeds.n...?
__________________
All posts are my opinion and should not be taken as an authoritative source

Last edited by ralphchadkirk; 1st July 2012 at 20:51. Reason: Double post prevention system
ralphchadkirk is online now   Reply With Quote
Unread 1st July 2012, 20:57   #23
DAH
Member
 
Join Date: 17 Apr 2008
Posts: 12
Default

Quote:
Originally Posted by ralphchadkirk View Post
Are you adding the tcp:// prefix to datafeeds.n...?
Yep, I sure am.
DAH is offline   Reply With Quote
Unread 1st July 2012, 20:57   #24
dooton
Member
 
dooton's Avatar
 
Join Date: 18 Nov 2010
Posts: 49
Default

Ok so i've just got some JSON back. Tried putting the train ID and schedule id that it returned into open train times and it wasn't found? It was just for fun to see what I had gotten back..

The programming I am ok with, understanding the railways inner workings could be trickier than i thought.
dooton is offline   Reply With Quote
Unread 1st July 2012, 20:59   #25
ralphchadkirk
Does not work for the BBC
Established Member
 
ralphchadkirk's Avatar
 
Join Date: 20 Oct 2008
Location: Hatfield or Surrey
Posts: 5,065
Default

Quote:
Originally Posted by DAH View Post
Yep, I sure am.
That's me out of suggestions then!

For reference, this is the quick 'n' dirty code I'm using just to try and extract a JSON message to see if it all works (unfortunately, it doesn't yet).

PHP Code:
<?php
set_time_limit
(120);

    
// include a library
    
require_once("Stomp.php");
    
// make a connection
    
$con = new Stomp("tcp://datafeeds.networkrail.co.uk:61618");
    
// connect
    
$con->connect($user,$pass);

$con->subscribe("/topic/TSR_LNE_S_ROUTE",array('transformation' => 'jms-map-json'));
$msg $con->readFrame(); // Code stalls on this line
if ( $msg != null) {
        echo 
"Received array: "
        
print_r($msg->map);
        
// mark the message as received in the queue
        
$con->ack($msg);
    } else {
        echo 
"Failed to receive a message\n";
    }
?>
__________________
All posts are my opinion and should not be taken as an authoritative source
ralphchadkirk is online now   Reply With Quote
Unread 1st July 2012, 21:00   #26
ian13
Member
 
Join Date: 17 Jul 2008
Posts: 162
Default

My advice in PHP is to completely ignore the developer pack.

First, install the PECL STOMP package (just type "pecl install stomp" in the command line).

Then, use code such at the following:

PHP Code:
<?php
// Network Rail Stomp Handler example by ian13
$server "tcp://datafeeds.networkrail.co.uk:61618";
$user "username";
$password "password";
$channel "TRAIN_MVT_ALL_TOC";

$con = new Stomp($server$user$password);
if (!
$con) {
    die(
'Connection failed: ' stomp_connect_error());
}
$con->subscribe("/topic/" $channel);
while(
$con){
    if (
$con->hasFrame()){
        
$msg $con->readFrame();
        foreach (
json_decode($msg->body) as $event) {
          
// do stuff with $event here
        
}
        
$con->ack($msg);
    }
}
die(
'Connection lost: ' time());
?>
__________________
Want digital train timetables with mileages and maps? Try http://trains.im

Last edited by ian13; 1st July 2012 at 21:19.
ian13 is offline   Reply With Quote
Unread 1st July 2012, 21:04   #27
ralphchadkirk
Does not work for the BBC
Established Member
 
ralphchadkirk's Avatar
 
Join Date: 20 Oct 2008
Location: Hatfield or Surrey
Posts: 5,065
Default

Ah, interesting, I can get the RTTPM feed with my code, but not the TSR feed. Haven't tried anything else yet.

I'll try your code in a minute Ian.
__________________
All posts are my opinion and should not be taken as an authoritative source
ralphchadkirk is online now   Reply With Quote
Unread 1st July 2012, 22:34   #28
DynamicSpirit
Member
 
DynamicSpirit's Avatar
 
Join Date: 12 Apr 2012
Posts: 225
Default

Quote:
Originally Posted by Poggs View Post
I deliberately steered the platform down the Stomp route because it's a simple, neutral standard.

Have you looked at http://activemq.apache.org/nms/ for your .NET requirements?
Thanks for the link. That looks potentially useful. I haven't looked at that side yet because I'm still trying to figure out how to download the schedules (getting what I'd assume is the easy bit out of the way first).

Out of interest, you say 'I'. Does that mean you had some influence in the choice of platform? (And no problem about the neutral standard. I totally understand that you need something that can be accessed from any platform).

On the schedules, do you need to have a your own Amazon S3 account set up to download them? I don't and I had assumed that was fine since the URL to download schedules is a networkrail one, not an amazon one, but now wondering if that's the problem. I see one of my download attempts has caused a page redirect to https://nr-datafeed-cif.s3.amazonaws.com/.
DynamicSpirit is offline   Reply With Quote
Unread 2nd July 2012, 06:55   #29
Indigo2
Established Member
 
Join Date: 16 Apr 2010
Posts: 1,367
Default

Quote:
Originally Posted by dooton View Post
Ok so i've just got some JSON back. Tried putting the train ID and schedule id that it returned into open train times and it wasn't found?
Timetable sites such as OpenTrainTimes etc. use codes from the train planning systems, i.e. TIPLOC codes for locations (e.g. HTHRGRN for Hither Green, OXFD for Oxford) and UID codes for individual trains (e.g. C01238, G26384, etc.).

The real-time running data is derived from TRUST/TOPS and uses a completely different set of codes, i.e. STANOX codes for locations (e.g. 88451 for Hither Green, 74446 for Oxford) and TOPS train codes for individual trains, made up of part of the STANOX code for the origin station, the train headcode, and a couple of codes to indicate the rough time of day and date the train started its journey (e.g. 861M58MP01, 121O32MV01 etc.).

Translating between these two sets of codes is a whole big job in itself!

Some good information on codes here and here.
Indigo2 is offline   Reply With Quote
Unread 2nd July 2012, 10:50   #30
DAH
Member
 
Join Date: 17 Apr 2008
Posts: 12
Default

Have tried Ian's way, gone is the 'cannot connect' message and appears to connect but then throws another exception :

Socket connection hasn't been established

Confused

Update, just altered my password and get the same 'socket' message, so guess it isnt connecting afterall.

Last edited by DAH; 2nd July 2012 at 10:59. Reason: tried something different
DAH is offline   Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT. The time now is 17:19.
Powered by vBulletin® Version 3.8.7
Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.
© RailUK Forums 2005 - the year after 2012