Skip to main content
1-Visitor
July 23, 2018
Question

how can a thing Enable it's own subscription via a service

  • July 23, 2018
  • 2 replies
  • 1583 views

Hi,

I have a thingshape that has 2 subscriptions.

  1. a DataChange subscription to one of its own properties
  2. a subscription to the timer event of a separate timer thing. By default this subscription is disabled.

I would like to enable the second subscription from within the first. I have tried to use the service EnableSubscription

var subParams = {
propertyName: undefined /* STRING */,
thingName: "RemoteTimerThing" /* THINGNAME */,
eventName: "Timer" /* STRING */
};

me.EnableSubscription(subParams);

 

This fails as it says it 'Cannot Update A Subscription That Does Not Exist'. Originally I thought it was a permissions issue and so changed the permissions, but it still failed. I have also tried running this service directly from within the composer (as an administrator) using the Test button and it also fails. Now I'm thinking it isn't a permissions issue at all, but maybe there is something wrong with my service call above. 

If I manually enable the service via the checkbox it all works fine.

 

Does anyone know how to enable a thing's own subscription from within it's one of it's own services?

Thanks,

K

 

 

2 replies

5-Regular Member
July 24, 2018

I tested here and worked fine:

 

var params = {
	propertyName: undefined /* STRING */,
	thingName: "TIMER60s" /* THINGNAME OF THE SOURCE OF THE SUBSCRIPTION*/,
	eventName: "Timer" /* STRING OF THE NAME OF THE EVENT OF THE SUBSCRIPTION */
};
me.EnableSubscription(params);

 Using data change:

 

var params = {
	propertyName: "value1" /* STRING */,
	thingName: me.name /* THINGNAME */,
	eventName: "DataChange" /* STRING */
};
me.EnableSubscription(params);
khayes11-VisitorAuthor
1-Visitor
July 25, 2018

Hi,

thanks for the reply. Not sure what is happening with mine as it still doesn't work. I have incorporated a work around by using a dynamic subscription to a timer event run in Administator context. Not ideal but at least it works.

Thanks again for the reply.

K