BLL
Posts: 195
Joined: Fri Jun 07, 2013 2:30 pm

Web server for RasPi 3?

Mon Jan 01, 2018 6:08 pm

Hi
I am looking for some advice. I have a RasPi model 3, running jessie. It is installed in my caravan (RV), where it acts as my internet router and also has a program I have written in lazarus/fpc (1.7/3.0.0), which monitors the health of my caravan systems.
I would like to communicate with this program remotely over the internet.
My first attempt was to implement a very simple webserver by using the weblaz package in lazarus. However, it won't install and pleas on the lazarus forum have not been answered, so it looks as though that way is dead.
The alternative, I suppose is to install a simple webserver on the RasPi. The requirements are trivial:

To webserver From webserver
Ac on Ac is on
Ac off Ac is off
Heating on Heating is on
Heating off Heating is off
Status Sends about 600 bytes of text

and that's it!
Could somebody advise me on the simplest solution please? I have never done anything with webservers before, so this is all new to me.
I hope to then produce an Android app to send/receive info to/from the RasPi.
Any help much appreciated.

Thanks

Brian

fruitoftheloom
Posts: 17434
Joined: Tue Mar 25, 2014 12:40 pm

Re: Web server for RasPi 3?

Mon Jan 01, 2018 6:14 pm

BLL wrote:
Mon Jan 01, 2018 6:08 pm
Hi
I am looking for some advice. I have a RasPi model 3, running jessie. It is installed in my caravan (RV), where it acts as my internet router and also has a program I have written in lazarus/fpc (1.7/3.0.0), which monitors the health of my caravan systems.
I would like to communicate with this program remotely over the internet.
My first attempt was to implement a very simple webserver by using the weblaz package in lazarus. However, it won't install and pleas on the lazarus forum have not been answered, so it looks as though that way is dead.
The alternative, I suppose is to install a simple webserver on the RasPi. The requirements are trivial:

To webserver From webserver
Ac on Ac is on
Ac off Ac is off
Heating on Heating is on
Heating off Heating is off
Status Sends about 600 bytes of text

and that's it!
Could somebody advise me on the simplest solution please? I have never done anything with webservers before, so this is all new to me.
I hope to then produce an Android app to send/receive info to/from the RasPi.
Any help much appreciated.

Thanks

Brian


?? RealVNC Comnect ??

https://www.raspberrypi.org/blog/get-ba ... c-connect/
Adieu

Jagboy
Posts: 17
Joined: Thu Dec 28, 2017 5:19 pm

Re: Web server for RasPi 3?

Tue Jan 02, 2018 1:47 am

Why would you NOT just install Apache? It's a total no-brainer to install, and works perfectly.

sudo apt install Apache2

You'll be up and running in minutes.

Regards,
Ray L.

Heater
Posts: 9822
Joined: Tue Jul 17, 2012 3:02 pm

Re: Web server for RasPi 3?

Tue Jan 02, 2018 3:47 am

The simplest way to do this is to create a little web server using node.js that can easily read from whatever sensors you have, serve up web pages and deliver sensor data to those web pages.

See my recent answer to a similar question here:

viewtopic.php?f=31&t=201284&p=1253050#p1253050


@Jagboy
Why would you NOT just install Apache? It's a total no-brainer to install, and works perfectly.
Because installing Apache does not magically get the job done. And getting the job done from Apache is not nice.

As you have noticed here:
viewtopic.php?f=36&t=201325

BLL
Posts: 195
Joined: Fri Jun 07, 2013 2:30 pm

Re: Web server for RasPi 3?

Tue Jan 02, 2018 11:41 am

Hi both

Thanks for the replies.
I guess that installing Apache is the easy bit but learning how to get it to do what I want is likely to be something else!!

The javascript route sounds interesting but I don't want to read sensors - I already have a program which displays sensor data provided by a PIC micro. All I want to do is to remotely talk to that program.

I will look further into to both suggestions.

Thanks very much for your thoughts

Brian

Heater
Posts: 9822
Joined: Tue Jul 17, 2012 3:02 pm

Re: Web server for RasPi 3?

Tue Jan 02, 2018 12:02 pm

Is that program talking to your PIC over a serial port?

If so you can easily run that program from Javascript under node.js, send it commands and get it's responses back. Assuming that is a command line program not a GUI thing.

Use the inbuilt "spawn" or "exec" methods. Lot's of good explanation of that here:
https://medium.freecodecamp.org/node-js ... 9498fe970a

User avatar
Gavinmc42
Posts: 2105
Joined: Wed Aug 28, 2013 3:31 am

Re: Web server for RasPi 3?

Tue Jan 02, 2018 1:38 pm

Python comes with the SimpleHTTPServer example, good place to start if you want to stay with Raspbian.
I use it for quick HTML page testing on any OS.
I save my data as csv files, makes for very simple data extraction, one file per day.

Or if you are brave and want to learn a lot, Apache, MySQL, PHP, the AMP part of LAMP which a lot of the world runs on.
If you want to be more modern Nginx or LightHTTPD or even NodeJS.

I have also used simple HTML5 pages with dygraphs.js doing the plotting on PiCore running Busybox-httpd and a bunch of shell script doing the CGI stuff.

Or if you are already familiar with Laz/FPC do it bare metal with Ultibo , start with the Webserver example.
https://github.com/ultibohub/Examples
Probably better to run it on its own B+?

Episode 6 for web control of stuff.
https://ultibo.org/make/
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
r3d4
Posts: 934
Joined: Sat Jul 30, 2011 8:21 am
Location: ./

Re: Web server for RasPi 3?

Tue Jan 02, 2018 2:09 pm

BusyBox HTTP Daemon (httpd) should work

A page full of relevent information
and examples :arrow: https://wiki.openwrt.org/doc/howto/http.httpd

or you could look up websocketd and use (newer) websockets instead of (older) CGI
websocketd is the WebSocket daemon
a small command-line tool that will wrap an existing command-line interface program, and allow it to be accessed via a WebSocket.
Turn any program that uses STDIN/STDOUT into a WebSocket server. Like inetd, but for WebSockets.

User avatar
Gavinmc42
Posts: 2105
Joined: Wed Aug 28, 2013 3:31 am

Re: Web server for RasPi 3?

Wed Jan 03, 2018 6:27 am

you could look up websocketd
Forgot that one, it works fine too, very simple on Pi's just one binary file.
I compiled on Raspbian and just copied the binary to PiCore, ran fine :D
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

BLL
Posts: 195
Joined: Fri Jun 07, 2013 2:30 pm

Re: Web server for RasPi 3?

Wed Jan 03, 2018 10:06 am

Hi both

Thanks for the replies.
The program on the RasPi 3 is a gui program written in lazarus. It talks to the PIC via a usb-serial converter. Data also comes from a weather station and via modbus from my solar controller.

I will have a good loock at the Python idea, although I have never used Python.

The really annoying thing is that all this problem is due to being unable to install a package into lazarus. If I could do that, the webserver would only be a few lines of code within my lazarus program

Brian

RasPi 3, jessie, lazarus 1.7, fpc 3.0.0

Heater
Posts: 9822
Joined: Tue Jul 17, 2012 3:02 pm

Re: Web server for RasPi 3?

Wed Jan 03, 2018 10:24 am

I find the idea of creating a webserver in Pascal somewhat absurd.

Sounds like it would be easy enough to fetch that data from your serial ports and server up web pages containing said data.

Next step would be pushing updates to to the web page in real time using websockets. Or not-so-real-time by polling the server for updates.

All of this is much easier done in node.js.

iwbnwif
Posts: 7
Joined: Tue May 31, 2016 2:56 pm

Re: Web server for RasPi 3?

Wed Jan 03, 2018 3:50 pm

It might be worth taking a look at https://github.com/civetweb/civetweb.

I didn't use it recently, but before it was very lightweight and can be cross-compiled for ARM, but probably easier just to build it on your Pi.

Note: Seems to be okay, see here: viewtopic.php?f=33&t=107944

It should be reasonably straightforward to create HTML pages or a RESTful API to support your Android app.

BLL
Posts: 195
Joined: Fri Jun 07, 2013 2:30 pm

Re: Web server for RasPi 3?

Fri Jan 05, 2018 6:17 pm

Hi all
Thanks for the replies. Why would be creating the webserver in pascal be weird - my program is written in pascal!!! I am all for KISS!
Brian

stevend
Posts: 188
Joined: Fri Oct 11, 2013 12:28 pm

Re: Web server for RasPi 3?

Fri Jan 05, 2018 6:27 pm

BLL wrote:
Fri Jan 05, 2018 6:17 pm
Hi all
Thanks for the replies. Why would be creating the webserver in pascal be weird - my program is written in pascal!!! I am all for KISS!
Brian
Have you looked at the Indy offerings? IIRC they include a web server. (Or you could do direct comms using sockets - might even be easier!)
http://wiki.lazarus.freepascal.org/Indy_with_Lazarus
http://wiki.lazarus.freepascal.org/Curr ... n_projects
http://forum.lazarus.freepascal.org/ind ... 074.0.html
https://indy.fulgan.com/

The current version is 10.6.2 (SVN rev 5428 at the time of this writing), and is recommended over version 9

Heater
Posts: 9822
Joined: Tue Jul 17, 2012 3:02 pm

Re: Web server for RasPi 3?

Fri Jan 05, 2018 6:33 pm

I'm all for KISS as well.

When it comes to creating a cross-platform application that acts as web server whist at the same time juggling database connections, and other activities involving serial connections, GPIO and other interfaces, etc, etc, then I find Pascal is anything but the KISS solution.

mfa298
Posts: 1298
Joined: Tue Apr 22, 2014 11:18 am

Re: Web server for RasPi 3?

Fri Jan 05, 2018 6:58 pm

Heater wrote:
Fri Jan 05, 2018 6:33 pm
... then I find Pascal is anything but the KISS solution.
I think that really comes down to what you know, if your experienced in Pascal and have everything else already running then tacking on a web server might be a lot simpler then learning a new language and re-implimenting everything in that new language.

Heater
Posts: 9822
Joined: Tue Jul 17, 2012 3:02 pm

Re: Web server for RasPi 3?

Fri Jan 05, 2018 7:49 pm

I think that really comes down to what you know,...
Certainly "what you know" can save a lot of time and effort when it comes to getting things done than having to learn a whole new language and all it's infrastructure.

I certainly would not advise going to the lengths of rewriting a major piece of work just because some little feature is easier to add in some other language.

As it happens I'm quite familiar with Pascal and FPC. One of our companies major components is written in Pascal and from time to time I draw the short straw and have to add to it or tweak it some in way.

But, if you want a web server and a GUI in the browser you are going to need to learn Javascript. With that under your belt creating the web server itself in Javascript under node.js can be trivial.

If this is a major piece of Pascal I would consider leaving it mostly as it is. Create the web server in node.js and arrange to have them communicate. Probably over a socket.

BLL
Posts: 195
Joined: Fri Jun 07, 2013 2:30 pm

Re: Web server for RasPi 3?

Sat Jan 06, 2018 3:26 pm

Hi folks and thanks for more suggestions/comments.

I have no intention of re-writing my lazarus program in any other language. I had enough of a struggle getting to grips with pascal after 25 years of C++ and I have to say that I don't like it but lazarus gets the job done and similar to Borland CBuilder, which I used for years.

Javascript is not a problem so thast's probably the way to go, but I will also look an Indy.

Lots of studying to do!!

Thanks all

Brian

hippy
Posts: 3762
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Web server for RasPi 3?

Sat Jan 06, 2018 10:23 pm

BLL wrote:
Sat Jan 06, 2018 3:26 pm
I have no intention of re-writing my lazarus program in any other language.
Given what you want seems fairly simple, and you want to stick with Lazrus/Pascal, I would echo the suggestion of Gavinmc42 and take a look at Ultibo.

There is a Web Status HTTP server which can be added to any project in just a few lines.There's an equally simple example for serving pages from disk. Reading from and writing to serial ports is easy enough, UART and USB-to-serial (Prolific/FTDI) is supported.

It would seem everything you would likely need is already there though I have no idea how you would go about tying it all together.

BLL
Posts: 195
Joined: Fri Jun 07, 2013 2:30 pm

Re: Web server for RasPi 3?

Sun Jan 07, 2018 11:47 am

Hi
Thanks for the replies.

I have looked at Ultibo but I don't think it will allow me to run my lazarus written program which is absolutely essential.

It also seems very complicated!

Brian

User avatar
Gavinmc42
Posts: 2105
Joined: Wed Aug 28, 2013 3:31 am

Re: Web server for RasPi 3?

Sun Jan 07, 2018 12:48 pm

Are you doing any LCL stuff in your Laz code?
One thing with Ultibo is sometimes the Laz/FPC just compiles.
FPC is write once, compile everywhere, Ultibo is in that family.
Some libraries just work, some code just ports.

I spent 5+ years learning many other ways to do things on Pi's.
So learning Pascal(relearning TubrboPascal) was no big deal for me.
My coding skills are emergent but nothing is faster than Ultibo or smaller.
Well C baremetal maybe but it does not have the support that Ultibo now has.

If your code has all it's stuff in the green boxes then you have a good chance it will work
https://ultibo.org/wiki/Current_Status
Any red boxes, maybe next version :(

I think I have done modbus on Ultibo, it was a while back.
Whoops, no it was done in micropython, just before I started using Ultibo
http://forum.tinycorelinux.net/index.ph ... #msg124253
May revisit that project, i2c in Ultibo works much better.

Modbus in Ultibo could be useful. I did it in binary :o I ouch I remember that now.
https://ultibo.org/forum/viewtopic.php? ... dbus#p2659
Yep and thank goodness for forums and google, seems the only way for me to keep track these days.

I know I keep pushing Ultibo and sound like broken record, but for me an old 8bit microcontroller guy used to IDEs, it fits.
You coming from Laz/FPC are coming from the other direction.
Somewhere in that grey zone between Arduino and PC's/Linux is where Ultibo stands like a beacon, thumbing it's nose at Arduino and Linux :lol:
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

hippy
Posts: 3762
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Web server for RasPi 3?

Sun Jan 07, 2018 3:12 pm

BLL wrote:
Sun Jan 07, 2018 11:47 am
I have looked at Ultibo but I don't think it will allow me to run my lazarus written program which is absolutely essential.
I thought Lazarus was just an IDE for Pascal and Delphi code. I suppose it does depend on which units and libraries you are using if you have already created the code.

Perhaps the best thing to do is try it and see.
BLL wrote:
Sun Jan 07, 2018 11:47 am
It also seems very complicated!
I actually found it quite easy. It installed and just worked, gives an excellent, no tools set up, 'one-click' compilation process which turns Pascal source into a kernel.img which boots on the Pi, and rather quicker than Raspbian does.

My biggest problem is having not used Pascal for nearly four decades and finding out how to do things when interfacing with the Pi's and external hardware. I did however get an application which reads serial and uses the HDMI display as if a very large text LCD within just a couple of days of first using Ultibo.

Ultibo seems perfect for using the Pi as an Application Engine. I would have loved a Ultibo-like setup which could run full Python 2.7 or 3.x code from disk at boot-up - a 'mega MicroPython' - but, c'est la vie, that doesn't exist. It could be a lot of effort to create, and no one seems interested in creating that. So Ultibo and Pascal it is for me for the time being.

User avatar
Gavinmc42
Posts: 2105
Joined: Wed Aug 28, 2013 3:31 am

Re: Web server for RasPi 3?

Mon Jan 08, 2018 1:13 am

Unless you try you won't know and you have the advantage most of us don't, you already know Pascal.
Some if not most have to learn or relearn Pascal, it is much nicer than the old TP.
'mega MicroPython' - but, c'est la vie, that doesn't exist.
Yet ;)
I went looking for that too, the Pi micropython HAL does sort of exist as micropython comes with PiCore.
Probably use os.system calls or something like that, so pointless?.

However baremetal Pascal and C and Basic have been done, Python cannot be far behind?
A complete 2.7 or 3.x would be a big ask.
One thing I don't like about Python is the need for external libs like numpy etc.
That just comes with Pascal, multi dimension arrays etc.

Wonder if Pascalscript could be changed to be a python interpreter?
But I guess for web based stuff JS would be better.

hippy, did you use true type fonts for your big LCD?
Wonder if the Hardware Vector Scaler could just blowup normal fonts?
Internet clock displays etc.

I have found the biggest problem with Ultibo is it makes so many things now possible I will never find time to do them all :lol:
So many ideas so little time.
As a hardware designer I used to spend lots of time on software, with Ultibo it is now reversed.
Software that took weeks/months now take hours/days and I am still not a good coder.
Because I am just writing the application layer of code it is much quicker :D
And all the code lower down is written by better coders than me :ugeek:
Ultibo is RAD, Rapid Aided Development.
Now my stuff is Fast, Good and Cheap, it blows away the Iron triangle rule of pick two out of three.
Even cheaper if I could master the Zero W :lol:
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

hippy
Posts: 3762
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Web server for RasPi 3?

Mon Jan 08, 2018 2:19 am

Gavinmc42 wrote:
Mon Jan 08, 2018 1:13 am
'mega MicroPython' - but, c'est la vie, that doesn't exist.
Yet ;)
I went looking for that too, the Pi micropython HAL does sort of exist as micropython comes with PiCore.
I have been thinking long and hard on the best approach for turning a Pi into a Micro:Bit or PyBoard equivalent. MicroPython makes a lot of sense on a constrained device; having any Python is worth the limitations it brings. It makes less sense on a non-constrained device like the Pi where one wants 'full Python' to take advantage of everything the Pi has to offer. IMO anything less isn't really worth it.
Gavinmc42 wrote:
Mon Jan 08, 2018 1:13 am
hippy, did you use true type fonts for your big LCD?
No, just the default fonts. Bigger fonts, TT fonts, along with graphics, are things I have yet to investigate.

Return to “General discussion”

Who is online

Users browsing this forum: No registered users and 37 guests