Page 1 of 1

Ajax vs. websockets

Posted: Mon 01 Aug 2016 3:53 pm
by phloks
Hi,

Recently I installed cumulusmx on my rpi2b and everything looks great. To be able to see the site in the office, I proxied the rpi port 8998 on my webserver. The pages all load, but there is no update of data or gauges. Turns out my company does not allow websockets.....
Changed the three js files to enable Ajax instead of websockets, restarted mono, but the outcome is the same. No updates.
Does Ajax still work?

Thanks,
Hans

Re: Ajax vs. websockets

Posted: Mon 01 Aug 2016 3:59 pm
by steve
As far as I know it does, yes. Do you have any error messages in the F12 console in your browser?

Re: Ajax vs. websockets

Posted: Mon 01 Aug 2016 7:53 pm
by phloks
Hi Steve,

Thanks for giving a reaction very fast.

I had to search for it, but yes, indeed there are error msgs in the net log of firefox :

GET XHR http://www.hanslammerts.nl/cumulus/api/data/currentdata [HTTP/1.1 404 Not Found 0ms]

every 2 seconds or so.
If I do a curl -v http://localhost:8998/api/data/currentdata, on the Pi, I do get info back (json ?).
A curl -v https://www.hanslammerts.nl/cumulus/api ... urrentdata gives the 404.

I think there must be something wrong with my proxy or proxyreverse statements in apache2, but I can't
see what it is at the moment.
I can not expose port 8998 to the outside world (well, I could, but I don't want to, and besides, my company
won't let anything else through the firewall than 80 and 443) .

If you have a suggestion on how to fix this, or anyone else for that matter, I would be very grateful.
In the mean time I'll look into the proxy possibilities.

Thanks,
Hans

Re: Ajax vs. websockets

Posted: Mon 01 Aug 2016 8:01 pm
by steve
Sorry, it's beyond me. You're mapping port 80 onto port 8998 in some way? And that works for html pages but not for the api call? Hopefully someone who understands these things will be able to help.

Re: Ajax vs. websockets

Posted: Mon 01 Aug 2016 8:51 pm
by freddie
steve wrote:Hopefully someone who understands these things will be able to help.
Could you post your reverse proxy configuration, please?

Re: Ajax vs. websockets

Posted: Tue 02 Aug 2016 8:00 am
by phloks
Thanks Steve.
Hi Freddie,

Sure. This is it (probably too simple.....) :
<Location /cumulus>
ProxyPass http://192.168.0.105:8998/
ProxyPassReverse http://192.168.0.105:8998/
</Location>
Thanks,
Hans

Re: Ajax vs. websockets

Posted: Tue 02 Aug 2016 10:27 am
by freddie
phloks wrote:Thanks Steve.
Hi Freddie,

Sure. This is it (probably too simple.....) :
<Location /cumulus>
ProxyPass http://192.168.0.105:8998/
ProxyPassReverse http://192.168.0.105:8998/
</Location>
Thanks,
Hans
Looks fine to me. I don't recommend doing what you've done, by the way, as anybody can look at your internet settings and passwords, etc! If you must proxy the dahboard, I would ensure that the settings tab (and any data URLs it calls) is excluded.
Having said that, I've done some browsing of your interface with the F12 console switched on. As you say, calls to api/data/currentdata return 404 (not found) HTTP response. This is also true for a lot of the .json files that contain the data for the pages. Some but not all return 404 (not found). The puzzling thing is that some of the .json files sometimes return okay. So I think your reverse proxy configuration is sound - but something else isn't quite right. It would be a good idea to look in the Apache log files, and also the log files for the Cumulus webserver - if there are any. There may be clues in there.

A better way to access your dashboard would be through an SSH tunnel - assuming your company firewall allows you to make SSH connections to external hosts. Use a client (PuTTY is a good one on Windows) and Google how to create tunnels. That way it is only you who can access your interface externally - which is much safer than letting everybody!!

Re: Ajax vs. websockets

Posted: Tue 02 Aug 2016 3:19 pm
by phloks
Hi Freddie,

Thanks for the elaborate answer.
I do realise that what I've done sofar is not quite safe, and I intended to figure out how to disable the settings tab when proxying would have been successful.
Anyhow, I'll try to set debug levels to a higher level where I can, and see if I can detect something.

Thanks for thinking with me !
Oh, and BTW, no, my company does not allow to connect to remote ssh servers........ :x

Thanks,
Hans

Re: Ajax vs. websockets

Posted: Tue 02 Aug 2016 6:09 pm
by steve
You could just upload to a web site, and view the data that way. It would be much simpler ;)

Re: Ajax vs. websockets

Posted: Tue 02 Aug 2016 7:23 pm
by phloks
Hi Steve,

Yeah, I really should do some RTFM.... :bash: :groan:
instead of relying on my numerous attempts (and failures) of installing software on Linux..

My main concern is that I'd like the website to be as realtime as possible. Don't know if that
can be achieved using FTP only.
Then again, I did not read that section of the documentation thoroughly enough, and I also saw a post
of someone who has used rsync successfully.
So, thank you, gentlemen, for the assistance. Will go figure this out a bit more in-depth.

Keep up the good work !

Thanks,
Hans

Re: Ajax vs. websockets

Posted: Tue 02 Aug 2016 8:08 pm
by mcrossley
The website *could* be on your rPi, then there would no need to FTP, just copy the files locally. If you want it viewable by the public then a hosted server would be better, especially if you have a dynamic IP address.