Yes you are right:

while there is some experimental code that implements the idea of a "sensor" 
with attributes corresponding to values 
<https://github.com/miccoli/pyownet/tree/sensors> this is still very 
experimental.

Nevertheless the low level approach is not so much different:

from pyownet.protocol import OwnetProxy
proxy = OwnetProxy(host='localhost', port=4304)

props = ['address', 'family', 'id', 'type', 'crc8']
for sensor in proxy.dir():
        arg = [proxy.read(sensor+p) for p in props]
        querylist.append(
            pilib.makesqliteinsert(tablename, arg))

btw I have to confess that i prefer the explicit call to the the method 
(proxy.read(sens+p), instead of the implicit attribute lookup sensor.p)

Stefano

On 28 Mar 2014, at 20:07, Colin Reese <colin.re...@gmail.com> wrote:

> Stefano,
> 
> For me, this is all I need to list all my sensors, and have a similar 
> routine to read values:
> 
>     import ow
>     import pilib
>     querylist = []
>     ow.init('localhost:4304')
>     sensorlist = ow.Sensor('/').sensorList()
>     for sensor in sensorlist:
>         querylist.append(
>             pilib.makesqliteinsert(tablename, [sensor.address, 
> sensor.family, sensor.id, sensor.type, sensor.crc8]))
>     pilib.sqlitemultquery(database, querylist)
> 
> From what I can see of pyownet, I would have to write significantly 
> more code to get the same result. If I'm mistaken, please let me know.
> 
> Colin
> 
> 
> On 3/28/2014 10:57, Stefano Miccoli wrote:
>> Is there a reason for using ow (which is a SWIG binding of the owlib C
>> API) and not ownet (which is a pure python implementation of the ownet
>> protocol)?
>> 
>> If you do not have to access the bus master directly from python but you
>> have an owserver running, I would suggest using instead ownet, or even
>> better (shameless self promotion) my own pyownet.
>> 
>> pyownet is on pypi, so to install it you can just
>> 
>> # pip install pyownet
>> 
>> or if you prefer the source you can get it from
>> 
>> https://github.com/miccoli/pyownet/releases/latest
>> 
>> and run
>> 
>> # python setup.py install
>> 
>> If you have an owserver running on localhost minimal instructions are
>> 
>>>>> from pyownet.protocol import OwnetProxy
>>>>> proxy = OwnetProxy()
>>>>> for i in proxy.dir():
>>  ...     print i
>>  ...
>>  /26.64A340010000/
>>  /26.2BA640010000/
>>  /01.984087150000/
>>>>> proxy.read('/26.64A340010000/temperature')
>>  '     20.6562'
>>>>> 
>> 
>> The proxy object acts as (you guess) a proxy for the owserver, with
>> methods that implement the following ownet messages:
>> 
>> dir
>> ping
>> present
>> read
>> write
>> 
>> Docs are still to be written but
>> 
>>>>> help(OwnetProxy)
>> 
>> is a good starting point.
>> 
>> Stefano
>> 
>> 
>> On 28 Mar 2014, at 16:38, Colin Reese <colin.re...@gmail.com
>> <mailto:colin.re...@gmail.com>> wrote:
>> 
>>> Hell all,
>>> 
>>> I've run into an interesting error that results in sensors disappearing
>>> altogether, resulting in the error:
>>> 
>>> File "/usr/lib/python2.7/dist-packages/ow/__init__.py", line 271, in
>>> __init__
>>>    self.useCache( self._useCache )
>>>  File "/usr/lib/python2.7/dist-packages/ow/__init__.py", line 417, in
>>> useCache
>>>    for n in owfs_get( self._usePath ).split( ',' ) ] )
>>>  File "/usr/lib/python2.7/dist-packages/ow/__init__.py", line 159, in
>>> _get
>>>    raise exUnknownSensor(path)
>>> ow.exUnknownSensor: '/'
>>> 
>>> 
>>> Sure enough, my 1Wire directory is empty except the bus. Killing owfs,
>>> owserver and owhttpd and attempting to restart using the same commands I
>>> do at startup yields:
>>> 
>>> DEFAULT: owlib.c:(56) No valid 1-wire buses found
>>> 
>>> After rebooting, everything is fine again, until I run the questionable
>>> script. So the first question is how to reinitialize after fail without
>>> rebooting. The next is how to not have it fail in the first place. I see
>>> mention here, but no solution:
>>> http://owfs-developers.1086194.n5.nabble.com/Bug-in-re-init-ing-Python-ow-module-td4442.html
>>> 
>>> 
>>> What I'm using in owpython is pretty basic, and trimming out other code
>>> is really:
>>> 
>>> import ow
>>> ow.init('localhost:4304')
>>> for sensor in ow.Sensor('/').sensorList():
>>> # do stuff
>>> 
>>> Interestingly, if I have this in a function like:
>>> 
>>> def myowfsfun(args):
>>>   ow.init('localhost:4304')
>>>   for sensor in ow.Sensor('/').sensorList():
>>> #do stuff
>>> 
>>> if __name__ == "__main__":
>>>    myowfsfun(args)
>>> 
>>> 
>>> I can run the function via the script file until the cows come home. If
>>> I import it into another script, e.g.:
>>> 
>>> import owfslib
>>> 
>>> owfslib.myowfsfun(args)
>>> 
>>> and then run that script, it barfs immediately.
>>> 
>>> Ideas?
>>> 
>>> Thanks,
>>> Colin
>>> 
>>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> Owfs-developers mailing list
>>> Owfs-developers@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/owfs-developers
>> 
>> 
>> 
>> ------------------------------------------------------------------------------
>> 
>> 
>> 
>> _______________________________________________
>> Owfs-developers mailing list
>> Owfs-developers@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/owfs-developers
>> 
> 
> ------------------------------------------------------------------------------
> _______________________________________________
> Owfs-developers mailing list
> Owfs-developers@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/owfs-developers

------------------------------------------------------------------------------
_______________________________________________
Owfs-developers mailing list
Owfs-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/owfs-developers

Reply via email to