10 Replies Latest reply on Dec 7, 2017 9:37 AM by polinao RSS
    ktahkker Newbie

    How can I connect alert to mashup

    I have created a thing to detect the temperature. While displaying the temperature in mashup, I want to display an alert message everytime the temperature is in a certain range . I also want to deploy a colour according to the range of temperature.

     

    For e.g

     

    - if (temperature > 0 && temperature < 60)

       print ("the temperature is not that high")

     

    And the colour should be "green"

     

    - if (temperature > 60 && temperature < 80)

       print ("the temperature high")

     

    And the colour should be "red"

     

    How can I implement something like this!!

     

    Thank you in advance.

      • Re: How can I connect alert to mashup
        nmilleson Explorer

        For the alert, you can specify that in the property itself.  Edit the "temperature" property and select "Manage Alerts" and put the "Greater Than" alert on it.  Then under "Subscriptions" on the left, create a new subscription and tie it to the alert on that property (and then use scripting to perform some action).  If you want to drive a message and colors on a mashup, you can use a combination of a boolean that drives the "visibility" of a widget and state formatting of a shape or text.

          • Re: How can I connect alert to mashup
            ktahkker Newbie

            Hey Nick,

             

            Thank you for your reply. I tried doing what you said, but I am still not able to display the the message in the mashup.  Below is the method that I used,

            1) This is what my Thing looks like:

             

            2) This is my subscription

             

             

            3) when I connect mashup to this subscription, it doesnot display any data.

              • Re: How can I connect alert to mashup
                nmilleson Explorer

                After reading your subscription script I think I have a better idea of what you’re trying to accomplish. In this case, change your subscription to “Data Change” and tie it to your temperature property. You can keep the same script you wrote. Now, anytime the temperature changes it will change the message accordingly. Now in your mashup, use the GetPropertyValuesService to have the “message” property available. Drag a Label widget into your workspace and tie the “message” property to it.

                  • Re: How can I connect alert to mashup
                    ktahkker Newbie

                    Hey Nick, Thanks it sounds logical . I tried to impelment it but I am still facing some problem like:

                     

                    Currently my code says, if the temperature is greater then 50 degree it should print "Warning: The raspberry PI is too hot"

                     

                    But as you can see it still prints "îts okay to work now". I chnage my subscription to Data Change like you told me, but i still get the foloowing output even when the temperature is greater then 50 degree

                    let me know where I am going wrong. Thankyou for the help.

                      • Re: How can I connect alert to mashup
                        nmilleson Explorer

                        Can you verify that the "message" property is changing as the temperature changes?  In your Properties tab, click the little refresh icon when your temperature drifts into another range.  Also, do you have your AutoRefresh tied to the GetPropertyValues service?

                          • Re: How can I connect alert to mashup
                            ktahkker Newbie

                            Hey Nick, I tried doing that but theh result is same. I am attaching some snaps below, may be it will help you. I think there is something wrong with the code but I am not understanding where am I going wrong.

                             

                             

                             

                            Also, yes I have attached my auto refresh widget to label.

                              • Re: How can I connect alert to mashup
                                ktahkker Newbie

                                Also, If  i measuring the temperature of something (let's say water) do you think I can write a code to predict approximately what time will it take to cool down based on the temperature reading and then display it on the mashup. If yes, can you tell me how? . Thank you !!

                                  • Re: How can I connect alert to mashup
                                    polinao Ninja

                                    Approximate - yes :-) From the ThingWorx perspective, it's a simple servce you would run, with the input of your measured temperature and output to a value display in a mashup. From the code implementation itself, you would need to refer to your knowledge of thermodynamics and the Fourier's law.

                                    Thermal conduction - Wikipedia

                                     

                                    Since a change in temperature is directly proportional to the change in energy, you can form this into a fairly simple first-order differential equation. If we take one side (air in a room), at a temperature we'll call T0 as a cold reservoir, we can say:

                                    Where T1 is the temperature of the water, c is the water's specific heat, A is the surface area, k is the thermal conductivity of the material between them (i.e. styrofoam cup, say it has a styrofoam lid too so it surrounds the water completely), and w is the thickness of the container.

                                    You will notice that this equation leads to an exponential decay in the temperature difference.

                                    Simply plug in the appropriate constants and solve this equation for any given ΔT and you can find how long it takes to get that close (it will never quite reach zero).