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