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:
Sat Jun 04 06:51:04 2016 +0000
Revision:
114:f6aef16d4e60
Parent:
43:a182f2b5ff41
include????????; ???????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nyatla 42:f83aa17dcae5 1 #include <ModFileIo.h>
nyatla 42:f83aa17dcae5 2 #include <stdio.h>
nyatla 42:f83aa17dcae5 3 #include "mbed.h"
nyatla 42:f83aa17dcae5 4 using namespace MiMic;
nyatla 42:f83aa17dcae5 5 /*
nyatla 42:f83aa17dcae5 6 * FileIO class
nyatla 42:f83aa17dcae5 7 */
nyatla 42:f83aa17dcae5 8 typedef struct TcModFileIoDumy
nyatla 42:f83aa17dcae5 9 {
nyatla 42:f83aa17dcae5 10 NyLPC_TcModFileIoBaseClass_t super;
nyatla 42:f83aa17dcae5 11 }TcFileIoDumy_t;
nyatla 42:f83aa17dcae5 12
nyatla 42:f83aa17dcae5 13 const static char* STR_TEXT_HTML="text/html";
nyatla 42:f83aa17dcae5 14 #define SIZE_OF_FBUF 256
nyatla 42:f83aa17dcae5 15
nyatla 42:f83aa17dcae5 16
nyatla 42:f83aa17dcae5 17
nyatla 42:f83aa17dcae5 18 static NyLPC_TBool upload_handler(NyLPC_TcHttpdConnection_t* i_connection,const NyLPC_TChar* i_fname,NyLPC_TcHttpBodyParser_t* i_body_parser)
nyatla 42:f83aa17dcae5 19 {
nyatla 42:f83aa17dcae5 20 char* buf=Httpd::_shared_buf;// This handler called with lock!
nyatla 42:f83aa17dcae5 21
nyatla 42:f83aa17dcae5 22 //save to new file
nyatla 42:f83aa17dcae5 23 FILE *fp;
nyatla 42:f83aa17dcae5 24 fp = fopen(i_fname, "w");
nyatla 42:f83aa17dcae5 25 if(fp==NULL){
nyatla 43:a182f2b5ff41 26 NyLPC_cHttpdUtils_sendErrorResponse(i_connection,500);
nyatla 42:f83aa17dcae5 27 return NyLPC_TBool_FALSE;
nyatla 42:f83aa17dcae5 28 }
nyatla 42:f83aa17dcae5 29 NyLPC_TInt16 l;
nyatla 42:f83aa17dcae5 30 if(NyLPC_cHttpBodyParser_parseStream(i_body_parser,NyLPC_cHttpdConnection_refStream(i_connection),buf,SIZE_OF_FBUF,&l)){
nyatla 42:f83aa17dcae5 31 while(l>0){
nyatla 42:f83aa17dcae5 32 fwrite(buf,1,l,fp);
nyatla 42:f83aa17dcae5 33 if(!NyLPC_cHttpBodyParser_parseStream(i_body_parser,NyLPC_cHttpdConnection_refStream(i_connection),buf,SIZE_OF_FBUF,&l)){
nyatla 42:f83aa17dcae5 34 NyLPC_OnErrorGoto(Error_FILE);
nyatla 42:f83aa17dcae5 35 }
nyatla 42:f83aa17dcae5 36 }
nyatla 42:f83aa17dcae5 37 }
nyatla 42:f83aa17dcae5 38 fclose(fp);
nyatla 42:f83aa17dcae5 39 //write response
nyatla 42:f83aa17dcae5 40 NyLPC_cHttpdConnection_sendResponseHeader2(i_connection,200,STR_TEXT_HTML,0,NULL);
nyatla 42:f83aa17dcae5 41 return NyLPC_TBool_TRUE;
nyatla 42:f83aa17dcae5 42 Error_FILE:
nyatla 42:f83aa17dcae5 43 fclose(fp);
nyatla 43:a182f2b5ff41 44 NyLPC_cHttpdUtils_sendErrorResponse(i_connection,500);
nyatla 42:f83aa17dcae5 45 return NyLPC_TBool_FALSE;
nyatla 42:f83aa17dcae5 46 }
nyatla 42:f83aa17dcae5 47
nyatla 42:f83aa17dcae5 48 static NyLPC_TBool create_handler(NyLPC_TcHttpdConnection_t* i_connection,const NyLPC_TChar* i_fname)
nyatla 42:f83aa17dcae5 49 {
nyatla 42:f83aa17dcae5 50 FILE *fp;
nyatla 42:f83aa17dcae5 51 fp = fopen(i_fname, "w");
nyatla 42:f83aa17dcae5 52 if(fp!=NULL){
nyatla 42:f83aa17dcae5 53 fclose(fp);
nyatla 42:f83aa17dcae5 54 NyLPC_cHttpdConnection_sendResponseHeader2(i_connection,200,STR_TEXT_HTML,0,NULL);
nyatla 42:f83aa17dcae5 55 return NyLPC_TBool_TRUE;
nyatla 42:f83aa17dcae5 56 }
nyatla 43:a182f2b5ff41 57 NyLPC_cHttpdUtils_sendErrorResponse(i_connection,500);
nyatla 42:f83aa17dcae5 58 return NyLPC_TBool_FALSE;
nyatla 42:f83aa17dcae5 59 }
nyatla 42:f83aa17dcae5 60
nyatla 42:f83aa17dcae5 61 static NyLPC_TBool remove_handler(NyLPC_TcHttpdConnection_t* i_connection,const NyLPC_TChar* i_fname)
nyatla 42:f83aa17dcae5 62 {
nyatla 42:f83aa17dcae5 63 if(remove(i_fname)==0){
nyatla 42:f83aa17dcae5 64 NyLPC_cHttpdConnection_sendResponseHeader2(i_connection,200,STR_TEXT_HTML,0,NULL);
nyatla 42:f83aa17dcae5 65 return NyLPC_TBool_TRUE;
nyatla 42:f83aa17dcae5 66 }
nyatla 42:f83aa17dcae5 67 //500ERROR
nyatla 43:a182f2b5ff41 68 NyLPC_cHttpdUtils_sendErrorResponse(i_connection,500);
nyatla 42:f83aa17dcae5 69 return NyLPC_TBool_FALSE;
nyatla 42:f83aa17dcae5 70 }
nyatla 42:f83aa17dcae5 71
nyatla 42:f83aa17dcae5 72
nyatla 42:f83aa17dcae5 73
nyatla 42:f83aa17dcae5 74 static void cModFileIoDumy_initialize(TcFileIoDumy_t* i_inst,const char* i_root_path)
nyatla 42:f83aa17dcae5 75 {
nyatla 42:f83aa17dcae5 76 NyLPC_cModFileIoBaseClass_initialize(&(i_inst->super),i_root_path);
nyatla 42:f83aa17dcae5 77 i_inst->super._abstruct_function.upload=upload_handler;
nyatla 42:f83aa17dcae5 78 i_inst->super._abstruct_function.create=create_handler;
nyatla 42:f83aa17dcae5 79 i_inst->super._abstruct_function.remove=remove_handler;
nyatla 42:f83aa17dcae5 80 }
nyatla 42:f83aa17dcae5 81 #define cModFileIoDumy_finalize(i_inst) NyLPC_cModFileIoBaseClass_finalize(&(i_inst)->super)
nyatla 42:f83aa17dcae5 82 #define cModFileIoDumy_canHandle(i_inst,i_connection) NyLPC_cModFileIoBaseClass_canHandle(&(i_inst)->super,i_connection)
nyatla 42:f83aa17dcae5 83 #define cModFileIoDumy_execute(i_inst,i_connection) NyLPC_cModFileIoBaseClass_execute(&(i_inst)->super,i_connection)
nyatla 42:f83aa17dcae5 84
nyatla 42:f83aa17dcae5 85
nyatla 42:f83aa17dcae5 86
nyatla 42:f83aa17dcae5 87
nyatla 42:f83aa17dcae5 88
nyatla 42:f83aa17dcae5 89
nyatla 42:f83aa17dcae5 90
nyatla 42:f83aa17dcae5 91 namespace MiMic
nyatla 42:f83aa17dcae5 92 {
nyatla 42:f83aa17dcae5 93
nyatla 42:f83aa17dcae5 94
nyatla 42:f83aa17dcae5 95 ModFileIo::ModFileIo(const char* i_path):ModBaseClass(i_path)
nyatla 42:f83aa17dcae5 96 {
nyatla 42:f83aa17dcae5 97 }
nyatla 42:f83aa17dcae5 98 ModFileIo::ModFileIo()
nyatla 42:f83aa17dcae5 99 {
nyatla 42:f83aa17dcae5 100 }
nyatla 42:f83aa17dcae5 101 ModFileIo::~ModFileIo()
nyatla 42:f83aa17dcae5 102 {
nyatla 42:f83aa17dcae5 103 }
nyatla 42:f83aa17dcae5 104 void ModFileIo::setParam(const char* i_path)
nyatla 42:f83aa17dcae5 105 {
nyatla 42:f83aa17dcae5 106 ModBaseClass::setParam(i_path);
nyatla 42:f83aa17dcae5 107 }
nyatla 42:f83aa17dcae5 108 bool ModFileIo::execute(HttpdConnection& i_connection)
nyatla 42:f83aa17dcae5 109 {
nyatla 42:f83aa17dcae5 110 //check parametor
nyatla 42:f83aa17dcae5 111 if(this->_path==NULL){
nyatla 42:f83aa17dcae5 112 return false;
nyatla 42:f83aa17dcae5 113 }
nyatla 42:f83aa17dcae5 114 TcModFileIoDumy mod;
nyatla 42:f83aa17dcae5 115 cModFileIoDumy_initialize(&mod,this->_path);
nyatla 42:f83aa17dcae5 116 if(cModFileIoDumy_canHandle(&mod,i_connection._ref_inst)){
nyatla 42:f83aa17dcae5 117 cModFileIoDumy_execute(&mod,i_connection._ref_inst);
nyatla 42:f83aa17dcae5 118 cModFileIoDumy_finalize(&mod);
nyatla 42:f83aa17dcae5 119 return true;
nyatla 42:f83aa17dcae5 120 }
nyatla 42:f83aa17dcae5 121 cModFileIoDumy_finalize(&mod);
nyatla 42:f83aa17dcae5 122 return false;
nyatla 42:f83aa17dcae5 123 }
nyatla 42:f83aa17dcae5 124
nyatla 42:f83aa17dcae5 125
nyatla 42:f83aa17dcae5 126
nyatla 42:f83aa17dcae5 127
nyatla 42:f83aa17dcae5 128 }