Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Colin Reese
Here is the script:

https://github.com/iinnovations/iicontrollibs/blob/master/cupid/owfslib.py

And the calling script (see line 123)

https://github.com/iinnovations/iicontrollibs/blob/master/cupid/updateio.py

Everything in the first script is debugged to not do anything except 
print the id of the sensor. I just added in ow.finish(), although it's 
unclear whether this is necessary from the docs. I figured that this is 
cleanup that might automatically occur when the first script terminates, 
but perhaps does not for some reason when it is called externally. It's 
not as if they are being run in a loop, and I've commented out the 
second calling function, so only one ow.init and sensor read occurs for 
each run of updateio.py.

Colin



On 3/28/2014 09:00, Michael Markstaller wrote:
 Which busmaster(s) and owfs-Version are you using?

 Michael

 --
 ___
 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


Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Colin Reese
Well, this works, so it's something else in that calling script:

https://github.com/iinnovations/iicontrollibs/blob/master/cupid/mytest.py

On 3/28/2014 09:00, Michael Markstaller wrote:
 Which busmaster(s) and owfs-Version are you using?

 Michael

 --
 ___
 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


Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Colin Reese
2.9p1 and DS2483

It has been absolutely bulletproof up until now. Still is if I run the 
script as a standalone.

On 3/28/2014 09:00, Michael Markstaller wrote:
 Which busmaster(s) and owfs-Version are you using?

 Michael

 --
 ___
 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] ow Python makes sensors disappear

2014-03-28 Thread Colin Reese
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


Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Stefano Miccoli
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.64A34001/
 /26.2BA64001/
 /01.98408715/
  proxy.read('/26.64A34001/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 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


Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Colin Reese
I use owpython to connect to owserver:

ow.init('localhost:4304')

The reason (at the moment) is that owpython does everything I need to do 
and I've built code around it.

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.64A34001/
   /26.2BA64001/
   /01.98408715/
proxy.read('/26.64A34001/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


Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Michael Markstaller
Which busmaster(s) and owfs-Version are you using?

Michael

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


Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Colin Reese
Ok, this is truly bizarre.

I narrowed it down to the inclusion of a statement that does will cause 
ow.init to fail as described, even when the code is not run. The 
offensive statements were the creation of strings for sqlite queries, 
such as :

querylist.append('insert into inputs values(\'' + interface['id'] + 
'\',\'' + interface['interface'] + '\')')

Now, again, this code does not even execute and it causes ow.init fail. 
The code executes properly when I disable the section of code with 
ow.init in it, and if I replace the append line with:

print('insert into inputs values(\'' + interface['id'] + '\',\'' + 
interface['interface'] + '\')')

I get a nice print as expected. I've also tried this with double quotes 
rather than escaping the single quotes. Same result.

Here's the really interesting part. Each time I get ow fail, I have to 
reboot to get to a working state. From that working state, if I run the 
above print statement with the owfs functions disabled, it works fine. 
If I then run the owfs functions directly (not with the script 
containing the print statements), they fail.

Pass/fail detail:

OK:
print(interface['id'])
print('insert into inputs values(\' stuff \')')

NOT OK:
print('insert into inputs values(\'' + interface['id'] + '\')')

Once again - these functions do NOT execute but cause owpython read 
fail. How on earth is this possible?

Thanks,
Colin



On 3/28/2014 09:00, Michael Markstaller wrote:
 Which busmaster(s) and owfs-Version are you using?

 Michael

 --
 ___
 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


Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Colin Reese
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.64A34001/
   /26.2BA64001/
   /01.98408715/
proxy.read('/26.64A34001/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


Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Colin Reese
Ok, after becoming thoroughly annoyed with owpython, I wrote around 
pyownet. See the first three functions/classes. I did not install 
pyownet, but located it in a subdirectory. I will add sufficient 
attribution when I get a minute. Let me know what you think.

https://github.com/iinnovations/iicontrollibs/blob/master/cupid/owfslib.py

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.64A34001/
   /26.2BA64001/
   /01.98408715/
proxy.read('/26.64A34001/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


Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Colin Reese
And I've now successfully duplicated the error in pyownet:

  File /usr/lib/iicontrollibs/cupid/owfslib.py, line 27, in owbuslist
 for dir in OwnetProxy(host).dir():
   File /usr/lib/iicontrollibs/resource/pyownet/protocol.py, line 408, 
in dir
 raise OwnetError(-ret, self.errmess[-ret], path)
resource.pyownet.protocol.OwnetError: [Errno 5] legacy - IO error: '/'

What on earth is nuking the directory?

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.64A34001/
   /26.2BA64001/
   /01.98408715/
proxy.read('/26.64A34001/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


Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Stefano Miccoli
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.64A34001/
  /26.2BA64001/
  /01.98408715/
 proxy.read('/26.64A34001/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
 
 
 

Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Stefano Miccoli
I would avoid calls like

OwnetProxy(host).read(prop).strip()

you should reuse the proxy object between calls:

__init__(self, )
self.proxy = OwnetProxy(host)

def method(self, ...)
self.proxy.read(prop).strip()

There is a cost in creating the proxy object, but no significant resource is 
associated with storing this object. I'm not 100% sure, but my code should be 
thread safe, so you can store a single proxy object for each owserver you 
query, and share it among different threads.

Stefano

On 28 Mar 2014, at 22:09, Colin Reese colin.re...@gmail.com wrote:

 Ok, after becoming thoroughly annoyed with owpython, I wrote around 
 pyownet. See the first three functions/classes. I did not install 
 pyownet, but located it in a subdirectory. I will add sufficient 
 attribution when I get a minute. Let me know what you think.
 
 https://github.com/iinnovations/iicontrollibs/blob/master/cupid/owfslib.py
 
 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.64A34001/
  /26.2BA64001/
  /01.98408715/
 proxy.read('/26.64A34001/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

Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Colin Reese
Got it. Fixed within functions/methods. I'll look at passing the 
reference around later.

On 3/28/2014 14:42, Stefano Miccoli wrote:
 I would avoid calls like

 OwnetProxy(host).read(prop).strip()

 you should reuse the proxy object between calls:

 __init__(self, )
  self.proxy = OwnetProxy(host)

 def method(self, ...)
 self.proxy.read(prop).strip()

 There is a cost in creating the proxy object, but no significant
 resource is associated with storing this object. I'm not 100% sure, but
 my code should be thread safe, so you can store a single proxy object
 for each owserver you query, and share it among different threads.

 Stefano

 On 28 Mar 2014, at 22:09, Colin Reese colin.re...@gmail.com
 mailto:colin.re...@gmail.com wrote:

 Ok, after becoming thoroughly annoyed with owpython, I wrote around
 pyownet. See the first three functions/classes. I did not install
 pyownet, but located it in a subdirectory. I will add sufficient
 attribution when I get a minute. Let me know what you think.

 https://github.com/iinnovations/iicontrollibs/blob/master/cupid/owfslib.py

 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.64A34001/
  /26.2BA64001/
  /01.98408715/
 proxy.read('/26.64A34001/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
 mailto:Owfs-developers@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/owfs-developers



 --



 

Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Stefano Miccoli
This error is entirely on the owserver side... owpython and the friends seem 
not to be responsible.

 pyownet.protocol.OwnetError

exceptions are raised when the remote owserver answers with an error code, in 
this case -5, that according to

owserver --help=error

is

  5. legacy - IO error

you shoud inspect the owserver code to find out.

Stefano

On 28 Mar 2014, at 22:23, Colin Reese colin.re...@gmail.com wrote:

 And I've now successfully duplicated the error in pyownet:
 
  File /usr/lib/iicontrollibs/cupid/owfslib.py, line 27, in owbuslist
 for dir in OwnetProxy(host).dir():
   File /usr/lib/iicontrollibs/resource/pyownet/protocol.py, line 408, 
 in dir
 raise OwnetError(-ret, self.errmess[-ret], path)
 resource.pyownet.protocol.OwnetError: [Errno 5] legacy - IO error: '/'
 
 What on earth is nuking the directory?
 
 Colin

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


Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Colin Reese
I've no idea where to even start on this.


On 3/28/2014 14:49, Stefano Miccoli wrote:
 This error is entirely on the owserver side... owpython and the friends
 seem not to be responsible.

 pyownet.protocol.OwnetError

 exceptions are raised when the remote owserver answers with an error
 code, in this case -5, that according to

 owserver --help=error

 is

5. legacy - IO error

 you shoud inspect the owserver code to find out.

 Stefano

 On 28 Mar 2014, at 22:23, Colin Reese colin.re...@gmail.com
 mailto:colin.re...@gmail.com wrote:

 And I've now successfully duplicated the error in pyownet:

  File /usr/lib/iicontrollibs/cupid/owfslib.py, line 27, in owbuslist
 for dir in OwnetProxy(host).dir():
   File /usr/lib/iicontrollibs/resource/pyownet/protocol.py, line 408,
 in dir
 raise OwnetError(-ret, self.errmess[-ret], path)
 resource.pyownet.protocol.OwnetError: [Errno 5] legacy - IO error: '/'

 What on earth is nuking the directory?

 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


Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Stefano Miccoli
Try running 

owserver --debug

and watch for error messages.

S.

On 28 Mar 2014, at 23:33, Colin Reese colin.re...@gmail.com wrote:

 I've no idea where to even start on this.
 
 
 On 3/28/2014 14:49, Stefano Miccoli wrote:
 This error is entirely on the owserver side... owpython and the friends
 seem not to be responsible.
 
 pyownet.protocol.OwnetError
 
 exceptions are raised when the remote owserver answers with an error
 code, in this case -5, that according to
 
 owserver --help=error
 
 is
 
   5. legacy - IO error
 
 you shoud inspect the owserver code to find out.
 
 Stefano
 
 On 28 Mar 2014, at 22:23, Colin Reese colin.re...@gmail.com
 mailto:colin.re...@gmail.com wrote:
 
 And I've now successfully duplicated the error in pyownet:
 
 File /usr/lib/iicontrollibs/cupid/owfslib.py, line 27, in owbuslist
for dir in OwnetProxy(host).dir():
  File /usr/lib/iicontrollibs/resource/pyownet/protocol.py, line 408,
 in dir
raise OwnetError(-ret, self.errmess[-ret], path)
 resource.pyownet.protocol.OwnetError: [Errno 5] legacy - IO error: '/'
 
 What on earth is nuking the directory?
 
 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


Re: [Owfs-developers] ow Python makes sensors disappear

2014-03-28 Thread Colin Reese
and ... drum roll ... the answer was to remove all double quotes from 
sqlite query preparation statements in the calling script, escaping 
included single quotes.

I don't understand it, but it fixed it.

Colin




On 3/28/2014 15:55, Stefano Miccoli wrote:
 Try running

 owserver --debug

 and watch for error messages.

 S.

 On 28 Mar 2014, at 23:33, Colin Reese colin.re...@gmail.com
 mailto:colin.re...@gmail.com wrote:

 I've no idea where to even start on this.


 On 3/28/2014 14:49, Stefano Miccoli wrote:
 This error is entirely on the owserver side... owpython and the friends
 seem not to be responsible.

 pyownet.protocol.OwnetError

 exceptions are raised when the remote owserver answers with an error
 code, in this case -5, that according to

 owserver --help=error

 is

   5. legacy - IO error

 you shoud inspect the owserver code to find out.

 Stefano

 On 28 Mar 2014, at 22:23, Colin Reese colin.re...@gmail.com
 mailto:colin.re...@gmail.com
 mailto:colin.re...@gmail.com wrote:

 And I've now successfully duplicated the error in pyownet:

 File /usr/lib/iicontrollibs/cupid/owfslib.py, line 27, in owbuslist
for dir in OwnetProxy(host).dir():
  File /usr/lib/iicontrollibs/resource/pyownet/protocol.py, line 408,
 in dir
raise OwnetError(-ret, self.errmess[-ret], path)
 resource.pyownet.protocol.OwnetError: [Errno 5] legacy - IO error: '/'

 What on earth is nuking the directory?

 Colin



 --



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


 --
 ___
 Owfs-developers mailing list
 Owfs-developers@lists.sourceforge.net
 mailto: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