That’s nicely packaged up. Mine is still ‘on the bench’, but think I’ve probably got to the end of the physical wiring, so it needs a home now. Am exploring the idea of making an acrylic/perspex box…
Note from the photo that my Imp also warns me of the next train now, done with some HTML web scraping. National Rail declined my request for access to their API. Expected…
Yes, no problem seeing that, although I’ve had the odd (lucky) escape in that I’ve reversed out of the garage while the traffic light was amber (not green).
Yes, scraping with the agent and here’s the code. It’s very dependent on the format presented by this one particular web site. It’s not realtime and I’m not sure how often the site scraps the national rail web site, but it seems to be fairly frequent.
function TrainTimetableRequest ()
{
local Request = http.get (URL_TRAINTIMETABLE)
Request.sendasync (TrainTimetableResponse)
imp.wakeup (60, TrainTimetableRequest)
}
function TrainTimetableResponse (Fields)
{ //server.log (“Response received”)
local ScheduledTrainArrival
local ScheduleTrainStatus
// Ensure the parsing is ok
if ((ScheduledTrainArrival = FindTagValue (Fields, "<tr><td>")) != null) {
if ((ScheduleTrainStatus = FindTagValue (Fields, "<small>")) != null) {
// Decide whether the train is on time or late, then communicate to Device
device.send ("TrainStatus", (ScheduleTrainStatus == "On time" ? ScheduledTrainArrival : StatusTrainStatus))
}
}
}
function FindTagValue (Fields, Tag)
{
local Start = Fields.body.find (Tag)
local End
local TagValue = null
Yesterday morning was pretty cold. When I looked at the distance display, it read 7 inches and was stuck there. Everything else was working just fine, but I think the sensor may have been affected by something to do with the cold. It was working fine today.