2016年8月7日 星期日

ARM mbed client Code


What is mbed client?

ARM mbed Client is a library that provides the means to connect constrained embedded devices to mbed Device Connector Service, mbed Device Server and to mbed-enabled cloud services from our partners.


  • Manage devices on mbed Device Server.
  • Securely communicate with internet services over the industry standard TLS/DTLS.
  • Fully control the endpoint and application logic.
class MbedClient: public M2MInterfaceObserver {
public:
    MbedClient(){
        _security = NULL;
        _interface = NULL;    // 產生M2M Interface : M2MInterfaceFactory::create_interface
        _device = NULL;     // 產生Device Object : M2MInterfaceFactory::create_device();
        _object = NULL;    // 產生Resource Object : M2MInterfaceFactory::create_object("Monitor");
_object_gpio = NULL;
        _error = false;
        _registered = false;   //,一旦 M2MObjectList object_registered 成功後, 將 _registered設為true
        _unregistered = false;
        _registration_updated = false;

    }

 ....

}


M2MInterface  --> register_object()          ----callback--> object_register()
                               unregistered_object()  ----callback--> object_unregister()
                               update_registration()    ----callback--> registration_updated()



M2MInterfaceObserver 類別上的5個Callback函式列表

virtual void bootstrap_done (M2MSecurity *server_object)=0
A callback indicating that the bootstap has been performed successfully. More...
virtual void object_registered (M2MSecurity *security_object, const M2MServer &server_object)=0
A callback indicating that the device object has been registered successfully to the LWM2M server. More...
virtual void object_unregistered (M2MSecurity *server_object)=0
A callback indicating that the device object has been successfully unregistered from the LWM2M server. More...
virtual void registration_updated (M2MSecurity *security_object, const M2MServer &server_object)=0
A callback indicating that the device object registration has been successfully updated on the LWM2M server. More...
virtual void error (M2MInterface::Error error)=0
A callback indicating that there was an error during the operation. More...
virtual void value_updated (M2MBase *base, M2MBase::BaseType type)=0
A callback indicating that the value of the resource object is updated by the server.Whenever there is a valid PUT operation for any of the resources, the application will receive a callback:


void error(M2MInterface::Error error){
        _error = true;
        String error_code;
switch(error) {
        case M2MInterface::ErrorNone:
             error_code += "M2MInterface::ErrorNone";
             break;
        case M2MInterface::AlreadyExists:
             error_code += "M2MInterface::AlreadyExists";
             break;

  .....


           }
        printf("\nError occured  : %s\n", error_code.c_str());
    }



There are two types of resources you can create
Dynamic: 值會改變, 當server 請求時要負責傳回值
Static: 值不改變
 configure different types of Objects, Object Instances and Resources 



  • mbed client Document

  1. ARM mbed Client Guide
  2. ARM mbed Client API





沒有留言 :

張貼留言