Last active
May 15, 2021 19:38
-
-
Save jjeising/54a84cb2a7a8150f3cdc23829b6d10d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Receive values from a CO2 Monitor via node-hid | |
AirControl Mini CO2 | |
TFA 31.5006 | |
https://hackaday.io/project/5301-reverse-engineering-a-low-cost-usb-co-monitor/log/17909-all-your-base-are-belong-to-us | |
*/ | |
const HID = require('node-hid'); | |
let dev; | |
try { | |
dev = new HID.HID(0x04d9, 0xa052); | |
} catch (e) { | |
console.error('Error: Failed to open device: ' + e.message); | |
process.exit(1); | |
} | |
dev.sendFeatureReport(Buffer.from([0xc4])); | |
dev.on('data', (data) => { | |
if ( | |
data[4] !== 0x0d || | |
((data[0] + data[1] + data[2]) & 0xff) !== data[3] | |
) { | |
console.error('Error: Checksum error.'); | |
return; | |
} | |
switch (data[0]) { | |
case 80: | |
console.log('CO2: ', data.readInt16BE(1)); | |
break; | |
case 66: | |
console.log('Temp: ', (data.readInt16BE(1) / 16.0 - 273.15).toFixed(3)); | |
break; | |
} | |
}); | |
dev.on('error', (error) => { | |
console.error('Error: ', error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment