Iot command prototype design and framework

By Rodney Sullivan,2015-03-21 16:41
24 views 0
Iot command prototype design and framework


    In another article tells the client API design (IOT command (-based on sip) client API design for Java ;。

    Recently, combed the command framework design and, in fact, in a narrow sense the equipment control, management, namely can manage family within the local area network (LAN), can also remote management (through open source sip server: opensips), of course also includes equipment linkage rule of prototype implementation (i.e., iot ITTT).

    Command contains two parts: client and server (eg. Client app on the phone, the gateway on the server)

    Process as shown in the figure below:

    Long-range request: 1. The mobile phone to send to the room open lamp hue

    2. The Internet cloud platform receives the request is forwarded to the corresponding gateway

    3. Command_svr receiving, parsing sent to hue module, hue communication module for this device type agreement, turn on the light request

    4-5. Command_svr send back the operation results, by opensips is forwarded to the client, the client informed lights successful results.

The client main functions:

1. Request gateway devices list, function, state

2. Send the equipment operation request and receiving equipment operating results

3. To subscribe to and receiving device notifications

Sever main functions:

    1. The management to the gateway access to the different device types list, plug-in equipment in the form of a dynamic library access, convenient access by a third party.

    2. Receive the client's equipment operation request, forwarded to the corresponding equipment module (eg above ip_camera), protocol conversion by the module, making the actual equipment control, and then receive operation results, and transform it into the command protocol, returned to the client response.

    3. Active push message receiver module, and pushed to the client accordingly.

    4. Ittt function: receive and storage equipment linkage rules regarding client, check the client device control request, if accord with the if, trigger then device control.

    At present the implementation of the command is implemented based on sip, method of sip extension, which add a custom methods sip - command, and on the basis of its implementation

    Equipment control layer, the command on the basis of pjsip open-source library implementation, while using open source opensips server, remote management to achieve rapid prototyping;Another reason is the project requirements on the stream media transmission is based on sip/RTP, unified under the sip, reduce the learning cost, the prototype as soon as possible.

    Below is a command frame, the bottom is the sip layer, based on the pjsip increased the command method;Cmd_mng defines two main interface (cmd_send_inf cmd_recv_inf) to communicate and sip layer, consider convenient replacement or compatible with different protocols in the future, to achieve loose coupling between modules.Upper cmd_mng dev_mng and iot_cmd_proc two modules, dev_mng contains

    The command to the server management, load, plug-in equipment, namely metadata file parsing function function of the equipment and equipment import (by definition plugin_interface interface, provide to the third party to develop new equipment for the

    gateway access type), and the meta information for client queries equipment of internal interfaces.Iot_cmd_proc module contains a client and server to send and receive the command message processing framework, and provide to a third party develop client side interface (i.e.,start talking about the client API design).

    1. Below is the server side for third party access to the development of new device type interface definition (the third party implementation, and provides the gateway in the form of dynamic library command - SVR)

    Plugin_interface interface:

typedef struct dev_func


     const char * funcname;

     int (* dev_method)(cmd_arg * param_list[], uint8_t plist_size);


typedef struct dev_plugin {

     char dev_pluginname[NAME_MAXSIZE]; //

     const dev_func * pt_func_array; //

     char dev_metafile[NAME_MAXSIZE]; //


    typedef int (* init_devplugin)(dev_plugin * pt_plugin, dev_cmd_interface * pt_inf);

    Command - SVR by init_devplugin function, can read into the equipment of the plugin information above, the gateway will know the device type has the attributes and functions.

    (later also need to have hot update plug-in equipment, delete, runtime loading, etc)

    2. Iot_cmd_proc module introduces below, it is logic to handle the core of the command

    In the case of the client end,

    In the form of message queue memory (usingmini_mq) to decouple the business layer (cli_proxy), the command layer (cmdhandler_proc), bearing the MSG protocol layer (sip_proxy)

    After the prototype development, summarizes the development and use of encounter all

    sorts of problems:

    1. The command control device design, based on the action of equipment as the goal, the

    following test equipment types of metadata definitions

< device type ="test_plugin" >

    < method name ="test1" >

    < param name ="a" type ="int" direction ="IN" />

    < param name ="b" type ="string" direction ="IN" />

    < param name ="c" type ="float" direction ="OUT" />

    < param name ="d" type ="string" direction ="OUT" />

    </ method >

</ device >

    If join equipment propery attributes, can be a good fit into the next phase of the command protocol USES HTTP restful style, aiming at equipment resource properties, simple pass

    To get the set, to achieve to the operation of the equipment (as not all, of course, can perfect use restful web services, equipment control operation can use properties, actions are defined).

    2. As described above, I consider the command protocol using HTTP, the gateway using web services, the client end adopts the hybrid method, which avoids the command

    Client, server update problem, and use native to avoid the shortage of the web, is now in the research.

    3. Design a iot_cloud prototypes, tentative function remote management equipment, mainly for the convenience of users and data storing user equipment, and simple data analysis.

Report this document

For any questions or suggestions please email