xbee-android
xbee-android copied to clipboard
Xbee Device Not Found
I need to create an android application for communication purpose using Xbee device over USB. I have created a simple program to open the device but it throws the exception Xbee Device Not Found.
Here is the code:
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import com.digi.xbee.api.android.XBeeBLEDevice;
import com.digi.xbee.api.android.XBeeDevice;
import com.digi.xbee.api.exceptions.XBeeException;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Thread(new Runnable() {
@Override
public void run() {
XBeeDevice myXBeeDevice = new XBeeDevice(MainActivity.this, 115200);
try {
myXBeeDevice.open();
showToastMessage("Device Opened: ");
} catch (XBeeException e) {
showToastMessage("Could not open device: " + e.getMessage());
}
}
}).start();
}
private void showToastMessage(final String message) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
}
});
}
}
Hi @shubham9436,
What XBee module do you have and how is it connected to the Android device? Are you using a Digi development board?
Best regards.
I have XBee pro S2C. Xbee is mounted on CP2102. https://robu.in/product/xbee-usb-adaptercp/ This USB adapter is connected to my android device via OTG. No, I am not using Digi development board.
Alright, that seems to be the problem. That specific board is not registered in the list of supported boards (see this file), so the library cannot find the module.
You have two options:
-
Instead of using that
XBeeDeviceconstructor, use the other that allows passing aUsbDeviceobject, something similar toUsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList(); // Get the USB device associated to your board. UsbDevice usbDevice = [...] // Create the XBee device object. XBeeDevice xbeeDevice = new XBeeDevice(context, 115200, usbDevice);Note that this constructor was added to the library recently, so it is not included in the latest release. You will need to checkout the code from
masterand compile the library in order to use it. -
Add the VID and PID of your board to the list mentioned above in the
AndroidUSBInterfaceclass. As in the other option, you will need to checkout the code and compile the library.
Hope this helps.
I tried the first option. When I try to call the open function, it throws an exception could not determine operating mode
I tried the first option. When I try to call the open function, it throws an exception
could not determine operating mode
Did you ever solve this error? I am seeing the same error on Android 14 https://github.com/digidotcom/xbee-android/issues/30