Public Transport - Stib-Mvib - Brussels company.

Moderators: leecollings, htilburgs, robgeerts

Post Reply
red73390
Posts: 16
Joined: Wednesday 30 December 2020 13:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: Belgium
Contact:

Public Transport - Stib-Mvib - Brussels company.

Post by red73390 »

Hello,
Do you think it's possible to add the company Stib-Mvib, the transport company of Brussels (Belgium)?
I see there's already the delijn (Belgium) company.

There's an api function provide by the stib company
https://opendata.stib-mivb.be/store/data

There's already some python plugin:
https://pypi.org/project/pyodstibmivb/
https://pypi.org/project/pystibmivb/

I don't know if it's can be use.

Thank you.
User avatar
FireWizard
Posts: 1771
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Public Transport - Stib-Mvib - Brussels company.

Post by FireWizard »

HI,

As there is an API available, it should not be too difficult to read that API. E.g Node Red can collect the data and push the required information to e.g. a "Text" sensor in Domoticz. As there is more than one API available, you should indicate which one you like to use and what the data is, that will be sent.

Regards
red73390
Posts: 16
Joined: Wednesday 30 December 2020 13:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: Belgium
Contact:

Re: Public Transport - Stib-Mvib - Brussels company.

Post by red73390 »

Hello,
I'm using for test the "OperationMonitoring" api, and the sub function "PassingTimeByPoint".

There's a test console on the stib website:

When you choose what you want, it make this function :
CURL:
curl -X GET --header "Accept: application/json" --header "Authorization: Bearer **********************" "https://opendata-api.stib-mivb.be/Opera ... oint/6934F"

REQUEST :
https://opendata-api.stib-mivb.be/Opera ... oint/6934F

And it show a response :
Spoiler: show
{
"points": [
{
"passingTimes": [
{
"destination": {
"fr": "SCHAERBEEK G.",
"nl": "SCHAARBEEK S."
},
"expectedArrivalTime": "2021-01-03T16:43:00+01:00",
"lineId": "92"
},
{
"destination": {
"fr": "SCHAERBEEK G.",
"nl": "SCHAARBEEK S."
},
"expectedArrivalTime": "2021-01-03T16:55:00+01:00",
"lineId": "92"
}
],
"pointId": "6934"
}
]
}
RESPONSE CODE
200

RESPONSE HEADERS
{
"cache-control": "no-cache",
"content-type": "application/json; charset=utf-8",
"expires": "-1",
"pragma": "no-cache"
}

I will take a look into Node Red to see how it works.
User avatar
FireWizard
Posts: 1771
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Public Transport - Stib-Mvib - Brussels company.

Post by FireWizard »

HI,@red73390,

If you need some support with Node Red and/or MQTT do not hesitate to ask.

Regards
red73390
Posts: 16
Joined: Wednesday 30 December 2020 13:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: Belgium
Contact:

Re: Public Transport - Stib-Mvib - Brussels company.

Post by red73390 »

Thanks.

i've just finished to install node red on the pi.
I'm watching some tutos, and I find this example which looks like what I should achieve.
https://discourse.nodered.org/t/best-wa ... nd/29594/7
User avatar
FireWizard
Posts: 1771
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Public Transport - Stib-Mvib - Brussels company.

Post by FireWizard »

Hi,

Yes, I see you are on the way.
Have you already installed Mosquitto as well?

If you need support, please publish the contents of the Debug node, connected to the http request node.

Regards
red73390
Posts: 16
Joined: Wednesday 30 December 2020 13:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: Belgium
Contact:

Re: Public Transport - Stib-Mvib - Brussels company.

Post by red73390 »

FireWizard wrote: Sunday 03 January 2021 20:30 Hi,

Yes, I see you are on the way.
Have you already installed Mosquitto as well?

If you need support, please publish the contents of the Debug node, connected to the http request node.

Regards
Yes not far away!

step 1 : Make the node red running with the stib api -> Done.
step 2 : Make the node red work with domoticz with Mosquitto -> Done.
step 3 : Make the stib api->domoticz -> Done.
step 4 : Show it on Dashticz -> Done.

But all the step are in alpha version...
Node red:
Spoiler: show
[{"id":"fb9ae2ee.3f7ab","type":"tab","label":"STIB","disabled":false,"info":""},{"id":"c03a3d1a.04348","type":"inject","z":"fb9ae2ee.3f7ab","name":"Execution","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":40,"wires":[["79734214.ea902c"]]},{"id":"79734214.ea902c","type":"change","z":"fb9ae2ee.3f7ab","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"6934F","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":100,"wires":[["72e8090b.8b47f8"]]},{"id":"83222736.c28998","type":"debug","z":"fb9ae2ee.3f7ab","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":40,"wires":[]},{"id":"72e8090b.8b47f8","type":"http request","z":"fb9ae2ee.3f7ab","name":"object_resultat","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://opendata-api.stib-mivb.be/Opera ... 140,"wires":[["83222736.c28998","8a07898c.75f878","f2c5cf48.be444"]]},{"id":"b1254314.4edac","type":"mqtt out","z":"fb9ae2ee.3f7ab","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"86f0c28c.790f4","x":750,"y":340,"wires":[]},{"id":"8a07898c.75f878","type":"function","z":"fb9ae2ee.3f7ab","name":"Fill Message","func":"var dt = new Date();\n\nvar now = {\n\t'month':\tdt.getMonth() + 1,\n\t'day':\t\tdt.getDate(),\n\t'year':\t\tdt.getFullYear(),\n\t'hours':\tdt.getHours(),\n\t'mins':\t\tdt.getMinutes(),\n\t'msecs':\tdt.getMilliseconds()\n};\n\n\n\nmsg.payload.idx = 53;\nmsg.payload.svalue = \"The time is now \" + now.hours + \":\" + now.mins;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":330,"y":280,"wires":[["822de88d.1137c8"]]},{"id":"822de88d.1137c8","type":"change","z":"fb9ae2ee.3f7ab","name":"","rules":[{"t":"set","p":"payload.svalue","pt":"msg","to":"payload.points[0].passingTimes[0].expectedArrivalTime","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":300,"wires":[["b1254314.4edac"]]},{"id":"f2c5cf48.be444","type":"function","z":"fb9ae2ee.3f7ab","name":"Fill Message 2","func":"var dt = new Date();\n\nvar now = {\n\t'month':\tdt.getMonth() + 1,\n\t'day':\t\tdt.getDate(),\n\t'year':\t\tdt.getFullYear(),\n\t'hours':\tdt.getHours(),\n\t'mins':\t\tdt.getMinutes(),\n\t'msecs':\tdt.getMilliseconds()\n};\n\n\n\nmsg.payload.idx = 54;\nmsg.payload.svalue = \"The time is now \" + now.hours + \":\" + now.mins;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":380,"wires":[["2623b3bd.af1ccc"]]},{"id":"2623b3bd.af1ccc","type":"change","z":"fb9ae2ee.3f7ab","name":"","rules":[{"t":"set","p":"payload.svalue","pt":"msg","to":"payload.points[0].passingTimes[1].expectedArrivalTime","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":380,"wires":[["b1254314.4edac"]]},{"id":"86f0c28c.790f4","type":"mqtt-broker","name":"","broker":"192.168.0.54","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]


I'm not really familiar by working with json, and data... Everything is named msg.payload but it's working :o .

The results shown are also raw, "2021-01-03T21:00:00+01:00" Is there a way to get them more understandable? From which part do I need to format it (Node-Red, Domoticz (but I don't think), Dashticz (Css?)?

Thanks.
User avatar
FireWizard
Posts: 1771
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Public Transport - Stib-Mvib - Brussels company.

Post by FireWizard »

Hi, @red73390,

A node to refornat the time is "bigtimer".
You can load it through the palette of Node Red.
With this node you can create more or less any format, you want.

Regards
red73390
Posts: 16
Joined: Wednesday 30 December 2020 13:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: Belgium
Contact:

Re: Public Transport - Stib-Mvib - Brussels company.

Post by red73390 »

FireWizard wrote: Sunday 03 January 2021 21:03 Hi, @red73390,

A node to refornat the time is "bigtimer".
You can load it through the palette of Node Red.
With this node you can create more or less any format, you want.

Regards
Sorry I didn't explain very well. I was looking for an object to shrink the string "2021-01-03T21:00:00+01:00" to fit something more understandable like 21:00:00.

Finally I find, in node-red the .match function, and now i can provide to domoticz and dashticz 21:00:00 :D :D .

@FireWizard Thank you to told me the way to create the function with node-red!
ddum
Posts: 4
Joined: Tuesday 31 August 2021 16:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Public Transport - Stib-Mvib - Brussels company.

Post by ddum »

Hi, @red73390

I'm setting up a Dashticz board. I have already setup things like "irailbe" public transport blocks and was looking to also be able to setup things for Stib public transport stops close to me.
I was glad I found this post and read it carefully. Do I understand correctly that the solution is not through a "transportation" block in Dashticz directly but that a "Domoticz" node first has to be created using the Stib API?
Did you manage to create something that would be "portable" onto somebody else's setup or could you otherwise indicate to me how you managed to get what you wanted?
Thanks!
ddum
Posts: 4
Joined: Tuesday 31 August 2021 16:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Public Transport - Stib-Mvib - Brussels company.

Post by ddum »

If ever it can be useful to others, this is how I finally managed to get passing times working on Domoticz and then inserted in my Dashticz screen. I didn't use Node Red finally, but just String and Date formats in LUA to get the data into a device:

1) Created a "developper" account on the STIB/MIVB internet site (https://opendata.stib-mivb.be/store/data)
2) Generated an "api application subscription key" to be able to query their data through http
3) Found the IDs of the stops I was interested in and generated a "OperationMonitoring" query through the STIB/MIVB console that I could simply copy.
4) In Domoticz "Hardware" screen, I created a "HTTP/HTTPS poller" with a virtual sensor for each one of the stops included in my query using:
-Header: Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX (given in STIB console)
-URL: https://opendata-api.stib-mivb.be/Opera ... 2CIDpoint4 (where the IDpointX where found using the NETWORKDESCRIPTION console of the STIB/MIVB api)
- Command: stibmivb_json.lua
5) Wrote a parser (stibmivb_json.lua) script to convert the JSON format generated from the query in order to place the values in the Virtual devices created for each stop.
6) Include the IDs of the devices in Dashticz choosing the appropriate icons (for example: ['icon'] = 'fas fa-bus')

And voilà... will be able to wait until the right moment inside before catching my bus/tram/metro...
Capture.PNG
Capture.PNG (14.14 KiB) Viewed 2681 times
Last edited by ddum on Thursday 30 September 2021 15:33, edited 1 time in total.
ddum
Posts: 4
Joined: Tuesday 31 August 2021 16:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Public Transport - Stib-Mvib - Brussels company.

Post by ddum »

Slight correction, the data for stops of the MIVB/STIB can be found on https://transitfeeds.com/p/societe-des- ... /stops.txt
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests