Looking for some help creating or modifying web server
New Omega2 user, with some limited Linux/Unix experience so far.
I'm trying to start simple, just adding a bit of html code to the OnionOS index page.
Goal is to create a browser-accessible server (local WIFi networks access only), later adding server-side code to accept user button inputs and drive GPIO output pins. Probably also read input pins and display status.
The code the stock server returns when accessing Onion OmegaOS is rather simple; too simple, maybe:
var newUrl = window.location.href + 'OnionOS';
window.location = newUrl;
OK, that appends OnioOS to the URL and opens the new page, which has the exact same code!
(from browser ctrl-U, Show Source)
Where do I go from here?
@dbell Take a look at
These are the webcam app and Sparkfun QWIIC App respectively for OnionOS, you can see how to integrate your page.
If you don't need to integrate with OnionOS (most of us don't) you just place your web pages in a new directory and then reconfigure the webserver to serve those pages instead.
Suppose your files are in /var/mysite you can reconfigure the webserver to point to those pages by using these command in the command prompt:
uci set uhttpd.main.home='/var/mysite'
uci commit uhttpd
service uhttpd restart
Now try opening your browser to the Omega again and you should see your pages.
Thank you very much for the links and the pointers to how to link my pages!
I'll try this out today.
One question about modifying the site location.
Is there a variable I can query, to know the current location, so I can reset it?
@dbell As a general rule configuration files are kept in /etc/config in the case of the webserver (uhttpd) the configuration file is /etc/config/uhttpd
The uci commands I gave you above is the correct way to modify configuration files so it's a good idea to familiarise yourself with the uci command. In this case you want to see the current site location you could use the following command:
uci show uhttpd
This will list the configuration file contents, as you can see from my earlier email, we can then use uci to change the home configuration parameter. You must remember to commit your changes, which seems a bit redundant but if you are making multiple changes to this config, or you may be making multiple changes multiple configuration files, so you can commit them all at once in case you have dependencies.
Again, thanks for the help! WRT UCI makes sense.
Here's a maybe-dumb question:
Commonly, a URL for a Web server might address one of multiple landing pages
http:\foo.com/bar or foo.com/bat, etc.
The URL I'm using to connect to the Omega is Omega-Axxx.local/OnionOS
UCI set would point the server to /mysite, or wherever.
In that directory, could I then have multiple HTML/PHP files, preferably having index.html, at least, and other pages as well?
Or would it have to be (or better practice) putting each page set into its own directory under /mysite/ ?
If I read it correctly, that's what Onion did for the OnionOS landing page...
@dbell uhttpd is just a lightweight web server so your decision process here is no different to setting up any other web server.
You can see the docs here:
I use PHP for my IoT device administration, I also have 2 separate "sites" configured, each listening on a different port, and each site uses a structured file layout in order to organise site resources.
OnionOS is a great tool to get new users up and running quickly with limited knowledge. Once you get your head around the setup and use of OpenWrt, you realise it is just a minimistic version of Linux.
@crispyoz Thanks for all of that. The docs link was indeed helpful.
I realize Omega uses a stripped-down Linux distro, but it's been donkey's years since I did any real work in Unix or even Linux , and never any Web development under them.
Now, off to learn more PHP... I can see it's superior for IoT, which is where I'm headed!