Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
Hi, I have this current situation:
ThingTemplate named "MyTemplate" with three properties: Prop1 (Number), Prop2 (number), Prop3 (number).
25 Things named "TH-1"..."TH-25".
Those properties will change every x seconds (where x is a random number) and I can see on a mashup the new value on three gauges each one binded to a property.
Now I have the following questions:
Thank you
Solved! Go to Solution.
1. With a normal timer, which every time it's executed "rolls a dice" to decide it has to be executed the corresponding service or not. How to roll a dice? with for instance (Math.random()>0.5)
2. Right now TW doesn't supports to send events to the browser from the server. Then you need to do a Poll every n-seconds, if you don't want to refresh the whole gauges every fixed n-seconds, you can set a property called "anyUpdates" and every n-seconds you query for that property, if that property it's true then you call the real data pull and you set again anyUpdates=false. If you have multiple users looking each one from their browser, then you will need to set this anyUpdates on the user session.
1. With a normal timer, which every time it's executed "rolls a dice" to decide it has to be executed the corresponding service or not. How to roll a dice? with for instance (Math.random()>0.5)
2. Right now TW doesn't supports to send events to the browser from the server. Then you need to do a Poll every n-seconds, if you don't want to refresh the whole gauges every fixed n-seconds, you can set a property called "anyUpdates" and every n-seconds you query for that property, if that property it's true then you call the real data pull and you set again anyUpdates=false. If you have multiple users looking each one from their browser, then you will need to set this anyUpdates on the user session.
I am sorry for my question but, since I'm quite new in "ThingWorx's world", I still didn't understand very well the services situation, so I didn't understand your answer.
From what I got the service is a function while the subscription is an action that "happens" when an event occurs.
If I see it in this way, I guess that what I need is not a service but a subscription and that my event should occur randomly.
So, that's what I've done. May you please tell me if there is something wrong?
I would like to know: According to what are you saying, am I right in part or I'm totally wrong?
Thank you
7. You don't have a setTimeout on ThingWorx, if you want it, you will have to implement with a "queue" an a timer which consumes the pending timeout services.
Ok, but if I want to make a queue, don't I have to make a service instead of a subscription (as I did in 4)?
I mean, queue is an option of services, isn't it?
No, there's no queue services for the platform itself ( you can queue Remote Thing Service calls, but not service calls on the platform itself ). If you want a queue you should implement it.
I was thinking about your "roll the dice" solution.
I don't know if, maybe, I got it wrong, but I don't know if it is the right solution.
What I understood was this kind of solution, tell me if you meant something else:
You make a regular timer thing (RandTimer) which is configured any 1 second.
In your thing template you make one more property that you call "var".
In the subscription of the thing template you give a random value to var from 0 to 1.
If var<0.5 you change myProp, else you don't.
Is it correct according to your idea?
Because in this case it is not exactly a really random amount of time because my value change any 1*(number of failures) seconds, but the number of failures follow the 2^(-n) law and it obviously is bigger for 1, 2 or 3, and lower (almost 0) for 10, 11. For sure I will never get to 100.
*******
Instead, I was thinking about this, but I don't know if it is possible.
Any second, I "stop" the timer
var timer = Things["RandTimer"];
timer.DisableTimer();
(Is this correct to stop my timer?)
I declare a new variable calle newTimeRate which i a random number.
I change via code randTimer rate with the new value, than I enable the Timer.
Is it possible to do this?
And, if so, would you please tell me which is the code to change the timer rate?
Thank you very much
First approach should work, you can also store the Timeout on a variable, and only execute it when Timeout<"now"
For the Second approach you will need a second timer which Enables the Timer, you can try to play around changing the UpdateRate on the timer, but for my experience that will put you in troubles ( for instance, without a restart some TW versions doesn't updates the Timer frequency ).
Carles.