Android aar module to ease the AudioMoth configuration via Android USB interfaces. Currently works for Firmware version 1.4.4
Portions from https://github.com/452/USBHIDTerminal/
- Clone this repo.
- Open it in Android Studio
- Connect your phone to WiFi
- Connect your phone to PC
- Open adb (from command line)
- Issue the command >adb tcpip 5555
- Issue the command >adb connect [your-phohe-ip-address]:5555
- Open testapp
- Press debug button
- Connect your AudioMoth to the mini-usb to the phone and set the AudioMoth switch USB/OFF
- Press detect button, select a device and accept the permission request
- Press configure button
- Press set date button
- On Android Studio press Alt+6 Logcat console
- Select your phone if it's not already selected
- Select the running process com.undercurrency.audiomoth.test
- Then, you will see the log messages, try to notice the byte arrays printed on the log, this byte arrays confirm the correct send/receive of the configuration
This code includes a Test App (testapp), it contains a main activity with 4 buttons to test all the functions included in the audiomoth-usbhid aar library, in the code, inside the assets directory, there's a json file called Ultrasonic.json, this file was generated by the AudioMoth desktop application, if you like you are free to change the contents of this json file, compile and install the testapp to your favorite Android Phone.
- Run the AudioMoth test demo.
- Plug AudioMoth device to the phone and set the AudioMoth switch USB/OFF.
- Tap Detect button. 3.1 Select the device from the list. 3.2 Accept the permission request to let the app use USB communication. This will send the correct packet to the AudioMoth and get back the Device Info (Firmware, Batery level, Date and Serial number) and display it in the screen.
- Tap Configure button. This will send a Json file called Ultrasonic.json to AudioMoth, then it will receive the configuration bytes on return from the AudioMoth, convert it to json again and show it in the screen.
- Tap SetDate button. This will send the correct packet to set the current date to AudioMoth. Then it will receive the same bytes in return, convert it to a Date and print it on the screen.
The audiomoth-usbhid library works as an Android Service. This means that the only way to use it is througth events in and events out. If you send an event in, this event have its corresponding event out
Event In | Event Out |
---|---|
PrepareDevicesListEvent | AudioMothPacketReceiveEvent |
AudioMothSetDateEvent | AudioMothSetDateReceiveEvent |
AudioMothConfigEvent | AudioMothConfigReceiveEvent |
This library also have the capability to seriallize and deserialize an AudioMoth binary arrays to the corresponding Java Object called RecordingSettings Please review the RecordingSettings class and their corresponding methods: serializeToBytes and the corresponding RecordingSettings(byte[] array) constructor.
To use this aar you may compile it, and then add it in your module gradle.properties like this:
In project structure:
- Create a folder in libs directory, if it doesn't exists yet.
- Put your aar lib into the libs folder.
- Add the following dependencies: (the first includes all the aar files in lib, the latter an eventbus handler):
dependencies {
...
implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])
implementation 'de.greenrobot:eventbus:2.4.0'
...
}
to your gradle.properties app module.
In an Activity
- Add an event bus in onCreate method
- Write a function called startService with a new Intent to all USBHidTool.class this call start up the android service responsible for calling AudioMoth
- In onStart method add a call to startService() and a call to eventBus.register(this)
- The way to interact with audiomoth is by calling events to configure it:
4.1 If you want to receive the date, firmware and serial number you must send a PrepareDevicesListEvent() and write the corresponding code to handle an AudioMothPacketReceiveEvent, inside this event an object called DeviceConfig is instantiated.
4.2 If you want to set the Date to the device, you must send the corresponding AudioMothSetDateEvent(new Date()); and write the corresponding code to receive the response AudioMothSetDateReceiveEvent, inside this event lives the Date from the device.
4.3 If you want to set the AudioMothConfig, you must send the corresponding AudioMothConfigEvent(rs); with the RecordingSettings object set, you must create a RecordingSettings object with all the values you want. The RecordingSettings must include an instance of DeviceInfo, so for example, before that you need to call at least the PrepareDevicesListEvent and receive the DeviceConfig and then set it to the new RecordingSettings. Then you must receive the AudioMothConfigReceiveEvent, inside this event lives a regenerated RecordingSettings rebuild from the AudioMoth response.