Boa Application-Web Configuration A40i Development Board

1. Brief description

This article focuses on the A40i Boa application, applicable to the Forlinx A40i series FETA40i-C core board Linux 3.10 operating system, other platforms can also be referenced, but there will be differences between different platforms, customers need to modify to adapt to their own use. The main purpose of writing this article is to assist customers to speed up the development of products, due to the limited level of small compilation, in the course of the service to provide any information and information, are for reference only, customers have the right not to use or self-reference modification, reference materials and information in this article integrity, reliability and other issues please verify.

Introduction to the hardware platform:

The FETA40i-C core board is based on Allwinner industry platform-level processor quad-core Cortex-A7 A40i design, main frequency 1.2GHz, integrated MAli400MP2 GPU, memory 1GB/2GB DDR3L, storage 8GB eMMC. Supports most of the current popular video and image format decoding, with stable and reliable industrial-grade product performance and cost-effective low power consumption and other advantages, equipped with Linux and Android operating system, suitable for visual interaction-based industrial control products, target applications include embedded devices, smart terminals, industrial control, data acquisition, machine vision, industrial IOT, mobile Internet of Things devices, digital signage and so on.


A40i SoM

A40i SoM data


Chapter 2 A40i Series Boa Application

Boa is a very small Web server with only about 60KB of executable code. As a single-task Web server, Boa can only complete user requests in turn, rather than fork out new processes to handle concurrent connection requests. But Boa supports CGI and is able to execute a process for CGI program fork, which boa is designed to be speed and safety.

1, Boa profile

Boa profile at/etc/boa/boa.conf

A40i Series Boa Application


Common configuration instructions:

(The following configurations can be added to the configuration file as required by the project)
Group nogroup
User nobody

These two configurations are the master and host groups that configure the operation of the boa, and if cgi wants to configure the network card address, it must be modified to User root

A40i Series Boa Application


CGIPath /bin:/usr/bin:/usr/local/bin:/sbin

A program that runs a program search path;
The /sbin path must be configured;
/usr/lib/cgi-bin/ is the absolute address placed by the cgi program in the.cgi boa, /cgi-bin/ is the cgi address submitted by the customer on the web page; Use the /cgi-bin/app .cgi when visiting a web page? type-conf-random-0.1111
DocumentRoot /var/www
This is the real directory of the virtual directory in the board
/var/log/boa/access_log
The folder and name required for the log
VerboseCGILogs
Debug the log switch and turn it off when it is officially running.

2, cgi application test demo

CGI is the specification of external programs when the Web server is running, and programs written by CGI can extend the function of the server. CGI applications can interact with browsers and communicate with external data sources such as database servers through database APIs to obtain data from database servers. Once formatted as an HTML document, it is sent to the browser, or the data obtained from the browser can be placed in the database.

2.1 Configure the server

Run #boa first

Then the computer browser browses http://192.168.0.232/

Normal browsing does not report errors, indicating that boa runs ok.

Place boa/boa.conf on the A40i board/etc/boa/boa.conf to replace the original boa.conf

2.2 Placer

cgi-bin internal files are placed in
/usr/lib/cgi-bin/app.cgi
index.html ,xmlhttpreq.js
Put it under /var/www/ajax/folder


Place the files inside cgi-bin
/usr/lib/cgi-bin/app.cgi
index.html ,xmlhttpreq.js
Put it in the /var/www/ajax/ folder
Modify permissions /etc/boa/boa.conf
chown root:root /var/www/ajax/*
chown root:root /usr/lib/cgi-bin/app.cgi
chmod o+x /usr/lib/cgi-bin/app.cgi
chmod o+r /usr/lib/cgi-bin/app.cgi

2.3 Open boa test

Run #boa first

Then the computer browser browses http://192.168.0.232/ajax/

2.4 Development and debugging code description

When the configuration file VerboseCGILogs is opened, the debugging information will generate access_log error_log

After the formal debugging of the program is completed, the program should be closed. You need to look at these two log files when debugging the program.

Web page

<script language="JavaScript" src="xmlhttpreq.js"></script> describes the script that the xmlhttpreq.js program runs
<p><input type="button" value="Get time" onclick="sender()" /> </p> The get time function calls sender().
<p><input type="button" value="Set ip address" onclick="configip()" />
</p> The function to configure ip calls configip() function to configure ip request;

Special note: index.html and xmlhttpreq.js program scripts are downloaded and executed in the local browser; cgi is not downloaded to the local browser and executed.

Js application

Asynchronously returned time request

xhr.open("GET", "/cgi-bin/app.cgi?type=time&random="+Math.random(),true);

It sends a request to the remote app.cgi, and returns to the web browser after the request gets the time.

When the remote boa returns the correct data.

var returnValue = xhr.responseText; is the result returned
Asynchronously set ip request
//Configure ip address
var data={"name":"ipconfig"};
//ip_address
var str_ip=document.getElementById("ip_address").value;
data.address=str_ip;
xhr.onreadystatechange=callback_configipFunction;
//test.cgi is followed by a cur_time parameter to prevent Ajax page caching
xhr.open("POST", "/cgi-bin/app.cgi?type=conf&random="+Math.random(),true);
xhr.setRequestHeader("content-type","application/json");
xhr.send(JSON.stringify(data));

Send an asynchronous json object to app.cgi

The content of the object is {"name":"ipconfig", "address" :"192.168.0.232"}

The server retrieves this string, and then interprets this string for configuration IP

After the configuration is successful, you will receive {"status":"ok"} return result.

Cgi program description

Program segment 1
item = cJSON_GetObjectItem(root, "address");//
value=cJSON_Print(item);
if(value!=0)
{
sprintf(str_configip,"ifconfig eth0 %s",value);
ret=system(str_configip);
}
Program segment 2
if(ret==0)
{
char* retstr="{\"status\":\"ok\"}";
printf("%s",retstr);
}else{
char* retstr="{\"status\":\"error\"}";
printf("%s",retstr);
}

Program 1 explains the json configuration network.

Program segment 2 returns the configuration execution result.

Through this demo, customers can configure various hardware resources of the A40i development board through the web page.