I have just started playing with an ibutton (a DS1921G) and a DS9490 running kernel 2.6.31-22-generic.
I am running owfs with some python scripts. At the moment I am just able to get the current temperature and it all has to be using sudo so there is some way to go. It's my first time with fuse which owfs uses and I need to figure out why I have to use sudo for every command. The code I have so far is
Code:
sudo /opt/owfs/bin/owfs -F -u -m /home/norman/1-wire
which sets up the fuse file access to the ibutton
Code:
#! /usr/bin/env python
# $Id: one_wire_sensors.py 23 2004-07-22 04:35:36Z peter $
#
# need to check for /1-wire mounted but Vendor=04fa is not
# in the usb usb devices file. this can occur when the usb
# dongle is no longer connected.
#
# check that /1-wire is mounted
# if not, check that Vendor=04fa is in the usb devices file.
# if it is, then kick /etc/init.d/owfs to start up again
# if not, then ?
import os
import syslog
import csv
import time
##import util
Debug = True
OWUSBVendor = '04fa'
USBDevices = '/home/norman/1-wire/21.B5fb22000000/temperature'
MountFile = '/proc/mounts'
OWUSBMount = '/home/norman/1-wire/21.B5fb22000000/temperature'
MountCommand = '/etc/init.d/owfs.init start'
UnmountCommand = '/etc/init.d/owfs.init stop'
SensorLogName = 'sensor.log'
Sensors = {
'Temperature1' : os.path.join( OWUSBMount, '10.B7B64D000800' ),
'Temperature2' : os.path.join( OWUSBMount, '10.54BA4D000800' ),
#'Humidity1' : os.path.join( OWUSBMount, '12.386623000000' ),
#'Humidity2' : os.path.join( OWUSBMount, '12.3B6F23000000' ),
}
Messages = {
'MountedNoPresence' :
'1-wire mounted but no usb presence, unmounting 1-wire',
'UnmountedPresence' :
'1-wire not mounted but usb presence, mounting 1-wire',
'UnmountedNoPresence' :
'1-wire not mounted and no usb presence, nothing can be done',
'MountedNoSensors' :
'1-wire mounted and usb presense but no sensors, remounting 1-wire',
}
def log_message( message ):
if Debug:
print message
syslog.syslog( syslog.LOG_DAEMON|syslog.LOG_WARNING, message )
def check_mount( mount_point ):
known_mounts = open( MountFile, 'r' ).readlines()
for mount in known_mounts:
if mount_point in mount:
return True
return False
def check_usb_vendor( vendor ):
usb_lines = open( USBDevices, 'r' ).readlines( )
vendor = 'Vendor=' + vendor
for line in usb_lines:
if vendor in line:
return True
return False
def check_sensors( ):
for sensor in Sensors:
if not os.path.isdir( Sensors[ sensor ] ):
return False
return True
def read_temperature( ):
path = os.path.join( Sensors[ 'Temperature1' ], 'temperature' )
temperature1 = open( path, 'r' ).readlines( )
path = os.path.join( Sensors[ 'Temperature1' ], 'temperature' )
temperature2 = open( path, 'r' ).readlines( )
return ( float( temperature1[ 0 ] ), float( temperature2[ 0 ] ) )
def log_sensors( ):
current_time = time.time( )
path = util.log_path( '', SensorLogName )
temperature1, temperature2 = read_temperature( )
writer = csv.writer( file( path, 'a' ) )
writer.writerow( ( current_time, temperature1, temperature2 ) )
def one_wire( ):
mounted = check_mount( OWUSBMount )
usb_presence = check_usb_vendor( OWUSBVendor )
sensors = check_sensors( )
## if mounted:
## if not usb_presence:
## log_message( Messages[ 'MountedNoPresence' ] )
## os.system( UnmountCommand )
## elif not sensors:
## log_message( Messages[ 'MountedNoSensors' ] )
## os.system( UnmountCommand )
## os.system( MountCommand )
## elif Debug:
## print 'all is right with the world'
## elif usb_presence:
## log_message( Messages[ 'UnmountedPresence' ] )
## os.system( MountCommand )
## else:
## log_message( Messages[ 'UnmountedNoPresence' ] )
if __name__ == '__main__':
one_wire( )
if check_mount( OWUSBMount ):
log_sensors( )
This is code I found here: http://www.pyzine.com/Issue007/Secti...ollection.html
I saved it as readbutton.py and run it with sudo again.
All the lines with ## at the beginning are lines I had to comment out so it would run. Mainly because I had access errors otherwise.
Then
Code:
sudo cat 1-wire/21.B5fb22000000/temperature
to see the current value held in the ibutton.
Hope this helps and maybe someone can help me get it all working fully. I could not find the util module anywhere nor would it work without sudo. I am a member of the fuse group but all I see for the 1-wire directory is
d????????? ? ? ? ? ? 1-wire
Bookmarks