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
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:
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?
Solved! Go to Solution.
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).
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).