Exemplo n.º 1
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.º 2
0
    def post(self, request, device_id):
        device_instance = Device.objects.get(
            Q(device_id=device_id) & Q(user=request.user))
        device_instance.delete()
        authentication = Authentication()
        ag = authentication.getAuthToken(Constant().clientInfo())
        accesstoken = ag.split(",")[0].split(":")[1]

        device_management = DeviceManagement()
        device_management.deleteDirectDevice(deviceId=device_id,
                                             accessToken=accesstoken[1:-1],
                                             cascade="true",
                                             appId=None)
        return redirect(to="/device/list")
Exemplo n.º 3
0
    def get(self, request, device_id):
        authentication = Authentication()
        ag = authentication.getAuthToken(Constant().clientInfo())
        accesstoken = ag.split(",")[0].split(":")[1]

        data_collect = DataCollection()
        data = data_collect.querySingleDeviceInfo(
            deviceId=device_id,
            appId=None,
            select="imsi",
            accessToken=accesstoken[1:-1])

        dict_data = json.loads(data)
        #获网关id以便查询历史数据时填入
        gatewayid = dict_data.get("gatewayId", None)

        querydatahistory = QueryDeviceDataHistoryInDTO()
        querydatahistory.setAppId(None)
        querydatahistory.setDeviceId(deviceId=device_id)
        querydatahistory.setGatewayId(gatewayId=gatewayid)
        querydatahistory.setPageSize(100)
        histoty_data = data_collect.queryDeviceDataHistory(
            qddhInDTO=querydatahistory, accessToken=accesstoken[1:-1])

        dict_history_data = json.loads(histoty_data)
        histoty_dto = dict_history_data['deviceDataHistoryDTOs']
        return_data = []
        time_data = []
        for dto in histoty_dto:
            return_data.append(dto["data"])
            time_data.append(change_timestamp_to_realtime(dto["timestamp"]))
        data = zip(return_data, time_data)
        AirTemp, AirHumidity, LightIntensity, OilHumidity = [], [], [], []
        for single_dict in return_data:
            AirTemp.append(single_dict["AirTemp"])
            AirHumidity.append(single_dict["AirHumidity"])
            LightIntensity.append(single_dict["LightIntensity"])
            OilHumidity.append(single_dict["OilHumidity"])
        return render(
            request, "device_detail.html", {
                "data": data,
                "AirTemp": AirTemp,
                "AirHumidity": AirHumidity,
                "LightIntensity": LightIntensity,
                "OilHumidity": OilHumidity
            })
Exemplo n.º 4
0
    def post(self, request):
        device_name = request.POST.get("device_name", "")
        imsi = request.POST.get("imsi", "")
        device_form = DeviceForm(request.POST)
        if device_form.is_valid():
            device_instance = Device()
            authentication = Authentication()
            ag = authentication.getAuthToken(Constant().clientInfo())
            accesstoken = ag.split(",")[0].split(":")[1]

            deviceinfodto = DeviceInfoDTO()  # 表示要注册设备的信息,只需要填写设备model(型号)即可
            deviceinfodto.setModel("00000001")  # 设置设备的型号
            deviceinfodto.setManufacturerId(
                "8d2cb5b1888d459a914983c791e17bc1")  #设置厂商ID
            deviceinfodto.setmanufacturerName("HUAWEI")  #设置厂商名
            deviceinfodto.setDeviceType("MultiSensor")  #设置设备类型
            deviceinfodto.setProtocolType("LWM2M")  #设置设备协议
            deviceinfodto = clastodict(deviceinfodto)

            redirectdeviceindto = RegDirectDeviceInDTO()
            redirectdeviceindto.deviceInfo = deviceinfodto
            redirectdeviceindto.setDeviceName(device_name)
            redirectdeviceindto.setNodeId(imsi)
            redirectdeviceindto.setProductId("604219a122768f094ccb74b1")

            device_management = DeviceManagement()
            return_data = device_management.regDirectDevice(
                rddInDto=redirectdeviceindto,
                appId="Y2fIeoKaw4Sizm0lZjGOZNfhRkoa",
                accessToken=accesstoken[1:-1])

            return_date_dict = json.loads(return_data)
            device_instance.device_id = return_date_dict["deviceId"]
            device_instance.user = request.user
            device_instance.device_name = device_name
            device_instance.belonged_product = "jujube_environment"
            device_instance.product_type = "MultiSensor"
            device_instance.save()

            return redirect(to="/device/list")
Exemplo n.º 5
0
 def get(self, request):
     authentication = Authentication()
     ag = authentication.getAuthToken(Constant().clientInfo())
     accesstoken = ag.split(",")[0].split(":")[1]
     #获取设备列表前先更新设备状态
     data_collect = DataCollection()
     querybatchdevicesinfoindto = QueryBatchDevicesInfoInDTO()
     querybatchdevicesinfoindto.setPageSize('20')
     data = data_collect.queryBatchDevicesInfo(
         qbdiInDTO=querybatchdevicesinfoindto,
         accessToken=accesstoken[1:-1])
     devices = []
     if json.loads(data).get("devices", ""):
         devices = json.loads(data)["devices"]
     for device in devices:
         device_id = device["deviceId"]
         device_instance = Device.objects.get(device_id=device_id)
         device_instance.status = device['deviceInfo']['status']
         device_instance.save()
     user = self.request.user
     devices = Device.objects.filter(user=self.request.user)
     online_num = Device.objects.filter(status="ONLINE").count()
     offline_num = Device.objects.filter(status="OFFLINE").count()
     err_num = Device.objects.filter(status="ABNORMAL").count()
     #求出离线设备和在线设备的比例
     online_num_res = online_num / (online_num + offline_num + err_num)
     offline_num_res = offline_num / (online_num + offline_num + err_num)
     err_num_res = err_num / (online_num + offline_num + err_num)
     return render(
         request, "device_list.html", {
             "devices": devices,
             "online": online_num,
             "offline": offline_num,
             "err": err_num,
             "device_num": online_num + offline_num + err_num
         })
Exemplo n.º 6
0
"""批量查询设备信息"""

import sys

sys.path.insert(0,'C:/Users/admin/Desktop/PythonSDK_V20190905/Python_SDK_Demo')
sys.path.insert(0,"E:/envs/IOT_LIGHT/Lib/site-packages/PythonSDK_V20190905")

from PythonSDK_V20190905.com.huawei.iotplatform.client.invokeapi.Authentication import Authentication
from PythonSDK_V20190905.com.huawei.iotplatform.client.invokeapi.DataCollection import DataCollection
from Python_SDK_Demo.com.huawei.iotplatform.constant.Constant import Constant
from Python_SDK_Demo.com.huawei.iotplatform.client.dto.QueryBatchDevicesInfoInDTO import QueryBatchDevicesInfoInDTO


if __name__=="__main__":
    authentication = Authentication()
    ag = authentication.getAuthToken(Constant().clientInfo())
    accesstoken = ag.split(",")[0].split(":")[1]

    data_collection=DataCollection()
    querybatchdevicesinfoindto=QueryBatchDevicesInfoInDTO()
    querybatchdevicesinfoindto.setAppId(None)
    #查询在线设备的数据
    querybatchdevicesinfoindto.setStatus("ONLINE")

    print(data_collection.queryBatchDevicesInfo(qbdiInDTO=querybatchdevicesinfoindto,accessToken=accesstoken[1:-1]))