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:
Thu Oct 02 05:21:58 2014 +0000
Revision:
93:6afc7c06037f
Parent:
92:4f77028cce64
???????????K64????????????????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nyatla 92:4f77028cce64 1 #include "NyLPC_config.h"
nyatla 92:4f77028cce64 2 #if NyLPC_MCU==NyLPC_MCU_K64F
nyatla 92:4f77028cce64 3 #include "NyLPC_stdlib.h"
nyatla 92:4f77028cce64 4 #include "NyLPC_flash.h"
nyatla 92:4f77028cce64 5 #include "NyLPC_http.h"
nyatla 92:4f77028cce64 6 #include "NyLPC_net.h"
nyatla 92:4f77028cce64 7 #include "K64F_IAP.h"
nyatla 92:4f77028cce64 8 #ifdef __cplusplus
nyatla 92:4f77028cce64 9 extern "C" {
nyatla 92:4f77028cce64 10 #endif /* __cplusplus */
nyatla 92:4f77028cce64 11 /**
nyatla 92:4f77028cce64 12 * Onchip flashを使ったコンフィギュレーション保存システムです。
nyatla 92:4f77028cce64 13 * K64Fの0x0080000に構造体NyLPC_TMiMicConfigulationを保存します。
nyatla 92:4f77028cce64 14 */
nyatla 92:4f77028cce64 15
nyatla 92:4f77028cce64 16
nyatla 92:4f77028cce64 17
nyatla 92:4f77028cce64 18
nyatla 92:4f77028cce64 19 #define IP2Int(a0,a1,a2,a3) ((0xff000000&(((NyLPC_TUInt32)(a0))<<24))|(0x00ff0000&(((NyLPC_TUInt32)(a1))<<16))|(0x0000ff00&(((NyLPC_TUInt32)(a2))<<8))|(0x000000ff&(((NyLPC_TUInt32)(a3)))))
nyatla 92:4f77028cce64 20 /**
nyatla 92:4f77028cce64 21 * コンフィギュレーションの保存セクタ
nyatla 92:4f77028cce64 22 */
nyatla 92:4f77028cce64 23 #define MIMIC_CONFIGLATION_FLASH_ADDR ((void*)0x00080000)
nyatla 92:4f77028cce64 24
nyatla 92:4f77028cce64 25 /**
nyatla 92:4f77028cce64 26 * コンフィギュレーション値はホストオーダーで保存する。
nyatla 92:4f77028cce64 27 */
nyatla 92:4f77028cce64 28 const struct NyLPC_TMiMicConfigulation factory_default=
nyatla 92:4f77028cce64 29 {
nyatla 92:4f77028cce64 30 0xffffffff, //fastboot
nyatla 92:4f77028cce64 31 "MiMic020102030405",
nyatla 92:4f77028cce64 32 0x02010203,0x0405ffff, //Mac addr
nyatla 92:4f77028cce64 33 //IPv4
nyatla 92:4f77028cce64 34 NyLPC_TcNetConfig_IPV4_FLAG_MODE_MANUAL, //flags
nyatla 92:4f77028cce64 35 IP2Int(192,168,0,39),
nyatla 92:4f77028cce64 36 IP2Int(255,255,255,0),
nyatla 92:4f77028cce64 37 IP2Int(192,168,0,254),
nyatla 92:4f77028cce64 38 //ServerFlags
nyatla 92:4f77028cce64 39 NyLPC_TcNetConfig_SERVICE_FLAG_MDNS|NyLPC_TcNetConfig_SERVICE_FLAG_UPNP,
nyatla 92:4f77028cce64 40 //HTTP
nyatla 92:4f77028cce64 41 80, //HTTP-Port
nyatla 92:4f77028cce64 42 0 //padding
nyatla 92:4f77028cce64 43 };
nyatla 92:4f77028cce64 44
nyatla 92:4f77028cce64 45
nyatla 92:4f77028cce64 46 #define FAST_BOOT_DATA 0xfffffffe
nyatla 92:4f77028cce64 47 /**
nyatla 92:4f77028cce64 48 * ユーザコンフィギュレーションを更新する。
nyatla 92:4f77028cce64 49 * この関数をコールするときは、割込/FreeRTOSを一時停止すること。
nyatla 92:4f77028cce64 50 */
nyatla 92:4f77028cce64 51 NyLPC_TBool NyLPC_cMiMicConfiglation_updateConfigulation(const struct NyLPC_TMiMicConfigulation* i_congfiglation)
nyatla 92:4f77028cce64 52 {
nyatla 92:4f77028cce64 53 struct NyLPC_TMiMicConfigulation d;
nyatla 92:4f77028cce64 54 d.fast_boot=FAST_BOOT_DATA;
nyatla 92:4f77028cce64 55 memcpy(d.hostname,i_congfiglation->hostname,NyLPC_TcNetConfig_HOSTNAME_LEN);
nyatla 92:4f77028cce64 56 d.mac_00_01_02_03=i_congfiglation->mac_00_01_02_03;
nyatla 92:4f77028cce64 57 d.mac_04_05_xx_xx=i_congfiglation->mac_04_05_xx_xx;
nyatla 92:4f77028cce64 58 d.ipv4_flags=i_congfiglation->ipv4_flags;
nyatla 92:4f77028cce64 59 d.ipv4_addr_net=i_congfiglation->ipv4_addr_net;
nyatla 93:6afc7c06037f 60 d.ipv4_mask_net=i_congfiglation->ipv4_mask_net;
nyatla 93:6afc7c06037f 61 d.ipv4_drut_net=i_congfiglation->ipv4_drut_net;
nyatla 92:4f77028cce64 62 d.srv_flags=i_congfiglation->srv_flags;
nyatla 92:4f77028cce64 63 d.http_port=i_congfiglation->http_port;
nyatla 92:4f77028cce64 64 d.padding32=0xffff;
nyatla 92:4f77028cce64 65 d.padding64=0xffffffff;
nyatla 92:4f77028cce64 66
nyatla 92:4f77028cce64 67
nyatla 92:4f77028cce64 68 if(K64F_IAP_erase_sector((int)MIMIC_CONFIGLATION_FLASH_ADDR)!=K64F_IAP_TIAPCode_Success){
nyatla 92:4f77028cce64 69 NyLPC_OnErrorGoto(Error);
nyatla 92:4f77028cce64 70 }
nyatla 92:4f77028cce64 71 if(K64F_IAP_program_flash((int)MIMIC_CONFIGLATION_FLASH_ADDR,(char*)(&d), sizeof(struct NyLPC_TMiMicConfigulation))!=K64F_IAP_TIAPCode_Success){
nyatla 92:4f77028cce64 72 NyLPC_OnErrorGoto(Error);
nyatla 92:4f77028cce64 73 }
nyatla 92:4f77028cce64 74 return NyLPC_TBool_TRUE;
nyatla 92:4f77028cce64 75 Error:
nyatla 92:4f77028cce64 76 return NyLPC_TBool_FALSE;
nyatla 92:4f77028cce64 77 }
nyatla 92:4f77028cce64 78 /**
nyatla 92:4f77028cce64 79 * コンフィギュレーション値を返す。
nyatla 92:4f77028cce64 80 */
nyatla 92:4f77028cce64 81 const struct NyLPC_TMiMicConfigulation* NyLPC_cMiMicConfiglation_loadFromFlash(void)
nyatla 92:4f77028cce64 82 {
nyatla 92:4f77028cce64 83 if(NyLPC_cMiMicConfiglation_hasUserConfigulation()){
nyatla 92:4f77028cce64 84 //userコンフィギュレーション読むよ
nyatla 92:4f77028cce64 85 return (const struct NyLPC_TMiMicConfigulation*)(MIMIC_CONFIGLATION_FLASH_ADDR);
nyatla 92:4f77028cce64 86 }else{
nyatla 92:4f77028cce64 87 //Userコンフィギュレーションない
nyatla 92:4f77028cce64 88 return &factory_default;
nyatla 92:4f77028cce64 89 }
nyatla 92:4f77028cce64 90 }
nyatla 92:4f77028cce64 91 const struct NyLPC_TMiMicConfigulation* NyLPC_cMiMicConfiglation_loadFactoryDefault(void)
nyatla 92:4f77028cce64 92 {
nyatla 92:4f77028cce64 93 return &factory_default;
nyatla 92:4f77028cce64 94 }
nyatla 92:4f77028cce64 95
nyatla 92:4f77028cce64 96
nyatla 92:4f77028cce64 97
nyatla 92:4f77028cce64 98
nyatla 92:4f77028cce64 99
nyatla 92:4f77028cce64 100 /**
nyatla 92:4f77028cce64 101 * ユーザコンフィギュレーションが存在すると、true.
nyatla 92:4f77028cce64 102 */
nyatla 92:4f77028cce64 103 NyLPC_TBool NyLPC_cMiMicConfiglation_hasUserConfigulation(void)
nyatla 92:4f77028cce64 104 {
nyatla 92:4f77028cce64 105 //初回読出しはFlashにFFFFFFFFが格納されているのを期待する。
nyatla 92:4f77028cce64 106 volatile const NyLPC_TUInt32* fast_boot=((NyLPC_TUInt32*)MIMIC_CONFIGLATION_FLASH_ADDR);
nyatla 92:4f77028cce64 107 return (*fast_boot)!=0xffffffff;
nyatla 92:4f77028cce64 108 }
nyatla 92:4f77028cce64 109
nyatla 92:4f77028cce64 110 #ifdef __cplusplus
nyatla 92:4f77028cce64 111 }
nyatla 92:4f77028cce64 112 #endif /* __cplusplus */
nyatla 92:4f77028cce64 113 #endif