源碼下載
goahead源碼 |
git clone http://github.com/embedthis/goahead |
|
Makeme源碼 |
git clone https://github.com/embedthis/makeme.git |
交叉編譯(使用Makeme)
Makeme安裝
- make boot
- sudo make install
goahead交叉編譯
- CC=/xxxx/bin/mipsel-linux-gcc CFLAGS=-I/xxxx/include LDFLAGS=-L/xxxx/lib ./configure --platform linux-mips --without ssl
- me
action模塊測試
定義action方法
static void myactiontest(Webs *wp)
{
char *name = websGetVar(wp, "name", "");
char *age = websGetVar(wp, "age", "");
char writedata[128];
int length = 0;
if(strlen(name)<1 || strlen(age)<1)
{
length = snprintf(writedata, sizeof(writedata), "name or age is NULL, please check !!!");
}
else
{
length = snprintf(writedata, sizeof(writedata), "name = %s, age = %s", name, age);
}
websSetStatus(wp, 200);
websWriteHeaders(wp, length, 0);
websWriteEndHeaders(wp);
websWrite(wp, writedata);
websDone(wp);
}
註冊action方法
websDefineAction("actiontest", myactiontest);
測試action方法
<form action="action/actiontest" method="get">
<input type="text" name="name" placeholder="姓名"/>
<input type="text" name="age" placeholder="年齡"/>
<input type="submit" name="" id="" value="goActions" />
</form>
JST模塊測試
定義JST方法
extern int outputmytable(int ejid, Webs *wp, int argc, char **argv)
{
websWrite(wp, "<tr>");
websWrite(wp, "<td>CH340</td>");
websWrite(wp, "<td>115200</td>");
websWrite(wp, "<td>8</td>");
websWrite(wp, "<td>1</td>");
websWrite(wp, "<td>0</td>");
websWrite(wp, "</tr>");
}
註冊JST方法
websDefineJst("outputmytable", outputmytable);
測試JST方法
<table border="1" cellpadding="5" cellspacing="0" id="mytable">
<caption style="font-weight: bold;">串口狀態</caption>
<tr>
<th width="20%">線路協議</th>
<th width="20%">波特率</th>
<th width="20%">數據位</th>
<th width="20%">起始位</th>
<th width="20%">停止位</th>
</tr>
<%outputmytable();%>
</table>
配置文件:route.txt
route uri=/cgi-bin dir=cgi-bin handler=cgi //cgi方法請求的路徑
route uri=/action handler=action //action方法
route uri=/ extensions=jst,asp,html handler=jst //可以使用jst方法頁面的聲明
route uri=/ methods=OPTIONS|TRACE handler=options
# For legacy GoAhead applications using /goform
route uri=/goform handler=action
運行
編譯完成後在 build/linux-mips-debug/bin 目錄產生可執行文件和鏈接庫,將 src 目錄下的 auth.txt 、route.txt 和 web 拷貝到該目錄,交叉編譯情況下將這些文件拷貝到板子上即可
sudo ./goahead -v --home PATH1 PATH2
-v : 打開運行日誌
--home : 指定運行目錄, 第一個參數 PATH1 是配置文件的所在目錄 第二個參數 PATH2 是web頁面所在目錄