This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088

Dependents:   MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more

libMiMic(MiMic library for mbed)は、WebService機能を提供するSDKです。 mbedでWebAPIに対応したネットワークデバイスを簡単に作ることが出来ます。

libMiMicはMiMic projectで開発しています。MiMic projectについてはこちらをご覧ください。 http://nyatla.jp/mimic/wp/

構成

libMiMicはmbedRTOS上で動作し、ユーザアプリケーションにAPIを提供します。コアAPIはC言語で記述されていますが、使用頻度の高いものについてはmbed向けのC++APIが準備されています。

/media/uploads/nyatla/libmimic-sdk.png

※libMiMicはmbedの標準イーサネットドライバをしようしていません。

標準イーサネットドライバと同時に使用することはできません。

  • MiMicIP - IPv4スタックです。レテンシとメモリ消費量を抑えたuipベースのライブラリです。
  • ARP/ICMP/UDP/TCP - 基礎的なソケットAPIを提供します。APIは独自です。
  • HTTP/1.1 Server - HTTP/1.1に対応したサーバです。マルチセッション・Chunked・持続性接続に対応しています。
  • HTTP Modules - HTTP/1.1の機能モジュールです。以下のモジュールがあります。
    • ROM file provider - ROMに格納したファイルイメージを公開します。
    • File system provider - mbedファイルシステムを公開します。
    • Onchip configuration - プログラムフラッシュを利用して設定を保存します。
    • MiMicVM processor - RPCリクエスト(MiMicVM)を処理します。
    • FileUpload - ファイルアップロードを受け取ります。
    • URL decoder - HTTPリクエストを解析します。
    • UPnP handler -UPnPメッセージを処理します。
    • WebSocket - Websocketサーバです。
  • mDNS - マルチキャストDNSサービスです。
  • UPnP - UPnP/1.0の機能を提供します。UPnP handlerと協調して動作します。(現在はデバイス探索(SSDP)・デスクリプション(Description)のみ実装してあります。)
  • DHCP/APIPA - ゼロコンフィギュレーション用のモジュールです。
  • HTTP/1.1 Client
  • mbed C++ class library - mbed向けのC++CPIです。C言語のものより簡単です。

対応機種

  • mbed(mbed LPC1768)
  • LPCXpresso1769

プログラム

Import programMiMicRemoteMCU-for-Mbed

MiMic RemoteMCU for mbed. This program provides MCU control API over REST API. It can control MCU from Javascript,PHP or any HTTP rest client directly. And, The application has self development environment.

Import programMbedFileServer

The program publishes files at local directory and SD filesystem. It is a full-fledged webServer somewhat.

サンプル

Import programMiMicSimpleHttpd

This is a simplest HTTP server made ​​of libMiMic. It will echo back a request path.

Import programUPnPBasicDevice

Simplest UPnP basic device example. This program to run UPnP basic device on the mbed.

Import programWebSocketSample

MiMicSDK Websocket module sample program.

Import programHttpClientSamlpe

A http client sample program.

Import programTcpSocketClientSamlpe

MiMicSDK Tcp client socket sample program.

Import programUdpSocketSamlpe

Udp socket sample program. This program will send back the received packet.

チュートリアル

English

libMiMic(MiMic library for mbed) is SDK which provides Webservice functions. It can be created networking device easily using mbed.

See more MiMic information, See MiMic project website. http://nyatla.jp/mimic/wp/

Structure

libMiMic run on mbed RTOS and provides networking API to user application. This library has C++ class API for the mbed, and low-level C language API.

/media/uploads/nyatla/libmimic-sdk.png

For WebService general, it can be written in a simple C + + API.

libMiMic does not have the standard Ethernet driver of mbed. It is not possible that will be used with the standard Ethernet driver.

  • MiMicIP - IPv4 protocol stack. This is based uip which is reduced memory and latency.
  • ARP / ICMP / UDP / TCP - Those are provide basic IP protocols.
  • HTTP/1.1 Server - The Http server compatible HTTP/1.1. It supports multi-session, chunked transport, persistent connection.
  • HTTP Modules - There are addon-module for HTTP server. The following modules.
    • ROM file module - Publish the file images in ROM.
    • File system module - Publish thefiles in mbed file system.
    • Onchip configuration module - To save the network settings to the program flash via REST.
    • MiMicVM module - To handle the (MiMicVM) RPC request.
    • FileUpload module - Accept a file via HTTP POST.
    • URL dedoce module - A versatility URL decoder.
    • UPnP handle module - To handle UPnP messages.
    • UPnP - This provides UPnP/1.0 device functions. It works together with UPnP handler.
    • Websocket - websocket (version13) server
  • mDNS Service - DNS-SD protocol server.
  • UPnP - This provides UPnP/1.0 device functions which works with UPnP handler. (You have been implemented (SSDP) ? description only (Description) device search now.) It is a module zero configuration for - DHCP / APIPA. mbed C + + class library - C of mbed for + + is the CPI. It is simple than that of the C language.
  • DHCP/APIPA - It support zero-cpnfigulation.
  • mbed C++ class library. Almost APIs for Web applications are available.
  • HTTP/1.1 Client

Supported target

  • mbed(mbed LPC1768)
  • LPCXpresso1769

Application

Import programMiMicRemoteMCU-for-Mbed

MiMic RemoteMCU for mbed. This program provides MCU control API over REST API. It can control MCU from Javascript,PHP or any HTTP rest client directly. And, The application has self development environment.

Import programMbedFileServer

The program publishes files at local directory and SD filesystem. It is a full-fledged webServer somewhat.

Sample

Import programMiMicSimpleHttpd

This is a simplest HTTP server made ​​of libMiMic. It will echo back a request path.

Import programUPnPBasicDevice

Simplest UPnP basic device example. This program to run UPnP basic device on the mbed.

Import programWebSocketSample

MiMicSDK Websocket module sample program.

Import programHttpClientSamlpe

A http client sample program.

Import programTcpSocketClientSamlpe

MiMicSDK Tcp client socket sample program.

Import programUdpSocketSamlpe

Udp socket sample program. This program will send back the received packet.

Tutorial

Committer:
nyatla
Date:
Sun Jun 30 14:17:42 2013 +0000
Revision:
41:2389bd6b6f74
Parent:
19:33b9ba0859ee
Child:
43:a182f2b5ff41
update core r270;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nyatla 5:6d67db3875cb 1 /*********************************************************************************
nyatla 5:6d67db3875cb 2 * PROJECT: MiMic
nyatla 5:6d67db3875cb 3 * --------------------------------------------------------------------------------
nyatla 5:6d67db3875cb 4 *
nyatla 5:6d67db3875cb 5 * This file is part of MiMic
nyatla 5:6d67db3875cb 6 * Copyright (C)2011 Ryo Iizuka
nyatla 5:6d67db3875cb 7 *
nyatla 5:6d67db3875cb 8 * MiMic is free software: you can redistribute it and/or modify
nyatla 5:6d67db3875cb 9 * it under the terms of the GNU Lesser General Public License as published
nyatla 5:6d67db3875cb 10 * by the Free Software Foundation, either version 3 of the License, or
nyatla 5:6d67db3875cb 11 * (at your option) any later version.
nyatla 5:6d67db3875cb 12 *
nyatla 5:6d67db3875cb 13 * This program is distributed in the hope that it will be useful,
nyatla 5:6d67db3875cb 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nyatla 5:6d67db3875cb 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
nyatla 5:6d67db3875cb 16 * GNU General Public License for more details.
nyatla 5:6d67db3875cb 17 *
nyatla 5:6d67db3875cb 18 * You should have received a copy of the GNU Lesser General Public License
nyatla 5:6d67db3875cb 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
nyatla 5:6d67db3875cb 20 *
nyatla 5:6d67db3875cb 21 * For further information please contact.
nyatla 5:6d67db3875cb 22 * http://nyatla.jp/
nyatla 5:6d67db3875cb 23 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
nyatla 5:6d67db3875cb 24 *
nyatla 5:6d67db3875cb 25 *********************************************************************************/
nyatla 5:6d67db3875cb 26 #include "NyLPC_cModUrl.h"
nyatla 5:6d67db3875cb 27 #include "NyLPC_stdlib.h"
nyatla 5:6d67db3875cb 28 #include "NyLPC_http.h"
nyatla 14:4618692ec239 29 #include "../NyLPC_cHttpdUtils.h"
nyatla 5:6d67db3875cb 30 #include "../NyLPC_cHttpdConnection_protected.h"
nyatla 5:6d67db3875cb 31
nyatla 5:6d67db3875cb 32 typedef struct TcHeaderParser
nyatla 5:6d67db3875cb 33 {
nyatla 5:6d67db3875cb 34 NyLPC_TcHttpBasicHeaderParser_t super;
nyatla 5:6d67db3875cb 35 char* url_buf;
nyatla 7:2b33a8d84eb3 36 NyLPC_TInt16 length_of_buf;
nyatla 7:2b33a8d84eb3 37 NyLPC_TInt16 length_of_url;
nyatla 19:33b9ba0859ee 38 NyLPC_TInt16 reason;
nyatla 19:33b9ba0859ee 39 NyLPC_TInt8 skip;
nyatla 19:33b9ba0859ee 40 NyLPC_TInt8 mode;
nyatla 5:6d67db3875cb 41 }TcHeaderParser_t;
nyatla 5:6d67db3875cb 42
nyatla 5:6d67db3875cb 43 static NyLPC_TBool NyLPC_cModUrl_messageHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,const NyLPC_TChar* i_name,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)
nyatla 5:6d67db3875cb 44 {
nyatla 5:6d67db3875cb 45 (void)i_inst;
nyatla 5:6d67db3875cb 46 (void)i_name;
nyatla 5:6d67db3875cb 47 (void)i_c;
nyatla 5:6d67db3875cb 48 return NyLPC_TBool_TRUE;
nyatla 5:6d67db3875cb 49 }
nyatla 19:33b9ba0859ee 50
nyatla 5:6d67db3875cb 51 static NyLPC_TBool NyLPC_cModUrl_urlHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)
nyatla 5:6d67db3875cb 52 {
nyatla 5:6d67db3875cb 53 TcHeaderParser_t* inst=(TcHeaderParser_t*)i_inst;
nyatla 19:33b9ba0859ee 54 if(inst->skip){
nyatla 19:33b9ba0859ee 55 //SKIPが有効な場合
nyatla 19:33b9ba0859ee 56 if(inst->length_of_url<0){
nyatla 19:33b9ba0859ee 57 inst->length_of_url++;
nyatla 19:33b9ba0859ee 58 if(inst->length_of_url==0){
nyatla 19:33b9ba0859ee 59 inst->skip=NyLPC_TUInt8_FALSE;
nyatla 19:33b9ba0859ee 60 }
nyatla 19:33b9ba0859ee 61 }
nyatla 7:2b33a8d84eb3 62 return NyLPC_TBool_TRUE;
nyatla 7:2b33a8d84eb3 63 }
nyatla 19:33b9ba0859ee 64 if((inst->mode & NyLPC_cModUrl_ParseMode_PATH_ONLY)==NyLPC_cModUrl_ParseMode_PATH_ONLY){
nyatla 19:33b9ba0859ee 65 if(strchr("?#",i_c)){
nyatla 19:33b9ba0859ee 66 inst->url_buf[inst->length_of_url]='\0';
nyatla 19:33b9ba0859ee 67 inst->skip=NyLPC_TUInt8_TRUE;
nyatla 19:33b9ba0859ee 68 return NyLPC_TBool_TRUE;//Terminate
nyatla 19:33b9ba0859ee 69 }
nyatla 19:33b9ba0859ee 70 }
nyatla 5:6d67db3875cb 71 inst->url_buf[inst->length_of_url]=i_c;
nyatla 5:6d67db3875cb 72 if(i_c=='\0'){
nyatla 5:6d67db3875cb 73 return NyLPC_TBool_TRUE;//Terminate
nyatla 5:6d67db3875cb 74 }
nyatla 19:33b9ba0859ee 75 inst->length_of_url++;
nyatla 5:6d67db3875cb 76 if(inst->length_of_url==inst->length_of_buf){
nyatla 19:33b9ba0859ee 77 inst->reason=414;
nyatla 5:6d67db3875cb 78 return NyLPC_TBool_FALSE;//長すぎる。
nyatla 5:6d67db3875cb 79 }
nyatla 19:33b9ba0859ee 80
nyatla 5:6d67db3875cb 81 return NyLPC_TBool_TRUE;
nyatla 5:6d67db3875cb 82 }
nyatla 5:6d67db3875cb 83 /**
nyatla 5:6d67db3875cb 84 * デフォルトハンドラ
nyatla 5:6d67db3875cb 85 */
nyatla 5:6d67db3875cb 86 static const struct NyLPC_TcHttpBasicHeaderParser_Handler _handler=
nyatla 5:6d67db3875cb 87 {
nyatla 5:6d67db3875cb 88 NyLPC_cModUrl_messageHandler,
nyatla 5:6d67db3875cb 89 NyLPC_cModUrl_urlHandler
nyatla 5:6d67db3875cb 90 };
nyatla 5:6d67db3875cb 91
nyatla 5:6d67db3875cb 92
nyatla 5:6d67db3875cb 93
nyatla 5:6d67db3875cb 94 void NyLPC_cModUrl_initialize(NyLPC_TcModUrl_t* i_inst)
nyatla 5:6d67db3875cb 95 {
nyatla 41:2389bd6b6f74 96 NyLPC_cHttpBodyParser_initialize(&i_inst->_body_parser);
nyatla 5:6d67db3875cb 97 }
nyatla 5:6d67db3875cb 98 void NyLPC_cModUrl_finalize(NyLPC_TcModUrl_t* i_inst)
nyatla 5:6d67db3875cb 99 {
nyatla 41:2389bd6b6f74 100 NyLPC_cHttpBodyParser_finalize(&i_inst->_body_parser);
nyatla 5:6d67db3875cb 101 }
nyatla 5:6d67db3875cb 102
nyatla 5:6d67db3875cb 103 const struct NyLPC_THttpBasicHeader* NyLPC_cModUrl_getHeader(const NyLPC_TcModUrl_t* i_inst)
nyatla 5:6d67db3875cb 104 {
nyatla 5:6d67db3875cb 105 return &(i_inst->_header);
nyatla 5:6d67db3875cb 106 }
nyatla 5:6d67db3875cb 107
nyatla 5:6d67db3875cb 108 /**
nyatla 5:6d67db3875cb 109 * Methodタイプを返します。
nyatla 5:6d67db3875cb 110 */
nyatla 5:6d67db3875cb 111 NyLPC_THttpMethodType NyLPC_cModUrl_getMethod(const NyLPC_TcModUrl_t* i_inst)
nyatla 5:6d67db3875cb 112 {
nyatla 5:6d67db3875cb 113 return i_inst->_header.startline.req.method;
nyatla 5:6d67db3875cb 114 }
nyatla 5:6d67db3875cb 115
nyatla 5:6d67db3875cb 116
nyatla 5:6d67db3875cb 117
nyatla 19:33b9ba0859ee 118 NyLPC_TBool NyLPC_cModUrl_execute2(NyLPC_TcModUrl_t* i_inst,NyLPC_TcHttpdConnection_t* i_connection,char* o_url_buf,NyLPC_TInt16 i_length_buf,NyLPC_TInt16 i_pass_prefix_len,NyLPC_cModUrl_ParseMode i_mode)
nyatla 5:6d67db3875cb 119 {
nyatla 5:6d67db3875cb 120 TcHeaderParser_t parser;
nyatla 7:2b33a8d84eb3 121 NyLPC_Assert(i_length_buf>0);
nyatla 7:2b33a8d84eb3 122 NyLPC_Assert(i_pass_prefix_len>=0);
nyatla 19:33b9ba0859ee 123 //コネクションのステータスチェック
nyatla 5:6d67db3875cb 124 if(!NyLPC_cHttpdConnection_getReqStatus(i_connection)==NyLPC_cHttpdConnection_ReqStatus_REQPARSE)
nyatla 5:6d67db3875cb 125 {
nyatla 5:6d67db3875cb 126 NyLPC_OnErrorGoto(Error1);
nyatla 5:6d67db3875cb 127 }
nyatla 5:6d67db3875cb 128 //リクエストParse済へ遷移
nyatla 5:6d67db3875cb 129 NyLPC_cHttpdConnection_setReqStatusParsed(i_connection);
nyatla 5:6d67db3875cb 130
nyatla 5:6d67db3875cb 131 NyLPC_cHttpBasicHeaderParser_initialize(&parser.super,&_handler);
nyatla 5:6d67db3875cb 132 parser.length_of_buf=i_length_buf;
nyatla 7:2b33a8d84eb3 133 parser.length_of_url=-i_pass_prefix_len;//無視するPrefix長
nyatla 19:33b9ba0859ee 134 parser.skip=(parser.length_of_url<0)?NyLPC_TUInt8_TRUE:NyLPC_TUInt8_FALSE;//スキップの初期値の設定
nyatla 5:6d67db3875cb 135 parser.url_buf=o_url_buf;
nyatla 7:2b33a8d84eb3 136 parser.url_buf[0]='0';//URL長<=prefix長に備えてNULLターミネイト
nyatla 19:33b9ba0859ee 137 parser.reason=400;
nyatla 19:33b9ba0859ee 138 parser.mode=i_mode;
nyatla 5:6d67db3875cb 139 //プリフェッチしたデータを流す
nyatla 5:6d67db3875cb 140 NyLPC_cHttpBasicHeaderParser_parseInit(&parser.super,&(i_inst->_header));
nyatla 5:6d67db3875cb 141 NyLPC_cHttpdConnection_pushPrefetchInfo(i_connection,&parser.super,&(i_inst->_header));
nyatla 5:6d67db3875cb 142 //後続をストリームから取り込む
nyatla 5:6d67db3875cb 143 if(!NyLPC_cHttpBasicHeaderParser_parseStream(&parser.super,NyLPC_cHttpdConnection_refStream(i_connection),&(i_inst->_header))){
nyatla 5:6d67db3875cb 144 NyLPC_OnErrorGoto(Error2);
nyatla 5:6d67db3875cb 145 }
nyatla 5:6d67db3875cb 146 if(!NyLPC_cHttpBasicHeaderParser_parseFinish(&parser.super,&(i_inst->_header))){
nyatla 5:6d67db3875cb 147 NyLPC_OnErrorGoto(Error2);
nyatla 5:6d67db3875cb 148 }
nyatla 41:2389bd6b6f74 149 if(i_inst->_header.startline.req.version==NyLPC_THttpVersion_11){
nyatla 41:2389bd6b6f74 150 //Connection Modeの設定 1.1 && !closeの場合はCONTINUE
nyatla 41:2389bd6b6f74 151 if(i_inst->_header.connection!=NyLPC_THttpMessgeHeader_Connection_CLOSE)
nyatla 41:2389bd6b6f74 152 {
nyatla 41:2389bd6b6f74 153 NyLPC_cHttpdConnection_setConnectionMode(i_connection,NyLPC_TcHttpdConnection_CONNECTION_MODE_CONTINUE);
nyatla 41:2389bd6b6f74 154 }
nyatla 41:2389bd6b6f74 155 //@todo http/1.1 && POSTの場合はcontinueを送る。
nyatla 41:2389bd6b6f74 156 if(i_inst->_header.startline.req.method==NyLPC_THttpMethodType_POST)
nyatla 41:2389bd6b6f74 157 {
nyatla 41:2389bd6b6f74 158 NyLPC_cHttpdConnection_send100Continue(i_connection);
nyatla 41:2389bd6b6f74 159 }
nyatla 5:6d67db3875cb 160 }
nyatla 5:6d67db3875cb 161 NyLPC_cHttpBasicHeaderParser_finalize(&parser);
nyatla 41:2389bd6b6f74 162 //BodyParserの初期化
nyatla 41:2389bd6b6f74 163 if(NyLPC_cHttpBodyParser_getState(&i_inst->_body_parser)!=NyLPC_TcHttpBasicBodyParser_ST_NULL){
nyatla 41:2389bd6b6f74 164 NyLPC_cHttpBodyParser_parseFinish(&i_inst->_body_parser);
nyatla 41:2389bd6b6f74 165 }
nyatla 41:2389bd6b6f74 166 NyLPC_cHttpBodyParser_parseInit(&i_inst->_body_parser,&i_inst->_header);
nyatla 5:6d67db3875cb 167 return NyLPC_TBool_TRUE;
nyatla 5:6d67db3875cb 168 Error2:
nyatla 5:6d67db3875cb 169 //400Error
nyatla 19:33b9ba0859ee 170 NyLPC_cHttpdUtils_sendErrorResponse(i_connection,parser.reason);
nyatla 5:6d67db3875cb 171 NyLPC_cHttpBasicHeaderParser_finalize(&parser);
nyatla 5:6d67db3875cb 172 Error1:
nyatla 5:6d67db3875cb 173 return NyLPC_TBool_FALSE;
nyatla 5:6d67db3875cb 174 }
nyatla 5:6d67db3875cb 175
nyatla 5:6d67db3875cb 176
nyatla 5:6d67db3875cb 177
nyatla 41:2389bd6b6f74 178
nyatla 41:2389bd6b6f74 179
nyatla 41:2389bd6b6f74 180 NyLPC_TInt16 NyLPC_cModUrl_readBody(NyLPC_TcModUrl_t* i_inst,NyLPC_TcHttpdConnection_t* i_connection,void* i_buf,NyLPC_TInt16 i_buf_size)
nyatla 41:2389bd6b6f74 181 {
nyatla 41:2389bd6b6f74 182 NyLPC_TInt16 l;
nyatla 41:2389bd6b6f74 183 //リクエストは解析済であること
nyatla 41:2389bd6b6f74 184 if(!NyLPC_cHttpdConnection_getReqStatus(i_connection)==NyLPC_cHttpdConnection_ReqStatus_END)
nyatla 41:2389bd6b6f74 185 {
nyatla 41:2389bd6b6f74 186 return -1;
nyatla 41:2389bd6b6f74 187 }
nyatla 41:2389bd6b6f74 188 if(!NyLPC_cHttpBodyParser_parseStream(&i_inst->_body_parser,NyLPC_cHttpdConnection_refStream(i_connection),i_buf,i_buf_size,&l)){
nyatla 41:2389bd6b6f74 189 return -1;
nyatla 41:2389bd6b6f74 190 }
nyatla 41:2389bd6b6f74 191 return l;
nyatla 41:2389bd6b6f74 192 }
nyatla 41:2389bd6b6f74 193