예제 #1
0
def get_device_twin(device_id):
    iot_hub = IoTHub(os.environ['IOT_HUB_NAME'],
                     os.environ['IOT_HUB_OWNER_KEY'])
    twin_data = iot_hub.get_device_twin(device_id)
    resp = Response(twin_data)
    resp.headers['Content-type'] = 'application/json'
    return resp
예제 #2
0
    healthy_spectral_profile = {
        'W': [1, 2, 3, 4, 5, 12, 15],
        'A': [5, 8, 2 / 3, 9, 8, 13, 5]
    }

    rotor_imbalance_speactral_profile = {
        'W': [1 / 2, 1, 2, 3, 5, 7, 12, 18],
        'A': [1, 5, 80, 2 / 3, 8, 2, 14, 50]
    }

    rotor_imbalance_device_id = devices[-1].deviceId
    low_pressure_device_id = devices[-2].deviceId

    for device in devices:
        twin_data = iot_hub.get_device_twin(device.deviceId)
        twin_data_json = json.loads(twin_data)
        twin_properties = twin_data_json['properties']
        if 'speed' not in twin_properties['desired']:
            twin_properties = {
                'properties': {
                    'desired': {
                        'speed':
                        random.randint(600, 1500),
                        'spectralProfile':
                        json.dumps(healthy_spectral_profile if
                                   device.deviceId != rotor_imbalance_device_id
                                   else rotor_imbalance_speactral_profile),
                        'pressureFactor':
                        2 if device.deviceId != low_pressure_device_id else 1.5
                    }