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

core/net/httpcl/NyLPC_cHttpClient.h

Committer:
nyatla
Date:
2013-09-27
Revision:
58:03b89038b21a
Parent:
57:bc4330dfa62f
Child:
109:18f12ac01097

File content as of revision 58:03b89038b21a:

/*
 * NyLPC_cHttpClient.h
 *
 *  Created on: 2013/08/24
 *      Author: nyatla
 */

#ifndef NYLPC_CHTTPCLIENT_H_
#define NYLPC_CHTTPCLIENT_H_

#include "NyLPC_stdlib.h"
#include "NyLPC_net.h"
#include "NyLPC_http.h"
#include "NyLPC_uipService.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

typedef struct NyLPC_TcHttpClient NyLPC_TcHttpClient_t;

#define NyLPC_cHttpHeaderWriter_CONTENT_LENGTH_UNLIMITED 0xffffffff
struct NyLPC_TcHttpClient
{
	NyLPC_TUInt8 _state;
	NyLPC_TUInt8 _padding1;
	NyLPC_TcTcpSocket_t _sock;
	NyLPC_TcHttpStream_t _stream;
	union{
		NyLPC_TcHttpHeaderWriter_t head_writer;
		NyLPC_TcHttpBodyWriter_t body_writer;
		NyLPC_TcHttpBasicHeaderParser_t head_parser;
		NyLPC_TcHttpBodyParser_t body_parser;
	}pw;
};


void NyLPC_cHttpClient_initialize(NyLPC_TcHttpClient_t* i_inst,void* i_rx_buf,NyLPC_TUInt16 i_rx_size);

void NyLPC_cHttpClient_finalize(NyLPC_TcHttpClient_t* i_inst);

/**
 * サーバとの接続を切断する。
 * ステータスはCLOSEDになる。
 */
void NyLPC_cHttpClient_close(NyLPC_TcHttpClient_t* i_inst);


/**
 * サーバに接続する。
 * 関数はステータスをIDLEへ遷移する。
 * インスタンスのステータスは何でも構わない。
 * @return
 * TRUE - ステータスはIDLEへ遷移する。
 * FALSE - ステータスはCLOSEDへ遷移する。
 */
NyLPC_TBool NyLPC_cHttpClient_connect(NyLPC_TcHttpClient_t* i_inst,const struct NyLPC_TIPv4Addr* i_addr,NyLPC_TUInt16 i_port);



/**
 * POSTリクエストを送信する。
 * ステータスはIDLEである必要がある。
 * @param i_content_length
 * 送信bodyのサイズ。最大 0xfffffffe
 * NyLPC_cHttpHeaderWriter_CONTENT_LENGTH_UNLIMITEDの場合はChunked転送になる。
 * @return
 * 引き続き処理が可能かを返す。
 * TRUE - 成功。ステータスはSEND_REQ_BODYになる。write/getStatusを呼び出せる。
 * FALSE - 失敗。ステータスはCLOSEDになる。
 */
NyLPC_TBool NyLPC_cHttpClient_sendMethod(
	NyLPC_TcHttpClient_t* i_inst,
	NyLPC_THttpMethodType i_method,
	const NyLPC_TChar* i_path,
	NyLPC_TUInt32 i_content_length,
	const NyLPC_TChar* i_mime_type,
	const NyLPC_TChar* i_additional_header);


/**
 * POSTリクエストのデータを送信する。
 * ステータスはSEND_REQ_BODYである必要がある。
 * @return
 * TRUE - 成功。
 * FALSE - 失敗。ステータスはCLOSEDになる。
 */
NyLPC_TBool NyLPC_cHttpClient_write(NyLPC_TcHttpClient_t* i_inst,const void* i_buf,NyLPC_TUInt32 i_buf_size);

/**
 * 書式文字列としてPOSTリクエストのデータを送信する。
 * ステータスはSEND_REQ_BODYである必要がある。
 * @param i_fmt
 * printfライクなフォーマット文字列
 * @return
 * TRUE - 成功。
 * FALSE - 失敗。ステータスはCLOSEDになる。
 */
NyLPC_TBool NyLPC_cHttpClient_writeFormat(NyLPC_TcHttpClient_t* i_inst,const NyLPC_TChar* i_fmt,...);
NyLPC_TBool NyLPC_cHttpClient_writeFormatV(NyLPC_TcHttpClient_t* i_inst,const NyLPC_TChar* i_fmt,va_list i_args);

/**
 * ステータスコードを返す。
 * ステータスはSEND_REQ_BODYである必要がある。
 * @return
 * 0 - 失敗。ステータスはCLOSEDになる。
 * その他 - ステータスコード。ステータスはRECV_RES_BODYになる。
 */
NyLPC_TUInt16 NyLPC_cHttpClient_getStatus(NyLPC_TcHttpClient_t* i_inst);


/**
 * GET/POSTリクエストで受信したデータを読み出す。
 * ステータスはRECV_RES_BODYである必要がある。
 * @param o_read_len
 * 戻り値TRUEの場合のみ有効。データ終端に達した場合は0になる。
 * @return
 * TRUE:正常読み出し。o_read_lenの値で終端判定
 * FALSE:失敗。コネクションはクローズされる。
 */
NyLPC_TBool NyLPC_cHttpClient_read(NyLPC_TcHttpClient_t* i_inst,void* i_buf,NyLPC_TUInt32 i_buf_size,NyLPC_TInt16* o_read_len);






#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* NYLPC_CHTTPCLIENT_H_ */