Arduino AJTC couldn't connect to android Daemon to set up the service

asked 2014-05-13 02:11:54 -0700

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi everyone,

I'm beginner in this domain. In order to learn about alljoyn API in C and Java, I'm trying to develop a simple application between AJSC on android 4.2.1 and AJTC on Arduino Due. I have followed almost the codes in this link: https://ask.allseenalliance.org/question/225/a-problem-about-communication-between-ajtcarduino-and-ajscandroid/ . However, I have some errors: On Android application, when I pressed the Daemon button, Android had advertised its daemon successfully but there were the error permission and tcp authentication links: 05-13 10:14:58.678: E/PERMISSION_MGR(12925): 93.279 * ERROR PERMISSION_MGR lepDisp ...ndroid/PermissionDB.cc:202 | 0x0001 05-13 10:14:58.704: I/alljoynAndroid(12925): connection succeed 05-13 10:14:58.704: I/alljoynAndroid(12925): AUTH set successfully 05-13 10:14:58.713: I/alljoynAndroid(12925): advertise daemon successfully 05-13 10:15:00.760: E/TCP(12925): 95.361 ERROR TCP auth ...router/TCPTransport.cc:768 | 0x9036 05-13 10:15:11.205: E/TCP(12925): 105.806 * ERROR TCP auth ...router/TCPTransport.cc:768 | 0x9036

And Arduino AJTC could be connected, then it was rejected by routing node: aj_net.cpp: 209 AJ_Net.Connect(): connect().success: status= AJ_OK aj_msg.cpp: 758 The connection was rejected by the routing node. aj_msg.cpp: 1087 Discarding bad message AJ_ERR_REJECTED

I have been blocked here for several days and I have any ideas to fix it. Could anybody help me to solve it, please?
Here this is the code for AJSC on android ( I use mobile wiko 4.2.1):

package com.example.alljoynandroid;

import org.alljoyn.bus.BusAttachment;
import org.alljoyn.bus.BusListener;
import org.alljoyn.bus.Mutable;
import org.alljoyn.bus.PasswordManager;
import org.alljoyn.bus.ProxyBusObject;
import org.alljoyn.bus.SessionListener;
import org.alljoyn.bus.SessionOpts;
import org.alljoyn.bus.Status;
import org.alljoyn.bus.alljoyn.DaemonInit;
//import org.alljoyn.bus.samples.simpleservice.R;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.os.Build;

    public class MainActivity extends ActionBarActivity {

     private static final String TAG = "alljoynAndroid";

     static {

    private static final String DAEMON_NAME_PREFIX = "org.alljoyn.BusNode.measure";
    private static final String DAEMON_QUIET_PREFIX = "quiet@";
    private static final String DAEMON_AUTH = "ALLJOYN_PIN_KEYX";
    private static final String DAEMON_PWD = "000000";

    private Button daemon, connect, quit;
    private Button play;
    private boolean isOff = true;
    private BusHandler handler;
    private HandlerThread handlerThread;

    protected void onCreate(Bundle savedInstanceState) {

        /*mListViewArrayAdapter = new ArrayAdapter<String>(this, R.layout.fragment_main);
        mListView = (ListView) findViewById(R.id.ListView);

        quit = (Button)findViewById(R.id.quit);
        daemon = (Button)findViewById(R.id.daemon);
        connect = (Button)findViewById(R.id.Connect);
        play = (Button ...
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-05-13 13:58:12 -0700

bspencer gravatar image

updated 2014-05-16 10:15:38 -0700

Hi, I have resolved the issue and must thank you for pointing out this problem as it is present in the service sample applications. First, since you are new to AllJoyn there is usually not a need to point a Thin Library application to a specific instance of an AllJoyn Router, IE you do not need to specify the daemonRealm. Second, there usually is not a case when you will need to use authentication between a Thin Library application and an AllJoyn Router. However nothing prohibits this from being done or used.

The issue can be resolved by moving the API cal to setCredentials above creating the BusAttachment. The setCredentials call MUST be called prior so it has the correct values that you want, otherwise it will fail without error. (An issue in some sample apps)

        Status status = PasswordManager.setCredentials(DAEMON_AUTH, DAEMON_PWD);
        if (status == Status.OK) {
             Log.i(TAG, "AUTH set successfully");

        busAttachment = new BusAttachment("com.example.alljoynAndroid", BusAttachment.RemoteMessage.Receive);

            status = busAttachment.connect();
            if (status != Status.OK) {
                Log.d(TAG, "connection failure");
            Log.i(TAG, "connection succeed");

You will also need to change the DAEMON_PWD you have set from 000000 to 1234:

private static final String DAEMON_PWD = "1234";

After that things should work.

edit flag offensive delete publish link more


Hi Bspencer, thank a lot for your help. I have changed my codes at the points where you marked: -- For the DaemonName at the creating thin client service line, I set null value for DaemonName: status = AJ_StartService(&bus, NULL, CONNECT_TIMEOUT, FALSE, ServicePort, ServiceName, AJ_NAME_REQ_DO_NOT_QUEUE, NULL); --I let SetCredentials before creating the busAttachment. Then I have ran the applications for android and arduino, there were the same errors for the both as above. And I tried these applications (on Android and on Arduino) without the authentication. There was a strange that I have the same errors.

congtam ( 2014-05-14 02:09:13 -0700 )edit

I have just observed that my codes for arduino have two lines: AJ_BusSetPasswordCallback(&bus, PasswordCallback);. I corrected it. I have tried in case that this line is before creating service and also after that. But I have still had the same errors.

congtam ( 2014-05-14 02:40:15 -0700 )edit

Hi Bspencer, I have seen carefully my projects for android AJSC and for Arduino AJTC. But I couldn't find out the solution to solve it. Would you mind seeing my projects, please? https://www.dropbox.com/s/wb9x0d7jgb6tffz/alljoyn_android_arduino.zip . I used Eclipse to build and compile these projects. For Arduino AJTC project, I have deleted the wifi method because my Arduino can't support wifi function. I have just set its Ethernet. I'm always looking forward for your answer. Thanks so much for your help.

congtam ( 2014-05-15 02:35:12 -0700 )edit

Sorry, in the Android application change the DAEMON_PWD, I have updated my answer to include this now.

bspencer ( 2014-05-16 10:13:41 -0700 )edit

Hi Bspencer,It works now, thanks a lot for your answer. I have some questions about the setting the parameters for Daemon password, Daemon name and proxy remote object path. For Daemon on Android, it is possible to set up our own password, isn't it? And the same question for the daemon name, could we give it the name that we like? because I tried to change the Daemon name but it does not work. And when we create the proxy bus object for a remote object, we call the method: public ProxyBusObject getProxyBusObject(String busName, String objPath, int sessionId, Class[] busInterfaces). Here, I would like to ask wether the objPath is the repertory path where the proxy bus object for the remote object is created? If that, I think that the proxy bus object is in our project. Why do we have to write always "/org/alljoyn/sample/measure"? Thanks.

congtam ( 2014-05-19 02:51:53 -0700 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2014-05-13 02:11:54 -0700

Seen: 624 times

Last updated: May 16 '14