[[PageOutline]] = Adding a Webserver To OpenWrt = Gateworks provides an OpenWrt board support package. By default, the LUCI admin has a default webserver uhttpd running on port 80 However, if one wants to add their own webserver for hosting custom content (with even CGI scripts...), it is best to install and configure one's own. OpenWrt makes it easy to add and install packages. For this project, we chose the webserver [http://www.lighttpd.net/ lighthttpd]. On this page we will show how to install the webserver lighthttpd and CGI-mod if desired, configure it, create an HTML file and create a CGI script. References: * http://wiki.openwrt.org/doc/howto/http.lighttpd == Basic Configuration == Please get familiar with building the OpenWrt BSP located [wiki:OpenWrt/building here] Please also be familiar with using the make menuconfig command discussed in [wiki:Configuration OpenWrt Configuration] 1. In the make menuconfig turn on libprce (lighthttpd depends on it) 2. Turn on lighthttpd (Network -> Webservers -> !LightHttpd) 3. Turn on lighthttpd-mod-cgi (If CGI is desired) (Network -> Webservers -> !LightHttpd -> lighthttpd-mod-cgi) 4. Exit and save 5. From the trunk directory, compile with the command: make -j8 V=99 && make package/index 6. Find the IPK files located in the /trunk/bin/cns3xxx/packages/ directory 7. Install via IPK method as discussed here: [wiki:ipkupload] 8. Configure the webserver on the Gateworks board by editing /etc/lighttpd/lighttpd.conf and making the following changes: * '''server.document-root = "/www1/"''' where www1 is the root directory of the web server. Then create the www1 directory * '''server.port=8000''' where 8000 is the port you want your webserver on '''(This is very important as by default the LUCI Web Admin is running on port 80. If you want to use port 80, you must re-configure LUCI to use something different)''' 9. Create a simple index.html file in the www1 directory (example down towards bottom of this page) 10. Start the lighthttpd server with the command {{{ /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf }}} 11. Access the server at an address like so: http://192.168.1.1:8000/index.html [[Image(m2mdemolighthttpd.png, 300px)]] == Common Gateway Interface (CG) == If a Common Gateway Interface (CGI) is desired, it can be configured. Modify the lighthttpd config file as noted above and make sure these lines are in the file: {{{ server.modules = ( "mod_cgi" ) }}} {{{ #### CGI module cgi.assign = ( ".pl" => "/usr/bin/perl", ".cgi" => "/usr/bin/perl", ".sh" => "" ) }}} Once configured, write a script to access the desired function and an appropriate index.html === CGI Script === Here is a script that reads the voltage on a Laguna board: (Find more commands on the GSC page [wiki:gsc]) {{{ root@OpenWrt:/www1# cat voltage.sh #!/bin/sh CAT=/bin/cat header() { echo Content-type: text/html echo "" } getvalue() { val="$(cat /sys/class/hwmon/hwmon0/device/in0_input)" let "vin = val/1000" echo -e "$vin" } footer() { echo "" } header case "$REQUEST_METHOD" in GET) getvalue;; esac footer }}} === Index html file === Here is a sample index.html file that is used in the above image. Note the library jquery is used for the javascript ajax calls to the cgi scripts: {{{ root@OpenWrt:/www1# cat index.html
Property | Value |
---|---|
Vin | |
Processor Temperature |