Sending a BusSignal from AJTCL to AJSCL

asked 2014-08-12 13:52:25 -0700

AllJoyner gravatar image

Hello, so I have been stuck on this for a few days now. I was able to pull info from my ajtcl app but now i am trying to push it automatically to my phone using @BusSignal. I have read over the explanation in the link below and was using AJ_Signal_Service as a model but i am still not getting results:

Signal and method, simultaneously

I am confused with GetName and SetName functions and the BusProperty (@name=s) that is being used here. I understand that the idea is to send the BusSignal when the BusProperty has changed but in this sample I can see that we always copy data in the "propertyName" global variable and then we use that value when sending signal. So, i dont get what is the purpose of the BusProperty here. Can I just create a boolean global variable and then send BusSignal when it has changed instead of having BusProperty? Can I have something like this:

!stateChanged newState>s

static boolean currentState = false;  
static void SendSignal(){

const char* on = "ON";
const char* off = "OFF"; 
AJ_Message msg;

int state = checkState();

if(state == 1 && !currentState ){
  AJ_MarshalSignal(&busAttachment, &msg, APP_STATE_SIGNAL, NULL, 0, ALLJOYN_FLAG_SESSIONLESS, 0);
  AJ_MarshalArgs(&msg, "s", on);
  currentState = !currentState;
  return AJ_DeliverMsg(&msg);
else if(state == 0 && currentState ){
  AJ_MarshalSignal(&busAttachment, &msg, APP_STATE_SIGNAL, NULL, 0, ALLJOYN_FLAG_SESSIONLESS, 0);
  AJ_MarshalArgs(&msg, "s", off);
  currentState = !currentState;
  return AJ_DeliverMsg(&msg);

Also would this be a proper way of using @BusSignalHandler in Ajscl app:

class SignalTest implements SignalTestInterface, BusObject {

@BusSignalHandler(iface = "org.alljoyn.bus.interface", signal = "stateChanged")
  public void stateChanged(String newState) {

             mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_UPDATE_STATE, newState));

Lastly, when I created a BusObject in Android app, I called registerBusObject() after conencting BusAttachment and I called registerSignalHandlers() just before joining a session.

I hope my explanation was clear enough and you understand what I am trying to do.

Thanks in advance!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2014-08-15 15:16:52 -0700

bspencer gravatar image

You are using the flag ALLJOYN_FLAG_SESSIONLESS and you are not supplying a sessionId. You can either: on the Android application add a line to: <busAttachment variable>.addMatch("sessionless=t"); or Change the Thin Client application to send the signal on the session by providing the SessionId and a flag of 0 when sending the signal.

edit flag offensive delete publish link more


I added the "addMatch" to Android app but nothing is still happening. Here is my connection/advertisement flow: mBus = new BusAttachment mBus.registerBusListener mBus.registerBusObject mBus.connect mBus.registerSignalHandlers mBus.addMatch mBus.requestName mBus.advertiseName mBus.findAdvertisedName

AllJoyner ( 2014-08-19 08:14:51 -0700 )edit

Am I doing everything correctly in SendSignal() method in ajtcl app? Also, on Android side where i have stateChanged(String newState), does the variable "newState" store what ever is marshaled in AJ_MarshalArgs(&msg, "s", on) , in this case "const char* on = "ON"? Thanks

AllJoyner ( 2014-08-19 08:22:00 -0700 )edit

answered 2014-08-26 08:18:25 -0700

AllJoyner gravatar image

Just to answer this, the code above actually works after either supplying sessionId or adding "addMatch" on the Android app. The reason why it did not work for me after @bspencer 's suggestion is that I had created two different BusAttachments by accident as I was following one of the samples when I was adding the BusSignal. Regards.

edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2014-08-12 13:52:25 -0700

Seen: 204 times

Last updated: Aug 26 '14