def create_devices(): iot_hub = IoTHub(os.environ['IOT_HUB_NAME'], os.environ['IOT_HUB_OWNER_KEY']) iot_device_count = 10 devices = [] for i in range(iot_device_count): device_id = 'MACHINE-{0:03d}'.format(i) device = iot_hub.create_device(device_id) devices.append(device) rotor_imbalance_device_id = devices[-1].deviceId low_pressure_device_id = devices[-2].deviceId def failure_onset(device_id): if device_id == rotor_imbalance_device_id: return 'F01' if device_id == low_pressure_device_id: return 'F02' return None for device in devices: twin_properties = { 'tags': { 'simulated': True, 'simulator': 'devices.engines.Engine' }, 'properties': { 'desired': { 'speed': random.randint(600, 1500), 'mode': 'auto', 'failureOnset': failure_onset(device.deviceId) } } } iot_hub.update_twin(device.deviceId, json.dumps(twin_properties)) return redirect(url_for('telemetry'))
# print('Cadence: {0}'.format(time_elapsed)) time.sleep(max(1 - time_elapsed, 0)) if __name__ == '__main__': iot_hub = IoTHub(IOT_HUB_NAME, IOT_HUB_OWNER_KEY) iot_device_count = 10 devices = iot_hub.get_device_list() if len(devices) == 0: devices = [] for i in range(iot_device_count): device_id = 'MACHINE-{0:03d}'.format(i) device = iot_hub.create_device(device_id) devices.append(device) 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