[ivory-search id="2373" title="AJAX Search Form"]
Search

Become a leader in the IoT community!

New DevHeads get a 320-point leaderboard boost when joining the DevHeads IoT Integration Community. In addition to learning and advising, active community leaders are rewarded with community recognition and free tech stuff. Start your Legendary Collaboration now!

Step 1 of 5

CREATE YOUR PROFILE *Required

OR
Step 2 of 5

WHAT BRINGS YOU TO DEVHEADS? *Choose 1 or more

Collaboration & Work 🤝
Learn & Grow 📚
Contribute Experience & Expertise 🔧
Step 3 of 5

WHAT'S YOUR INTEREST OR EXPERTISE? *Choose 1 or more

Hardware & Design 💡
Embedded Software 💻
Edge Networking
Step 4 of 5

Personalize your profile

Step 5 of 5

Read & agree to our COMMUNITY RULES

  1. We want this server to be a welcoming space! Treat everyone with respect. Absolutely no harassment, witch hunting, sexism, racism, or hate speech will be tolerated.
  2. If you see something against the rules or something that makes you feel unsafe, let staff know by messaging @admin in the "support-tickets" tab in the Live DevChat menu.
  3. No age-restricted, obscene or NSFW content. This includes text, images, or links featuring nudity, sex, hard violence, or other graphically disturbing content.
  4. No spam. This includes DMing fellow members.
  5. You must be over the age of 18 years old to participate in our community.
  6. Our community uses Answer Overflow to index content on the web. By posting in this channel your messages will be indexed on the worldwide web to help others find answers.
  7. You agree to our Terms of Service (https://www.devheads.io/terms-of-service/) and Privacy Policy (https://www.devheads.io/privacy-policy)
By clicking "Finish", you have read and agreed to the our Terms of Service and Privacy Policy.

Why is my TI CC2652 smart lighting control system unable to read light sensor data?

hey guys am creating a smart lighting control system using a `TI CC2652` with Embedded Linux. The system should read data from a Thread light sensor, I am using the NCP Thread Border Router Software (Model: OpenThread Border Router, Version: 0.3.0).
But am getting the error

`Error reading light level: Device not found`

i have verified the Thread network configuration and device commissioning, checked the light sensor status and connection, made sure the OpenThread library is correctly installed and configured

here is my code

import openthread

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

try:
    ot_instance.thread_start()
    light_sensor = ot_instance.device_manager.get_device('LightSensor')
    light_level = light_sensor.read_attribute('LightLevel')
except Exception as e:
    print(f"Error reading light level: {e}")
finally:
    ot_instance.thread_stop()

@Middleware & OS

  1. Camila_99$$#0000

    Hi I think your problem is with the device name you’re using in your code, make sure the device name ‘LightSensor’ matches exactly what the Thread network recognizes.

  2. Dark AI#0000

    it looks like the code assumes the door sensor is always node 1, have you confirmed the node ID of the door sensor? Nodes might not always be in a sequential order. You might need to scan the network for the correct node ID. Also, openzwave.network.ZWaveNetwork and openzwave.options.ZWaveOption might require proper initialization parameters. Make sure to configure the Z-Wave options correctly. Here’s a bit more detailed setup:

    “`python
    import openzwave.option
    import openzwave.network
    import time

    options = openzwave.option.ZWaveOption(“/dev/ttyUSB0″, config_path=”/path/to/openzwave/config”, user_path=”.”, cmd_line=””)
    options.lock()
    network = openzwave.network.ZWaveNetwork(options, log=None)

    network.start()

    for i in range(0, 300):
    if network.state >= network.STATE_AWAKED:
    break
    time.sleep(1)

    print(“Network state:”, network.state)

    for node in network.nodes:
    print(f”Node {node.node_id}: {node}”)

    door_sensor = None
    for node in network.nodes:
    if node.product_name == “Your Door Sensor Product Name”:
    door_sensor = node
    break

    if door_sensor:
    try:
    door_status = door_sensor.get_sensor_binary_value()
    print(f”Door Status: {door_status}”)
    except Exception as e:
    print(f”Error reading door status: {e}”)
    else:
    print(“Door sensor not found”)

    network.stop()
    “`

  3. Enthernet Code#0000

    @bosslady0299 it’s good practice to ensure the network is fully initialized before trying to access nodes. Sometimes the initialization might take a bit longer. You might want to increase the waiting time or add additional checks.

  4. RED HAT#0000

    Hey @bosslady0299 , 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:

    “`python
    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()
    “`

  5. Boss lady#0000

    Okay @camila_9900 should I scan for device name

  6. Boss lady#0000

    Thanks @darkai042 it’s already been resolved, I updated the code to scan for the correct node and added some initialization checks. Here’s the updated version:

    “`python
    import openzwave.option
    import openzwave.network
    import time

    options = openzwave.option.ZWaveOption(“/dev/ttyUSB0″, config_path=”/path/to/openzwave/config”, user_path=”.”, cmd_line=””)
    options.lock()
    network = openzwave.network.ZWaveNetwork(options, log=None)

    network.start()

    for i in range(0, 300):
    if network.state >= network.STATE_AWAKED:
    break
    time.sleep(1)

    print(“Network state:”, network.state)

    door_sensor = None
    for node in network.nodes.values():
    print(f”Node {node.node_id}: {node}”)
    if node.product_name == “Your Door Sensor Product Name”:
    door_sensor = node
    break

    if door_sensor:
    try:
    door_status = door_sensor.get_sensor_binary_value()
    print(f”Door Status: {door_status}”)
    except Exception as e:
    print(f”Error reading door status: {e}”)
    else:
    print(“Door sensor not found”)

    network.stop()
    “`

CONTRIBUTE TO THIS THREAD

Leaderboard

RANKED BY XP

All time
  • 1.
    Avatar
    @Nayel115
    1620 XP
  • 2.
    Avatar
    @UcGee
    650 XP
  • 3.
    Avatar
    @melta101
    600 XP
  • 4.
    Avatar
    @lifegochi
    250 XP
  • 5.
    Avatar
    @Youuce
    180 XP
  • 6.
    Avatar
    @hemalchevli
    170 XP