Exemplo n.º 1
0
 def oc_lwm2m_device_cmd_send(self, deviceId, serviceId, mode, method, payload):
     # get accessToken at first   
     result = Authentication().getAuthToken(self.developClient)
     print("AuthToken: ", result)
     authOutDTO = AuthOutDTO()
     authOutDTO.setAccessToken(json.loads(result)['accessToken'])
     accessToken = authOutDTO.getAccessToken()       
     # appId
     appId = self.developClient["appId"] 
     # invoke device service
     pdcInDTO = PostDeviceCommandInDTO()
     pdcInDTO.deviceId = deviceId
     pdcInDTO.command = {
         pdcInDTO.command.method: method,
         pdcInDTO.command.serviceId: serviceId,
         pdcInDTO.command.paras: payload 
     }
     # send command to device
     cmd_class = SignalDelivery
     cmd_result = cmd_class.postDeviceCommand(self, pdcInDTO, appId, accessToken)      
     print("====== invoke device service ======")
     print("result:", cmd_result)  
    
     # get commandId And deviceId
     pdcOutDTO = PostDeviceCommandOutDTO()
     pdcOutDTO.setCommandId(json.loads(cmd_result)['commandId'])
     commandId = pdcOutDTO.getCommandId()
     pdcOutDTO.setDeviceId(json.loads(cmd_result)['deviceId'])
     deviceId = pdcOutDTO.getDeviceId()
     print("commandId==", commandId)
     print("deviceId==", deviceId + "\n")
Exemplo n.º 2
0
 def refreshAuthTokenInfo(self):
     arInDTO = AuthRefreshInDTO()
     arInDTO.appId = (Constant().readConfFile())[2]
     arInDTO.secret = (Constant().readConfFile())[3]
     authOutDTO = AuthOutDTO()
     result = Authentication().getAuthToken(Constant().clientInfo())
     authOutDTO.setRefreshToken(json.loads(result)['refreshToken'])
     arInDTO.refreshToken = authOutDTO.getRefreshToken()
     return arInDTO
Exemplo n.º 3
0
    def oc_mqtt_get_device_shadowstatus_business(self, deivceid):
        deviceManagement = DeviceManagement()
        result = Authentication().getAuthToken(self.businessClient)
        print(result)
        print(json.loads(result))
        authOutDTO = AuthOutDTO()
        authOutDTO.setAccessToken(json.loads(result)['accessToken'])
        accessToken = authOutDTO.getAccessToken()
        print(accessToken)
        # query device shadow
        dq = deviceManagement.queryDeviceShadow(deivceid, None, accessToken)
        print("====== query device shadow ======")
        print("result:", dq + "\n")

        dev_status = json.loads(dq).get("deviceInfo").get("status")
        print("dev_status :", dev_status)
        return dev_status
Exemplo n.º 4
0
 def oc_coap_device_cmd_send(self, deviceId, serviceId, method, payload):
     appId = self.developClient["appId"]
     dss = SignalDelivery()
     result = Authentication().getAuthToken(Constant().clientInfo())
     print(Constant().clientInfo())
     authOutDTO = AuthOutDTO()
     authOutDTO.setAccessToken(json.loads(result)['accessToken'])
     accessToken = authOutDTO.getAccessToken()
     pdcInDTO = PostDeviceCommandInDTO()
     pdcInDTO.deviceId = deviceId
     pdcInDTO.command = {
         pdcInDTO.command.method: method,
         pdcInDTO.command.serviceId: serviceId,
         pdcInDTO.command.paras: payload
         }
     di = dss.postDeviceCommand(pdcInDTO, appId, accessToken)
     print("====== invoke device service ======")
     print("result:", di)	
Exemplo n.º 5
0
 def oc_lwm2m_get_device_shadowstatus(self, deivceid):
     deviceManagement = DeviceManagement()
     # get accessToken at first
     result = Authentication().getAuthToken(self.developClient)
     print(result)
     authOutDTO = AuthOutDTO()
     authOutDTO.setAccessToken(json.loads(result)['accessToken'])
     accessToken = authOutDTO.getAccessToken()
     # query device status
     dq = deviceManagement.queryDeviceStatus(deivceid, None, accessToken)
     print("====== query device status ======")
     print("result:", dq + "\n")
     # query device shadow
     dq = deviceManagement.queryDeviceShadow(deivceid, None, accessToken)
     print("====== query device shadow ======")
     print("result:", dq + "\n")
     dev_status = json.loads(dq).get("deviceInfo").get("status")
     print("dev_status :", dev_status)
     return dev_status
Exemplo n.º 6
0
    def oc_mqtt_device_cmd_send(self, deviceId, serviceId, mode, method, payload):
        # get accessToken at first
        appId = self.developClient["appId"]

        dss = DeviceServiceInvocation()
        result = Authentication().getAuthToken(Constant().clientInfo())
        print(Constant().clientInfo())
        authOutDTO = AuthOutDTO()
        authOutDTO.setAccessToken(json.loads(result)['accessToken'])
        accessToken = authOutDTO.getAccessToken()
        # invoke device service
        commandDTO = CommandDTO()
        commandDTO.header = {
            commandDTO.header.mode: mode,
            commandDTO.header.method: method
        }

        commandDTO.body = payload

        di = dss.invokeDeviceService(commandDTO, deviceId, serviceId, appId,
                                     accessToken)
        print("====== invoke device service ======")
        print("result:", di)
Exemplo n.º 7
0
    def queryDeviceCapabilities(self):
        qdcInDTO = QueryDeviceCapabilitiesInDTO()
        qdcInDTO.deviceId = "bd6394ed-b41d-430d-85f8-5d0290cfee24"
        qdcInDTO.gatewayId = "bd6394ed-b41d-430d-85f8-5d0290cfee24"
        qdcInDTO.appId = "wk14orhpOumkAouraCpOsoQ3iO4a"
        return qdcInDTO


if __name__ == "__main__":
    dcTest = DataCollectionTest()
    authentication = Authentication()
    dataCollection = DataCollection()

    # get accessToken at first
    result = authentication.getAuthToken(Constant().clientInfo())
    authOutDTO = AuthOutDTO()
    authOutDTO.setAccessToken(json.loads(result)['accessToken'])
    accessToken = authOutDTO.getAccessToken()

    # query device info
    deviceId = "782eb286-9ead-424f-a910-c235b6090edc"
    dq = dataCollection.querySingleDeviceInfo(deviceId, None, None,
                                              accessToken)
    print("====== query device info ======")
    print("result:", dq + "\n")

    # query batch device info
    dataCollection.queryBatchDevicesInfo(dcTest.queryBatchDevicesInfo(),
                                         accessToken)
    print("====== query batch device info ======")
    print("result:", dq + "\n")