Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to integrate SBB profile? #228

Closed
Nattinger opened this issue Apr 7, 2021 · 9 comments
Closed

How to integrate SBB profile? #228

Nattinger opened this issue Apr 7, 2021 · 9 comments
Labels

Comments

@Nattinger
Copy link

Hi there. I'm a beginner in Programming so sorry if i don't understand everything :)

Having this said, i've got quite the struggles to integrate the SBB Profile to the hafas-client. Can somone help me?

Best Regards

@derhuerst
Copy link
Member

Hey!

What do you want to do? If you explain which data you want to query from the SBB HAFAS API, I can provide more details.

Have you seen the small code snippet in the SBB profile?

It shows you how to create a hafas-client instance (named client in the snippet) that points to the SBB HAFAS endpoint. With that client, you can do (almost) every call from the API documentation), e.g. client.departures('161500300').

Please ask more questions, and let me know what information you were looking for but couldn't find.

@derhuerst derhuerst changed the title How to integrate Profile How to integrate SBB profile? Apr 7, 2021
@Nattinger
Copy link
Author

Hi DerHürst

Thank you for reaching out.

So i‘m in the making of an information Display using Smart Mirror 2.
While doing so i added the MMM-PublicTransportHafas module. Now it‘s working quite well. But 2 things annoy me.

1st of all there is an InterRegio-line (IR) stopping at my town each hour in each direction. Those aren‘t being picked up by the vanilla hafas-client. After a quick research i found out i‘d have to somehow add this sbb profile to it in order for it to work.

2nd There is a RegioExpress-Line (RE) which is being displayed in full numbers than the conventional „RE“ which SBB refers to. Another User has also opened an issue with a similiar issue-description. I‘d have slight hope that this issue will also be resolved by adding this profile to the hafas-client.

The small snippet of code you are referring to couldn‘t help me any further. I tried adding those to various files in the hafas-clients with no succes.

I hope this information helps you and would love to hear back from you.

Best Regards

@KristjanESPERANTO
Copy link
Collaborator

Hello @Nattinger, the original MMM-PublicTransportHafas module only use the db profile. You can't easily switch to other hafas profiles.

I recommend to use my fork of this module. Then you can add hafasProfile: "sbb" to the module config to switch to the sbb profile. Maybe this already resolves your problems.

@derhuerst
Copy link
Member

So i‘m in the making of an information Display using Smart Mirror 2.
While doing so i added the MMM-PublicTransportHafas module. Now it‘s working quite well. But 2 things annoy me.

Note that I'm not familiar with the MMM-PublicTransportHafas code base, I just know that it uses hafas-client. @raywo can probably answer specific questions about it.


1st of all there is an InterRegio-line (IR) stopping at my town each hour in each direction. Those aren‘t being picked up by the vanilla hafas-client.

What do you mean by "not picked up"? Are these trains missing from hafas-client's output? Does it identify them as the wrong product (or means of transport)?

After a quick research i found out i‘d have to somehow add this sbb profile to it in order for it to work.

We might have a misunderstanding here.

hafas-client supports many different HAFAS API endpoints. Because each one is slightly different, it has one set of customizations per HAFAS API, called profile. There are many profiles, among them hafas-client/p/db for German Railways and hafas-client/p/sbb for Swiss Railways.

MMM-PublicTransportHafas currently uses the hafas-client/p/db profile, so it pulls the data from the German Railways's HAFAS API.

If you want to use MMM-PublicTransportHafas with the data of the Swiss Railways, you will have to

  • either convince @raywo to build a feature where MMM-PublicTransportHafas users can choose the hafas-client profile to be used, or
  • use @KristjanESPERANTO's fork, which has that feature, or
  • fork MMM-PublicTransportHafas and hardcode the hafas-client/p/sbb profile.

2nd There is a RegioExpress-Line (RE) which is being displayed in full numbers than the conventional „RE“ which SBB refers to. Another User has also opened an issue with a similiar issue-description. I‘d have slight hope that this issue will also be resolved by adding this profile to the hafas-client.

If you want to propose changes to hafas-client, e.g. parsing train names/numbers in a smarter way, please open another issue with specific examples.

@derhuerst
Copy link
Member

@KristjanESPERANTO I assume you forked MMM-PublicTransportHafas because @raywo doesn't want to or can't maintain it anymore. Have you tried contacting @raywo to take over maintenance?

@derhuerst
Copy link
Member

@Nattinger I'm going to close this issue, as your questions seem to be specific to MMM-PublicTransportHafas. Please reopen if you have more questions about hafas-client usage, or open a new Issue if it's a new topic.

@KristjanESPERANTO
Copy link
Collaborator

@derhuerst: Yes, you are right, since @raywo doesn't seem to care about the module, I forked it.

At first I didn't want to take over the maintenance, but I changed my mind. I'll try to contact him 🙂

@derhuerst
Copy link
Member

At first I didn't want to take over the maintenance, but I changed my mind. I'll try to contact him 🙂

(It may be obvious, but I'll say it anyways: You don't have to maintain it up to anyone's expectations. But since you've made improvements in your fork already, why not let everyone benefit from them? 🙂)

@KristjanESPERANTO
Copy link
Collaborator

Okay, I looked into it. There is something strange what I can't explain and has nothing to do with the MagicMirror module.

I propose to reopen this issue or we open a new one.

The sbb profil works fine with the station 'Zürich Kreuzplatz' (ID: 8530813). The problem occurs with the Station 'Thalwil' (ID: 8503202).

When I'm asking for departures in the next minute I get a valid answer.

Code snipped:

const thalwil = '8503202' // Thalwil
client.departures(thalwil, {duration: 1})
...

Response:

[
  {
    tripId: '1|115564|15|85|11042021',
    stop: {
      type: 'stop',
      id: '8573167',
      name: 'Thalwil, Zentrum',
      location: {
        type: 'location',
        id: '8573167',
        latitude: 47.294919,
        longitude: 8.564464
      },
      products: {
        'express-train': false,
        'international-train': false,
        'interregional-train': true,
        'regional-express-train': true,
        watercraft: true,
        'suburban-train': true,
        'bus-taxi': true,
        gondola: false,
        'car-train': false,
        tram: false
      }
    },
    when: '2021-04-11T22:49:00+02:00',
    plannedWhen: '2021-04-11T22:49:00+02:00',
    delay: null,
    platform: null,
    plannedPlatform: null,
    direction: 'Thalwil, Böni',
    provenance: null,
    line: {
      type: 'line',
      id: 'h-142-000807',
      fahrtNr: '20153',
      name: 'B 142',
      public: true,
      adminCode: '000807',
      mode: 'bus',
      product: 'bus-taxi',
      operator: {
        type: 'operator',
        id: 'automobildienst-szu',
        name: 'Automobildienst SZU'
      }
    },
    remarks: [
      { type: 'hint', code: '1', text: 'B 142' },
      { type: 'hint', code: '2', text: 'Bus 142 20153' },
      { type: 'hint', code: '3', text: 'B 142 20153' },
      { type: 'hint', code: '4', text: 'B 142 20153' },
      { type: 'hint', code: '1', text: 'B 142' },
      { type: 'hint', code: '2', text: 'Bus 142 20153' },
      { type: 'hint', code: '3', text: 'B 142 20153' },
      { type: 'hint', code: '4', text: 'B 142 20153' },
      { type: 'hint', code: 'NF', text: 'Niederflureinstieg' },
      {
        type: 'hint',
        code: 'OM',
        text: 'Maskenpflicht für Reisende ab 12 Jahren'
      },
      { type: 'hint', code: 'FD', text: '20153' }
    ]
  }
]

But when I'm asking for departures in the next 10 minutes I get an error.

Code snipped:

const thalwil = '8503202' // Thalwil
client.departures(thalwil, {duration: 10})
...

Response:

Error: CGI_READ_FAILED
    at Object.request (/.../hafas-client/lib/request.js:108:14)
    at _stationBoard (/.../hafas-client/index.js:76:18)
    at Object.departures (/.../hafas-client/index.js:87:10)
    at Object.<anonymous> (/.../hafas-client/p/sbb/example.js:11:8)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47 {
  isHafasError: true,
  request: '{"lang":"deu","svcReqL":[{"meth":"StationBoard","req":{"type":"DEP","date":"20210411","time":"224817","stbLoc":{"type":"S","lid":"A=1@L=8503202@"},"dirLoc":null,"jnyFltrL":[{"type":"PROD","mode":"INC","value":"1023"}],"dur":10,"getPasslist":false,"stbFltrEquiv":false}}],"client":{"type":"AND","id":"DBZUGRADARNETZ","v":""},"ver":"1.18","auth":{"aid":"hf7mcf9bv3nv8g5f","type":"AID"}}',
  url: 'http:https://fahrplan.sbb.ch/bin/mgate.exe?',
  statusCode: 200,
  code: 'CGI_READ_FAILED',
  responseId: null
}

At the moment I have no idea how to continue looking for the cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants