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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

JavaSDK Event will not fire on Thingworx

drichter
15-Moonstone

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?

ACCEPTED SOLUTION

Accepted Solutions
drichter
15-Moonstone
(To:drichter)

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

1 REPLY 1
drichter
15-Moonstone
(To:drichter)

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).

Announcements


Top Tags