[[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

Gateworks

Gateworks M2M Demo


GSC Values:


Property Value
Vin
Processor Temperature
}}} == Troubleshooting == To see if the server is listening on a port, use the netstat command: {{{ root@OpenWrt:/www1# netstat -a Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:www 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:domain 0.0.0.0:* LISTEN tcp 0 0 :::domain :::* LISTEN tcp 0 0 :::ssh :::* LISTEN tcp 0 0 :::telnet :::* LISTEN tcp 0 0 ::ffff:192.168.1.73:telnet ::ffff:192.168.1.22:38861 ESTABLISHED udp 0 0 0.0.0.0:domain 0.0.0.0:* udp 0 0 192.168.1.73:ntp 0.0.0.0:* udp 0 0 localhost:ntp 0.0.0.0:* udp 0 0 0.0.0.0:ntp 0.0.0.0:* udp 0 0 :::domain :::* udp 0 0 ::1:ntp :::* udp 0 0 fe80::2d0:12ff:fe9b:ede0:ntp :::* udp 0 0 :::ntp :::* Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node Path unix 2 [ ] DGRAM 1314 /var/run/hostapd-phy0/wlan0 unix 8 [ ] DGRAM 254 /dev/log unix 2 [ ] DGRAM 1966 unix 2 [ ] DGRAM 1912 unix 2 [ ] DGRAM 1907 unix 2 [ ] DGRAM 1729 unix 2 [ ] DGRAM 1397 unix 2 [ ] DGRAM 305 }}} Verify the process is running with the ps command: {{{ root@OpenWrt:/www1# ps -aef | grep light 2541 root 2680 S /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf 2557 root 1140 S grep light root@OpenWrt:/www1# }}}