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

JavaSDK Event will not fire on Thingworx

SOLVED
Highlighted
Aquamarine

JavaSDK Event will not fire on Thingworx

Hi,


I'm trying to write a program (with Java SDK) that monitors a folder and shoude fire an event in thingworx if a new file is in this folder.


On TWX I have a thing based on RemoteThingWithFileTransfer. I also add a remote event to the thing:

drichter_0-1581578190830.png

In my program I have a class that inherits from FileTransferVirtualThing. Via code a add a event to my class

 

public static final String NEW_FILE_DETECTED = "NewFileDetected";

...

EventDefinition newFileDetectedEvent = new EventDefinition(NEW_FILE_DETECTED, "");
newFileDetectedEvent.setDataShapeName("NewFileEvent");
newFileDetectedEvent.setLocalOnly(false);
this.defineEvent(newFileDetectedEvent);

 

On a separate thread I fire this event every 10 seconds.

 

@Override
public void run() {
    while (true) {
        try {
            Thread.sleep(10000);

            log.info("Fire Event " + NEW_FILE_DETECTED);
            ValueCollection values = new ValueCollection();
            values.put("FileName", new StringPrimitive("abc"));
            virtualThing.queueEvent(NEW_FILE_DETECTED, new DateTime(), values);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

 

 

I add a subscriptions to the event which will only write into the log.

 

When I start my program it shows me every 10 seconds "Fire Event NewFileDetected" but on thingworx I don't get any logs.

 

To test if the connection and other stuff works correct, I add a propery via code. This test property was displayed to me in "Manage Bindings" dialog. That makes me believe my program largely works. Only the events will not triggered in Thingworx.

 

What could be the cause?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: JavaSDK Event will not fire on Thingworx

I could fix the issue.

After calling virtualThing.queueEvent I have to call virtualThing.updateSubscribedEvents to send the events to TWX.

Maybe PTC should include this information in the tutorial for the JavaSDK (https://developer.thingworx.com/en/resources/guides/thingworx-java-sdk-tutorial/services-and-events).

View solution in original post

Tags (1)
1 REPLY 1

Re: JavaSDK Event will not fire on Thingworx

I could fix the issue.

After calling virtualThing.queueEvent I have to call virtualThing.updateSubscribedEvents to send the events to TWX.

Maybe PTC should include this information in the tutorial for the JavaSDK (https://developer.thingworx.com/en/resources/guides/thingworx-java-sdk-tutorial/services-and-events).

View solution in original post

Tags (1)
Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum!