Changing Alias with pyownet

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Changing Alias with pyownet

Mick Sulley
Stefano,
I took your ex.py and modified it slightly to use a variable as the base
device name -

==========================
import sys
import time
import pyownet.protocol

TIMEOUT = 10

def main():

     timeout_time = time.time() + TIMEOUT
     while time.time() < timeout_time:
         try:
             owp = pyownet.protocol.proxy()
         except pyownet.protocol.ConnError:
             time.sleep(1)
         else:
             break
     else:
         # Error! creation of owp has timed out
         sys.exit('Unable to open connection to owserver')
     # Success! we have a connection to owserver
     assert owp.present('/')

     name = 'sensor'

     for i, sens in enumerate(owp.dir()):
         print 'i = ',  i,  ' sens = ',  sens
         owp.write(sens+'alias', name + '%d' % i)

     for j in range(i):
         assert owp.present(name + '%d' % j)

     for f in owp.dir():
         print 'f = ',  f

if __name__ == '__main__':
     main()
==========================

I have tested this and it works, but if I change line 23 to
name = 'Xsensor'
and run it again I get

$ ./ex.py
i =  0  sens =  /sensor0/
i =  1  sens =  /sensor1/
Traceback (most recent call last):
   File "./ex.py", line 39, in <module>
     main()
   File "./ex.py", line 30, in main
     owp.write(sens+'alias', name + '%d' % i)
   File "/usr/local/lib/python2.7/dist-packages/pyownet/protocol.py",
line 636, in write
     raise OwnetError(-ret, self.errmess[-ret], path)
pyownet.protocol.OwnetError: [Errno 1] Startup - command line parameters
invalid: u'/sensor1/alias'

Is there some reason why I cannot change an alias a second time? Have I
done something stupid?

Thanks
Mick

------------------------------------------------------------------------------
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers
Reply | Threaded
Open this post in threaded view
|

Re: Changing Alias with pyownet

Stefano Miccoli
From the python point of view it’s OK…

I think it’s an owserver bug (or feature, I do not know  ;-) since I have your very same behaviour.

S

> On 08 Sep 2016, at 00:03, Mick Sulley <[hidden email]> wrote:
>
> Stefano,
> I took your ex.py and modified it slightly to use a variable as the base
> device name -
>
> ==========================
> import sys
> import time
> import pyownet.protocol
>
> TIMEOUT = 10
>
> def main():
>
>     timeout_time = time.time() + TIMEOUT
>     while time.time() < timeout_time:
>         try:
>             owp = pyownet.protocol.proxy()
>         except pyownet.protocol.ConnError:
>             time.sleep(1)
>         else:
>             break
>     else:
>         # Error! creation of owp has timed out
>         sys.exit('Unable to open connection to owserver')
>     # Success! we have a connection to owserver
>     assert owp.present('/')
>
>     name = 'sensor'
>
>     for i, sens in enumerate(owp.dir()):
>         print 'i = ',  i,  ' sens = ',  sens
>         owp.write(sens+'alias', name + '%d' % i)
>
>     for j in range(i):
>         assert owp.present(name + '%d' % j)
>
>     for f in owp.dir():
>         print 'f = ',  f
>
> if __name__ == '__main__':
>     main()
> ==========================
>
> I have tested this and it works, but if I change line 23 to
> name = 'Xsensor'
> and run it again I get
>
> $ ./ex.py
> i =  0  sens =  /sensor0/
> i =  1  sens =  /sensor1/
> Traceback (most recent call last):
>   File "./ex.py", line 39, in <module>
>     main()
>   File "./ex.py", line 30, in main
>     owp.write(sens+'alias', name + '%d' % i)
>   File "/usr/local/lib/python2.7/dist-packages/pyownet/protocol.py",
> line 636, in write
>     raise OwnetError(-ret, self.errmess[-ret], path)
> pyownet.protocol.OwnetError: [Errno 1] Startup - command line parameters
> invalid: u'/sensor1/alias'
>
> Is there some reason why I cannot change an alias a second time? Have I
> done something stupid?
>
> Thanks
> Mick
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Owfs-developers mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/owfs-developers


------------------------------------------------------------------------------
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers
Reply | Threaded
Open this post in threaded view
|

Re: Changing Alias with pyownet

Mick Sulley
Well it's reassuring to know that it is not just me :)

I have been testing some more and with multiple devices it seems to
rename some and then fail part way through.  I have code that list all
of the devices, the fields and their values.  If I run that after a
rename failure that fails as well.

Now that I know about it I can work around it.

Thanks

Mick


On 08/09/16 15:42, Stefano Miccoli wrote:

>  From the python point of view it’s OK…
>
> I think it’s an owserver bug (or feature, I do not know  ;-) since I have your very same behaviour.
>
> S
>
>> On 08 Sep 2016, at 00:03, Mick Sulley <[hidden email]> wrote:
>>
>> Stefano,
>> I took your ex.py and modified it slightly to use a variable as the base
>> device name -
>>
>> ==========================
>> import sys
>> import time
>> import pyownet.protocol
>>
>> TIMEOUT = 10
>>
>> def main():
>>
>>      timeout_time = time.time() + TIMEOUT
>>      while time.time() < timeout_time:
>>          try:
>>              owp = pyownet.protocol.proxy()
>>          except pyownet.protocol.ConnError:
>>              time.sleep(1)
>>          else:
>>              break
>>      else:
>>          # Error! creation of owp has timed out
>>          sys.exit('Unable to open connection to owserver')
>>      # Success! we have a connection to owserver
>>      assert owp.present('/')
>>
>>      name = 'sensor'
>>
>>      for i, sens in enumerate(owp.dir()):
>>          print 'i = ',  i,  ' sens = ',  sens
>>          owp.write(sens+'alias', name + '%d' % i)
>>
>>      for j in range(i):
>>          assert owp.present(name + '%d' % j)
>>
>>      for f in owp.dir():
>>          print 'f = ',  f
>>
>> if __name__ == '__main__':
>>      main()
>> ==========================
>>
>> I have tested this and it works, but if I change line 23 to
>> name = 'Xsensor'
>> and run it again I get
>>
>> $ ./ex.py
>> i =  0  sens =  /sensor0/
>> i =  1  sens =  /sensor1/
>> Traceback (most recent call last):
>>    File "./ex.py", line 39, in <module>
>>      main()
>>    File "./ex.py", line 30, in main
>>      owp.write(sens+'alias', name + '%d' % i)
>>    File "/usr/local/lib/python2.7/dist-packages/pyownet/protocol.py",
>> line 636, in write
>>      raise OwnetError(-ret, self.errmess[-ret], path)
>> pyownet.protocol.OwnetError: [Errno 1] Startup - command line parameters
>> invalid: u'/sensor1/alias'
>>
>> Is there some reason why I cannot change an alias a second time? Have I
>> done something stupid?
>>
>> Thanks
>> Mick
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Owfs-developers mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/owfs-developers
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Owfs-developers mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/owfs-developers


------------------------------------------------------------------------------
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers