2.3.0 • Published 5 months ago

audiomoth-hid v2.3.0

Weekly downloads
62
License
-
Repository
github
Last release
5 months ago

AudioMoth-HID

A Node.js library for interfacing with AudioMoth devices over USB. The module is hosted on npm under the name 'audiomoth-hid'.

Usage

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, packet) {
    if (packet[0] === 0x0A) {
        if (packet[1] === 0x01) {
            console.log("Attached device switching 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);
});

Linux

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"

Updating module

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.

Example applications using this module

License

Copyright 2017 Open Acoustic Devices.

MIT license.

2.3.0

5 months ago

2.2.0

5 months ago

2.1.0

3 years ago

2.0.3

4 years ago

2.0.4

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.0

5 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago