Speed up 1-wire reads with simualtenous conversion!

Post Reply
marin849
Posts: 65
Joined: Tuesday 27 May 2014 10:36
Target OS: Raspberry Pi
Domoticz version: 2.4xxx
Location: Sweden
Contact:

Speed up 1-wire reads with simualtenous conversion!

Post by marin849 » Monday 11 January 2016 19:31

I have 25 1-wire temperature sensors, and I will add another 20. I'm using Domoticz native OWFS-support.
Domoticz is reading from the unchached directory (hardware/1Wire/1WireByOWFS.cpp), so every sensor takes about 750 ms to read.
With a hardcoded 1-wire polling interval of 30 seconds (hardware/1Wire.cpp) it will not finish in time when I add more sensors!

OWFS can issue a command to ALL temperature and voltage sensors o do a conversion simulatenously, and then the data is available directly after the conversion.

Code: Select all

[email protected] /mnt/1wire/uncached/simultaneous $ echo 1 > temperature
[email protected] /mnt/1wire/uncached/simultaneous $ echo 1 > voltage
I changed the path in 1WireByOWFS.cpp to not read from the "uncached", and wrote "1" to the simulatenous temperature manually in a ssh-session just before Domoticz started to read. Here is the difference:
WITHOUT simulatenous conversion:

Code: Select all

2016-01-11 18:23:08.350  (OWFS) Temp (Frys)
2016-01-11 18:23:09.101  (OWFS) Temp (Kyl)
2016-01-11 18:23:09.855  (OWFS) Temp (Köksbänk)
2016-01-11 18:23:10.582  (OWFS) Temp (OWFS-test)
2016-01-11 18:23:11.338  (OWFS) Temp (GV-retur: Dusch)
2016-01-11 18:23:12.085  (OWFS) Temp (GV-retur: Kök)
2016-01-11 18:23:12.835  (OWFS) Temp (GV: Tillopp VVX)
2016-01-11 18:23:13.586  (OWFS) Temp (GV: Retur VVX)
2016-01-11 18:23:14.334  (OWFS) Temp (GV-retur: Vard3)
2016-01-11 18:23:15.086  (OWFS) Temp (GV-retur: Hall)
2016-01-11 18:23:15.845  (OWFS) Temp (GV-tillopp: Kök)
2016-01-11 18:23:16.597  (OWFS) Temp (GV-tillopp: Dusch)
2016-01-11 18:23:17.347  (OWFS) Temp (GV-retur: Klv)
2016-01-11 18:23:18.095  (OWFS) Temp (GV-tillopp: Klv)
2016-01-11 18:23:18.841  (OWFS) Temp (GV: Tillopp fördelare)
2016-01-11 18:23:19.592  (OWFS) Temp (V: Retur: Garage)
2016-01-11 18:23:20.342  (OWFS) Temp (GV-retur: Vard4)
2016-01-11 18:23:21.090  (OWFS) Temp (Tillopp: Garage)
2016-01-11 18:23:21.838  (OWFS) Temp (GV-tillopp: Kontor)
2016-01-11 18:23:22.585  (OWFS) Temp (Gv-retur: Kontor)
2016-01-11 18:23:23.332  (OWFS) Temp (GV-tillopp: Vard4)
2016-01-11 18:23:24.080  (OWFS) Temp (GV: Bypass)
2016-01-11 18:23:24.826  (OWFS) Temp (GV-tillopp: Vard3)
2016-01-11 18:23:25.573  (OWFS) Temp (GV: Retur fördelare)
2016-01-11 18:23:26.321  (OWFS) Temp (GV-tillopp: Hall)
WITH simulateous conversion:

Code: Select all

2016-01-11 18:24:46.083  (OWFS) Temp (Frys)
2016-01-11 18:24:46.178  (OWFS) Temp (Kyl)
2016-01-11 18:24:46.267  (OWFS) Temp (Köksbänk)
2016-01-11 18:24:46.342  (OWFS) Temp (OWFS-test)
2016-01-11 18:24:46.431  (OWFS) Temp (GV-retur: Dusch)
2016-01-11 18:24:46.520  (OWFS) Temp (GV-retur: Kök)
2016-01-11 18:24:46.608  (OWFS) Temp (GV: Tillopp VVX)
2016-01-11 18:24:46.696  (OWFS) Temp (GV: Retur VVX)
2016-01-11 18:24:46.783  (OWFS) Temp (GV-retur: Vard3)
2016-01-11 18:24:46.873  (OWFS) Temp (GV-retur: Hall)
2016-01-11 18:24:46.964  (OWFS) Temp (GV-tillopp: Kök)
2016-01-11 18:24:47.061  (OWFS) Temp (GV-tillopp: Dusch)
2016-01-11 18:24:47.160  (OWFS) Temp (GV-retur: Klv)
2016-01-11 18:24:47.248  (OWFS) Temp (GV-tillopp: Klv)
2016-01-11 18:24:47.335  (OWFS) Temp (GV: Tillopp fördelare)
2016-01-11 18:24:47.421  (OWFS) Temp (V: Retur: Garage)
2016-01-11 18:24:47.508  (OWFS) Temp (GV-retur: Vard4)
2016-01-11 18:24:47.595  (OWFS) Temp (Tillopp: Garage)
2016-01-11 18:24:47.684  (OWFS) Temp (GV-tillopp: Kontor)
2016-01-11 18:24:47.770  (OWFS) Temp (Gv-retur: Kontor)
2016-01-11 18:24:47.857  (OWFS) Temp (GV-tillopp: Vard4)
2016-01-11 18:24:47.943  (OWFS) Temp (GV: Bypass)
2016-01-11 18:24:48.031  (OWFS) Temp (GV-tillopp: Vard3)
2016-01-11 18:24:48.119  (OWFS) Temp (GV: Retur fördelare)
2016-01-11 18:24:48.206  (OWFS) Temp (GV-tillopp: Hall)
A reduction from 17,97 to 2,03 seconds! (0,72 to 0,08 seconds/sensor).

Now, I can't figure out exactly how Domoticz gather the data, but I would like Domoticz to write 1 to mnt/1wire/uncached/simulatenous/temperature just before it starts to read temperature ensors, and 1 to /mnt/1wire/uncached/simultaneous/voltage just before it starts to read 1-wire devices with analog input.

Since OWFS has a default cache time of 15 seconds, I guess it would work perfect just to write 1 to both temperature and voltage just before the periodic 1-wire data readout every 30 seconds.

Anyone know where the code to write the two ones to the right file should be placed?
Last edited by marin849 on Monday 11 January 2016 19:49, edited 1 time in total.

marin849
Posts: 65
Joined: Tuesday 27 May 2014 10:36
Target OS: Raspberry Pi
Domoticz version: 2.4xxx
Location: Sweden
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by marin849 » Monday 11 January 2016 19:40

Hm, here?

Code: Select all

domoticz/hardware/1Wire.cpp

void C1Wire::Do_Work()
{
	int pCounter = Wire1_POLL_INTERVAL-2;
	while (!m_stoprequested)
	{
		sleep_seconds(1);

		pCounter++;
		if (pCounter % Wire1_POLL_INTERVAL == 0)
		{

----> DO SOMETHING HERE TO write 1 to temperature and voltage??? <----

			GetDeviceDetails();
		}
	}
}
If yes, what is the syntax to write 1 to the two files?

marin849
Posts: 65
Joined: Tuesday 27 May 2014 10:36
Target OS: Raspberry Pi
Domoticz version: 2.4xxx
Location: Sweden
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by marin849 » Saturday 23 January 2016 23:14

I have verified that it is the correct place to put the code.
So: How do I write "1" to the file mnt/1wire/uncached/simulatenous/temperature?
Simple C syntax for anyone who is a C-programmer, difficult for someone who is not! :)

fantom
Posts: 282
Joined: Thursday 26 March 2015 11:40
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by fantom » Monday 15 February 2016 22:21

marin849 wrote:I have 25 1-wire temperature sensors, and I will add another 20. I'm using Domoticz native OWFS-support.
Domoticz is reading from the unchached directory (hardware/1Wire/1WireByOWFS.cpp), so every sensor takes about 750 ms to read.
With a hardcoded 1-wire polling interval of 30 seconds (hardware/1Wire.cpp) it will not finish in time when I add more sensors!

OWFS can issue a command to ALL temperature and voltage sensors o do a conversion simulatenously, and then the data is available directly after the conversion.
1) Finish, finish. Domoticz start reading 1wire, with interval 30 sec after LAST read sensor.

2) "simulatenously" - this working only, when sensors use 3 wire (not in parasite mode)

3) Set path from uncached to "normal" nothing changes, because (how you say) owfs have default refresh time = 15 sec. Domoticz reading less often. Therefore, always anyway owfs will have to read the data from sensor

Fantom
Last edited by fantom on Monday 15 February 2016 22:37, edited 1 time in total.

fantom
Posts: 282
Joined: Thursday 26 March 2015 11:40
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by fantom » Monday 15 February 2016 22:26

Im trying set 1 in mnt/1wire/uncached/simulatenous/temperature, but it is not work. All time i see 0 :)
OWFS is changing all time to 0 for me :(
When do you set "1" you have this pernament ? Or OWFS set 0 after first reading etc ?

Fantom
ps. Today i wrote small improvement for 1wire owfs. Now domoticz reading info about existsng sensors only once - when module started. Not every 30 sec.

marin849
Posts: 65
Joined: Tuesday 27 May 2014 10:36
Target OS: Raspberry Pi
Domoticz version: 2.4xxx
Location: Sweden
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by marin849 » Monday 15 February 2016 22:38

That is how it is supposed to work.
It changes back to zero after the command has been sent out on the 1-wire network.

Yes, you are right. This only works if sensors are connected in powered (3wire) mode.

I'm not sure if it is an improvent to scan existing sensors only once. OWFS maintains a list of connected sensors automatically (by handling timeouts and rescan itnerval) so I don't think that it generates any extra bus activity when Domoticz is checking available sensors. Actually, I have found it very useful that Domoticz automatically "picks up" any sensor I reconnect if I have disconnected a branch of the network while the system is running!

I have implemented a typical ugly hack to get quick readings. :)

I have a simple script that is called in /etc/rc.local, and I have changed the hardcoded path in Domoticz NOT to read from the "uncached" directory.

Code: Select all

echo $BASHPID > /run/1wsimul.pid
while true
do
echo "1" > /mnt/1wire/uncached/simultaneous/temperature
grep '.' /mnt/1wire/*/temperature > /tmp/1wiretemps.txt
sleep 10
done
It works very well.

fantom
Posts: 282
Joined: Thursday 26 March 2015 11:40
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by fantom » Monday 15 February 2016 22:47

What do you think, about one simply idea : not reading from "temperature", but from " temperature10" ?
This is much faster (5 times ?): reading temperature with 10 bit resolution (not 12).
We see in domoticz for example 21,35 oC. Not 21,35815 oC.

Fantom

marin849
Posts: 65
Joined: Tuesday 27 May 2014 10:36
Target OS: Raspberry Pi
Domoticz version: 2.4xxx
Location: Sweden
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by marin849 » Monday 15 February 2016 22:57

Yes, that is faster. But still quite slow compared to read the data directly from the cache as I am doing now.

fantom
Posts: 282
Joined: Thursday 26 March 2015 11:40
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by fantom » Tuesday 16 February 2016 13:57

I think, that this line "echo "1" > /mnt/1wire/uncached/simultaneous/temperature" doing "almost nothing" for you.
Pls check without this line.

And, simultaneous is works only for temperature DS1820 sensor and voltage (is it ?).
When you change catalog to "cached", for example switch refresh in domoticz after ... 5 minutes !

Fantom

fantom
Posts: 282
Joined: Thursday 26 March 2015 11:40
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by fantom » Tuesday 16 February 2016 18:44

I implemented this :
https://github.com/szczukot/domoticz/co ... 84277b35c7
You can testing it

I tested it in my network - i think that its work. I'm not sure, because i have many sensor in parasite mode.

Fantom

fantom
Posts: 282
Joined: Thursday 26 March 2015 11:40
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by fantom » Wednesday 17 February 2016 10:17

Its merged to master branch.

Pls testing in the version above 2.4621

Fantom

marin849
Posts: 65
Joined: Tuesday 27 May 2014 10:36
Target OS: Raspberry Pi
Domoticz version: 2.4xxx
Location: Sweden
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by marin849 » Wednesday 17 February 2016 19:04

fantom wrote:I think, that this line "echo "1" > /mnt/1wire/uncached/simultaneous/temperature" doing "almost nothing" for you.
Pls check without this line.

Fantom
I am 100% sure that this is the line that triggers the simulatenous read! So it does everything. :)

marin849
Posts: 65
Joined: Tuesday 27 May 2014 10:36
Target OS: Raspberry Pi
Domoticz version: 2.4xxx
Location: Sweden
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by marin849 » Wednesday 17 February 2016 19:07

fantom wrote:Its merged to master branch.

Pls testing in the version above 2.4621

Fantom
I will test it as soon as I can!

fantom
Posts: 282
Joined: Thursday 26 March 2015 11:40
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by fantom » Wednesday 17 February 2016 20:15

marin849 wrote:
fantom wrote:I think, that this line "echo "1" > /mnt/1wire/uncached/simultaneous/temperature" doing "almost nothing" for you.
Pls check without this line.

Fantom
I am 100% sure that this is the line that triggers the simulatenous read! So it does everything. :)
Yes - this is the line that triggers the simulatenous read
No - it does nothing
If you read from unchached, you read data from max 15 sec ago. This line is doing "almost nothing"

Fantom

fantom
Posts: 282
Joined: Thursday 26 March 2015 11:40
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by fantom » Wednesday 17 February 2016 20:15

marin849 wrote:
fantom wrote:Its merged to master branch.

Pls testing in the version above 2.4621

Fantom
I will test it as soon as I can!
This patch is exists in the newest beta 2.4623

Fantom

marin849
Posts: 65
Joined: Tuesday 27 May 2014 10:36
Target OS: Raspberry Pi
Domoticz version: 2.4xxx
Location: Sweden
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by marin849 » Thursday 18 February 2016 8:11

fantom wrote:
marin849 wrote:
fantom wrote:I think, that this line "echo "1" > /mnt/1wire/uncached/simultaneous/temperature" doing "almost nothing" for you.
Pls check without this line.

Fantom
I am 100% sure that this is the line that triggers the simulatenous read! So it does everything. :)
Yes - this is the line that triggers the simulatenous read
No - it does nothing
If you read from unchached, you read data from max 15 sec ago. This line is doing "almost nothing"

Fantom
If I read from unchached I always gets new data, and then the simultaneous read is "wasted" yes. And the reading also takes LONG time.

What I do is every 10 second the script triggers a read, and I have changed so Domoticz is reading cached values.
If Domoticz would issue simulataneous read command and then read from unchached, the simultaenous read command is meaningsless.

My Domoticz is reading every 60 seconds, so the values can be max 10 seconds old (doesn't matter), but I also have some other scripts that reads from OWFS outside Domoticz so it makes sense to update the cache every 10 seconds to always have fresh values without having to wait for conversion.

fantom
Posts: 282
Joined: Thursday 26 March 2015 11:40
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by fantom » Thursday 18 February 2016 9:17

If it is important for you, is it maksimum 10 or 15 seconds .... ok
But this is doing nothing.
I say too, about CACHED value.
You may remove this line, and set cache in OWFS to 10 sec. You will have exactly the same effect.

Fantom

marin849
Posts: 65
Joined: Tuesday 27 May 2014 10:36
Target OS: Raspberry Pi
Domoticz version: 2.4xxx
Location: Sweden
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by marin849 » Friday 19 February 2016 8:26

Hm.
I am making sure that all values in the cache are refreshed automatically every 10 seconds which means that the cache content can never be more than 10 seconds old and ALL reads are happening from the cache!

If i remove the line and change the cache to 10 sec the effect would be that the cache will become obsolete and sensors would need to be physically read every time, causing very long read times.

Now with your fix the script is not needed since Domoticz is triggering the simulataneous read before reading the values. However, since I have other scripts accessing the values I still want to "refresh the cache" every 10 seconds in the background, which means I HAVE TO trigger the simulatenous read every ten seconds, and read sensors once (and throwaway the values). Otherwise the other scripts would have to wait for new values.

fantom
Posts: 282
Joined: Thursday 26 March 2015 11:40
Target OS: Raspberry Pi
Domoticz version:
Location: Poland
Contact:

Re: Speed up 1-wire reads with simualtenous conversion!

Post by fantom » Friday 19 February 2016 9:14

Ok
Please close this topic - faster reading is implemented.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest