feverish
Posts: 486
Joined: Wed Jun 27, 2012 2:29 pm

Displaying an HTML file remotely

Thu Aug 21, 2014 5:16 pm

I am part-way-on to making a stand-alone Raspi project.
My RaspiB+ I shall be using now has Python and Cherrypy and pip installed and a work-in-progress single-page HTML file installed in /home/pi. The HTML file for the moment only contains visual layout information.. I have setup the CherryPy HTTP server to work on LAN address 192.168.1.x via port 8083 and I can 'see' it, both using iceweasel on the Raspi and remotely over the LAN using Firefox on a Windows PC. To test this so far, I copied the much-quoted simplest tutorial example using only a textual message from the server and added the necessary few extra lines of code from examples to let me do this.
My next step needs to be enabled to 'see' the html file. Having spent several wasted days failing to get a sufficient grip on lots of CherryPy tutorials, I'd be gratefukl for a pointer to a HowTo or a code snippet that will let me point Firefox at the server and display the HTML file, using http://192.168.1.x:8083. I've tried adding <return open(os.path.join('/home/pi', u'yyyy.html'))>, without the arrows, in the .py script. I don't know what the 'u' is there for (just taken from tutorial text) that seems to want to help but fails. I've also tried removing the 'u' but that's no good, either.
Thanks in advance for anything that works.
If discrimination is not challenged then we are effectively in collusion with the perpetrators of such behaviour:-Oxford dictionaries

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Displaying an HTML file remotely

Thu Aug 21, 2014 6:10 pm

Sounds like a very complex way of doing things. Whats in the html file that a plain html file knocked up in anyone of hundreds of tools and served up with lighttpd or nginx wouldn't do ? That could be achieved in 10 minutes. Default install of lighttpd, shove the file in /var/www called index.html and point a browser at the ip address of the pi.

You could install lighttpd (sudo apt-get install lighttpd) and then point a browser on another computer on your network at http://192.168.1.251 (or whatever the ip address of the pi is) and it will display the welcome screen of lighttpd. Then delete or rename the file in /var/www and put your html file named index.html in there. Refreshing the browser will bring up your page.

Or you you have to do it in python ?
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

feverish
Posts: 486
Joined: Wed Jun 27, 2012 2:29 pm

Re: Displaying an HTML file remotely

Thu Aug 21, 2014 7:05 pm

tfyi. My project is to start and stop heaters and control water-coolant flow valves remotely from different LAN-linked locations and to extract the temperature changes from the returned data from various 1-wire thermistors, themselves controlled from the Raspi GPIO, to HTTP browsers situated in randomly-selected locations having 802.11 access from the LAN. Later, I may need to extend this to the WAN.

I usually programme preferably in Delphi or Lazarus but having sought advice on good ways to do this sort of thing on Raspi the consensus was to use python, CherryPy, possibly also Ajax and json. I do not know lightpd - can it do this sort of thing? I suspect it should be a relatively simple thing to do using python etc but I am a total beginner there and am currently stuck at the point I described.
If discrimination is not challenged then we are effectively in collusion with the perpetrators of such behaviour:-Oxford dictionaries

ghans
Posts: 7877
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Displaying an HTML file remotely

Thu Aug 21, 2014 7:20 pm

Code: Select all

return open(os.path.join('/home/pi', u'yyyy.html'))
is propably not what you want. Try something along the
lines of

Code: Select all

file = open ('/home/pi/yyyy.html')
text = file.read()
file.close()
return text
ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

User avatar
tedhale
Posts: 114
Joined: Thu Sep 20, 2012 4:52 pm
Location: Williamsburg, VA, USA
Contact: Website

Re: Displaying an HTML file remotely

Thu Aug 21, 2014 7:52 pm

I had to solve a similar problem - how to interface a web page to a program running on the Pi. What I do is create program that does all of the GPIO, sensor reading, etc needed for the task. Then I add a thread to that program that listens on a socket. I use Apache and PHP to run a PHP script to generate the output that I want on the web browser. This script uses socket IO to communicate with the program.

Another way to achieve it would be to create programs that the web server runs via a CGI POST.
- Ted B. Hale
http://raspberrypihobbyist.blogspot.com

feverish
Posts: 486
Joined: Wed Jun 27, 2012 2:29 pm

Re: Displaying an HTML file remotely

Thu Aug 21, 2014 8:04 pm

Thanks to tedhale for something I miay need to use later, but parfticularly to ghans, whose solution not only worked immediately, but I understood it!.
If discrimination is not challenged then we are effectively in collusion with the perpetrators of such behaviour:-Oxford dictionaries

ghans
Posts: 7877
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Displaying an HTML file remotely

Thu Aug 21, 2014 8:25 pm

Note that this is propably not the "proper" way to do serve
static files with CherryPy. The tutorial 6 shows how to do that
within the framework , exposing the contents of a complete
directory.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

feverish
Posts: 486
Joined: Wed Jun 27, 2012 2:29 pm

Re: Displaying an HTML file remotely

Fri Aug 22, 2014 7:46 am

I've read the included CherryPy tutorials a number of times but confess that although I think I can understand what they say they are doing, I don't really understand why and so cannot yet extrapolate from there to what I want to do. Hopefully, I will, in time, if I ever get a proper grip on the jargon, the help given here is very geneorus.
If discrimination is not challenged then we are effectively in collusion with the perpetrators of such behaviour:-Oxford dictionaries

ghans
Posts: 7877
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Displaying an HTML file remotely

Fri Aug 22, 2014 8:07 am

The point of a framework is to enable devolopers to
get fast and good results as long they follow the frameworks
design. If they want to take shortcuts or do things their
own way , the framework will just complicate things.

I think you will have to spend some time trawling through
the documentation :D .

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

gkreidl
Posts: 6120
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Displaying an HTML file remotely

Fri Aug 22, 2014 9:13 am

Running a python web server from a python solution is definitely the best approach. Installing a separate web server like lighttpd and using PHP to access GPIO programs written in Python will only complicate things (and slow them down and need more resources).

Either you have to study the cherrypy documentation carefully and learn how to use it or you may choose another framework. My recommendation (not only) for beginners is Karrigell. A simple "hello world" script is a s simple as

print "hello world" (saved as index.px)

or a bit more HTML friendly

print "<html><body>hello world</body></html>"

http://karrigell.sourceforge.net/en/index.html
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

feverish
Posts: 486
Joined: Wed Jun 27, 2012 2:29 pm

Re: Displaying an HTML file remotely

Fri Aug 22, 2014 5:41 pm

Thank you for more interesting information. I've invested days on end so far grappling with python and CherryPy and prefer not to start all over again with something different if I can reasonably avoid it, but if push does come to shove I'll try your suggestion.
If discrimination is not challenged then we are effectively in collusion with the perpetrators of such behaviour:-Oxford dictionaries

Return to “Beginners”