Embedded Linux project Development (i)--web data interaction __oracle

Source: Internet
Author: User
Tags echo message sqlite sqlite database
Embedded Linux project development (i)--web data interaction

This article explains how to configure personal information through a data interactive Web page on a ported boa, cgic, sqlite embedded Web server, and the CGI program saves the configured information to the SQLite database. First, the embedded Web server working principle

The Server Software (BOA) always waits for a client's connection request on the HTTP port, and after the client initiates a connection request to the server, the client and the server establish a "three-step handshake" connection. After receiving the HTTP request message from the client, the server resolves the message, including: Reading the request URL, mapping to the corresponding physical file, separating the client request from the static page or the CGI application, and so on. If the client requests a static file, then the server reads the appropriate disk file and returns it to the client as an entity in the HTTP response message, and if the client requests a CGI application, the server creates the corresponding CGI application process and brings the various required information (client request information, Server-side related information, etc.) is passed to the CGI application process by the CGI specification, which is then taken over by the CGI application.

The CGI application reads the various information passed from the Web server, and the client's request interpretation and processing, such as the use of SQL statements to retrieve or update the database, or will be obtained from the client data, in accordance with the monitoring of the object defined by the communication protocol reset frame, from the UART port to be monitored objects. The final CGI application will return the processing results to the Web server in accordance with the CGI specification, and the Web server will parse the results of the CGI application and generate HTTP response information back to the client on this basis.

The function of the embedded Web server is to let the client use the browser to send the HTTP request to the server, the server responds to the client's request, and directs to the specified script program, resolves the command, and gives the information to the backstage--cgi to deal with. After the CGI resolves the information, it emits control information to the remote device. When the device responds, it returns to the CGI control information, the CGI then parses the information into a variable output to the Web server, and finally the client gets the page message (HTML) sent back by the webserver, can get the operation status of the field equipment, and realizes the remote monitoring of the field equipment.

The main features of the BOA server are shown in the following illustration:


The server consists mainly of Boa and CGI, where Boa manages the return of the client's Web page, while CGI controls the exchange of information between the client and the server, so we can write the corresponding CGI program to achieve the required functionality. The implementation of BOA server is mainly divided into two steps, Boa Server porting and CGI program design.

CGI program writing consists of two parts: HTML code and C code, and the CGI program communicates with the BOA Web server through environment variables, command-line parameters, and standard input. In general, form coding information is passed through environment variable query_string. When writing a CGI program, you need to be aware

A, Request_method

There are two types of request methods: Get and post.

<form Method=get action=/cgi-bin/config.cgi>

B, Environment variables

When choosing different methods, the corresponding environment variables are also different. When you select Get, the corresponding environment variable is query_string, by calling the library function getenv () to obtain the specific value of the environment variable, that is, querystring=getenv (query_string). The system function frame is as follows:

This article mainly uses the form to realize the personal information submission, through the CGI program processing will store the information data to the SQLite database, the other camera information collection and the GPRS module because does not have the related hardware equipment, does not realize in this article.

HTML Data Interactive Web design


Config.html:

<!doctype html> 
third, CGI programming 

Returns the configuration information received to the client browser while writing the configuration information to the SQLite database.

CONFIG.C Source:

#include  <stdio.h>    #include  <string.h>    #include   <unistd.h>    #include  <fcntl.h>    #include  <sys/stat.h >    #include  <stdlib.h> #include   "cgic.h"   #include   "Sqlite3.h"   #define  sql_size 256 int cgimain (INT&NBSP;ARGC,&NBSP;CHAR&NBSP;**ARGV) {char  name[64];char age[4];char sex[8];char company[64];char profession[16];char idnumber[ 24];char qq[24];char email[64];char telephone[16];//echo message to HTML page cgiheadercontenttype ("text/html" );  printf (" 

Note: The program needs to use the Cgic library interface functions, SQLite database interface functions, so compile-time need to include related files sqlite3.c, CGIC.C, you need to sqlite the dynamic link library support for the database, so you need to copy the files in the Lib directory of the compiled SQLite database to the Lib directory of the Cross compilation tool and specify-lsqlite3 at compile time.

Compiling program: Arm-linux-gcc-o config.cgi config.c sqlite3.c cgic.c-lsqlite3

Copy the compiled config.cgi program to the Cgi-bin directory under the WWW directory of the Development Board

Open client Browser: http://192.168.6.210/config.html

Enter the configuration information and the submission will display the content information for the configuration

To view the contents of a database:

Sqlite> select * from person;

1234567899876543| |30|boy| | |123455678|hello@qq.com|123344

Sqlite>


At this point, on the embedded Web server built by Boa, the simple project that was stored to the SQLite database was completed using Cgic to process the information submitted by the HTML Web page form. This project is just a simple introduction to the entire process and is an entry-level project. If you have actual project requirements, you need more detailed knowledge of learning.


This article comes from "Life is endless, struggle more than" blog, reprint please contact the author.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.