File: example.py

package info (click to toggle)
python-onewire 0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 104 kB
  • sloc: python: 121; ansic: 73; makefile: 6
file content (17 lines) | stat: -rw-r--r-- 581 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from onewire import Onewire

# Use USB-adapter
with Onewire('u') as o:

    # Find all temperature sensors in the bus, and print family, id and temperature as float.
    print('\n'.join([
        '%s.%s %.02f' % (s.family, s.id, s.read_float('temperature'))
        for s in o.find(has_all=['temperature'])
    ]))

    # Read temperature from specific sensor
    # (note: when accessing values directly, the return value is always a string).
    print(o.sensor('28.D035DE060000').temperature)

    # Find all DS18B20 -sensors
    print([s for s in o.find(sensor_type='DS18B20')])