【问题标题】:How do I use owfs to read an iButton temperature logger?如何使用 owfs 读取 iButton 温度记录器?
【发布时间】:2008-09-22 04:30:19
【问题描述】:

我已经安装了owfs 并试图从iButton temperature logger 中读取数据。

owfs 让我将 iButton 挂载为 fuse 文件系统,我可以看到所有数据。不过,我无法弄清楚访问数据的最佳方式是什么。我可以通过catting 文件获得个人读数,例如cat onewire/{deviceid}/log/temperature.1,但 onewire/{deviceid}/log/temperature.ALL 文件已“损坏”(可能太大,因为 histogram/temperature.ALL 工作正常)。

读取所有文件的 python 脚本似乎可以工作,但需要很长时间。有更好的方法吗?有人有例子吗?

我使用的是 Ubuntu 8.04,但无法运行 Java“单线查看器”应用程序。

更新:使用owpython(与owfs 一起安装),我可以获得当前温度,但不知道如何访问记录的日志:

>>> import ow
>>> ow.init("u") # initialize USB
>>> ow.Sensor("/").sensorList()
[Sensor("/81.7FD921000000"), Sensor("/21.C4B912000000")]
>>> x = ow.Sensor("/21.C4B912000000")
>>> print x.type, x.temperature
DS1921           22

x.log 给出一个AttributeError

【问题讨论】:

    标签: python ubuntu 1wire


    【解决方案1】:

    我也遇到了 owfs 的问题。我发现它是一个简单问题的过度设计的解决方案。现在我使用DigiTemp 代码没有问题。我发现它灵活可靠。例如,我通过运行每分钟将房间的温度存储在一个日志文件中

    /usr/local/bin/digitemp_DS9097U -c /usr/local/etc/digitemp.conf \
        -q -t0 -n0 -d60 -l/var/log/temperature
    

    为了达到这一点,我下载了源文件,解压它,然后执行以下操作。

    # Compile the hardware-specific command
    make ds9097u
    # Initialize the configuration file
    ./digitemp_DS9097U -s/dev/ttyS0 -i
    # Run command to obtain temperature, and verify your setup
    ./digitemp_DS9097U -a 
    # Copy the configuration file to an accessible place
    cp .digitemprc /usr/local/etc/digitemp.conf
    

    我还手动编辑了我的配置文件以根据我的设置进行调整。这就是它的结局。

    TTY /dev/ttyS0
    READ_TIME 1000
    LOG_TYPE 1
    LOG_FORMAT "%b %d %H:%M:%S Sensor %s C: %.2C F: %.2F"
    CNT_FORMAT "%b %d %H:%M:%S Sensor %s #%n %C"
    HUM_FORMAT "%b %d %H:%M:%S Sensor %s C: %.2C F: %.2F H: %h%%"
    SENSORS 1
    ROM 0 0x10 0xD3 0x5B 0x07 0x00 0x00 0x00 0x05 
    

    在我的例子中,我还创建了一个 /etc/init.d/digitemp 文件并让它在启动时运行。

    #! /bin/sh
    #
    # System startup script for the temperature monitoring daemon
    #
    ### BEGIN INIT INFO
    # Provides: digitemp
    # Required-Start:
    # Should-Start:
    # Required-Stop:
    # Should-Stop:
    # Default-Start:  2 3 5
    # Default-Stop:   0 1 6
    # Description:    Start the temperature monitoring daemon
    ### END INIT INFO
    
    DIGITEMP=/usr/local/bin/digitemp_DS9097U
    test -x $DIGITEMP || exit 5
    
    DIGITEMP_CONFIG=/root/digitemp.conf
    test -f $DIGITEMP_CONFIG || exit 6
    
    DIGITEMP_LOGFILE=/var/log/temperature
    
    # Source SuSE config
    . /etc/rc.status
    
    rc_reset
    case "$1" in
        start)
            echo -n "Starting temperature monitoring daemon"
            startproc $DIGITEMP -c $DIGITEMP_CONFIG  -q -t0 -n0 -d60 -l$DIGITEMP_LOGFILE
            rc_status -v
            ;;
        stop)
            echo -n "Shutting down temperature monitoring daemon"
            killproc -TERM $DIGITEMP
            rc_status -v
            ;;
        try-restart)
            $0 status >/dev/null && $0 restart
            rc_status
            ;;
        restart)
            $0 stop
            $0 start
            rc_status
            ;;
        force-reload)
            $0 try-restart
            rc_status
            ;;
        reload)
            $0 try-restart
            rc_status
            ;;
        status)
            echo -n "Checking for temperature monitoring service"
            checkproc $DIGITEMP
            rc_status -v
            ;;
        *)
            echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
            exit 1
            ;;
    esac
    rc_exit
    

    【讨论】:

    • 感谢您提供信息,但我认为这无助于访问存储在 DS1922T 上的日志。我可以使用 owpython 或 owfs 读取当前温度,它只是访问我正在努力处理的存储测量值。
    【解决方案2】:

    我不认为有什么聪明的方法。 owpython 不支持 API 文档中的说明。我猜/proc 是您最安全的选择。也许看看 owpython 模块的源代码,看看你是否能找出它是如何工作的。

    【讨论】:

    • 除了文档字符串之外,我找不到任何文档。还有什么吗?
    【解决方案3】:

    嗯,我刚开始看ibuttons,想用python。

    这看起来更有希望:

    http://www.ohloh.net/p/pyonewire

    【讨论】:

      猜你喜欢
      • 2011-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-08
      • 1970-01-01
      • 2021-09-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多