Android AllJoyn: Connection with second machine gives error of BusAttachement

0 votes

I have developed application for two different sensors. They are working fine separately but when I try to use them togather and create two diffent buses than Alljoyn gives this exception.

org.alljoyn.services.common.BusAlreadyExistException: The object has been set previously with a BusAttachment.

Below is my source code for connection. Can anyone tell me why I'm having this issue.

private void connect() 
        {           org.alljoyn.bus.alljoyn.DaemonInit.PrepareDaemon(getApplicationContext());

            bus = new BusAttachment("ControlPanelBrowser", BusAttachment.RemoteMessage.Receive);
            bus.registerBusListener(new BusListener());


            Status status = bus.registerBusObject(mControlPanelSignalInterface, Constants.SERVICE_PATH);


            if (status != Status.OK) {

                Log.d(TAG, "Problem while registering bus object");

            }   

            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            srpPassword = settings.getString(PREFS_PASSWORD, DEFAULT_SECURED_SRP_PASSWORD);

            SrpAnonymousKeyListener authListener = new SrpAnonymousKeyListener(this, logger, AUTH_MECHANISMS);
            Status authStatus = bus.registerAuthListener(authListener.getAuthMechanismsAsString(), 
                    authListener, getKeyStoreFileName());

            if ( authStatus != Status.OK ) {
                Log.e(TAG, "Failed to register AuthListener");
            }

            status = bus.connect();


            if (Status.OK == status){

                String daemonName = Constants.DAEMON_NAME_PREFIX + ".ControlPanelBrowser.G" + 
                        bus.getGlobalGUIDString();

                int flag = BusAttachment.ALLJOYN_REQUESTNAME_FLAG_DO_NOT_QUEUE;

                Status reqStatus = bus.requestName(daemonName, flag);

                if (reqStatus == Status.OK) {

                    Status adStatus = bus.advertiseName(Constants.DAEMON_QUIET_PREFIX +
                            daemonName, SessionOpts.TRANSPORT_ANY);

                    if (adStatus != Status.OK){
                        bus.releaseName(daemonName);
                        Log.e(TAG, "Failed to advertise daemon name: '" + daemonName + "', Error: '" + status + "'");
                    }
                    else{
                        Log.d(TAG, "Succefully advertised daemon name: '" + daemonName + "'");
                    }
                }
                else {
                    Log.e(TAG, "Failed to request daemon name: '" + daemonName + "', Error: '" + status + "'");
                }
            }


            status = bus.registerSignalHandlers(mControlPanelSignalInterface);

            if (status != Status.OK) {
                Log.d(TAG, "Problem while registering signal handlers");
            }

            // Initialize AboutService

            aboutClient = AboutServiceImpl.getInstance();
            aboutClient.setLogger(logger);
            try {
                aboutClient.startAboutClient(bus);

                for (String iface :  ANNOUNCE_IFACES) {


                    aboutClient.addAnnouncementHandler(this, new String[] {iface});

                }
            } catch (Exception e) {

                logger.error(TAG, "Unable to start AboutService, Error: " + e.getMessage());

            }


        }
Jul 25, 2018 in IoT (Internet of Things) by Matt
• 2,260 points
21 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Why dont you create two Interfaces, one interface for one sensor respectively. then add these two interfaces in a class which implements these two interfaces and the busObject and register an implemntation of this class as a BusObject.

For example

Sensor1_interface.java and Sensor2_interface.java //are my two interface classes

create a new class Sensor_InterfaceList which inplements the two interfaces and the BusObject

class Sensor_InterfaceList implements Sensor1_interface,Sensor2_interface,BusObject
   {
    // implment your interfaces here
    .....
    }
private Sensor_InterfaceList mySensor_InterfaceList;
mySensor_InterfaceList = new Sensor_InterfaceList();
myBus.registerBusObject(mySensor_InterfaceList,"/your/path");

This should solve your problem :)

answered Jul 25, 2018 by anonymous2
• 4,260 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer
0 votes
1 answer

Android M - Sending request over WiFi (without connection) when Mobile data is ON (with connection)

Binding the network using ConnectivityManager.setProcessDefaultNetwork() will help ...READ MORE

answered Oct 11, 2018 in IoT (Internet of Things) by nirvana
• 3,040 points
142 views
0 votes
1 answer

Android Ble GATT_ERROR 133 getting often with samsung devices

I tried the following code #!/usr/bin/python import ibmiotf.device from time ...READ MORE

answered Jul 18, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
104 views
0 votes
1 answer

Unable to communicate to device with .local domain using android, corova-zeroconf-plugin

Use IP address instead of http://iotdevice.local..Use http ...READ MORE

answered Aug 2, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
158 views
0 votes
1 answer
0 votes
1 answer

Creating Android Things' bundle and pushing it over OTA

Here are all the steps necessary to ...READ MORE

answered Jul 6, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
30 views
0 votes
1 answer

Restrict Android Internet usage to WiFi without Internet Access

You can check if wifi is connected ...READ MORE

answered Jul 17, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
53 views
0 votes
1 answer

Connect Android Things based Raspberry Pi 3 to wifi network for the first time!

Hey, I think its alright!  Your Raspberry Pi ...READ MORE

answered Jul 18, 2018 in IoT (Internet of Things) by nirvana
• 3,040 points
158 views
0 votes
1 answer

Downloading source code of Android Things

No because AndroidThings is still in preview ...READ MORE

answered Jul 5, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
334 views
0 votes
1 answer

MQTT protocol connection error

Ok so you need two libraries to ...READ MORE

answered Jul 6, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points

reshown Jul 6, 2018 by Vardhan 284 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.