Dynamic HTTP Server

A few illustrated reminds about simple static http server.
For complete explanations, please have a look at : https://web.enib.fr/~harrouet


Getting server script results in a web browser client

REM : think about making the CGI file executable (chmod +x).

code_cgi.zip

dynamic_http_server_1.svg

dynamic_http_server_2.svg

dynamic_http_server_3.svg

httpServer_dyn_1.c
Le fichier iot/linux-server-programming/dynamic-http-server/code_cgi/httpServer_dyn_1.c n'a pas été trouvé à l'emplacement spécifié.
# RPI Terminal

./exec_httpServer_dyn_1 5555
new HTTP connection from 192.168.0.1:40256
GET /script.cgi HTTP/1.1
Host: 192.168.0.2:5555
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1

Application : Controlling RPI Led from the web browser

code_led.zip

Configuring GPIO4 LED

image_rotation.jpg

Here we are in the RPI Terminal.
The following lines should be written in a bash script and recorded in /etc/profile.d to be executed on RPI startup.

$ echo 4 > /sys/class/gpio/export				# create the GPIO4 folder
$ echo out > /sys/class/gpio/gpio4/direction 	# make direction out for led

Once config done, try :

$ echo 1 > /sys/class/gpio/gpio4/value		# switch the LED on
$ echo 0 > /sys/class/gpio/gpio4/value		# switch the LED off

Control GPIO4 with CGI script

browser1_1.svg

browser1_2.svg

browser1_3.svg

The executed script is a bash one ; another example can be done with a lua script ( in www/cgi )

control_led.html - control_gpio4.sh
Le fichier iot/linux-server-programming/dynamic-http-server/code_led/www/control_led.html n'a pas été trouvé à l'emplacement spécifié.
Le fichier iot/linux-server-programming/dynamic-http-server/code_led/www/cgi/control_gpio4.sh n'a pas été trouvé à l'emplacement spécifié.

Control GPIO4 led with AJAX

Previously we were obliged to download the whole page.
The ajax-way permits to refresh only a part of this page after a client request.

browser2.svg

control_led_ajax.html - ajax_gpio4.sh
Le fichier iot/linux-server-programming/dynamic-http-server/code_led/www/control_led_ajax.html n'a pas été trouvé à l'emplacement spécifié.
Le fichier iot/linux-server-programming/dynamic-http-server/code_led/www/cgi/ajax_gpio4.sh n'a pas été trouvé à l'emplacement spécifié.