Languages

Menu
Sites
Language
Accessory SAP communication Tizen and Android PeerAgent_No_Response

Currently i am creating a safety application for the samsung smartwatch. I want users to be able to register on their smartphone and send these data to the smartwatch app. I followed the samsung tutorial for Accessory SAP communication. Most things work, i click on connect on the smartwatch and it tries to connect. 

The method i call on tizen is this:

SAAgent.setServiceConnectionListener(agentCallback);

var agentCallback = {
        onconnect: function(socket){
            alert("agentCallback connect" + socket);
            SASocket = socket;
            alert("connected");
            SASocket.setSocketStatusListener(function(reason){
                console.log("Service Connection lost, Reason: ["+ reason+"]");
                disconnect();
            })
        },
        onerror: function(error){
            alert("agentCallBack"+error);
        }
};

When i call SAAgent.setServiceConnectionListener(agentCallback), the android code below here is triggered. But this always returns PEERAGENT_NO_RESPONSE error.

@Override

protected void onServiceConnectionRequested(SAPeerAgent peerAgent){ 
//Toast.makeText(getBaseContext(), "TESTG", Toast.LENGTH_SHORT).show();
 super.acceptServiceConnectionRequest(peerAgent)
}

I was wondering what i am doing wrong.

Edited by: Siebert Elhorst on 27 Mar, 2015
View Selected Answer

Responses

5 Replies
daniel kim

Hi,

I could find below description which is related to PEERAGENT_NO_RESPONSE in Accessory SDK.

           [CONNECTION_FAILURE_PEERAGENT_NO_RESPONSE]
             public static final int CONNECTION_FAILURE_PEERAGENT_NO_RESPONSE

             Connection failed because the remote Accessory Peer Agent gave no response.
             Constant Value: 1030 (0x00000406)
             Since:2.0.19See Also:onServiceConnectionResponse(SASocket, int), onServiceConnectionResponse(SAPeerAgent, SASocket, int), Constant Field Values

Could you upload serviceprofile of provider and consumer?  It looks like that onServiceConnectionResponse() in provider doesn't get response from consumer.

Regards,

 

 

 

Siebert Elhorst

The following code is called from the Tizen side, as soon as the button connect is called this method will be triggered:

function connect(){
    if(connect == true) return;
    else{
        connect = true;
        $("#fetchText").append("connecting \n");
        if(SASocket){
            return false;
        }
        try{
            webapis.sa.requestSAAgent(onsuccess, function(error){
                console.log("webapis"+ error)
            });
        }catch(err){
            console.log("error"+err);
        }
    }
}

This calls the onsucces method:

function onsuccess(agents){
    try{
        if(agents.length > 0){
            SAAgent = agents[0];
            SAAgent.setPeerAgentFindListener(peerAgentFindCallback);
            SAAgent.findPeerAgents();
            alert("response: " + SAAgent.name);
        }else{
            alert("SAAgent connection failed");
        }
    }catch(err){
        console.log(err);
    }
};

Then it will try to start connection, setPeerAgentFindListener(peerAgentFindCallback)

var peerAgentFindCallback = {
        onpeeragentfound: function(peerAgent){
            try{ 
                if(peerAgent.appName = ProviderAppName){
                    SAAgent.setServiceConnectionListener(agentCallback);
                    SAAgent.requestServiceConnection(peerAgent);
                }
            }catch(err){
                console.log("peerAgentCallBack: "+err);
            }
        },
        onerror:onerror
};

This will lead to setServiceConnectionListener(agentCallback), that's were the error occurs. This code is in my post.

The android side:

    @Override
    public void onCreate(){
        super.onCreate();
        SA mAccessory = new SA();
        try{
            mAccessory.initialize(this);
        }catch(SsdkUnsupportedException e){
        }catch(Exception e){
            e.printStackTrace();
            stopSelf();
        }
    }

First initialize the SA Accessory, then it's basically waiting for a "consumer" to connect to the "provider", which is this method. Of course i have some more code on both sides but this is the code that runs before it crashes.

    @Override
    protected void onServiceConnectionRequested(SAPeerAgent peerAgent){
        acceptServiceConnectionRequest(peerAgent);
    }

Since the error occurs after around 10 seconds, it looks like a timeout error. When i look at my code i think SAAgent.requestServiceConnection(peerAgent) (tizen side) is not being called.

 

daniel kim

Hi,


I could observe below error message in consumer if I change the id of serviceChannel(104-->107) in Provider.

   js/main.js (126) :exception [TypeError] msg['null' is not an object (evaluating 'SASocket.setDataReceiveListener')]

   js/main.js (44) :err [PEERAGENT_NO_RESPONSE]

 

As your code looks fine, I suggest you to check the serviceProfile of consumer& provider.

Id of each profile should be matched.

I wish this will help you.

Siebert Elhorst

Well i looked at the serviceChannel id and they are both the same. This is my Android side service file:

<resources>
    <application name="GuardTest">
        <serviceProfile 
            name="guard" 
            id="/system/guard" 
            role="provider" 
            serviceImpl="com.google.android.GuardTest.SAPServiceProvider" 
            version="1.0" 
            serviceLimit="ANY" 
            serviceTimeout="10">
            <supportedTransports>'
                <transport type="TRANSPORT_BT"/>
            </supportedTransports>
            <serviceChannel
                id="104"
                dataRate="low"
                priority="low"
                reliability="DISABLE"/>
        </serviceProfile>
    </application>
</resources>

Ánd this is my Tizen side serviceProfile:

<resources>
    <application name="SmartWatch">
        <serviceProfile 
            name="guard" 
            id="/system/guard" 
            role="consumer" 
            version="w.0" 
            serviceLimit="ANY" 
            serviceTimeout="10">
            <supportedTransports>
                <transport type="TRANSPORT_BT"/>
            </supportedTransports>
            <serviceChannel
                id="104"
                dataRate="low"
                priority="low"
                reliability="DISABLE"/>
        </serviceProfile>
    </application>
</resources>

 

Mark as answer
Siebert Elhorst

After debugging and some help i finally fixed the problem:

This had to be Public instead of protected on android side. Which caused the runtime to crash and not send any data to the tizen wearable.

public SAPServiceProviderConnection() {
    super(SAPServiceProviderConnection.class.getName());
}

I also changed supportedTransports on both android and tizen side to: (i had BT on android side and WIFI/BT on tizin side.)

<transport type="TRANSPORT_BT"/>
<transport type="TRANSPORT_WIFI"/>

Servicechannel, data to high:

 <serviceChannel
                id="104"
                dataRate="high"
                priority="low"
                reliability="enable"/>