Skip to main content
12-Amethyst
October 23, 2024
Solved

data change event in subscription doesn't work

  • October 23, 2024
  • 2 replies
  • 3222 views

hi,

 

i am new to thingworx and I am using it for IOT app involves MQTT,

i am trying to create an mqtt parser thing, the parser will recive raw data from mqtt broker and in the same thing i want to extract the data from the message and save it in properties 
here is my raw data json :
{"deviceId" : "3102-0153-21", "Timestamp":"23/10/2024 11:18:52", "Digital Input":7}
my thing can get this message no problem and save it inside the Intrusion_raw_data property,
next i created a subscription to run on data change event for the Intrusion_raw_data property , here is the script:

me.Timestamp = me.Intrusion_raw_data["Timestamp"];
me.sn = me.Intrusion_raw_data["deviceId"];
me.Digital_Input = me.Intrusion_raw_data["Digital Input"];

when new data comes from the broker the Intrusion_raw_data property updates fine and get the new data and i can see it, but it looks like the subscription does not run , but when i try to change the Intrusion_raw_data manually inside the thing it self the subscription script runs fine and update the other properties without any problems,

in short , when the Intrusion_raw_data recive new data the script doesn't work but when i change the data inside the Intrusion_raw_data manually the script works,

thanks for your time 

Best answer by javed_a

Additionally, you can try permission shown in attached image and code snippet as below:

 

 

 var params = {
 infoTableName: "UpdatePropertiesInfoTableTMP" /* STRING */,
 dataShapeName: "NamedVTQ" /* DATASHAPENAME */
 };
 var updateValues = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
 var time = new Date();
 updateValues.AddRow({'time': time, 'name': propName, 'quality': 'GOOD', 'value': propValue});
 Things[thingName].UpdatePropertyValues({values: updateValues});

 

 

2 replies

18-Opal
October 23, 2024

Hey,

 

New subscriptions are disabled by default. Make sure you check the corresponding checkbox.

 

Also, check "Data change type" on your Intrusion_raw_data property -- it controls how it fires DataChange events. If it's set to "Value" (default), then your subscription will only fire when data actually changes, not every time you received something. To troubleshoot you can try setting it to "Always".

 

/ Constantine

12-Amethyst
October 23, 2024

can you explain more what you mean as i did enable all of these 

IA_10816220_0-1729680507775.pngIA_10816220_1-1729680537739.png

 

18-Opal
October 23, 2024

I was referring to "Enabled" checkbox -- you have it. Also check this one, maybe try setting it to "Always" and see if it helps:

Constantine_0-1729681344560.png

Finally, try to change its data type from JSON to STRING, see what happens.

One more thing you can try is replace your subscription code with something like logger.error('FIRED'); and check your logs.

javed_a13-AquamarineAnswer
13-Aquamarine
October 23, 2024

Additionally, you can try permission shown in attached image and code snippet as below:

 

 

 var params = {
 infoTableName: "UpdatePropertiesInfoTableTMP" /* STRING */,
 dataShapeName: "NamedVTQ" /* DATASHAPENAME */
 };
 var updateValues = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
 var time = new Date();
 updateValues.AddRow({'time': time, 'name': propName, 'quality': 'GOOD', 'value': propValue});
 Things[thingName].UpdatePropertyValues({values: updateValues});

 

 

12-Amethyst
October 23, 2024

sorry maybe I am a bit confused, is there a difference between the permissions section on the bottom far left of the menu and the permissions tab inside the thing itself ? 
as i tried to re-do it again from the permissions section inside the thing itself but set all properties to "checked" it also worked , so is there a difference between these two permissions section ether from the left menu or from inside the thing ?

13-Aquamarine
November 5, 2024

Yes, there is difference.

The step I suggested will be applied to all the Things available in platform, however if you do it at thing level you need to do it, every time for each applicable thing.