aromajoin / controller-sdk-java

Enable developers to connect and control Aroma Shooter.
https://aromajoin.com/software/sdk
Apache License 2.0
4 stars 0 forks source link

Connecting to Aroma Shooter disables Bluetooth in Raspberry Pi #4

Open danielle-h opened 2 years ago

danielle-h commented 2 years ago

Once connection was made to an Aroma Shooter, the Bluetooth becomes inoperative with error "Operation already in progress". Only a reboot restores the Bluetooth (until next Aroma Shooter connection).

Using Raspberry pi running Linux 10 (buster).

output of java -version:

openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment (build 11.0.12+7-post-Raspbian-2deb10u1)
OpenJDK Server VM (build 11.0.12+7-post-Raspbian-2deb10u1, mixed mode)

Using Bleak and Python 3.7.3 to connect to Bluetooth device.

To reproduce: Python code to discover devices vi ble:

import asyncio
from bleak import BleakScanner,BleakClient,BleakError

async def discoverDevices():
    devices = await BleakScanner.discover()
    for d in devices:
        print(d)

async def main():
    await discoverDevices()

asyncio.run(main())

Java code to connect to Aroma Shooter: (error occurs after running this script regardless of whether saw aroma shooter or not, see issue #3 )

import com.aromajoin.sdk.core.device.AromaShooter;
import com.aromajoin.sdk.core.device.Port;
import com.aromajoin.sdk.jvm.usb.USBASController;

/**
 * Minimal example for connection to Aroma Shooter
 *
 */
public class App {
  public static void main(String[] args) {

    System.out.println("Initializing Aroma Shooter...");
    USBASController usbController = initAromajoin();
    //waiting makes no difference to the error.
    /*try {
        Thread.sleep(5000);
    }catch (Exception e){
      System.out.println(e.getStackTrace());
    }*/
      System.out.println("exiting...");
      usbController.disconnectAll();
  }

  private static USBASController initAromajoin() {
    USBASController usbController = new USBASController();
    usbController.scanAndConnect();
    if (!usbController.getConnectedDevices().isEmpty()) {
      for (AromaShooter aromaShooter : usbController.getConnectedDevices()) {
        System.out.println("Connected to AromaShooter: " + aromaShooter.getSerial());
      }
    }
    return usbController;
  }
}

Steps to reproduce:

  1. Run Python code. Output will be available Bluetooth devices in your area. No Errors. My output:
    3C:3F:EC:43:4A:D5: 3C-3F-EC-43-4A-D5
    84:0D:8E:D7:D1:EA: ASN2A00306
  2. Run Java code. My output:
    Initializing Aroma Shooter...
    com.fazecast.jSerialComm.SerialPortTimeoutException: The write operation timed out before all data was written.
        at com.fazecast.jSerialComm.SerialPort$SerialPortOutputStream.write(SerialPort.java:1470)
        at com.fazecast.jSerialComm.SerialPort$SerialPortOutputStream.write(SerialPort.java:1449)
        at com.aromajoin.sdk.jvm.SerialReader.query(SerialReader.java:33)
        at com.aromajoin.sdk.jvm.usb.USBASController.scanAndConnect(USBASController.java:74)
        at worg.weizmann.App.initAromajoin(App.java:107)
        at worg.weizmann.App.main(App.java:27)
    exiting...
  3. Re-run Python code. My output:
    Traceback (most recent call last):
    File "/home/pi/Documents/Danielle/rpi-box-python/bleak_poc.py", line 53, in <module>
    asyncio.run(main())
    File "/usr/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
    File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
    File "/home/pi/Documents/Danielle/rpi-box-python/bleak_poc.py", line 51, in main
    await discoverDevices()
    File "/home/pi/Documents/Danielle/rpi-box-python/bleak_poc.py", line 14, in discoverDevices
    devices = await BleakScanner.discover()
    File "/home/pi/Documents/Danielle/rpi-box-python/.venv/lib/python3.7/site-packages/bleak/backends/scanner.py", line 115, in discover
    async with cls(**kwargs) as scanner:
    File "/home/pi/Documents/Danielle/rpi-box-python/.venv/lib/python3.7/site-packages/bleak/backends/scanner.py", line 95, in __aenter__
    await self.start()
    File "/home/pi/Documents/Danielle/rpi-box-python/.venv/lib/python3.7/site-packages/bleak/backends/bluezdbus/scanner.py", line 166, in start
    assert_reply(reply)
    File "/home/pi/Documents/Danielle/rpi-box-python/.venv/lib/python3.7/site-packages/bleak/backends/bluezdbus/utils.py", line 23, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
    bleak.exc.BleakDBusError: [org.bluez.Error.InProgress] Operation already in progress

Any help would be most appreciated, as I require analysis of Bluetooth data in order to trigger the Aroma Shooter in my system.

danielle-h commented 2 years ago

From previous experience in Raspberry Pi, attempting to talk to the Bluetooth port /dev/ttyAMA0 as if is was a USB port /dev/ttyACM* can result in this type of crash. Perhaps it's connected?

quangctkm9207 commented 2 years ago

@danielle-h : Thanks for reporting the issue. This library (Java version) is supposed to connect Aroma Shooter via USB only. You are trying to connect via Bluetooth?

danielle-h commented 2 years ago

No. I am trying to connecting to another device via Bluetooth while Aroma Shooter is connected via USB. This is impossible as connecting the Aroma Shooter (using USB) crashes Bluetooth on a Raspberry Pi.