Languages

Menu
Sites
Language
Gear S2 Companion App Data Sync Issue

I am currently building a Gear S2 Companion app using SAP (Samsung Accessory SDK) which consists of:
a) Android mobile app as Tizen provider.
b) Tizen wearable web application (watch face) as Tizen Consumer.

 

The watch face web app will fetch daily timing data (5 timings per day) from the android app (The timing data will be different each day).
The watch face will show current time as well as counting down to the subsequent timing.
When the last timing has passed, the wearable web application will try to resync the data (by requesting the subsequent day's timing data from android app). It will show <Resyncing...>  in the countdown panel & at the same time fetching the subsequent day's timing. Once data is refreshed, it will start counting down to the next timing again.

However, sometimes the resync action will fail. It will sometimes show PEERAGENT_NO_RESPONSE error, sometimes it syncs well.

What could have caused the sync issue (the sync happens when the Bluetooth connection is active)? Would it be more of the android app side or watch side issue?

 

a) Partial of the javascript:

var SAAgent, SASocket, connectionListener;
var SAAgent = null;
var SASocket = null;
var connectionListener = null;
var CHANNELID = 200;
var ProviderAppName = "TizenProvider";
var connecting = false;


function connect() {
    if (SASocket) {
        return false;
    }
    try {
        webapis.sa.requestSAAgent(onsuccess, function(err) {
            var error_msg = "err [" + err.name + "] msg[" + err.message + "]";
        });
    } catch (err) {
        connecting = false;
        var failure_msg = "exception [" + err.name + "] msg[" + err.message + "]";
    }
}

// On fetch agents success
function onsuccess(agents) {
    try {
        if (agents.length > 0) {
            SAAgent = agents[0];
            SAAgent.setPeerAgentFindListener(peerAgentFindCallback);
            SAAgent.findPeerAgents();
        } else {}
    } catch (err) {
        connecting = false;
        var error = err.message;
    }
}

// Peer agent found.
var peerAgentFindCallback = {
    onpeeragentfound: function(peerAgent) {
        try {
            if (peerAgent.appName == ProviderAppName) {
                SAAgent.setServiceConnectionListener(agentCallback);
                SAAgent.requestServiceConnection(peerAgent);
            } else {
                var error = "Not expected app!! : " + peerAgent.appName;
            }
        } catch (err) {
            var error = "exception [" + err.name + "] msg[" + err.message + "]";
            connecting = false;
        }
    },
    onerror: onerror
}

var agentCallback = {
    onconnect: function(socket) {
        SASocket = socket;
        fetch();
        SASocket.setSocketStatusListener(function(reason) {
            disconnect();
            close_connection();
        });
        SASocket.setDataReceiveListener(onreceive);
    },
    onerror: onerror
};

function fetch() {
    try {
        var date = getFetchDate();
        SASocket.sendData(CHANNELID, date);
    } catch (err) {
        var failure_msg = "exception [" + err.name + "] msg[" + err.message + "]";
    }
}


function onerror(err) {
    connecting = false;
    close_connection();
}

function close_connection() {
    SASocket.close();
    SASocket = null;
}

/**
 * Cache response in local storage
 */
function onreceive(channelId, data) {
    connecting = false;
    if (data) {
        // Store data returned in localStorage
    }
}

//
function displayCountDown() {
    if (localStorage && localStorage.length > 0) {
        // Display countdown
        // But if last timing has passed, load subsequent day's prayer timing.
        connectAndFetchData();
    } else {
        // no data in local storage
        connectAndFetchData();
    }
}


// close connection and re-connect else it will occasionally result in sync/connection issue
function connectAndFetchData() {
    if (connecting == false) {
        connecting = true;
        close_connection();
        connect();
    }
}

function initCountDownEvent() {
    clearInterval(interval);
    interval = setInterval(displayCountDown, 1000);
}

 

b) accessoryservices.xml xml:

<?xml version="1.0" encoding="UTF-8"?>

<resources>

    <application name="TizenConsumer" >

        <serviceProfile

            id="/watch/face"

            name="tizen_consumer"

            role="consumer"

            version="1.0" >

            <supportedTransports>

                <transport type="TRANSPORT_BT" />

                <transport type="TRANSPORT_WIFI"/>

            </supportedTransports>

            <serviceChannel

                id="200"

                dataRate="high"

                priority="low"

                reliability="enable" >

            </serviceChannel>

        </serviceProfile>

        

    </application>

</resources>

 

 

Edited by: ping on 21 Jul, 2016

Responses

2 Replies
Iqbal Hossain

This had to be Public instead of protected on android side. 

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

You can also  check these links
1. developer.samsung.com/forum/board/thread/view.do
2. developer.tizen.org/ko/forums/web-application-development/accessory-sap-communication-tizen-and-android-peeragent_no_response
3. stackoverflow.com/questions/29303636/accessory-sap-communication-tizen-and-android-peeragent-no-response