API for linking to the Huxley National Rail REST proxy for the retrieval of live National Rail data. Still needs work (sadly), but works well for the time being!

Dependencies:   EthernetInterface

National Rail Huxley Integration Interface

This API provides a clear link between the National Rail Huxley Integration JSON interface (available at https://huxley.unop.uk/), and mbed devices, over an Ethernet connection. This project is still very much a work-in-progress, but hopefully I will be able to provide a comprehensive method of retrieving live National Rail departures data in a simple and effective way.

/media/uploads/Leigh_LbR/nre_powered_logo.jpg

Committer:
Leigh_LbR
Date:
Tue May 24 15:17:38 2016 +0000
Revision:
11:4532ff549fcf
Parent:
6:dae1cdf19e90
Fixed a small glitch with NR_Network.cpp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Leigh_LbR 6:dae1cdf19e90 1 #include "MbedJSONValue.h"
Leigh_LbR 0:bf04f62339a4 2 #include "departure_board.h"
Leigh_LbR 6:dae1cdf19e90 3
Leigh_LbR 0:bf04f62339a4 4
Leigh_LbR 0:bf04f62339a4 5 using std::string;
Leigh_LbR 0:bf04f62339a4 6
Leigh_LbR 4:7e8a23454d85 7 Departure_Board::Departure_Board(Departure* _departures, const int& _num_departures, std::string* _messages, const int& _num_messages)
Leigh_LbR 0:bf04f62339a4 8 {
Leigh_LbR 0:bf04f62339a4 9 departures = _departures;
Leigh_LbR 4:7e8a23454d85 10 num_departures = _num_departures;
Leigh_LbR 4:7e8a23454d85 11 messages = _messages;
Leigh_LbR 4:7e8a23454d85 12 num_messages = _num_messages;
Leigh_LbR 0:bf04f62339a4 13 }
Leigh_LbR 0:bf04f62339a4 14
Leigh_LbR 0:bf04f62339a4 15 Departure_Board::~Departure_Board()
Leigh_LbR 0:bf04f62339a4 16 {
Leigh_LbR 0:bf04f62339a4 17 delete departures;
Leigh_LbR 0:bf04f62339a4 18 delete messages;
Leigh_LbR 0:bf04f62339a4 19 }
Leigh_LbR 0:bf04f62339a4 20
Leigh_LbR 0:bf04f62339a4 21 Departure_Board depBoardFromJson(const string& jsonObject)
Leigh_LbR 0:bf04f62339a4 22 {
Leigh_LbR 0:bf04f62339a4 23 Departure_Board board;
Leigh_LbR 0:bf04f62339a4 24
Leigh_LbR 0:bf04f62339a4 25 MbedJSONValue json (jsonObject);
Leigh_LbR 0:bf04f62339a4 26
Leigh_LbR 6:dae1cdf19e90 27 MbedJSONValue trainServices = json["trainServices"];
Leigh_LbR 6:dae1cdf19e90 28 MbedJSONValue messages = json["nrccMessages"];
Leigh_LbR 0:bf04f62339a4 29
Leigh_LbR 0:bf04f62339a4 30 board.departures = new Departure[trainServices.size()];
Leigh_LbR 0:bf04f62339a4 31 board.num_departures = trainServices.size();
Leigh_LbR 0:bf04f62339a4 32
Leigh_LbR 0:bf04f62339a4 33 board.messages = new string[messages.size()];
Leigh_LbR 0:bf04f62339a4 34 board.num_messages = messages.size();
Leigh_LbR 0:bf04f62339a4 35
Leigh_LbR 0:bf04f62339a4 36 for(int i = 0; i < trainServices.size(); ++i) {
Leigh_LbR 0:bf04f62339a4 37 Departure d;
Leigh_LbR 0:bf04f62339a4 38
Leigh_LbR 0:bf04f62339a4 39 d.crs = trainServices[i]["destination"]["crs"].get<string>();
Leigh_LbR 0:bf04f62339a4 40 d.locationName = trainServices[i]["destination"]["locationName"].get<string>();
Leigh_LbR 0:bf04f62339a4 41 d.std = trainServices[i]["std"].get<string>();
Leigh_LbR 0:bf04f62339a4 42 d.etd = trainServices[i]["etd"].get<string>();
Leigh_LbR 0:bf04f62339a4 43 d.platform = trainServices[i]["platform"].get<string>();
Leigh_LbR 0:bf04f62339a4 44 d.operatorName = trainServices[i]["operator"].get<string>();
Leigh_LbR 0:bf04f62339a4 45 d.operatorCode = trainServices[i]["operatorCode"].get<string>();
Leigh_LbR 0:bf04f62339a4 46
Leigh_LbR 0:bf04f62339a4 47 board.departures[i] = d;
Leigh_LbR 0:bf04f62339a4 48 }
Leigh_LbR 0:bf04f62339a4 49
Leigh_LbR 0:bf04f62339a4 50 for(int i = 0; i < messages.size(); ++i) {
Leigh_LbR 0:bf04f62339a4 51 board.messages[i] = messages[i]["value"].get<string>();
Leigh_LbR 0:bf04f62339a4 52 }
Leigh_LbR 0:bf04f62339a4 53
Leigh_LbR 0:bf04f62339a4 54 return board;
Leigh_LbR 0:bf04f62339a4 55 }