OWNet(3pm)
π¦ OWNet π¦
okay bestie, gather round, because this is OWNet(3pm) from the User Contributed Perl Documentation section and it is lowkey iconic π
β¨ NAME β¨
OWNet β Light weight access to owserver π«Ά
πΈ SYNOPSIS πΈ
so, OWNet is an easy way to access owserver and thence the 1-wire bus. no cap.
Dallas Semiconductor's 1-wire system uses simple wiring and unique addresses for its interesting devices. The One Wire File System (OWFS) is a suite of programs that hide 1-wire details behind a file system metaphor. owserver connects to the 1-wire bus and provides network access.
OWNet is a perl module that connects to owserver and allows reading, writing and listing the 1-wire bus. it's giving "small but mighty" β¨
Example perl program that prints the temperature:
use OWNet ;
print OWNet::read( "localhost:4304" , "/10.67C6697351FF/temperature" ) ."\n" ;
There is the alternative object oriented form:
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:
- 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 π«Ά
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
Trim whitespace from numeric values
-trimβ trim spaces
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
dirmethod. E.g."/""/uncached""/1F.321432320000/main" - device directory β Used for the
dirandpresentmethod. 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:
- Badly formed tcp/ip address
- No
owserverat 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:
- (Non object) No
owserverat address - (Object form) Not called with a valid OWNet object
- Bad path
- 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:
- (Non object) No
owserverat address - (Object form) Not called with a valid OWNet object
- Bad path
- path not a writable device property
- 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:
- (Non object) No
owserverat address - (Object form) Not called with a valid OWNet object
- Bad path
- path not a directory
present (deprecated)
π¨ bestie, heads up: present is deprecated. it's still here, but it's giving "legacy era". π¨
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:
- (Non object) No
owserverat address - (Object form) Not called with a valid OWNet object
- Bad path
- path not a device
π DESCRIPTION π
OWFS
OWFS is a suite of programs that allows easy access to Dallas Semiconductor's 1-wire bus and devices. OWFS 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.
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. The data line also provides power. 1-wire devices come in a variety of packages β chips, commercial boxes, and iButtons (stainless steel cans). 1-wire devices have a variety of capabilities, from simple ID to complex voltage, temperature, current measurements, memory, and switch control.
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.
OWNet is a light-weight module. It connects only to an owserver, does not link in the OWFS library, and should be more portable.. π
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. β‘
β EXAMPLES β
owserver
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.
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 bestie, this is the backstage area. no flashy lights, just the machinery. but it's so iconic, fr fr.
π Object properties (All private) π
ngl these are all private, so don't go poking at them like they're public API. they're the object's little diary entries.
ADDRβ a literalstingfor the IP address, in dotted-quad or host format. lowkey this one does double duty: it's also the flag that says an object is substantiated. like, "yes this is a real one, she's here."PORTβ a string for the port number (or the service name, bestie). if you're using a service name it must be written like:owserveror the like. no shortcuts, sorry not sorry.SGβ a flag that gets sent to the server and comes back. it encodes the temperature scale and the display format. in the actual tcp message, persistence is also crammed into this word β but in the object itself it's kept separately. sneaky. πVERBOSEβ print error messages or nah? set by-vwhen the object is invoked. turn it on and she'll start talking.SLASHβ adds a/to the end of directory entries. set by-slashwhen the object is invoked. it's giving "trailing slash aesthetic."SOCKβ the socket address (an object) used for communication. for persistent connections it stays defined; otherwise it gets deleted between calls. she comes and goes. main character energy but make it ephemeral.PERSISTβ the state of the socket connection. when it's persistent, the same socket gets reused, which speeds up network communication. slay. β‘VERβ the owprotocol version number (currently0).
π Private methods π
these are the internal functions, the little helpers running around backstage. all private. do not touch. (iykyk)
_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 properly set, and the address gets parsed. returns the object reference, orundefon error. every external method (read,write,dir) calls this on the first parameter. she's the one who sets everything up π_newβ takes the command line invocation parameters (for an object or not) and properly parses and sets up the properties in a hash array. the constructor vibes._Sockβ socket processing, including tests for persistence and opening. if no host is specified,localhost(127.0.0.1) is used. if no port is specified, it uses the IANA allocated well known port (4304) forowserver. first it looks in/etc/services, then it just tries4304. persistence queen._ToServerβ sends a message toowserver. formats it in owserver protocol. if a persistent socket fails, it retries after a new socket is created. she's resilient like that π«Ά_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. she doesn't even acknowledge them. iconic._BonjourLookupβ uses the mDNS service discovery protocol to find an availableowserver. employsNET::Rendezvous(an earlier name for Apple's Bonjour). this module is loaded only if available. (uses the method ofhttp://sial.org/blog/2006/12/optional_perl_module_loading.html)
β¨ AUTHOR β¨
Paul H Alfille <paul.alfille@gmail.com> β we stan, fr fr π
π BUGS π
support for proper timeout using the "select" function seems broken in perl. this might leave the routines vulnerable to network timing errors. not her fault, blame perl. π
π SEE ALSO π
http://www.owfs.orgβ documentation for the fullowfsprogram suite, including man pages for each of the supported 1-wire devices, and more extensive explanatation ofowfscomponents.http://owfs.sourceforge.net/projects/owfsβ location where the source code is hosted. the mothership, basically.
π COPYRIGHT π
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 bestie πβ¨ this whole page comes from perl v5.40.1 and it was last touched on 2025-05-04, filed under OWNet(3pm) β go forth and talk to your 1-wire devices, you absolute legend ππ¦
π¦ where this page comes from
- debian trixie: libownet-perl 3.2p4+dfsg1-6 Β· GPL-2.0-only
- ubuntu questing: libownet-perl 3.2p4+dfsg1-6
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms