コード例 #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")
コード例 #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
コード例 #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
コード例 #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)	
コード例 #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
コード例 #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)
コード例 #7
0
    def updateBatchRuleStatusInfo(self):
        ubrsInDTO = UpdateBatchRuleStatusInDTO()
        ubrsInDTO.requests = [{
            ubrsInDTO.ruleId: "as",
            ubrsInDTO.status: "active"
        }, {
            ubrsInDTO.ruleId: "ss",
            ubrsInDTO.status: "active"
        }]
        return ubrsInDTO


if __name__ == "__main__":
    reTest = RuleEngineTest()
    authentication = Authentication()
    ruleEngine = RuleEngine()

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

    # create a rule
    rc = ruleEngine.createRule(reTest.createRuleInfo(), None, accessToken)
    print("====== create a rule ======")
    print("result:", rc + "\n")

    # get ruleId
    rcouOutDTO = RuleCreateOrUpdateOutDTO()
コード例 #8
0
from com.huawei.iotplatform.client.invokeapi.Authentication import Authentication

from com.huawei.iotplatform.client.dto.AuthOutDTO import AuthOutDTO
from com.huawei.iotplatform.client.dto.AuthRefreshInDTO import AuthRefreshInDTO
from com.huawei.iotplatform.constant.Constant import Constant


class AuthenticationTest(object):
    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


if __name__ == "__main__":
    auTest = AuthenticationTest()
    authentication = Authentication()

    ag = authentication.getAuthToken(Constant().clientInfo())
    print("====== get access token ======")
    print("result:", ag + "\n")

    ar = authentication.refreshAuthToken(auTest.refreshAuthTokenInfo())
    print("====== refresh token ======")
    print("result:", ar + "\n")