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

Files at this revision

API Documentation at this revision

Comitter:
nyatla
Date:
Thu Aug 08 15:21:43 2013 +0000
Parent:
49:d4334acc3ec3
Child:
51:45d42af201c2
Commit message:
bugfix; ????????????????; UPnP??????????????

Changed in this revision

core/net/NyLPC_cNet.c Show annotated file Show diff for this revision Revisions of this file
core/net/httpd/mod/NyLPC_cModUPnPDevice.c Show annotated file Show diff for this revision Revisions of this file
core/net/upnp/NyLPC_cSsdpSocket.c Show annotated file Show diff for this revision Revisions of this file
core/os/mbedrtos/NyLPC_cThread.cpp Show annotated file Show diff for this revision Revisions of this file
core/uip/NyLPC_cUipService.c Show annotated file Show diff for this revision Revisions of this file
mbed/Net.cpp Show annotated file Show diff for this revision Revisions of this file
mbed/Net.h Show annotated file Show diff for this revision Revisions of this file
mbed/NetConfig.cpp Show annotated file Show diff for this revision Revisions of this file
mbed/NetConfig.h Show annotated file Show diff for this revision Revisions of this file
mbed/mod/ModUPnPDevice.cpp Show annotated file Show diff for this revision Revisions of this file
mbed/mod/ModUPnPDevice.h Show annotated file Show diff for this revision Revisions of this file
--- a/core/net/NyLPC_cNet.c	Wed Aug 07 16:43:32 2013 +0000
+++ b/core/net/NyLPC_cNet.c	Thu Aug 08 15:21:43 2013 +0000
@@ -25,6 +25,7 @@
  *********************************************************************************/
 #include "NyLPC_cNet.h"
 #include "dhcp/NyLPC_cDhcpClient.h"
+#include "../uip/NyLPC_cUipService_protected.h"
 
 
 const char* NyLPC_cNet_PlatformName;
@@ -35,7 +36,9 @@
 void NyLPC_cNet_initialize(NyLPC_TcNet_t* i_inst)
 {
     //uipサービス初期化。いろいろ利用可能に。
-    NyLPC_cUipService_initialize();
+    if(!NyLPC_TcUipService_isInitService()){
+        NyLPC_cUipService_initialize();
+    }
 }
 
 void NyLPC_cNet_start(NyLPC_TcNet_t* i_inst,const NyLPC_TcNetConfig_t* i_ref_config)
--- a/core/net/httpd/mod/NyLPC_cModUPnPDevice.c	Wed Aug 07 16:43:32 2013 +0000
+++ b/core/net/httpd/mod/NyLPC_cModUPnPDevice.c	Thu Aug 08 15:21:43 2013 +0000
@@ -146,7 +146,7 @@
                 "<width>%d</width>"
                 "<height>%d</height>"
                 "<depth>%d</depth>"
-                "<url>%d</url>"
+                "<url>%s</url>"
                 "</icon>",
                 i_dev->icons[i].mimetype,
                 i_dev->icons[i].width,
@@ -157,8 +157,8 @@
         NyLPC_cHttpdConnection_sendResponseBodyF(i_connection,
             "</iconList>");
     }else{
-//      NyLPC_cHttpdConnection_sendResponseBodyF(i_connection,
-//          "<iconList/>");
+        NyLPC_cHttpdConnection_sendResponseBodyF(i_connection,
+            "<iconList/>");
     }
     //Optional
     if(i_dev->number_of_service>0){
--- a/core/net/upnp/NyLPC_cSsdpSocket.c	Wed Aug 07 16:43:32 2013 +0000
+++ b/core/net/upnp/NyLPC_cSsdpSocket.c	Thu Aug 08 15:21:43 2013 +0000
@@ -218,12 +218,12 @@
 	const NyLPC_TChar* i_usn,
 	NyLPC_TInt16* o_len)
 {
-
 	NyLPC_TChar* obuf;
 	NyLPC_TUInt16 l,l2;
 	NyLPC_TUInt16 len_usn=(NyLPC_TUInt16)(i_usn!=NULL?strlen(i_usn):0);
 	NyLPC_TUInt16 len_udn=(NyLPC_TUInt16)strlen(i_udn);
 	NyLPC_TUInt16 len_location=(NyLPC_TUInt16)strlen(i_inst->location_path);
+
 	//	//193Byte
 	//	"NOTIFY * HTTP/1.1\r\n" 						//15+2=17
 	//	"HOST: 239.255.255.250:1900\r\n"				//26+2=28
@@ -578,6 +578,7 @@
 	NyLPC_cUdpSocket_joinMulticast(&(i_inst->super),&SSDP_MCAST_IPADDR);
 	i_inst->_flags=0;
 	NyLPC_cStopwatch_initialize(&(i_inst->_periodic_sw));
+	i_inst->number_of_device=0;
 	expandDeviceTree(i_inst,i_ref_dev_record);
 	i_inst->location_port=i_server_port;
 	i_inst->location_path=i_ref_location_path;
--- a/core/os/mbedrtos/NyLPC_cThread.cpp	Wed Aug 07 16:43:32 2013 +0000
+++ b/core/os/mbedrtos/NyLPC_cThread.cpp	Thu Aug 08 15:21:43 2013 +0000
@@ -47,7 +47,6 @@
 }
 
 
-
 void NyLPC_cThread_initialize(NyLPC_TcThread_t* i_inst,NyLPC_TInt32 i_stack,NyLPC_TInt32 i_prio)
 {
     NyLPC_TUInt32_setBit(i_inst->_sbit,NyLPC_TcThread_BIT_IS_TERMINATED);
--- a/core/uip/NyLPC_cUipService.c	Wed Aug 07 16:43:32 2013 +0000
+++ b/core/uip/NyLPC_cUipService.c	Thu Aug 08 15:21:43 2013 +0000
@@ -136,6 +136,7 @@
 
 NyLPC_TcThread_t th;
 
+void led(int i);
 NyLPC_TBool NyLPC_cUipService_initialize(void)
 {
     NyLPC_TcUipService_t* inst=&_service_instance;
--- a/mbed/Net.cpp	Wed Aug 07 16:43:32 2013 +0000
+++ b/mbed/Net.cpp	Thu Aug 08 15:21:43 2013 +0000
@@ -5,12 +5,10 @@
 #include "Net.h"
 #include "NetConfig.h"
 #include "mbed.h"
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
-DigitalOut led3(LED3);
-DigitalOut led4(LED4);
 namespace MiMic
 {
+    const char* Net::UPNP_ROOT_PATH="upnp";
+
     Net::Net()
     {
         NyLPC_cNet_initialize(&(this->_inst));
@@ -43,26 +41,21 @@
                 }
             }
         }
-        led1=1;
         //start mDNS
         if(base_cfg->services.flags & NyLPC_TcNetConfig_SERVICE_FLAG_MDNS !=0){
             this->_mdns=(NyLPC_TcMDnsServer_t*)malloc(sizeof(NyLPC_TcMDnsServer_t));
             NyLPC_cMDnsServer_initialize(this->_mdns,i_cfg.refMdnsRecord());        
         }
-        led2=1;
         //start UPnP
         if(base_cfg->services.flags & NyLPC_TcNetConfig_SERVICE_FLAG_UPNP !=0){
             this->_upnp=(NyLPC_TcUPnP_t*)malloc(sizeof(NyLPC_TcUPnP_t));
-            NyLPC_cUPnP_initialize(this->_upnp,i_cfg.getHttpPort(),UPNP_HTTP_PATH,i_cfg.refUPnPDevDesc());        
+            NyLPC_cUPnP_initialize(this->_upnp,i_cfg.getHttpPort(),UPNP_ROOT_PATH,i_cfg.refUPnPDevDesc());        
 
         }
-        led3=1;
         NyLPC_cNet_start(&(this->_inst),base_cfg);
         if(this->_upnp!=NULL){
             NyLPC_cUPnP_start(this->_upnp);
-        }
-        led4=1;
-        
+        }        
     }
     void Net::stop()
     {
--- a/mbed/Net.h	Wed Aug 07 16:43:32 2013 +0000
+++ b/mbed/Net.h	Thu Aug 08 15:21:43 2013 +0000
@@ -5,16 +5,17 @@
 
 #include "NyLPC_net.h"
 
-/**
- * Path of upnp services on HTTP server.
- */
-const static char* UPNP_HTTP_PATH="upnp";
 
 namespace MiMic
 {
     class NetConfig;
     class Net
     {
+    public:
+        /**
+         * Path of upnp services on HTTP server.
+         */
+        const static char* UPNP_ROOT_PATH;
     private:
         NyLPC_TcMDnsServer_t* _mdns;
         NyLPC_TcUPnP_t* _upnp;
--- a/mbed/NetConfig.cpp	Wed Aug 07 16:43:32 2013 +0000
+++ b/mbed/NetConfig.cpp	Thu Aug 08 15:21:43 2013 +0000
@@ -17,6 +17,8 @@
 const static char* UPNP_DEFAULT_MODEL_NAME="MiMic UPnP device.";
 const static char* STR_EMPTY="";
 const static char* UPNP_DEFAULT_PRESENTATION_URL="/";
+const static char* UPNP_DEFAULT_ICON_MIMETYPE="image/png";
+const static char* UPNP_DEFAULT_ICON_URL="./icon.png";
 
 
 /*
@@ -97,22 +99,7 @@
         }
     }
     //updateUUID
-    this->setUPnPUdn(0,0,0,0);
-    //update mdns informations
-    this->_syncServiceInfo();
-    //update UPnP informations
-}
-void NetConfig::_syncServiceInfo()
-{
-    //update DNS record
-    this->_dns_record.name=UPNP_DEFAULT_FRENDLY_NAME;
-    this->_dns_record.a=this->_inst.hostname;
-    this->_dns_record.num_of_srv=1;
-    this->_srv_record.protocol=MDNS_SRV_HTTP;
-    this->_srv_record.port=this->_inst.services.http_port;
-    this->_dns_record.srv=&(this->_srv_record);
-
-    //update UPnP record
+    this->setUPnPUdn(0xe29f7100,0x4ba2,0x01e0,0);
     this->_upnp_desc.device_type=UPNP_DEVICE_TYPE;
     this->_upnp_desc.frendly_name=UPNP_DEFAULT_FRENDLY_NAME;
     this->_upnp_desc.manufacturer=UPNP_DEFAULT_MANUFACTUR_NAME;
@@ -122,15 +109,28 @@
     this->_upnp_desc.model_number=NULL;
     this->_upnp_desc.model_url=NULL;
     this->_upnp_desc.serial_number=STR_EMPTY;
-    this->_upnp_desc.udn=this->_udn;//AUTO GENERATE
+    this->_upnp_desc.udn=this->_udn;//pointer
     this->_upnp_desc.upc=NULL;
+    this->_upnp_icon.width=32;
+    this->_upnp_icon.height=32;
+    this->_upnp_icon.depth=8;
+    this->_upnp_icon.mimetype=UPNP_DEFAULT_ICON_MIMETYPE;
+    this->_upnp_icon.url=UPNP_DEFAULT_ICON_URL;
+    this->_upnp_desc.icons=&this->_upnp_icon;//pointer
     this->_upnp_desc.presentation_url=UPNP_DEFAULT_PRESENTATION_URL;
     this->_upnp_desc.number_of_devices=0;
     this->_upnp_desc.number_of_service=0;
-    this->_upnp_desc.number_of_icon=0;
+    this->_upnp_desc.number_of_icon=1;
     this->_upnp_desc.devices=NULL;
     this->_upnp_desc.services=NULL;
-    this->_upnp_desc.icons=NULL;
+    //mdns
+    this->_dns_record.name=UPNP_DEFAULT_FRENDLY_NAME;
+    this->_dns_record.a=this->_inst.hostname;//pointer
+    this->_dns_record.num_of_srv=1;
+    this->_srv_record.protocol=MDNS_SRV_HTTP;
+    this->_srv_record.port=this->_inst.services.http_port;
+    this->_dns_record.srv=&(this->_srv_record);
+
 }
 
 NetConfig::~NetConfig()
@@ -188,7 +188,7 @@
 }
 void NetConfig::setSrvHttpPort(unsigned short port)
 {
-    this->_inst.services.http_port=port;
+    this->_srv_record.port=this->_inst.services.http_port=port;
 }
 void NetConfig::setSrvMdns(bool i_enable)
 {
@@ -246,6 +246,14 @@
     NyLPC_cUuid_toString(&uuid,this->_udn+5);
     NyLPC_cUuid_finalize(&uuid);
 }
+void NetConfig::setUPnPIcon(unsigned short i_width,unsigned short i_height,unsigned short i_depth,const char* i_mimetype,const char* i_url)
+{
+    this->_upnp_icon.width=i_width;
+    this->_upnp_icon.height=i_height;
+    this->_upnp_icon.depth=i_depth;
+    this->_upnp_icon.mimetype=i_mimetype;
+    this->_upnp_icon.url=i_url;    
+}
 
 void NetConfig::setUPnPPresentationURL(const char* i_url)
 {
@@ -352,7 +360,6 @@
         }
     }
     fclose(fp);
-    this->_syncServiceInfo();
     return true;
 }
 };
\ No newline at end of file
--- a/mbed/NetConfig.h	Wed Aug 07 16:43:32 2013 +0000
+++ b/mbed/NetConfig.h	Thu Aug 08 15:21:43 2013 +0000
@@ -22,6 +22,7 @@
         void _syncServiceInfo();
         struct NyLPC_TDnsRecord _dns_record;
         struct NyLPC_TUPnPDevDescDevice _upnp_desc;
+        struct NyLPC_TUPnPDevDescIcon _upnp_icon;
         const struct NyLPC_TDnsRecord* _ref_custom_dns_record;
         const struct NyLPC_TUPnPDevDescDevice* _ref_custom_upnp_desc;
         char _udn[42];//uuid:00000000-0000-0000-0000-000000000000+'\0'
@@ -121,6 +122,7 @@
          * [i_time_l]-[i_time_m]-[i_time_h|0x80]-[i_sq&0x3F|0x80]-[MAC ADDRESS]
          */
         void setUPnPUdn(unsigned long i_time_l,unsigned short i_time_m,unsigned short i_time_h,unsigned short i_sq);
+        void setUPnPIcon(unsigned short i_width,unsigned short i_height,unsigned short i_depth,const char* i_mimetype,const char* i_url);
         /**
          * This function sets a custom UPnP device description to instance.
          * All UPnP description will be overwritten if set it.
@@ -138,7 +140,6 @@
         
         
         
-        
         /**
          * Load configulation from text file.
          * <p>File format example
--- a/mbed/mod/ModUPnPDevice.cpp	Wed Aug 07 16:43:32 2013 +0000
+++ b/mbed/mod/ModUPnPDevice.cpp	Thu Aug 08 15:21:43 2013 +0000
@@ -2,34 +2,33 @@
 #include <NyLPC_net.h>
 #include <stdio.h>
 #include "mbed.h"
-   
+   #include "../NyLPC_cHttpdConnection_protected.h"
    
 namespace MiMic
 {  
-    ModUPnPDevice::ModUPnPDevice(const Net& i_ref_net)
+    ModUPnPDevice::ModUPnPDevice():ModBaseClass(Net::UPNP_ROOT_PATH)
     {
-        setParam(i_ref_net);
-    }
-    ModUPnPDevice::ModUPnPDevice()
-    {
+        this->_ref_net=NULL;
     }
     ModUPnPDevice::~ModUPnPDevice()
     {
     }
     void ModUPnPDevice::setParam(const Net& i_ref_net)
     {
-        ModBaseClass::setParam(i_ref_net.refUPnPInstance()!=NULL?i_ref_net.refUPnPInstance()->_ref_root_path:NULL);
-        this->_ref_upnp_inst=i_ref_net.refUPnPInstance();
-    }
+        this->_ref_net=&i_ref_net;
+        ModBaseClass::setParam(Net::UPNP_ROOT_PATH);
+    }    
     bool ModUPnPDevice::execute(HttpdConnection& i_connection)
     {
         NyLPC_TcModUPnPDevice_t mod;
 
-        //check parametor
-        if(this->_path==NULL){
+        //check Net has UPnP Instance
+        const NyLPC_TcUPnP_t* upnp=this->_ref_net->refUPnPInstance();
+        if(upnp==NULL || this->_path==NULL){
             return false;
         }
-        NyLPC_cModUPnPDevice_initialize(&mod,this->_ref_upnp_inst);
+        //
+        NyLPC_cModUPnPDevice_initialize(&mod,upnp);
         if(NyLPC_cModUPnPDevice_canHandle(&mod,i_connection._ref_inst)){
             NyLPC_cModUPnPDevice_execute(&mod,i_connection._ref_inst);
             NyLPC_cModUPnPDevice_finalize(&mod);
--- a/mbed/mod/ModUPnPDevice.h	Wed Aug 07 16:43:32 2013 +0000
+++ b/mbed/mod/ModUPnPDevice.h	Thu Aug 08 15:21:43 2013 +0000
@@ -20,10 +20,10 @@
     class ModUPnPDevice:ModBaseClass
     {
     private:
-        const NyLPC_TcUPnP_t* _ref_upnp_inst;
+        const Net* _ref_net;
     public:
+        ModUPnPDevice();
         ModUPnPDevice(const Net& i_ref_upnp);
-        ModUPnPDevice();
         virtual ~ModUPnPDevice();
         void setParam(const Net& i_ref_upnp);
         bool execute(HttpdConnection& i_connection);