Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
Hello,
I would like my C SDK client to take an action when a property is updated on the corresponding Remote Thing on the platform. I have registered a propertyHandler callback, however this does not appear to be called when I use the "set" button on that property in the Thing's Properties to set it to a new value. When is this callback called, and how can I achieve the functionality I have described?
Solved! Go to Solution.
There are a lot of reasons why this problem could be occurring, I will go over some ideas.
1. Is you RemoteThing showing its isConnected property == true. This would indicate that your remote thing has been bound its equivelent Thing on the server
2. Have you bound your remote property to your RemoteThing on the server. Edit your RemoteThing on the server, go to properties and click on the button "Manage Bindings" button, select the "Remote" tab. Use the dialog that opens to bind your property to your RemoteThing. If your property does not appear in this list then it has not been declared properly in your remote application and this will take us down another path.
3. Once you have added your remote property to your RemoteThing on the server you should now see a column called "Additional Info" on the properties tab next to your property. It should read , "Read: Cache, Push: Always. This means that when you set this property on the server it will immediately cause a call back to your application that you must implement by registering a property_cb function. Incidentally, reading the property on the server will not cause your callback to be called because Read is set to Cache. This means that your application must push values to the server before they will show up in the cache where you read values from.
4. In your application you must have called twApi_RegisterProperty() at some point to even be able to see your properties in the remote tab. See the Steam Sensor example to see how this function should be called. Here is a sample from Steam Sensor,
twApi_RegisterProperty(TW_THING, thingName, "Pressure", TW_NUMBER, NULL, "ALWAYS", 0, propertyHandler, NULL);
The propertyHandler function will be invoked whenever you change a value on the server that is set to Push: Always. The propertyHandler() functions looks something like this:
enum msgCodeEnum propertyHandler(const char * entityName, const char * propertyName, twInfoTable ** value, char isWrite, void * userdata) {
TW_LOG(TW_TRACE,"propertyHandler - Function called for Entity %s, Property %s", entityName, propertyName);
if (value) {
if (isWrite && *value) {
/* Property Writes */
return TWX_SUCCESS;
}
}
}
5. In the section marked /* Property Writes */ you can respond to changes in this property value. The new value is inside the twInfoTable value. Again, see the Steam Sensor example for how to access the current value.
In the steps above, I just wanted to set your expectations for how this should be implemented. Let me know if things are working for you as I described above and if possible, post your code and I will see if I can spot where things might be going wrong.
There are a lot of reasons why this problem could be occurring, I will go over some ideas.
1. Is you RemoteThing showing its isConnected property == true. This would indicate that your remote thing has been bound its equivelent Thing on the server
2. Have you bound your remote property to your RemoteThing on the server. Edit your RemoteThing on the server, go to properties and click on the button "Manage Bindings" button, select the "Remote" tab. Use the dialog that opens to bind your property to your RemoteThing. If your property does not appear in this list then it has not been declared properly in your remote application and this will take us down another path.
3. Once you have added your remote property to your RemoteThing on the server you should now see a column called "Additional Info" on the properties tab next to your property. It should read , "Read: Cache, Push: Always. This means that when you set this property on the server it will immediately cause a call back to your application that you must implement by registering a property_cb function. Incidentally, reading the property on the server will not cause your callback to be called because Read is set to Cache. This means that your application must push values to the server before they will show up in the cache where you read values from.
4. In your application you must have called twApi_RegisterProperty() at some point to even be able to see your properties in the remote tab. See the Steam Sensor example to see how this function should be called. Here is a sample from Steam Sensor,
twApi_RegisterProperty(TW_THING, thingName, "Pressure", TW_NUMBER, NULL, "ALWAYS", 0, propertyHandler, NULL);
The propertyHandler function will be invoked whenever you change a value on the server that is set to Push: Always. The propertyHandler() functions looks something like this:
enum msgCodeEnum propertyHandler(const char * entityName, const char * propertyName, twInfoTable ** value, char isWrite, void * userdata) {
TW_LOG(TW_TRACE,"propertyHandler - Function called for Entity %s, Property %s", entityName, propertyName);
if (value) {
if (isWrite && *value) {
/* Property Writes */
return TWX_SUCCESS;
}
}
}
5. In the section marked /* Property Writes */ you can respond to changes in this property value. The new value is inside the twInfoTable value. Again, see the Steam Sensor example for how to access the current value.
In the steps above, I just wanted to set your expectations for how this should be implemented. Let me know if things are working for you as I described above and if possible, post your code and I will see if I can spot where things might be going wrong.