Couple of Questions

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

Couple of Questions

Mick Sulley
Still trying to transition from using owfs to ow-shell and I have a
couple of questions -

When owserver is installed from the repository it should start
automatically at boot and will read /etc/owfs.conf to configure it, but
if I run "service owserver restart" will it read /etc/owfs.conf again?  
I am guessing yes but would like confirmation as I may need to update
that file at boot then restart owserver.

If I have it installed from the repository and also installed manually
to /opt/owfs will that cause any problems?  OK I know it is not a good
idea, but my original system was installed manually and I cannot remove
it until I have the new version running successfully.

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: Couple of Questions

Stefano Miccoli

> On 30 Aug 2016, at 23:31, Mick Sulley <[hidden email]> wrote:
>
> Still trying to transition from using owfs to ow-shell and I have a
> couple of questions -
>
> When owserver is installed from the repository it should start
> automatically at boot and will read /etc/owfs.conf to configure it, but
> if I run "service owserver restart" will it read /etc/owfs.conf again?  
> I am guessing yes but would like confirmation as I may need to update
> that file at boot then restart owserver.

Yes, init.d scripts with the “restart" argument should stop and start the process. You can check by running

$ owread /system/process/pid

before and after the restart: the pid number should change: new process, new config file.

> If I have it installed from the repository and also installed manually
> to /opt/owfs will that cause any problems?  OK I know it is not a good
> idea, but my original system was installed manually and I cannot remove
> it until I have the new version running successfully.

No problem, provided you didn’t change the default search paths for executables and dynamic libraries.
Just to double check, run

$ lsof -p $(owread /system/process/pid)

to confirm that the owserver does not uses executables or libraries in /opt/owfs

Stefano


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

Re: Couple of Questions

Mick Sulley
I think I still have a problem here.  If I reboot owserver does not
start, I thought it should.  My owfs.conf file contains

============================================
# All owfs programs but owserver should connect to a running owserver.
! server: server = localhost:4304
# this is setting for a Raspberry Pi v2 onwards, early models should be
# server: device=/dev/i2c-0
server: device=/dev/i2c-1
# The port owhttpd listens for browser connections on 2121 (default anyway)
http: port = 2121
--alias = /home/control/solar/v11_0/sensor_list
============================================

$ owserver
does nothing
$ owserver -d /dev/i2c-1
starts the server
$ service owserver restart
returns "Failed to restart owserver.service: Access denied"
$ sudo service owserver restart
stops the server
$ owserver -c /etc/owfs.conf
does nothing

Makes me think there is something wrong with my owfs.conf file
Any suggestions?

Thanks
Mick

On 31/08/16 09:29, Stefano Miccoli wrote:

>> On 30 Aug 2016, at 23:31, Mick Sulley <[hidden email]> wrote:
>>
>> Still trying to transition from using owfs to ow-shell and I have a
>> couple of questions -
>>
>> When owserver is installed from the repository it should start
>> automatically at boot and will read /etc/owfs.conf to configure it, but
>> if I run "service owserver restart" will it read /etc/owfs.conf again?
>> I am guessing yes but would like confirmation as I may need to update
>> that file at boot then restart owserver.
> Yes, init.d scripts with the “restart" argument should stop and start the process. You can check by running
>
> $ owread /system/process/pid
>
> before and after the restart: the pid number should change: new process, new config file.
>
>> If I have it installed from the repository and also installed manually
>> to /opt/owfs will that cause any problems?  OK I know it is not a good
>> idea, but my original system was installed manually and I cannot remove
>> it until I have the new version running successfully.
> No problem, provided you didn’t change the default search paths for executables and dynamic libraries.
> Just to double check, run
>
> $ lsof -p $(owread /system/process/pid)
>
> to confirm that the owserver does not uses executables or libraries in /opt/owfs
>
> Stefano
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> 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: Couple of Questions

Jan Kandziora
Am 31.08.2016 um 22:28 schrieb Mick Sulley:
> I think I still have a problem here.  If I reboot owserver does not
> start, I thought it should.  My owfs.conf file contains
>
Contains? Or *is*?


> ============================================
> # All owfs programs but owserver should connect to a running owserver.
> ! server: server = localhost:4304
> # this is setting for a Raspberry Pi v2 onwards, early models should be
> # server: device=/dev/i2c-0
> # The port owhttpd listens for browser connections on 2121 (default anyway)
> http: port = 2121
> --alias = /home/control/solar/v11_0/sensor_list
> ============================================
>
Use this one to check
=================================
! server: server = localhost:4304
server: device=/dev/i2c-1
=================================



> $ owserver
> does nothing
>
It should exit immediately because no host adaptor was given.


> $ owserver -d /dev/i2c-1
> starts the server
> $ service owserver restart
> returns "Failed to restart owserver.service: Access denied"
> $ sudo service owserver restart
> stops the server
> $ owserver -c /etc/owfs.conf
> does nothing
>
Really? Start it with --debug and give us the log. If you don't start
with --debug, owserver runs in background automatically. No log then.


Kind regards

        Jan


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

Re: Couple of Questions

Stefano Miccoli
In reply to this post by Mick Sulley

On 31 Aug 2016, at 22:28, Mick Sulley <[hidden email]> wrote:

$ owserver
does nothing
$ owserver -d /dev/i2c-1
starts the server
$ service owserver restart
returns "Failed to restart owserver.service: Access denied"
$ sudo service owserver restart
stops the server
$ owserver -c /etc/owfs.conf
does nothing

Sounds a lot like permission problems. 

First, which distro are you using? I will assume you are on raspbian/jessie, but let us know if this is not true.

Debian/jessie is systemd based, so please forget about “service XXX start|stop|restart” and use “systemctl start|stop|restart XXX.service”

  • Check permissions of /dev/i2c-1:

$ ls -l /dev/i2c-1 
crw------- 1 root root 89, 1 Sep  1 09:16 /dev/i2c-1

  • enable owserver at boot

$ sudo systemctl enable owserver.service
Synchronizing state for owserver.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d owserver defaults
insserv: warning: current start runlevel(s) (empty) of script `owserver' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `owserver' overrides LSB defaults (0 1 6).
Executing /usr/sbin/update-rc.d owserver enable

  • to stop/start/restart

$ sudo systemctl stop owserver.service
$ sudo systemctl start owserver.service
$ sudo systemctl restart owserver.service

  • to check status

$ sudo systemctl status owserver.service
owserver.service - LSB: 1-wire TCP server
   Loaded: loaded (/etc/init.d/owserver)
   Active: active (running) since Thu 2016-09-01 09:35:12 CEST; 3s ago
  Process: 797 ExecStop=/etc/init.d/owserver stop (code=exited, status=0/SUCCESS)
  Process: 805 ExecStart=/etc/init.d/owserver start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/owserver.service
           └─809 /usr/bin/owserver -c /etc/owfs.conf --pid-file /var/run/owfs...


Try these commands (as root or with sudo) and see if systemctl records some useful info with

$ sudo journalctl -u owserver.service

Hope this helps

S.

PS:

I just noticed that the LSB scripts in raspbian/jessie are bugged: they return with a success status even if owserver failed to start… So do not trust to much systemctl status, but always check if the owserver process is really running.

------------------------------------------------------------------------------

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

Re: Couple of Questions

Nigel Titley

This sounds a lot like my problem with raspbian... which I've still not sorted.

Nigel


On 01/09/16 08:56, Stefano Miccoli wrote:

On 31 Aug 2016, at 22:28, Mick Sulley <[hidden email]> wrote:

$ owserver
does nothing
$ owserver -d /dev/i2c-1
starts the server
$ service owserver restart
returns "Failed to restart owserver.service: Access denied"
$ sudo service owserver restart
stops the server
$ owserver -c /etc/owfs.conf
does nothing

Sounds a lot like permission problems. 

First, which distro are you using? I will assume you are on raspbian/jessie, but let us know if this is not true.

Debian/jessie is systemd based, so please forget about “service XXX start|stop|restart” and use “systemctl start|stop|restart XXX.service”

  • Check permissions of /dev/i2c-1:

$ ls -l /dev/i2c-1 
crw------- 1 root root 89, 1 Sep  1 09:16 /dev/i2c-1

  • enable owserver at boot

$ sudo systemctl enable owserver.service
Synchronizing state for owserver.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d owserver defaults
insserv: warning: current start runlevel(s) (empty) of script `owserver' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `owserver' overrides LSB defaults (0 1 6).
Executing /usr/sbin/update-rc.d owserver enable

  • to stop/start/restart

$ sudo systemctl stop owserver.service
$ sudo systemctl start owserver.service
$ sudo systemctl restart owserver.service

  • to check status

$ sudo systemctl status owserver.service
owserver.service - LSB: 1-wire TCP server
   Loaded: loaded (/etc/init.d/owserver)
   Active: active (running) since Thu 2016-09-01 09:35:12 CEST; 3s ago
  Process: 797 ExecStop=/etc/init.d/owserver stop (code=exited, status=0/SUCCESS)
  Process: 805 ExecStart=/etc/init.d/owserver start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/owserver.service
           └─809 /usr/bin/owserver -c /etc/owfs.conf --pid-file /var/run/owfs...


Try these commands (as root or with sudo) and see if systemctl records some useful info with

$ sudo journalctl -u owserver.service

Hope this helps

S.

PS:

I just noticed that the LSB scripts in raspbian/jessie are bugged: they return with a success status even if owserver failed to start… So do not trust to much systemctl status, but always check if the owserver process is really running.


------------------------------------------------------------------------------


_______________________________________________
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: Couple of Questions

Mick Sulley

I am still in the process of converting my existing software, there have been many changes and even with the best intentions I don't think I have recorded them all, so once it is all sorted I intend to start again with a blank SD card, set it all up from scratch and make sure that I have a record of everything that I have done.  It is not just owfs, there are several other components as well, but I will share the results when complete.

One thing I have found following the mails from Stefano an Jan -

$ ls -l /dev/i2c-1
crw-rw---- 1 root i2c 89, 1 Aug 31 21:38 /dev/i2c-1

$ sudo systemctl status owserver.service
● owserver.service - Backend server for 1-wire control
   Loaded: loaded (/lib/systemd/system/owserver.service; enabled)
   Active: inactive (dead)
     Docs: <a class="moz-txt-link-freetext" href="man:owserver(1)">man:owserver(1)

My user was not a member of the i2c group so I added it and rebooted, now get

$  sudo systemctl status owserver.service
[sudo] password for control:
● owserver.service - Backend server for 1-wire control
   Loaded: loaded (/lib/systemd/system/owserver.service; enabled)
   Active: active (running) since Thu 2016-09-01 09:39:46 BST; 10min ago
     Docs: <a class="moz-txt-link-freetext" href="man:owserver(1)">man:owserver(1)
 Main PID: 1297 (owserver)
   CGroup: /system.slice/owserver.service
           └─1297 /opt/owfs/bin/owserver --w1

Sep 01 09:39:46 pi-solar systemd[1]: Started Backend server for 1-wire control.
Hint: Some lines were ellipsized, use -l to show in full.

which looks much better!  My work continues.......

Mick


On 01/09/16 18:13, Nigel Titley wrote:

This sounds a lot like my problem with raspbian... which I've still not sorted.

Nigel


On 01/09/16 08:56, Stefano Miccoli wrote:

On 31 Aug 2016, at 22:28, Mick Sulley <[hidden email]> wrote:

$ owserver
does nothing
$ owserver -d /dev/i2c-1
starts the server
$ service owserver restart
returns "Failed to restart owserver.service: Access denied"
$ sudo service owserver restart
stops the server
$ owserver -c /etc/owfs.conf
does nothing

Sounds a lot like permission problems. 

First, which distro are you using? I will assume you are on raspbian/jessie, but let us know if this is not true.

Debian/jessie is systemd based, so please forget about “service XXX start|stop|restart” and use “systemctl start|stop|restart XXX.service”

  • Check permissions of /dev/i2c-1:

$ ls -l /dev/i2c-1 
crw------- 1 root root 89, 1 Sep  1 09:16 /dev/i2c-1

  • enable owserver at boot

$ sudo systemctl enable owserver.service
Synchronizing state for owserver.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d owserver defaults
insserv: warning: current start runlevel(s) (empty) of script `owserver' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `owserver' overrides LSB defaults (0 1 6).
Executing /usr/sbin/update-rc.d owserver enable

  • to stop/start/restart

$ sudo systemctl stop owserver.service
$ sudo systemctl start owserver.service
$ sudo systemctl restart owserver.service

  • to check status

$ sudo systemctl status owserver.service
owserver.service - LSB: 1-wire TCP server
   Loaded: loaded (/etc/init.d/owserver)
   Active: active (running) since Thu 2016-09-01 09:35:12 CEST; 3s ago
  Process: 797 ExecStop=/etc/init.d/owserver stop (code=exited, status=0/SUCCESS)
  Process: 805 ExecStart=/etc/init.d/owserver start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/owserver.service
           └─809 /usr/bin/owserver -c /etc/owfs.conf --pid-file /var/run/owfs...


Try these commands (as root or with sudo) and see if systemctl records some useful info with

$ sudo journalctl -u owserver.service

Hope this helps

S.

PS:

I just noticed that the LSB scripts in raspbian/jessie are bugged: they return with a success status even if owserver failed to start… So do not trust to much systemctl status, but always check if the owserver process is really running.


------------------------------------------------------------------------------


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Couple of Questions

Jan Kandziora
Am 01.09.2016 um 20:43 schrieb Mick Sulley:

>
> $  sudo systemctl status owserver.service
> [sudo] password for control:
> ● owserver.service - Backend server for 1-wire control
>    Loaded: loaded (/lib/systemd/system/owserver.service; enabled)
>    Active: active (running) since Thu 2016-09-01 09:39:46 BST; 10min ago
>      Docs: man:owserver(1)
>  Main PID: 1297 (owserver)
>    CGroup: /system.slice/owserver.service
>            └─1297 /opt/owfs/bin/owserver --w1
>
> Sep 01 09:39:46 pi-solar systemd[1]: Started Backend server for 1-wire
> control.
> Hint: Some lines were ellipsized, use -l to show in full.
>
> which looks much better!  My work continues.......
>
This is fine as --w1 uses the w1 subsystem of the kernel to access the
onewire.

* It's the suggested choice for anyone who uses either the DS2490 USB
plug or one of the DS2482, DS2483 and compatible I²C host chips.

* It's the only way to have a bitbaning host adapter. On the Raspberry
Pi, that one is on GPIO4, given the w1-gpio or w1-gpio-pullup device
tree overlays are configured in config.txt.

* It's *not* useable with any of the RS232 based adapters, that includes
the DS2480, the LINK but also the MAXQ1010, LinkUSB and other adapters
which have a USB<->RS232 inside. For these, you have to configure owfs
to use that adapter directly.

* It's *not* useable for anything on Ethernet as the ENET host. But also
not other owservers at remote hosts of course.


Kind regards

        Jan

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

Re: Couple of Questions - another one

Mick Sulley
I have got my code to work, but I've come across something I don't
understand.

In my bash script that starts it all I copy a local owfs.conf file to
/etc/owfs.conf, then restart owserver, then start my python code, so
basically I have

cp owfs.conf /etc/
systemctl restart owserver.service
./control.py >> logfile

That fails with a message that ends
File "/usr/local/lib/python2.7/dist-packages/pyownet/protocol.py", line
729, in proxy
     raise ConnError(*lasterr)
pyownet.protocol.ConnError: [Errno 111] Connection refused

If I have removed the restart it still fails, however if I introduce a
delay it works

cp owfs.conf /etc/
sleep 5
./control.py >> logfile

Less than 5 seconds it fails, 5 or more it works

I have tried copying some file other than owfs.conf, that works OK, so
it seems to be copying to /etc/owfs.conf that causes my problem and I
need to be sure that it has completed before I start my code.

I can put a delay in there but does not seem to be the right way to do
it, any suggestions?

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: Couple of Questions - another one

Jan Kandziora
Am 02.09.2016 um 22:48 schrieb Mick Sulley:

>
> If I have removed the restart it still fails, however if I introduce a
> delay it works
>
> cp owfs.conf /etc/
> sleep 5
> ./control.py >> logfile
>
> Less than 5 seconds it fails, 5 or more it works
>
That is because owserver takes a while before it has it's socket listening.

Why do you restart owserver at all? It's not neccessary. It's designed
as a daemon to connect to the hardware at system boot and sit there and
wait until other programs connects to it.

Kind regards

        Jan

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

Re: Couple of Questions - another one

Mick Sulley
My code relies on aliases and so I wanted to copy the correct version of
owfs.conf to /etc/owfs.conf and I assumed that I would need to restart
after that for it to be read and the correct alias file used.

The thing I don't understand is that it is not the restart that causes
the failure, it is the copy.  I have tried it without the restart line
and it still fails.  Does owserver continually read /etc/owfs.conf and
detect that it being written?

Regards
Mick

On 03/09/16 00:10, Jan Kandziora wrote:

> Am 02.09.2016 um 22:48 schrieb Mick Sulley:
>> If I have removed the restart it still fails, however if I introduce a
>> delay it works
>>
>> cp owfs.conf /etc/
>> sleep 5
>> ./control.py >> logfile
>>
>> Less than 5 seconds it fails, 5 or more it works
>>
> That is because owserver takes a while before it has it's socket listening.
>
> Why do you restart owserver at all? It's not neccessary. It's designed
> as a daemon to connect to the hardware at system boot and sit there and
> wait until other programs connects to it.
>
> Kind regards
>
> Jan
>
> ------------------------------------------------------------------------------
> _______________________________________________
> 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: Couple of Questions - another one

Jan Kandziora
Am 03.09.2016 um 10:09 schrieb Mick Sulley:
> My code relies on aliases and so I wanted to copy the correct version of
> owfs.conf to /etc/owfs.conf and I assumed that I would need to restart
> after that for it to be read and the correct alias file used.
>
No. Owserver monitors its config file and restarts automatically. When
you start

# owserver --debug -c myowfs.conf

you see
----------------------------------------------------------------------
  DEBUG: ow_inotify.c:(52) Configuration file change -- time to resurrect
  DEBUG: ow_inotify.c:(61) Configuration file change detected. Will
restart /opt/owfs/bin/owserver
   CALL: ow_exec.c:(114) Restarting /opt/owfs/bin/owserver
  DEBUG: ow_net_server.c:(374) Stop listening process
  DEBUG: ow_net_server.c:(378) Listening loop stopped
DEBUG MODE
libow version:
        3.1p4
----------------------------------------------------------------------
as soon myowfs.conf is written to.

There is a drawback: When you write the configuration file, you have to
do that in one action. Scripting languages usually do this, they buffer
all the output written to a file and flush it on a "flush" or "close"
command.


> The thing I don't understand is that it is not the restart that causes
> the failure, it is the copy.  I have tried it without the restart line
> and it still fails.  Does owserver continually read /etc/owfs.conf and
> detect that it being written?
>
That is because your cp command triggers a restart in owserver and you
get a few seconds in which it is unresponsive.

Kind regards

        Jan


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

Re: Couple of Questions - another one

Stefano Miccoli
In reply to this post by Mick Sulley
My 1cent advice:

  1. do not insert a delay before your script, instead catch the pyownet.protocol.ConnError exception and retry
  2. if the alias file is dynamic (otherwise why copy it at every reboot?) you can also define/redefine aliases using owshell/ownet.

Please check this gist for an example of both techniques in python


After running this example all sensors on the localhost will be aliased to sens0, sens1, …

Ciao

Stefano


For the benefit of the list, here is also the present gist content.

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('/')

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

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

if __name__ == '__main__':
    main()



On 03 Sep 2016, at 10:09, Mick Sulley <[hidden email]> wrote:

My code relies on aliases and so I wanted to copy the correct version of
owfs.conf to /etc/owfs.conf and I assumed that I would need to restart
after that for it to be read and the correct alias file used.

The thing I don't understand is that it is not the restart that causes
the failure, it is the copy.  I have tried it without the restart line
and it still fails.  Does owserver continually read /etc/owfs.conf and
detect that it being written?

Regards
Mick

On 03/09/16 00:10, Jan Kandziora wrote:
Am 02.09.2016 um 22:48 schrieb Mick Sulley:
If I have removed the restart it still fails, however if I introduce a
delay it works

cp owfs.conf /etc/
sleep 5
./control.py >> logfile

Less than 5 seconds it fails, 5 or more it works

That is because owserver takes a while before it has it's socket listening.

Why do you restart owserver at all? It's not neccessary. It's designed
as a daemon to connect to the hardware at system boot and sit there and
wait until other programs connects to it.

Kind regards

Jan

------------------------------------------------------------------------------
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Couple of Questions - another one

Mick Sulley

Jan, Stefano,

Once again many thanks for your help and advise.  My alias file is not dynamic as such, but can change as I create a new version of my software, which is what I am doing at present, so it seemed safer to copy it over at startup.  I will look at redefining alias in owshell, then I won't need to copy owfs.conf.  Seems like a better solution, and checking pyownet.protocol.ConnError exception sounds sensible as well.

More work to do but I feel I am now much closer.

Thank you

Mick


On 03/09/16 14:35, Stefano Miccoli wrote:
My 1cent advice:

  1. do not insert a delay before your script, instead catch the pyownet.protocol.ConnError exception and retry
  2. if the alias file is dynamic (otherwise why copy it at every reboot?) you can also define/redefine aliases using owshell/ownet.

Please check this gist for an example of both techniques in python


After running this example all sensors on the localhost will be aliased to sens0, sens1, …

Ciao

Stefano


For the benefit of the list, here is also the present gist content.

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('/')

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

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

if __name__ == '__main__':
    main()



On 03 Sep 2016, at 10:09, Mick Sulley <[hidden email]> wrote:

My code relies on aliases and so I wanted to copy the correct version of
owfs.conf to /etc/owfs.conf and I assumed that I would need to restart
after that for it to be read and the correct alias file used.

The thing I don't understand is that it is not the restart that causes
the failure, it is the copy.  I have tried it without the restart line
and it still fails.  Does owserver continually read /etc/owfs.conf and
detect that it being written?

Regards
Mick

On 03/09/16 00:10, Jan Kandziora wrote:
Am 02.09.2016 um 22:48 schrieb Mick Sulley:
If I have removed the restart it still fails, however if I introduce a
delay it works

cp owfs.conf /etc/
sleep 5
./control.py >> logfile

Less than 5 seconds it fails, 5 or more it works

That is because owserver takes a while before it has it's socket listening.

Why do you restart owserver at all? It's not neccessary. It's designed
as a daemon to connect to the hardware at system boot and sit there and
wait until other programs connects to it.

Kind regards

Jan

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


------------------------------------------------------------------------------

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