User avatar
some_evil
Posts: 205
Joined: Thu Dec 18, 2014 3:16 am
Location: Albury, Australia

Two separate RPi's, each with a website, how to merge?

Tue Jul 19, 2016 11:27 am

Hey,

I have two Raspberry Pi, one is a temp logger, it has a website that is accessible to the outside world, and now I have a second Pi that also has a website, serving up flight tracking information via a website.

I have a bit of HTML knowledge, and was thinking of making a home page with a menu bar across the top with two buttons, one for Temperatures, one for Flight info... can I have the two hyperlinks open pages from two separate Pi on the same network?

I have made a crude sketch below for clarification:
Untitled.jpg
Sketch
Untitled.jpg (34.35 KiB) Viewed 941 times
Any comments as to whether what I am thinking is possible? Or do I need to use one single Pi to achieve this?

Cheers
PiZeroW - May 2017
Pi 3 - Oct 2016
PiZero - June 2016
Pi 2 - Jan 2016
Pi B+ - Dec 25 2014

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Two separate RPi's, each with a website, how to merge?

Tue Jul 19, 2016 12:06 pm

some_evil wrote:... can I have the two hyperlinks open pages from two separate Pi on the same network?
Of course you can !

(I must be missunderstanding you)

On a given web page (html5) you can have urls from all over the world (yes, from two different PIs on the same network) of course... ! ... that's the point of a URL (universal resource locator).

What about your communication am I missing ?

marcus
marcus
:ugeek:

User avatar
some_evil
Posts: 205
Joined: Thu Dec 18, 2014 3:16 am
Location: Albury, Australia

Re: Two separate RPi's, each with a website, how to merge?

Tue Jul 19, 2016 1:34 pm

Yeah ok, maybe this is a lot simpler than I thought..

I have an index.html on both Pi currently.
What I will do is rename them to be temp.html (on tee 192.168.2.10 device) and flights.html (on my 192.168.2.11 device).

then I will create the page with the frame and put this in the same directory as my temp.html file, this will be index.html.

The thing I am unsure about is how to reference the flight.html on the other Pi, do I simply make that file accessible (readable) to the other Pi, and reference it somehow? Like a url of //192.168.2.11/flight.html ?
PiZeroW - May 2017
Pi 3 - Oct 2016
PiZero - June 2016
Pi 2 - Jan 2016
Pi B+ - Dec 25 2014

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: Two separate RPi's, each with a website, how to merge?

Tue Jul 19, 2016 1:47 pm

given that frames are evil

given that

if both your pi are reachable by clients, you can build a html page with (brrrr) frames or iframes giving the url of pis (the url must be accessible by clients, obviously)

BUT

if only the first pi "is accessible to the outside world" while the second isn't, you can't do that with frames, since the "outside world" client will not see the "private" pi

User avatar
some_evil
Posts: 205
Joined: Thu Dec 18, 2014 3:16 am
Location: Albury, Australia

Re: Two separate RPi's, each with a website, how to merge?

Tue Jul 19, 2016 2:08 pm

Massi wrote:given that frames are evil
I know, old habits die hard! I learned HTML about 12 years ago in high school, I assume there is a much nicer way to do what I desire, but I have not gone looking. Would it be a CSS something at the top of each page that places the buttons? Just like this forum has the blue bar across it?
Massi wrote:if both your pi are reachable by clients, you can build a html page with (brrrr) frames or iframes giving the url of pis (the url must be accessible by clients, obviously)
Sorry I did forget to finish what I started saying in my last post... both sites that currenly reside at 192.168.2.10 and 192.168.2.11 are reachable by the outside world currently, I have simply ported my router for them to become visible.

Cheers for your tips, I will move forward and see how I go referencing the URL's from the two dif pi's... see if its noticable the end user that the websites are being served by two different devices.
PiZeroW - May 2017
Pi 3 - Oct 2016
PiZero - June 2016
Pi 2 - Jan 2016
Pi B+ - Dec 25 2014

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: Two separate RPi's, each with a website, how to merge?

Tue Jul 19, 2016 2:23 pm

given that frames are evil ( :lol: )

my point is somehow different.
what's the meaning of TWO web servers serving the same page?
we are not balancing load, doing something faster, lowering latency, nothing.
So why different servers?
if you need 2 different pi to do different things (temperature and flight-something-that-i-did-not-understand) that's ok, but if you need to serve informations to clients.. well, i'd look to a way to split DATA from REPRESENTATION

this would be a clearly better rolution.

But remaining in your question.. if both your pi will be accessible in the same domain by clients, you can try to build a good looking css page with divs and load content into divs with jquery load() method

BUT

given that (luckily) the same origin limit is quite rigorous ( https://en.wikipedia.org/wiki/Same-origin_policy ), i think this would require "something" (like a reverse proxy) in the middle.

Did i say that frames are evil? :)

Edit to add:
LOL i swear i was not referring to your nickname! :)

Edit again: reading the page i posted, interesting for you the "Relaxing the same-origin policy" section.
Try to get it to work using two different subdomains "pi1.you.com" and "pi2.you.com" setting the origin domain to you.com
should be interesting..
you need 2 different public ip for this (or again a reverse proxy), if you change port to reach pis it will still not work

Return to “Networking and servers”