cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Extension : Thingworx Event Subscription

SOLVED

Re: Extension : Thingworx Event Subscription

Thanks. So, how do I obtain my RemoteThing (that lives on the Thingwrox server) from my VirtualThing (running in my Edge device)?

Re: Extension : Thingworx Event Subscription

If you did a bind by name, then you already have the answer, since you had to use the name of the RemoteThing to perform the bind (you can call getBindingName() specifically to get this name).  If you do a bind by identifier, then you can call the GetThingNameForIdentifier service on the EntityServices resource, which will give you the name of the remote thing.

Re: Extension : Thingworx Event Subscription

package com.thingworx.sdk.simplething;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.thingworx.communications.client.ConnectedThingClient;
import com.thingworx.communications.client.things.VirtualThing;
import com.thingworx.metadata.EventDefinition;
import com.thingworx.metadata.FieldDefinition;
import com.thingworx.metadata.PropertyDefinition;
import com.thingworx.metadata.ServiceDefinition;
import com.thingworx.metadata.annotations.ThingworxPropertyDefinition;
import com.thingworx.metadata.annotations.ThingworxPropertyDefinitions;
import com.thingworx.metadata.annotations.ThingworxServiceDefinition;
import com.thingworx.metadata.annotations.ThingworxServiceHandler;
import com.thingworx.metadata.annotations.ThingworxServiceParameter;
import com.thingworx.metadata.annotations.ThingworxServiceResult;
import com.thingworx.metadata.annotations.ThingworxSubscription;
import com.thingworx.metadata.annotations.ThingworxSubscriptions;
import com.thingworx.metadata.collections.FieldDefinitionCollection;
import com.thingworx.types.BaseTypes;
import com.thingworx.types.InfoTable;
import com.thingworx.types.collections.AspectCollection;
import com.thingworx.types.collections.ValueCollection;
import com.thingworx.types.constants.Aspects;
import com.thingworx.types.constants.CommonPropertyNames;
@ThingworxSubscriptions(subscriptions = {

@ThingworxSubscription(eventName = "speedover", sourceProperty="spped1", enabled=true, handler="SubscriptionHandler")

})
public class SimpleThing extends VirtualThing {
private static final Logger LOG = LoggerFactory.getLogger(SimpleThing.class);
private static final String SERVICE = "Service1";
private static final String SubscriptionHandler = null;


public SimpleThing(String name, String description, ConnectedThingClient client) throws Exception {

super(name, description, client);

super.initializeFromAnnotations();

}


@ThingworxServiceDefinition(name="SubscriptionHandler", isPrivate=true)

public void SubscriptionHandler(

@ThingworxServiceParameter(name="eventData", baseType="INFOTABLE", aspects = {"datashape:speedover"}) InfoTable eventData,

@ThingworxServiceParameter(name="eventName", baseType="STRING") String eventName,

@ThingworxServiceParameter(name="eventTime", baseType="DATETIME") DateTime eventTime,

@ThingworxServiceParameter(name="source", baseType="STRING") String source,

@ThingworxServiceParameter(name="sourceProperty", baseType="STRING") String sourceProperty),

}
LOG.info("subscription is called");
}

 

I added Subscriptions in my code but still it is not working.

Hope some of you will be able to help me with this!!!

 Have a good day everyone!