RED HAT
RED HAT
DIIDevHeads IoT Integration Server
Created by Boss lady on 7/11/2024 in #middleware-and-os
Why is my TI CC2652 smart lighting control system unable to read light sensor data?
Hey @Boss lady , it seems like the code assumes the device name is always LightSensor. Have you confirmed the device name and address? Devices might not always have straightforward names. You might need to discover the device first and make sure the Thread network is fully initialized and the devices are properly discovered before accessing them. For instance:
import openthread
import time

ot_instance = openthread.Instance()
ot_instance.factory_reset()

try:
ot_instance.thread_start()

# Wait for the Thread network to be initialized
time.sleep(5)

device_list = ot_instance.device_manager.get_device_list()
light_sensor = None
for device in device_list:
print(f"Discovered device: {device}")
if device.name == 'LightSensor':
light_sensor = device
break

if light_sensor:
light_level = light_sensor.read_attribute('LightLevel')
print(f"Light Level: {light_level}")
else:
print("Light sensor not found")

except Exception as e:
print(f"Error reading light level: {e}")

finally:
ot_instance.thread_stop()
import openthread
import time

ot_instance = openthread.Instance()
ot_instance.factory_reset()

try:
ot_instance.thread_start()

# Wait for the Thread network to be initialized
time.sleep(5)

device_list = ot_instance.device_manager.get_device_list()
light_sensor = None
for device in device_list:
print(f"Discovered device: {device}")
if device.name == 'LightSensor':
light_sensor = device
break

if light_sensor:
light_level = light_sensor.read_attribute('LightLevel')
print(f"Light Level: {light_level}")
else:
print("Light sensor not found")

except Exception as e:
print(f"Error reading light level: {e}")

finally:
ot_instance.thread_stop()
8 replies