Thank you for so thoroughly answering my questions, its been gold worth to me who lack deeper understanding of the 1-wire devices and of OWFS!

After reading your answers in the mailthread I went and rewrote my program to use a single thread for Owserver and using a single connection to Owserver for that thread. Maybe some smarter bridges like DS2490 do support simultaneous scanning and reading a bus but it would be unwise of we to optimize my application just around how that single chip works.

The thread that communicates with owserver now execute the following mainloop over and over again:

- Collect all found 1-wire devices from a previous bus scan and separate them into three different lists, "temperaturedevices", "voltagedevices", "fastdevices" (the rest of the devices not being temp or voltage). - Execute all queued command to be written to Owserver from a queue. When you want to change a pin or write something to a device to add a <path, value>-entry to this queue and they are all executed on this step. - If there are any devices found in "temperaturedevices"-list, write "1" to "/simultaneous/temperature". - If there are any devices found in "voltagedevices"-list, write "1" to "/simultaneous/voltage". - Iterate though all devices in "fastdevices"-list and do a "this.owserverConnection.read(path)" on each of them (this is a /uncached-path!). Hopefully these can be read safely while the temperature and voltage-sensors are working on their own, we thus do some parallel work. - Check if there are any new queued commands to be executed. We do this several times between steps that possible could take a long to to execute just to get a responsive system for the endusers. - Iterate though all devices in "temperaturedevices"-list and do a "this.owserverConnection.read(path)" on each of them(this is a /uncached-path!). Hopefully the conversions are done by now, otherwise Owserver will block the rest of the time left and return the readings when they are done.
- Check if there are any new queued commands to be executed.
- Iterate though all devices in "voltagedevices"-list and do a "this.owserverConnection.read(path)" on each of them(this is a /uncached-path!). Hopefully the conversions are done by now, otherwise Owserver will block the rest of the time left and return the readings when they are done. - If 30 secs has elapsed, do a full bus scan against Owserver (we read from the CACHE). If 30 secs not has been reatched we just skip this step.

And that's it. Just one thread to not confuse the bus and the good thing is that I no longer experience the "found 0 devices"-problem I had before when running multiple thread and doing a bus scan. Probably the threads was lock too long in Owserver so somekind of timeout was reached as you suggested.

However I still having problem getting the simultaneous reading of temperature devices to work. I disconnected my whole 1-wire network from the Abiowire-card and solder on two DS18S20 on a short 10 cm cable, with 5v power, and connected it to the card. Just to rule out long cables and faulty soldering from the equation. I run my above program and recorded the times between each of these steps:

2016-01-05 21:30:33,973 [owfsAdapter-mainloop-1410803762] DEBUG se.liquidbytes.jel.owfs.OwfsAdapter - Mainloop execution statistics: command 0ms, simultaneous 147ms, fastdevices 0ms, temperaturedevices 1280ms, voltagedevices 0ms, busscan 0ms.

Many of the above steps reported 0 ms since there was no queued command, no other devices was present except temperaure-sensors, and no bus scan occured. Writing to /simultaneous/temperature took 147 ms, reading from the sensors took 1230 ms. Some more samples showed a average reading from sensors of about 1300 ms. If simultaneous had kicked in we should see something more close to 700 ms, right? I tested to connect my cable to both DS2482-800 and the single DS2482-100 the card is equipped with, but got the same result. I have and old DS2480-card somewhere, I will see if I get the same result on that one. Here is a interesting thread that at least suggest that it should work on DS2482-800: https://www.mail-archive.com/owfs-developers@lists.sourceforge.net/msg05631.html

Regarding how static the 1-wire network is, I would say it is for the most of the time is very static. I guess that some users may hotplug their networks by adding or removing devices on-the-fly without powering the network down, and for that I want to poll the bus for any added or removed devices. If they only could be removed then reading /power would be a excellent way (thanks for the idea!).

The "POR"-bit sounds interesting, so it get set when the chip has been powercycled? So during initialization I can set this to "0" and I could poll /alarm and it will be triggered if the chip has been powercycled (among other alarms)? Then I just set it back to "0" and initialize the DS2408 to correct state once more and continue. Sounds perfect to me. :-D
http://owfs.org/index.php?page=ds2408

Many thanks!

// Henrik



Den 2016-01-03 kl. 05:32, skrev Jan Kandziora:
Am 03.01.2016 um 00:11 schrieb Henrik Östman:
Note that I do
all my reading from "/uncached", is that possible even with
simultaneous-code? Or do I have to read from the cached-directories?

When you read from /uncached, you either

a) have to synchronize writing to /simultaneous with reading each node

or

b) have to trigger simulatenous conversions at least twice as often as
you read from /uncached

That is because reading /uncached reads the value from the chip stored
within from the last simultaneous conversion, and then resets the chip
state inside OWFS to "no result pending", which means another subsequent
reading of /uncached would trigger a normal single conversion.

When you can do neither a) nor b), you have to read the cached value and
trigger /simultaneous at a least twice as often as the cache timeout for
temperature values (that latter is usually 15 seconds.)


0trycoon@dixie:/mnt/1wire/simultaneous$ cat temperature
1trycoon@dixie:/mnt/1wire/simultaneous$ cat temperature
0trycoon@dixie:/mnt/1wire/simultaneous$ cat temperature

Is it normal that the value are jumping back and forth between 0 and
1?

Reading that node gives you an indication whether owfs thinks there is a
conversion running. The value is global for both temperature and
voltage. This is only based on OWFS' internal state, the slaves are not
checked.

No idea why it toggles. That code is a bit opaque. If you insist on
knowing, I go hunting for the reason.


Without my 1000ms delay a full bus reading took only 362ms. I got
about the same result without the /simultaneous/temperature-code. So
my question is, does fake Owfs-devices emulate the time
characteristics of the real devices (conversiontime of 700ms for a
DS18S20) and is the /simultaneous/temperature-effect correctly
emulated?

No. Using the fake adapter replaces all the device-specific code for
slave objects on that adapter by simple random-value "read" functions.

Writing to /simultaneous/temperature (or voltage) on a fake adapter is a
no-op.


Another problem I'm struggling with is that listing devices returns 0
  devices when concurrent requests to Owserver are in progress.

This should not happen. Owserver should block that connection until the
"Search ROM" command can be executed on the bus in question. Maybe you
have a hidden timeout in your client application?

The most likely case for reaching such a timeout is doing a lot of
non-simultaneous conversions, as they are clogging the bus for 800ms each.

Owserver is multithreaded by client itself, so the kernel is deciding
with message is processed first by selecting a thread. I seriously doubt
that's ordered by arriving time of single packets as TCP is not intended
to transport messages. The arriving time of packets just isn't of
interest for TCP. So, by using a multiple-socket client application, you
lose control about the order of message processing within owserver.

I recommend you to get rid of the concurrency within owserver by
serializing your requests within your client application and sending
them through one single socket. That way you can control the order of
commands all by yourself.


To overcome my slow single threaded application I introduced some more
threads, so now I basically has four of them:

- The presence-thread polls owfs.listDirectoryAll("/uncached") every
  30th seconds and stores all found devices in a list, lets call it
owDevices. (It has its own dedicated persistent connection to
Owserver)

Do you have an ever-changing setup? I don't think so.

Threading doesn't help you gain speed when you are doing a bus
enumeration, as this is an atomic operation on the host adapter.
Theoretically, one could have this interleaved with other bus traffic
but for the sake of doing things the simple way (and not breaking
anything with intelligent host adaptors like the DS2490) it is just a
single bulky operation which stops everything on the bus until all chips
are identified.

If you are reading the global /uncached directory, all buses are
occupied for up to a few seconds.


As enumerating the bus can be a very time-consuming operation, and as it
is the most brittle part of the whole protocol, I do it different in my
machines. They have a list of devices to expect on the bus (need it for
functional assignment anyway) and just check if all of these chips are
still there by reading a property from them. For temperature sensors,
you may use the "power" property for that check.

I trigger the check in the board-specific code that chip is on from a
timer thread, not in a bulk but interleaved with all the other
operations on the buses.


For those of you that strive for more resilient 1-wire networks, how
do you detect device-resets/device power failure? I setup a DS2408 by
a write "1" to "/<device id>/strobe", if the device is then power
cycled I'm back to square one without even knowing it.

Uh, the DS2408 has a dedicated "por" property, which indicates a
power-on condition. The chip even responds to conditional search as long
the POR bit isn't cleared.

In my machines, I have a loop which reads /alarm once in a second
-usually no slave responds to that- and then manages the alarm
conditions for all the slaves that do.


Kind regards

        Jan

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

Reply via email to