20151229_jeffrey - silenceuncrio/diary GitHub Wiki
- 0840 - IoT Platform - Control Box - Message Tx Handler
- 0940 - IoT Platform - Control Center - Message Tx Handler
- 0955 - IoT Platform - Control Center - Message Tx Handler - Makefile 修正前
- 1055 - IoT Platform - Control Center - Message Tx Handler - Makefile 修正後
- 1100 - IoT Platform - Control Center - Message Tx Handler - libcurl
- 1125 - IoT Platform - Control Center - newwifi mini - MT7620A 580MHz - 16MB Flash
- 1305 - 筆電 - 擴充記憶體
- 1340 - IoT Platform - Control Center - Message Tx Handler - libcurl - small example snippets
- 1525 - IoT Platform - Control Center - newwifi mini - OpenWrt JXcore Package Creation
- 1650 - IoT Platform - Control Center - newwifi mini - OpenWrt JXcore 效能測試
- 1740 - IoT Platform - Control Center - Message Tx Handler - 準備公司電腦環境
- 1810 - IoT Platform - Control Center - Message Tx Handler - curltest.c
簡單佈置一下自己的環境
就去工讀生的位置實作 HTTP GET/POST
參考 Wireshark capture
順便將自己電腦 node.js 的 hello.js 在 8888 port 開起來
搞定... 哈哈
atcmd_wifi.c
log_item_t at_wifi_items[ ] = {
...
{"ATWX", fATWX,}, // RESTful TX Test
...
};
tcptest.c
void cmd_restful_tx() {
struct sockaddr_in sAddr;
int iAddrSize;
int iSockFD;
int iStatus;
char *content =
"GET /cgi-bin/cgi_test HTTP/1.1\r\n"
"Host: brook.box\r\n"
"\r\n"
;
short content_len = strlen(content);
printf("\n\rcmd_restful_tx()");
FD_ZERO(&sAddr);
sAddr.sin_family = AF_INET;
sAddr.sin_port = htons(8888);
sAddr.sin_addr.s_addr = inet_addr("192.168.0.113");
iAddrSize = sizeof(struct sockaddr_in);
// creating a TCP socket
iSockFD = socket(AF_INET, SOCK_STREAM, 0);
if( iSockFD < 0 ) {
printf("\n\rTCP ERROR: create tcp client socket fd error!");
goto Exit;
}
printf("\n\rTCP: ServerIP=%s port=%d.", "192.168.0.113", 8888);
printf("\n\rTCP: Create socket %d.", iSockFD);
// connecting to TCP server
iStatus = connect(iSockFD, (struct sockaddr *)&sAddr, iAddrSize);
if (iStatus < 0) {
printf("\n\rTCP ERROR: tcp client connect server error! ");
goto Exit;
}
printf("\n\rTCP: Connect server successfully.");
// sending RESTful HTTP to the Control Center
iStatus = send(iSockFD, content, content_len, 0 );
if( iStatus <= 0 ) {
printf("\r\nTCP ERROR: tcp client send data error! iStatus:%d", iStatus);
goto Exit;
}
printf("\n\rControl Box: Sent RESTful HTTP successfully.");
Exit:
close(iSockFD);
return;
}
POST 的部分就讓工讀生禮拜四再去發揮吧
來做 Tx Handler
- JS9331 - HTTP Client - curl - TX Handler
- 公司電腦 - HTTP Server - Node.js - RX Handler
參考 2015-12-16 1345 FastCGI - 總結要告知 mips-openwrt-linux-gcc 那些事
修正昨天的 Makefile
cgi_test02: cgi_test02.c
mips-openwrt-linux-uclibc-gcc \
-I~/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/include/ \
-L~/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib/ \
-I/home/jeffrey/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/include/ \
-L/home/jeffrey/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib/ \
-lm -ldl -lpthread -lfcgi -ljson-c \
-o cgi_test02 cgi_test02.c cgihtml-1.69/cgihtml.a
cgi_test01: cgi_test01.c
mips-openwrt-linux-uclibc-gcc \
-I~/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/include/ \
-L~/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib/ \
-I/home/jeffrey/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/include/ \
-L/home/jeffrey/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib/ \
-lm -ldl -lpthread -lfcgi -ljson-c \
-o cgi_test01 cgi_test01.c
fcgi_test01: fcgi_test01.c
mips-openwrt-linux-uclibc-gcc \
-I~/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/include/ \
-L~/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib/ \
-I/home/jeffrey/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/include/ \
-L/home/jeffrey/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib/ \
-lm -ldl -lpthread -lfcgi -ljson-c \
-o fcgi_test01 fcgi_test01.c
fcgi_test: fcgi_test.c
mips-openwrt-linux-uclibc-gcc \
-I~/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/include/ \
-L~/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib/ \
-I/home/jeffrey/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/include/ \
-L/home/jeffrey/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib/ \
-lm -ldl -lpthread -lfcgi -ljson-c \
-o fcgi_test fcgi_test.c
修正後
CROSS_COMPILE = mips-openwrt-linux-uclibc-
CC = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
CC_I = -I/home/jeffrey/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/include/
CC_I += -I/home/jeffrey/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/include/
CC_L = -L/home/jeffrey/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib/
CC_L += -L/home/jeffrey/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib
LIBS = -lm -ldl -lpthread -lfcgi -ljson-c
cgi_test02: cgi_test02.c
$(CC) $(CC_I) $(CC_L) $(LIBS) -o $@ $< cgihtml-1.69/cgihtml.a
cgi_test01: cgi_test01.c
$(CC) $(CC_I) $(CC_L) $(LIBS) -o $@ $<
fcgi_test01: fcgi_test01.c
$(CC) $(CC_I) $(CC_L) $(LIBS) -o $@ $<
fcgi_test: fcgi_test.c
$(CC) $(CC_I) $(CC_L) $(LIBS) -o $@ $<
找到 libcurl
在 ~/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib
jeffrey@jeffrey-virtual-machine:~/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib$ ls
...
libcurl.a libjson_script.so libubox.so
libcurl.so libjson.so libubus.so
libcurl.so.4 libjson.so.0 libucimap.a
libcurl.so.4.3.0 libjson.so.0.1.0 libuci.so
...
相關的 header 在 ~/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/include/curl
jeffrey@jeffrey-virtual-machine:~/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/include/curl$ ls
curlbuild.h curlrules.h easy.h multi.h typecheck-gcc.h
curl.h curlver.h mprintf.h stdcheaders.h
官網有一堆範例 libcurl - small example snippets
看來可以偷玩一下 newifi mini
參考 2015-12-07 0940 jammy 給我上禮拜跟他一起買的 newifi mini
筆電的記憶體到貨囉 - Kingston 8GB DDR3 1600筆記型記憶體 給筆電用
4 + 8 = 12
參考 libcurl - small example snippets
參考 2015-12-26 0825 - OpenWrt JXcore - Package Creation
目前已經成功參考 OpenWrt JXcore Package Creation
build 出 package jxcore_0.3.0.3_ramips_24kec.ipk
該文件再來談到
You should find the packages below and download them on your computer.
libpthread...
librt..
libstdcpp..
Once you have all the
ipk
files, copy all of them to your device. In order to install aipk
package;
opkg install <ipk file>
You are expected to install all three packages before installing
jxcore
package.
準備一下材料
- libpthread_0.9.33.2-1_ramips_24kec.ipk
- librt_0.9.33.2-1_ramips_24kec.ipk
- libstdcpp_4.8-linaro-1_ramips_24kec.ipk
上傳這四個 ipk 到 newifi mini 上然後安裝
root@OpenWrt:/tmp# opkg install libpthread_0.9.33.2-1_ramips_24kec.ipk
Installing libpthread (0.9.33.2-1) to root...
Configuring libpthread.
root@OpenWrt:/tmp# opkg install librt_0.9.33.2-1_ramips_24kec.ipk
Installing librt (0.9.33.2-1) to root...
Configuring librt.
root@OpenWrt:/tmp# opkg install libstdcpp_4.8-linaro-1_ramips_24kec.ipk
Installing libstdcpp (4.8-linaro-1) to root...
Configuring libstdcpp.
root@OpenWrt:/tmp# opkg install jxcore_0.3.0.3_ramips_24kec.ipk
Installing jxcore (0.3.0.3) to root...
Configuring jxcore.
裝好了... then?
放一隻 hello.js
在 /tmp
下
root@OpenWrt:/tmp# cat hello.js
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
console.log("someone request");
response.end();
}).listen(8888);
console.log("Node.js running...")
跑吧... jx
root@OpenWrt:/tmp# jx hello.js
Node.js running...
眼淚快掉下來了
JXcore 的發展值得注意
以下是 JMeter Lan 端的測試結果
- newifi mini - JXcore - JMeter - lan_100_10_40_noLoading
取代傳統的 CGI 綽綽有餘
新增資料夾 D:\ubuntu_share\js9331_tx_handler
準備使用 curl
這邊有 curl 和 json-c 合體技... 帥