The following code (and the output from it) is to summarize my initial 
findings using Marcus Priesch's pyowfs library. It may help someone who 
wants to quickly evaluate this library and avoid some of the pitfalls I 
fell into. The most significant for me was how to locate a sensor based 
on the sensor's UUID without having to iterate and parse. [I intend to 
have multiple sensors of the same type in my application. Each one 
measures a different temperature and to access these different 
temperatures unambiguously I need to locate the specific sensor by 
UUID]. Thanks again Marcus for helping me sort this out.

Joe P.

-------- Code Start ----------

#! /usr/bin/env python

"""
Sample code to illustrate basic read operations using the pyowfs library

"""


from pyowfs import Connection

# Stage 1 - Connect to OWSERVER

root = Connection ("localhost:4304")

# Stage 2 - Access the 1-wire information

print "List of all devices present"
for s in root.find () : print s # This lists all the devices available 
on the bus.

print "This also is a listing of all devices present"
for i in root.iter_sensors () :
     print i

print "List of devices of type DS18B20 (a temperature sensor)"
s = root.find (type = "DS18B20")
print s

print 'Assigning DS18B20 Sensors ...'
s0 = root.find (type = "DS18B20")[0]
s1 = root.find (type = "DS18B20")[1]

print "Sensor 0:"
print s0
print "Temperature from Sensor 0:"
print s0.get("temperature")

print "Sensor 1:"
print s1
print "Temperature from Sensor 1:"
print s1.get("temperature")

print "Selecting a sensor by ID (F758DC020000)"
"""
NOTE
     The ID of a sensor does not include the characters before the 
decimal point
     (28 in this case) and the decimal point itself.
"""
s = root.find (id="F758DC020000") [0]
temp = s.get ("temperature")
print "Printing Temp from F758DC020000..."
print temp

print 'List One-wire filesystem content under the root node ...'
for e in root.iter_entries () : print e

print 'List One-wire filesystem content under the bus.0 directory ...'
for f in root.get ("bus.0").iter_entries () : print f
print 'List One-wire filesystem content under the bus.0\interface 
directory ...'
for g in root.get ("bus.0").get("interface").iter_entries () : print g
" ... etc. ..."

print "End of Program"

----------- End of Code -----------

-------- Output Start --------

pi@raspberrypi ~/MyFiles/OWFS/code $ ./temperature_pyowfs_3.py
List of all devices present
<Sensor /28.450EDC020000/ - DS18B20>
<Sensor /28.F758DC020000/ - DS18B20>
<Sensor /81.A7D12F000000/ - DS1420>
This also is a listing of all devices present
<Sensor /28.450EDC020000/ - DS18B20>
<Sensor /28.F758DC020000/ - DS18B20>
<Sensor /81.A7D12F000000/ - DS1420>
List of devices of type DS18B20 (a temperature sensor)
[<Sensor /28.450EDC020000/ - DS18B20>, <Sensor /28.F758DC020000/ - DS18B20>]
Assigning DS18B20 Sensors ...
Sensor 0:
<Sensor /28.450EDC020000/ - DS18B20>
Temperature from Sensor 0:
      21.8125
Sensor 1:
<Sensor /28.F758DC020000/ - DS18B20>
Temperature from Sensor 1:
      21.6875
Selecting a sensor by ID (F758DC020000)
Printing Temp from F758DC020000...
      21.6875
List One-wire filesystem content under the root node ...
<Dir '/bus.0/'>
<Dir '/uncached/'>
<Dir '/settings/'>
<Dir '/system/'>
<Dir '/statistics/'>
<Dir '/structure/'>
<Dir '/simultaneous/'>
<Dir '/alarm/'>
List One-wire filesystem content under the bus.0 directory ...
<Dir '/bus.0/interface/'>
<Dir '/bus.0/bus.0/'>
<Dir '/bus.0/uncached/'>
<Dir '/bus.0/settings/'>
<Dir '/bus.0/system/'>
<Dir '/bus.0/statistics/'>
<Dir '/bus.0/structure/'>
<Dir '/bus.0/simultaneous/'>
<Dir '/bus.0/alarm/'>
List One-wire filesystem content under the bus.0\interface directory ...
<Dir '/bus.0/interface/settings/'>
<Dir '/bus.0/interface/statistics/'>
End of Program

-------- Output End --------

-- 
Regards
Joe P.


------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Owfs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/owfs-developers

Reply via email to