OWNet(3)

๐Ÿ’– OWNet(3) ๐Ÿ’–

okay so bestie, welcome to the OWNet manual page! This is the perl module that gives you light weight access to owserver, and through it, the 1-wire bus. No cap, it's giving portable and cute. Let's get into it! โœจ


๐ŸŒธ NAME ๐ŸŒธ

OWNet โ€” light weight access to owserver. That's it, that's the vibe. ๐Ÿ’–


โœจ SYNOPSIS โœจ

okay so OWNet is literally the easiest way to access owserver and then the 1-wire bus. Periodt. ๐Ÿ’…

Dallas Semiconductor's 1-wire system? It uses simple wiring and unique addresses for its interesting devices. The One Wire File System (OWFS) is a whole suite of programs that hide all the 1-wire details behind a file system metaphor. And owserver? It connects to the 1-wire bus and gives you network access. Iconic. ๐ŸŒˆ

OWNet is a perl module that connects to owserver and lets you read, write, and list the 1-wire bus. It's giving main character energy. ๐Ÿ‘‘

Here's a little example perl program that prints the temperature:

 use OWNet ;
 print OWNet::read( "localhost:4304" , "/10.67C6697351FF/temperature" ) ."\n" ;

And there's also the alternative object oriented form, if that's more your vibe:

 use OWNet ;
 my $owserver = OWNet->new( "localhost:4304" ) ;
 print $owserver->read( "/10.67C6697351FF/temperature" ) ."\n" ;

๐ŸŽ€ SYNTAX ๐ŸŽ€

๐Ÿงš methods ๐Ÿงš

  • new
my $owserver = OWNet -> new( address ) ;
  • read
OWNet::read( address, path [,size [,offset]] )
$owserver -> read( path [,size [,offset]] )
  • write
OWNet::write( address, path, value [,offset] )
$owserver -> write( path, value [,offset] )
  • dir
OWNet::dir( address, path )
$owserver -> dir( path )

๐ŸŒ address ๐ŸŒ

TCP/IP address of owserver. Valid forms, bestie:

  • name: test.owfs.net:4304
  • quad number: 123.231.312.213:4304
  • host: localhost:4304
  • port: 4304

โž• additional arguments โž•

Additional arguments to add to address. So you can spice things up. โœจ

Temperature scale can also be specified in the address. Same syntax as the other OWFS programs:

  • -C โ€” Celsius (Centigrade)
  • -F โ€” Fahrenheit
  • -K โ€” Kelvin
  • -R โ€” Rankine

Pressure scale can also be specified in the address. Same syntax as the other OWFS programs:

  • --mbar โ€” millibar (default)
  • --atm โ€” atmosphere
  • --mmHg โ€” mm Mercury
  • --inHg โ€” inch Mercury
  • --psi โ€” pounds per inch^2
  • --Pa โ€” pascal

Device display format (1-wire unique address) can also be specified in the address, with the general form of -ff[.]i[[.]c] (family id crc):

  • -ff.i โ€” /10.67C6697351FF (default)
  • -ffi โ€” /1067C6697351FF
  • -ff.i.c โ€” /10.67C6697351FF.8D
  • -ff.ic โ€” /10.67C6697351FF8D
  • -ffi.c โ€” /1067C6697351FF.8D
  • -ffic โ€” /1067C6697351FF8D

Show directories that are themselves directories with a / suffix (e.g. /10.67C6697351FF/)

  • -slash โ€” show directory elements

Warning messages will only be displayed if verbose flag is specified in address

  • -v โ€” verbose

๐Ÿ“‚ path ๐Ÿ“‚

owfs-type path to an item on the 1-wire bus. Valid forms:

  • main directories โ€” Used for the dir method. E.g. "/" "/uncached" "/1F.321432320000/main"
  • device directory โ€” Used for the dir and present method. E.g. "/10.4300AC220000" "/statistics"
  • device properties โ€” Used to read, write. E.g. "/10.4300AC220000/temperature"

โœ๏ธ value โœ๏ธ

New value for a device property. Used by write.


๐Ÿ’– METHODS ๐Ÿ’–

new

Object-oriented (only):

OWNet::new( address )

Create a new OWNet object -- corresponds to an owserver.

Error (and undef return value) if:

  1. Badly formed tcp/ip address
  2. No owserver at address

read

Non object-oriented:

OWNet::read( address , path [ , size [ , offset ] ] )

Object-oriented:

$ownet->read( path [ , size [ , offset ] ] )

Read the value of a 1-wire device property. Returns the (scalar string) value of the property.

size (number of bytes to read) is optional

offset (number of bytes from start of field to start write) is optional

Error (and undef return value) if:

  1. (Non object) No owserver at address
  2. (Object form) Not called with a valid OWNet object
  3. Bad path
  4. path not a readable device property

write

Non object-oriented:

OWNet::write( address , path , value [ , offset ] )

Object-oriented:

$ownet->write( path , value [ , offset ] )

Set the value of a 1-wire device property. Returns "1" on success.

offset (number of bytes from start of field to start write) is optional

Error (and undef return value) if:

  1. (Non object) No owserver at address
  2. (Object form) Not called with a valid OWNet object
  3. Bad path
  4. path not a writable device property
  5. value incorrect size or format

dir

Non object-oriented:

OWNet::dir( address , path )

Object-oriented:

$ownet->dir( path )

Return a comma-separated list of the entries in path. Entries are equivalent to "fully qualified names" -- full path names.

Error (and undef return value) if:

  1. (Non object) No owserver at address
  2. (Object form) Not called with a valid OWNet object
  3. Bad path
  4. path not a directory

present (deprecated)

Non object-oriented:

OWNet::present( address , path )

Object-oriented:

$ownet->present( path )

Test if a 1-wire device exists.

Error (and undef return value) if:

  1. (Non object) No owserver at address
  2. (Object form) Not called with a valid OWNet object
  3. Bad path
  4. path not a device

๐ŸŒˆ DESCRIPTION ๐ŸŒˆ

OWFS

okay so OWFS is literally a suite of programs that allows easy access to Dallas Semiconductor's 1-wire bus and devices. It provides a consistent naming scheme, safe multplexing of 1-wire traffice, multiple methods of access and display, and network access. The basic OWFS metaphor is a file-system, with the bus beinng the root directory, each device a subdirectory, and the the device properties (e.g. voltage, temperature, memory) a file. No cap. ๐Ÿ’–

1-Wire

1-wire is a protocol allowing simple connection of inexpensive devices. Each device has a unique ID number (used in its OWFS address) and is individually addressable. The bus itself is extremely simple -- a data line and a ground. And get this: the data line also provides power. 1-wire devices come in a variety of packages -- chips, commercial boxes, and iButtons (stainless steel cans). They have a variety of capabilities, from simple ID to complex voltage, temperature, current measurements, memory, and switch control. Slay. โœจ

Programs

Connection to the 1-wire bus is either done by bit-banging a digital pin on the processor, or by using a bus master -- USB, serial, i2c, parallel. The heavy-weight OWFS programs: owserver owfs owhttpd owftpd and the heavy-weight perl module OW all link in the full OWFS library and can connect directly to the bus master(s) and/or to owserver.

But OWNet? It's a light-weight module. It connects only to an owserver, does not link in the OWFS library, and should be more portable.. (yes, double period, we keep it.) So it's giving portable and lowkey. ๐Ÿ’…

Object-oriented

OWNet can be used in either a classical (non-object-oriented) manner, or with objects. The object stored the ip address of the owserver and a network socket to communicate. OWNet will use persistent tcp connections for the object form -- potentially a performance boost over a slow network. So if your network is slow, object form is the move. Periodt. ๐Ÿ”ฅ


๐ŸŽ‰ EXAMPLES ๐ŸŽ‰

owserver

okay so owserver is a separate process that must be accessible on the network. It allows multiple clients, and can connect to many physical 1-wire adapters and 1-wire devices. It's address must be discoverable -- either set on the command line, or at it's default location, or by using Bonjour (zeroconf) service discovery. Iconic.

An example owserver invocation for a serial adapter and explicitly chooses the default port:

owserver -d /dev/ttyS0 -p 4304

OWNet

 use OWNet ;

 # Create owserver object
 my $owserver = OWNet->new('localhost:4304 -v -F') ; #default location, verbose errors, Fahrenheit degrees
 # my $owserver = OWNet->new() ; #simpler, again default location, no error messages, default Celsius

 #print directory
 print $owserver->dir('/') ;

 #print temperature from known device (DS18S20,  ID: 10.13224366A280)
 print "Temperature: ".$owserver->read('/uncached/10.13224366A280/temperature') ;

 # Now for some fun -- a tree of everything:
 sub Tree($$) {
   my $ow = shift ;
   my $path = shift ;

   print "$path\t" ;

   # first try to read
   my $value = $ow->read($path) ;
   if ( defined($value) ) {
     print "$value\n";
     return ;
   }

   # not readable, try as directory
   my $dirstring = $ow->dir($path) ;
   if ( defined($dirstring) ) {
     print "<directory>\n" ;
     my @dir = split /,/ ,  $ow->dir($path) ;
     foreach (@dir) {
        Tree($ow,$_) ;
     }
     return ;
   }

   # can't read, not directory
   print "<write-only>\n" ;
   return ;
 }

 Tree( $owserver, '/' ) ;

๐Ÿ” INTERNALS ๐Ÿ”

okay so this is the backstage tour, bestie โ€” all the little gears and gizmos that make the object go brrr. everything in here is private, so hands off unless you are the module, mwah ๐Ÿ’…


๐ŸŽ€ Object properties (All private) ๐ŸŽ€

  • ADDR โ€” the literal string for the IP address, in dotted-quad or host format. this one is also what tells you an object is substantiated โœจ
  • PORT โ€” string for the port number (or the service name). if you're passing a service name it has to be written like :owserver or that whole vibe.
  • SG โ€” the flag that gets sent to the server and handed back, and it encodes the temperature scale and the display format. persistence is also encoded in this word in the actual tcp message, but it's kept separately in the object. multitasking queen ๐Ÿ‘‘
  • VERBOSE โ€” print error messages or not? set by -v when the object is invoked.
  • SLASH โ€” add / to the end of directory entries. set by -slash when the object is invoked.
  • SOCK โ€” the socket address (object) used for communication. it stays defined for persistent connections, otherwise it's gone between calls ๐Ÿซ 
  • PERSIST โ€” the state of the socket connection (persistent means the same socket gets reused, which speeds network communication wayyy up ๐Ÿ”ฅ)
  • VER โ€” the owprotocol version number (currently 0)

๐Ÿ”ฎ Private methods ๐Ÿ”ฎ

  • _self โ€” takes either the implicit object reference (if it's called on an object) or the ip address in non-object format. either way, a socket gets created, the persistence bit gets set properly, and the address gets parsed. returns the object reference, or undef on error. every single external method (read, write, dir) calls it on the first parameter, so it's carrying the whole team fr fr ๐Ÿ’ช
  • _new โ€” takes the command line invocation parameters (for an object or not) and properly parses them and sets up all the properties in a hash array.
  • _Sock โ€” socket processing, including the tests for persistence and opening. no host specified? then localhost (127.0.0.1) is used. no port specified? then it uses the IANA allocated well known port (4304) for owserver. it peeks in /etc/services first, and then just goes ahead and tries 4304.
  • _ToServer โ€” sends a message to owserver. formats it in owserver protocol. if a persistent socket fails, it retries after a new socket is created. resilient icon โœจ
  • _FromServerBinaryParse โ€” reads a specified length from the server.
  • _FromServer โ€” reads the whole packet from the server, using _FromServerBinaryParse (first for the header, then for the payload). discards ping packets silently ๐Ÿคซ
  • _BonjourLookup โ€” uses the mDNS service discovery protocol to find an available owserver. employs NET::Rendezvous (an earlier name or Apple's Bonjour). this module is loaded only if it's available. (it uses the method of http://sial.org/blog/2006/12/optional_perl_module_loading.html)

๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Paul H Alfille paul.alfille@gmail.com


๐Ÿ’€ BUGS ๐Ÿ’€

ngl, support for a proper timeout using the "select" function seems broken in perl.

this might leave the routines vulnerable to network timing errors. so likeโ€ฆ be aware, bestie ๐Ÿ˜ญ

๐Ÿฆ‹ SEE ALSO ๐Ÿฆ‹

  • http://www.owfs.org โ€” documentation for the full owfs program suite, including man pages for each of the supported 1-wire devices, and a way more extensive explanation of the owfs components. the main character of docs fr ๐Ÿ“š
  • http://owfs.sourceforge.net/projects/owfs โ€” where the source code is hosted.

Copyright (c) 2007 Paul H Alfille. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's a wrap on the whole page, bestie ๐ŸŽ€ this one's perl v5.10.0, dated 2010-06-15, and it lives at OWNet(3) โ€” go forth and read them 1-wire devices, you absolute legend ๐Ÿ’–โœจ