| [5056] | 1 | How to write applications which use the hwmon drivers |
|---|
| 2 | ===================================================== |
|---|
| [1302] | 3 | |
|---|
| [5056] | 4 | You have several choices in accessing sensor devices using the hwmon drivers. |
|---|
| 5 | This document will briefly describe these methods, their advantages and |
|---|
| 6 | disadvantages, and provide examples. |
|---|
| [1302] | 7 | |
|---|
| 8 | From lowest-level to the highest-level, the access methods are: |
|---|
| 9 | |
|---|
| [5056] | 10 | 1. sysfs access |
|---|
| 11 | 2. libsensors library |
|---|
| 12 | 3. sensors program |
|---|
| [1302] | 13 | |
|---|
| 14 | |
|---|
| 15 | Details: |
|---|
| 16 | |
|---|
| [5056] | 17 | 1. sysfs access |
|---|
| [4484] | 18 | --------------- |
|---|
| [5056] | 19 | Hwmon drivers create subdirectories in the sysfs filesystem (usually /sys) |
|---|
| 20 | which can be accessed directly by applications. |
|---|
| [2142] | 21 | Naming and content standards for the entries in these subdirectories |
|---|
| [5056] | 22 | are documented in the file Documentation/hwmon/sysfs-interface in the 2.6 |
|---|
| 23 | kernel source tree. sysfs is the lowest-level access to sensor values. |
|---|
| [2142] | 24 | |
|---|
| 25 | Note that most drivers provide only raw sensor readings via /sys; |
|---|
| 26 | many readings must be scaled or adjusted, and these adjustments |
|---|
| [4484] | 27 | must often be changed by the user. An application using /sys must |
|---|
| [2142] | 28 | generally provide adjustment facilities and the requirements |
|---|
| [5056] | 29 | of the adjustments can be quite complex. For this reason, this |
|---|
| 30 | approach isn't recommended. Instead, consider the libsensors library, |
|---|
| 31 | which offers a higher-level interface on top of sysfs (see below.) |
|---|
| [2142] | 32 | |
|---|
| [5056] | 33 | Still, this method may work well for shell and perl scripts written to |
|---|
| 34 | access a specific device. |
|---|
| [2142] | 35 | |
|---|
| [5056] | 36 | For an example of a program using /sys accesses, see gkrellm (though |
|---|
| 37 | recent versions use libsensors instead.) See also lib/sysfs.c. |
|---|
| [2142] | 38 | |
|---|
| [5056] | 39 | 2. libsensors library |
|---|
| [1302] | 40 | --------------------- |
|---|
| 41 | The libsensors library provides standardized access to all chip drivers. |
|---|
| 42 | It also provides a translation layer with settings in /etc/sensors.conf |
|---|
| 43 | so that your application sees adjusted (scaled) values using settings |
|---|
| [5056] | 44 | provided by the user. Other facilities are sensor labelling, limit setting, |
|---|
| 45 | and ignoring individual sensors. This is the recommended way to access |
|---|
| 46 | the sensor chips. |
|---|
| [1302] | 47 | |
|---|
| [5056] | 48 | The library API is documented in the libsensors(3) manual page. The |
|---|
| 49 | configuration file format is documented in the sensors.conf(5) manual |
|---|
| 50 | page. |
|---|
| [1302] | 51 | |
|---|
| 52 | Note that libsensors falls under the GPL, not the LGPL. |
|---|
| 53 | In more human language, that means it is FORBIDDEN to link any application |
|---|
| 54 | to the library, even to the shared version, if the application itself |
|---|
| 55 | does not fall under the GPL. This may or may not be changed in the future. |
|---|
| 56 | Contact us if you wish to discuss your application. |
|---|
| [2142] | 57 | |
|---|
| [5056] | 58 | For examples of programs using libsensors accesses, see prog/sensors and |
|---|
| 59 | prog/sensord. |
|---|
| [2142] | 60 | |
|---|
| [5056] | 61 | 3. sensors program |
|---|
| [2142] | 62 | ------------------ |
|---|
| 63 | The 'sensors' program is a text-based application that uses libsensors. |
|---|
| 64 | The output is fairly standardized; therefore this output could be |
|---|
| 65 | used by other applications. |
|---|
| 66 | One simple method is 'sensors|grep ALARM'. |
|---|
| [5056] | 67 | Note though that there is no guarantee that the output format won't change |
|---|
| 68 | in the future, so be careful. We might improve the command-line interface |
|---|
| 69 | of 'sensors' someday to make it more convenient for external programs to |
|---|
| 70 | use it as a back-end. |
|---|