ambient-weather / api-docs

AmbientWeather.net API Documentation
64 stars 42 forks source link

Real-time API doesn't work #42

Closed wadetregaskis closed 1 year ago

wadetregaskis commented 2 years ago

I'm trying to use the realtime API via Socket.IO (for https://github.com/wadetregaskis/SwiftWeather) and I am able to connect but I never receive any response to anything I send. I do receive pings from the server, so something is actually active on the other end, but the "subscribe" command appears to just be silently ignored by the server…?

The documentation here in this repo isn't all that helpful since it refers specifically and exclusively to a random Node.js library, without actually documenting the protocol in any meaningful way. So I don't really know what the argument to "subscribe" is supposed to be at the Socket.IO layer let-alone the wire layer. The source of https://github.com/owise1/ambient-weather-api seems to imply that something like the string '{ "apiKeys": ["xyz"] }' should work, being the JSON serialisation of a nominal object with an apiKeys property etc. But it doesn't. Nor does any conceivable variation on serialisation format (e.g. single-quotes instead of double-quotes, no quotes, etc). Nor if I send the serialised form as a binary event. Etc.

mhilbush commented 2 years ago

If you want to look at an implementation (in Java), here's one I wrote to integrate the realtime API into the openHAB smarthome platform.

https://github.com/openhab/openhab-addons/tree/main/bundles/org.openhab.binding.ambientweather

wadetregaskis commented 2 years ago

Thanks. Unfortunately that sheds no light on the issue. You're doing seemingly the exact same thing I am. Yet the server never, ever responds to the "subscribe" command for me.

In fact it never responds to anything I send. I just get its pings every 25 seconds. That's the only sign of life.

mhilbush commented 2 years ago

Hmm. Sorry, I'm not sure what to suggest.

I don't know swift, so I can't really provide much help. I didn't see any of the Socket.IO code in the repo you posted above, so maybe it's in a local branch?

I assume you are setting up a handler/callback for the "subscribed" event? Such as what I'm doing here

wadetregaskis commented 2 years ago

Indeed I haven't pushed any of this [attempted] support to GitHub yet - seems pointless if it doesn't work.

I installed Charles proxy to snoop the actual WebSockets traffic, and it seems to confirm that I'm doing everything correctly. The server just simply never responds to anything. e.g. with EIO v4 to rt2.ambientweather.net:

rt2 ambientweather net

…or with EIO v3 to api.ambientweather.net:

api ambientweather net

Per the Socket.IO Protocl Spec, that's all exactly correct.

Note that in the screenshots above I replaced my API key with a dud value to preserve my API key's secrecy, but of course in real testing I'm using my real API key - the same API key that works just fine with the basic HTTP APIs.

wadetregaskis commented 2 years ago

I'm going to have to give up on supporting the 'Live' API in my library. I've run out of things to try, even blindly. All evidence suggests the AmbientWeather API is broken. 😔

I've stashed my hacky work-in-progress code in a branch, for posterity I guess.