A Node.js library for interfacing with AudioMoth devices over USB. The module is hosted on npm under the name 'audiomoth-hid'.
The module should be imported as normal:
var audiomoth = require('audiomoth-hid');
Asynchronous function calls then provide access to its functionality. To obtain the time used by the onboard clock:
audiomoth.getTime(function (err, date) {
console.log("Time/date on device: " + date);
});
Set the onboard clock with a Date()
object:
audiomoth.setTime(new Date(), function (err, date) {
console.log("New time/date of device: " + date);
});
Get AudioMoth's unique 16 digit ID number:
audiomoth.getID(function (err, id) {
console.log("Device unique ID: " + id);
});
Get string containing the current battery state of attached AudioMoth:
audiomoth.getBatteryState(function (err, batteryState) {
console.log("Attached device's current battery state: " + batteryState);
});
Send application packet of max length 62 (message limit of 64 bytes, 2 bytes required for message identification) :
var packet = new Uint8Array(62);
Insert date object into packet
var date = new Date();
writeLittleEndianBytes(packet, 0, 4, date.valueOf() / 1000);
Insert 32 bit number into packet
var i = 10000;
writeLittleEndianBytes(packet, 4, 4, i);
Insert arbitrary 8 bit values into packet:
packet[8] = 5;
packet[9] = 0x00;
packet[10] = 0x01;
audiomoth.setPacket(packet, function (err, packet) {
console.log("Data returned from application specific packet: " + packet);
});
Get application packet set in AudioMoth firmware:
audiomoth.getPacket(function (err, packet) {
console.log("Data returned from application specific packet: " + packet);
});
Get firmware version set in AudioMoth firmware:
audiomoth.getFirmwareVersion(function (err, firmwareVersion) {
console.log("Attached device's firmware version: " + firmwareVersion);
});
Get firmware description set in AudioMoth firmware:
audiomoth.getFirmwareDescription(function (err, firmwareDescription) {
console.log("Attached device's firmware description: " + firmwareDescription);
});
Query AudioMoth to see if it supports switching to bootloader with a USB command:
audiomoth.queryBootloader(function (err, supportsBootloaderSwitch) {
if (supportsBootloaderSwitch) {
console.log("Attached device's firmware supports bootloader switching over HID.");
} else {
console.error("Attached device's firmware does not support bootloader switching over HID.");
}
});
Switch AudioMoth to bootloader for flashing:
audiomoth.switchToBootloader(function (err, switchedToBootloader) {
if (switchedToBootloader) {
console.log("Attached device will switch to bootloader.");
} else {
console.error("Attached device's firmware does not support bootloader switching over HID.");
}
});
Query AudioMoth to see if it supports the USB HID bootloader:
audiomoth.queryUSBHIDBootloader(function (err, supportsUSBHIDBootloader) {
if (supportsUSBHIDBootloader) {
console.log("Attached device's firmware supports the USB HID bootloader.");
} else {
console.error("Attached device's firmware does not support the USB HID bootloader.");
}
});
Send single USB HID packet:
audiomoth.sendPacketToUSBHIDBootloader(function (err, packet) {
console.log("Data returned from USB HID bootloader: " + packet);
});
Send multiple USB HID packets:
audiomoth.sendMultiplePacketsToUSBHIDBootloader(function (err, packet) {
console.log("Data returned from USB HID bootloader: " + packet);
});
The module will work as is on macOS and Windows. However, Linux prevents USB HID devices from being writable by default. This can be fixed by navigating to /lib/udev/rules.d/ and adding a file called 99-audiomoth.rules. The content of this file should by:
SUBSYSTEM=="usb", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="0002", MODE="0666"
Execution permissions are lost when binaries are committed to npm repository from a Windows machine. To avoid this, all updates must be published from MacOS.
Copyright 2017 Open Acoustic Devices.