Ogadai / zwift-mobile-api

MIT License
118 stars 25 forks source link

Crash when using library #11

Closed justvervaart closed 6 years ago

justvervaart commented 6 years ago

I use the library in this project https://www.instructables.com/id/Internet-Connected-Fan-for-Use-With-Zwift/ and my javascript crashes every x minutes, but with errors outside my script. Can u tell if the problem lies somewhere in your library? (was very glad to find the library by the way, made my project possible!)

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: getaddrinfo ENOTFOUND api.particle.io api.particle.io:443
    at errnoException (dns.js:50:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
andy-lee-eng commented 6 years ago

Hi @justvervaart

There are no parts of zwift-mobile-api mentioned in that error message or call stack. It suggests some sort of dns lookup error, which could affect anything that tries to make an internet request (which zwift-mobile-api obviously does via axios and node.js libraries). How stable is your network connection from that device?

Even with a rock solid network though, internet requests sometimes fail. zwift-mobile-api wraps Zwift's api to make it easier for you to call it, but it doesn't attempt to handle errors or anything like that.

andy-lee-eng commented 6 years ago

I like the project by the way :-)

justvervaart commented 6 years ago

Thx for the feedback and the compliment. The network is quit stable. For now i made a bash script that relaunches after a crash. Does the job.

until node zwiftfan_script.js; do echo "Zwiftfan crashed! ....respawning..." >&2 sleep 1 done

andy-lee-eng commented 6 years ago

Congrats on the GCN multi-tool :-)

maartensiffels commented 6 years ago

People in the tinker/makerspace community without real coding skills want to build stuff (like the Smart Fan) for use with Zwift but need a more easy way to call the Zwift API endpoints. I see three options.

  1. Zwift builds a public API. But thats not going to happen soon. I recently asked them about it and it is not on any roadmap.
  2. Someone ports the Javascript library to an Arduino (C/C++) library. Raspberry Pi can run C/C++ as well. So we can call the Zwift servers direct from the device.
  3. Someone builds an API with endpoints on top of the current zwift-mobile-api Javascript library. What do you think is the most viable option, 2 or 3?
maartensiffels commented 6 years ago

ps. there really has only to be 1 endpoint, one that returns all the values from riderStatus (speed, heart rate etc) for any given rider which you can call with the Zwift credentials once per second. If anyone can build this, that would be really nice.

Ogadai commented 6 years ago

I think option 2 is best.

At it's most basic, zwift-mobile-api only does 2 things:

  1. Call the authentication end-point to get a bearer token and attach it to subsequent API calls as "Authorisation" header.

  2. Decode protobuf data.

The first is just a convenience, and the second should be easy in C/C++: https://developers.google.com/protocol-buffers/docs/cpptutorial

wiedmann commented 6 years ago

I know this issue is already closed, but just to add: as far as I know there is nothing stopping node.js from running on Arduino and/or Raspberry Pi. A brief web search turns up hits for both.

maartensiffels commented 6 years ago

Never thought of that. Will look into it. Thx!