OWNet perl write/read and a lost byte

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

OWNet perl write/read and a lost byte

Henry
Hello.

Using owfs-3.1p4.

I need to write binary data to an external sensor.

I do this settings:

owfs.conf
...
SCRIPT: "RELAY_SET", "constant_family", b1024, 1, u, /opt/_read,
/opt/_write, ''
...

The main is b1024. Is it right?

And write from a client by perl script:

OWNet::write( "$dev_ip:4304" , "/relay_setting/RELAY_SET", `echo -n $ss
| gzip -c` );

As you see, I write a gziped data.

Client Hexdump is -
[0000] 1F 8B 08 00 6C 3D 01 58 00 03 33 D4 F1 F3 D7 31....

But!

root@CONSTANT:~> owread -s 172.19.19.10 /relay_setting/RELAY_SET  | hexdump
0000000 088b 6c00 013d 0058 3303 f1d4 d7f3 d031
0000010 77f1 0373 0692 3a3a 46ca 02e8 e8c6 2602
0000020 02e8 e8a6 6602 02e8 e8e6 1602 02e8 be00
0000030 9c53 88e3 0000 0000 0000 0000 0000 0000
0000040 0000 0000 0000 0000 0000 0000 0000 0000
*
0000400

My script make a simple cat to file. We are can see this file:

cat constant_control.bin  | hexdump
0000000 088b 6c00 013d 0058 3303 f1d4 d7f3 d031
0000010 77f1 0373 0692 3a3a 46ca 02e8 e8c6 2602
0000020 02e8 e8a6 6602 02e8 e8e6 1602 02e8 be00
0000030 9c53 88e3 0000 0000
0000038

I think, first byte is lost and...
By another words, I can unzip the owread data.

Please, where is first byte or my mistake?

cat /opt/_write
#!/bin/sh
RW=$4

case "$RW" in
         read)  cat /etc/constant_control.bin ;;
         write) cat > /etc/constant_control.bin ;;
esac


Thanks.

--

== Henry Pootel ==


P.S.
root@CONSTANT:~> echo -n
'1,NO,0,OFF,0,0,,#2,NO,0,OFF,0,0,,#3,NO,0,OFF,0,0,,#4,NO,0,OFF,0,0,,#5,NO,0,OFF,0,0,,#6,NO,0,OFF,0,0,,#7,NO,0,OFF,0,0,,#8,NO,0,OFF,0,0,,#'|
gzip -c  | hexdump
0000000 8b1f 0008 4434 5801 0300 d433 f3f1 31d7
0000010 f1d0 7377 9203 3a06 ca3a e846 c602 02e8
0000020 e826 a602 02e8 e866 e602 02e8 e816 0002
0000030 53be e39c 0088 0000
0000038

root@CONSTANT:~> owwrite -s 172.19.19.10 /relay_setting/RELAY_SET  `echo
-n
'1,NO,0,OFF,0,0,,#2,NO,0,OFF,0,0,,#3,NO,0,OFF,0,0,,#4,NO,0,OFF,0,0,,#5,NO,0,OFF,0,0,,#6,NO,0,OFF,0,0,,#7,NO,0,OFF,0,0,,#8,NO,0,OFF,0,0,,#'|
gzip -c`

root@CONSTANT2:/etc> cat constant_control.bin  | hexdump
0000000 8b1f 3f08 0144 0358 d433 f3f1 31d7 f1d0
0000010 7377 9203 3a06 ca3a e846 c602 02e8 e826
0000020 a602 02e8 e866 e602 02e8 e816 be02 9c53
0000030 88e3
0000032

root@CONSTANT:~> owread -s 172.19.19.10 /relay_setting/RELAY_SET | hexdump
0000000 8b1f 3f08 0144 0358 d433 f3f1 31d7 f1d0
0000010 7377 9203 3a06 ca3a e846 c602 02e8 e826
0000020 a602 02e8 e866 e602 02e8 e816 be02 9c53
0000030 88e3 0000 0000 0000 0000 0000 0000 0000
0000040 0000 0000 0000 0000 0000 0000 0000 0000
*
0000400


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers
Reply | Threaded
Open this post in threaded view
|

Re: OWNet perl write/read and a lost byte

Henry
Hello dear friends.

New tests!


root@CONSTANT:~> echo -n
'1,NO,0,OFF,0,0,,#2,NO,0,OFF,0,0,,#3,NO,0,OFF,0,0,,#4,NO,0,OFF,0,0,,#5,NO,0,OFF,0,0,,#6,NO,0,OFF,0,0,,#7,NO,0,OFF,0,0,,#8,NO,0,OFF,0,0,,#'|
gzip -c  > ee

root@CONSTANT:~> cat ee | hexdump -C
00000000  1f 8b 08 00 03 2a 02 58  00 03 33 d4 f1 f3 d7 31
|.....*.X..3....1|
00000010  d0 f1 77 73 03 92 06 3a  3a ca 46 e8 02 c6 e8 02
|..ws...::.F.....|
00000020  26 e8 02 a6 e8 02 66 e8  02 e6 e8 02 16 e8 02 00
|&.....f.........|
00000030  be 53 9c e3 88 00 00 00                           |.S......|
00000038

root@CONSTANT:~> owwrite -s 172.19.19.10 /relay_setting/RELAY_SET  `cat ee`

And now at the owserver host:

root@CONSTANT2:~> cat /etc/constant_control.bin | hexdump -C
00000000  1f 8b 08 03 2a 02 58 03  33 d4 f1 f3 d7 31 d0 f1
|....*.X.3....1..|
00000010  77 73 03 92 06 3a 3a ca  46 e8 02 c6 e8 02 26 e8
|ws...::.F.....&.|
00000020  02 a6 e8 02 66 e8 02 e6  e8 02 16 e8 02 be 53 9c
|....f.........S.|
00000030  e3 88                                             |..|
00000032

Some bytes are lost. (00 - this bytes are lost!!! May be something
else..)

My server config:

root@CONSTANT2:~> cat /etc/owfs.conf
i2c=/dev/i2c-1:ALL

server: port=4304
server: i2c

owfs: mountpoint = /OWFS
owfs: server = 4304

external
SENSOR: "relay_setting", "constant_family", "owfs2relay_control",
'yet_more_params',
SCRIPT: "RELAY_SET", "constant_family", b1024, 1, u, /opt/nick_read,
/opt/nick_write, 'something_trash'

and /opt/nick_read or /opt/nick_write files:

root@CONSTANT2:~> cat /opt/nick
#!/bin/sh
RW=$4

case "$RW" in
         read)  cat /etc/constant_control.bin ;;
         write) cat > /etc/constant_control.bin ;;
esac

AND /etc/constant_control.bin file:

root@CONSTANT2:~> cat /etc/constant_control.bin | hexdump -C
00000000  1f 8b 08 03 2a 02 58 03  33 d4 f1 f3 d7 31 d0 f1
|....*.X.3....1..|
00000010  77 73 03 92 06 3a 3a ca  46 e8 02 c6 e8 02 26 e8
|ws...::.F.....&.|
00000020  02 a6 e8 02 66 e8 02 e6  e8 02 16 e8 02 be 53 9c
|....f.........S.|
00000030  e3 88                                             |..|
00000032

READ:root@CONSTANT:~> owread -s 172.19.19.10 /relay_setting/RELAY_SET |
hexdump -C
                     00000000  1f 8b 08 03 2a 02 58 03  33 d4 f1 f3 d7
31 d0 f1  |....*.X.3....1..|
00000010  77 73 03 92 06 3a 3a ca  46 e8 02 c6 e8 02 26 e8
|ws...::.F.....&.|
00000020  02 a6 e8 02 66 e8 02 e6  e8 02 16 e8 02 be 53 9c
|....f.........S.|
00000030  e3 88 00 00 00 00 00 00  00 00 00 00 00 00 00 00
|................|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
|................|
*
00000400

The read is normal (How many bytes it read? Is it round file length?),
but write is not good.

Can you show my error? Or is the error in the ownet?

Henry.



14.10.2016 22:53, Henry Pootel пишет:

> Hello.
>
> Using owfs-3.1p4.
>
> I need to write binary data to an external sensor.
>
> I do this settings:
>
> owfs.conf
> ...
> SCRIPT: "RELAY_SET", "constant_family", b1024, 1, u, /opt/_read,
> /opt/_write, ''
> ...
>
> The main is b1024. Is it right?
>
> And write from a client by perl script:
>
> OWNet::write( "$dev_ip:4304" , "/relay_setting/RELAY_SET", `echo -n $ss
> | gzip -c` );
>
> As you see, I write a gziped data.
>
> Client Hexdump is -
> [0000] 1F 8B 08 00 6C 3D 01 58 00 03 33 D4 F1 F3 D7 31....
>
> But!
>
> root@CONSTANT:~> owread -s 172.19.19.10 /relay_setting/RELAY_SET  | hexdump
> 0000000 088b 6c00 013d 0058 3303 f1d4 d7f3 d031
> 0000010 77f1 0373 0692 3a3a 46ca 02e8 e8c6 2602
> 0000020 02e8 e8a6 6602 02e8 e8e6 1602 02e8 be00
> 0000030 9c53 88e3 0000 0000 0000 0000 0000 0000
> 0000040 0000 0000 0000 0000 0000 0000 0000 0000
> *
> 0000400
>
> My script make a simple cat to file. We are can see this file:
>
> cat constant_control.bin  | hexdump
> 0000000 088b 6c00 013d 0058 3303 f1d4 d7f3 d031
> 0000010 77f1 0373 0692 3a3a 46ca 02e8 e8c6 2602
> 0000020 02e8 e8a6 6602 02e8 e8e6 1602 02e8 be00
> 0000030 9c53 88e3 0000 0000
> 0000038
>
> I think, first byte is lost and...
> By another words, I can unzip the owread data.
>
> Please, where is first byte or my mistake?
>
> cat /opt/_write
> #!/bin/sh
> RW=$4
>
> case "$RW" in
>          read)  cat /etc/constant_control.bin ;;
>          write) cat > /etc/constant_control.bin ;;
> esac
>
>
> Thanks.
>

--

== Henry Pootel ==

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers
Reply | Threaded
Open this post in threaded view
|

Re: OWNet perl write/read and a lost byte

Matthias Urlichs-3
On 15.10.2016 15:23, Henry Pootel wrote:
> Some bytes are lost. (00 - this bytes are lost!!! May be something
> else..)
Null bytes are end-of-string indicators in C. Apparently something
ignores the binary data length.

May I ask what your use case for sending binary data to your 1wire
server via OWFS *is*?
I'd use scp or some other protocol that actually works for arbitary
binary data, because the owfs protocol apparently does not.

--
-- Matthias Urlichs


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers
Reply | Threaded
Open this post in threaded view
|

Re: OWNet perl write/read and a lost byte

Jan Kandziora
Am 15.10.2016 um 17:43 schrieb Matthias Urlichs:

> On 15.10.2016 15:23, Henry Pootel wrote:
>> Some bytes are lost. (00 - this bytes are lost!!! May be something
>> else..)
> Null bytes are end-of-string indicators in C. Apparently something
> ignores the binary data length.
>
> May I ask what your use case for sending binary data to your 1wire
> server via OWFS *is*?
> I'd use scp or some other protocol that actually works for arbitary
> binary data, because the owfs protocol apparently does not.
>
It should be. We have binary data at several occasions.

Kind regards

        Jan


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers
Reply | Threaded
Open this post in threaded view
|

Re: OWNet perl write/read and a lost byte

Henry
In reply to this post by Matthias Urlichs-3
Thank you, Matthias, for your opinion. I see you, but...

15.10.2016 17:43, Matthias Urlichs wrote:
> On 15.10.2016 15:23, Henry Pootel wrote:
>> Some bytes are lost. (00 - this bytes are lost!!! May be something
>> else..)
> Null bytes are end-of-string indicators in C. Apparently something
> ignores the binary data length.
>

So, the binary data owwrite to an external sensor is not possible.
Isn't it?

> May I ask what your use case for sending binary data to your 1wire
> server via OWFS *is*?
> I'd use scp or some other protocol that actually works for arbitary
> binary data, because the owfs protocol apparently does not.
>

It's right, but I use a raspberry pi and would not use a lot of
protocols for connections to a base server. It's an economy of resources
of the raspberry pi. I think, the external sensor
(a virtual family device) is a way for make a cheap decision
for a feedback to a raspberry pi.

Of course, I can try owwrite an ascii data without compression.
But, it's a workaround of the binary write. It's not a decision.

Thank you.

--

== Henry Pootel ==

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers
Reply | Threaded
Open this post in threaded view
|

Re: OWNet perl write/read and a lost byte

Jan Kandziora
Am 15.10.2016 um 19:35 schrieb Henry Pootel:
>
> Of course, I can try owwrite an ascii data without compression.
> But, it's a workaround of the binary write. It's not a decision.
>
We had those 0x00 problems at various occasions. Let me look into it,
maybe it's easily fixable.

Kind regards

        Jan



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers
Reply | Threaded
Open this post in threaded view
|

Re: OWNet perl write/read and a lost byte

Stefano Miccoli
In reply to this post by Henry

On 15 Oct 2016, at 15:23, Henry Pootel <[hidden email]> wrote:

root@CONSTANT:~> owwrite -s 172.19.19.10 /relay_setting/RELAY_SET  `cat ee`

I see a couple of problems here. 

First, owwrite seems to have problems with nul characters in his arguments, but please wait for confirmation by Jan.

Second, assuming you are using bash, the command should be

$ owwrite -s 172.19.19.10 /relay_setting/RELAY_SET "$(< ee)"

Brief explanation

  • $(command) is preferred over `command` see http://mywiki.wooledge.org/BashFAQ/082
  • $(<pathname) is a shortcut for $(cat pathname) see bash manpage
  • double quotes are necessary because command substitution is subjected to word splitting, if not protected by double quotes.

In other words with your command the shell will split the content of ‘ee' at whitespace, thus causing further problems.

You can confirm that owserver is functioning properly with pyownet http://pyownet.readthedocs.io/en/latest/

>>> data = open('ee', 'rb').read()
>>> from pyownet import protocol
>>> owp = protocol.proxy(host=‘172.19.19.10’)
>>> owp.write('/relay_setting/RELAY_SET', data)

From my experiments, with pyownet+owserver the data is transmitted cleanly.

Stefano


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers
Reply | Threaded
Open this post in threaded view
|

Re: OWNet perl write/read and a lost byte

Matthias Urlichs-3
On 16.10.2016 01:18, Stefano Miccoli wrote:
> First, owwrite seems to have problems with nul characters in his arguments
*All* programs have problems with NUL characters in their arguments.
You don't need confirmation for that, that's basic C/UNIX.

To fix that, you need a flag for owwrite that reads the
content-to-be-written from stdin.

--
-- Matthias Urlichs


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers
Reply | Threaded
Open this post in threaded view
|

Re: OWNet perl write/read and a lost byte (RESOLVED)

Henry
In reply to this post by Stefano Miccoli
Dear friends!

I'm sorry, I distract you from your work...
I've made a mistake, I'll find it by own.
So, I've wrote a simple script and test my situation.

root@CONSTANT:~> cat test.pl
#!/usr/bin/perl

use OWNet;
use IO::Compress::Gzip qw(gzip $GzipError) ;
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);

$test_string =
'1,NO,0,OFF,0,0,,#2,NO,0,OFF,0,0,,#3,NO,0,OFF,0,0,,#4,NO,0,OFF,0,0,,#5,NO,0,OFF,0,0,,#6,NO,0,OFF,0,0,,#7,NO,0,OFF,0,0,,#8,NO,0,OFF,0,0,,#';

print "$test_string\n";
gzip \$test_string => \$gz_data;
OWNet::write( "172.19.19.10:4304" , "/relay_setting/RELAY_SET", $gz_data );

$result = OWNet::read( "172.19.19.10:4304" , "/relay_setting/RELAY_SET");
gunzip \$result => \$uncompressed;
print "$uncompressed\n";



root@CONSTANT:~> ./test.pl
1,NO,0,OFF,0,0,,#2,NO,0,OFF,0,0,,#3,NO,0,OFF,0,0,,#4,NO,0,OFF,0,0,,#5,NO,0,OFF,0,0,,#6,NO,0,OFF,0,0,,#7,NO,0,OFF,0,0,,#8,NO,0,OFF,0,0,,#
1,NO,0,OFF,0,0,,#2,NO,0,OFF,0,0,,#3,NO,0,OFF,0,0,,#4,NO,0,OFF,0,0,,#5,NO,0,OFF,0,0,,#6,NO,0,OFF,0,0,,#7,NO,0,OFF,0,0,,#8,NO,0,OFF,0,0,,#


As you see, all right.

;-) But we are can't send binary file by cli.

Thank you very much for help!


16.10.2016 01:18, Stefano Miccoli пишет:

>
>> On 15 Oct 2016, at 15:23, Henry Pootel <[hidden email]
>> <mailto:[hidden email]>> wrote:
>>
>> root@CONSTANT:~> owwrite -s 172.19.19.10 /relay_setting/RELAY_SET
>>  `cat ee`
>
> I see a couple of problems here.
>
> First, owwrite seems to have problems with nul characters in his
> arguments, but please wait for confirmation by Jan.
>
> Second, assuming you are using bash, the command should be
>
> $ owwrite -s 172.19.19.10 /relay_setting/RELAY_SET "$(< ee)"
>
> Brief explanation
>
>   * $(command) is preferred over `command` see
>     http://mywiki.wooledge.org/BashFAQ/082
>   * $(<pathname) is a shortcut for $(cat pathname) see bash manpage
>   * double quotes are necessary because command substitution is
>     subjected to word splitting, if not protected by double quotes.
>
>
> In other words with your command the shell will split the content of
> ‘ee' at whitespace, thus causing further problems.
>
> You can confirm that owserver is functioning properly with
> pyownet http://pyownet.readthedocs.io/en/latest/
>
>>>> data = open('ee', 'rb').read()
>>>> from pyownet import protocol
>>>> owp = protocol.proxy(host=‘172.19.19.10’)
>>>> owp.write('/relay_setting/RELAY_SET', data)
>
> From my experiments, with pyownet+owserver the data is transmitted cleanly.
>
> Stefano
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>
>
>
> _______________________________________________
> Owfs-developers mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/owfs-developers
>

--

== Henry Pootel ==

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers
Reply | Threaded
Open this post in threaded view
|

Re: OWNet perl write/read and a lost byte (RESOLVED)

Jan Kandziora
Am 16.10.2016 um 11:27 schrieb Henry Pootel:
>
> ;-) But we are can't send binary file by cli.
>
Then we have to change that. I change owwrite so it reads stdin instead
of complaining about a missing value argument.

Kind regards

        Jan



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers
Reply | Threaded
Open this post in threaded view
|

Re: OWNet perl write/read and a lost byte (RESOLVED)

Matthias Urlichs-3
On 16.10.2016 13:41, Jan Kandziora wrote:
> Am 16.10.2016 um 11:27 schrieb Henry Pootel:
>> ;-) But we are can't send binary file by cli.
>>
> Then we have to change that. I change owwrite so it reads stdin instead
> of complaining about a missing value argument.
+1

--
-- Matthias Urlichs


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers
Reply | Threaded
Open this post in threaded view
|

Re: OWNet perl write/read and a lost byte (RESOLVED)

Henry
Hello again.

I've found a strange situation. I'll try to resolve it.
While, what you say about this.

Do you remember "my lost first byte" of owwrite?
I use CGI perl module and have a simple script:


cat index.pl
#!/usr/bin/perl
use CGI;
use OWNet;
my $q = CGI->new;
print $q->header( -Content-type => 'text/html' );
OWNet::write( "172.19.19.10:4304" , "/relay_setting/RELAY_SET",
'123456789' );

==================================
owread -s 172.19.19.10 /relay_setting/RELAY_SET
23456789

This is my problem. CGI module? All work fine wo CGI.

Of course, I can't use compress wo first byte.

16.10.2016 15:01, Matthias Urlichs wrote:
> On 16.10.2016 13:41, Jan Kandziora wrote:
>> Am 16.10.2016 um 11:27 schrieb Henry Pootel:
>>> ;-) But we are can't send binary file by cli.
>>>
>> Then we have to change that. I change owwrite so it reads stdin instead
>> of complaining about a missing value argument.
> +1
>

--

== Henry Pootel ==

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers
Reply | Threaded
Open this post in threaded view
|

Re: OWNet perl write/read and a lost byte (RESOLVED)

Henry
Hello.

The problem was in an old apache2. :-(
My CGI scripts is working very good now, after apache2 update!

Thank you very much!!!!


--

== Henry Pootel ==

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Owfs-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/owfs-developers