Hardware Reference
In-Depth Information
Finally, add the code in
Example 2-14
in to a file named
onewire.js
, edit the path assigned
to
w1
so that the path points to your device, and then run it.
Example 2-14. Reading a temperature with a DS18B20 (onewire.js)
#!/usr/bin/env node
var
b
=
require
(
'bonescript'
);
var
w1
=
"/sys/bus/w1/devices/28-00000114ef1b/w1_slave"
setInterval
(
getTemp
,
1000
);
// read temperatue every 1000ms
function
getTemp
() {
b
.
readTextFile
(
w1
,
printStatus
);
}
function
printStatus
(
x
) {
console
.
log
(
'x.data = '
+
x
.
data
);
console
.
log
(
'x.err = '
+
x
.
err
);
}