Sunteți pe pagina 1din 26

Exercise Workbook

IOT MODELING 1 WITH THINGWORX

Revision 1
Milestone 2 Exercises
Create a ThingWorx Project
1. Open the ThingWorx Composer
2. Click New Entity on the top right of the ThingWorx Composer
3. Select Project from the drop-down window
4. Type MarsInterstellarShipyardProject in the Name field

NOTE: Your username will be appended automatically to the name you type in, this is expected and you
should not try to delete the username. Example: MarsInterstellarShipyardProject_jsmith

5. Click Save

*This concludes Milestone2 Exercise*

Model 1 Exercises Workbook |1


Milestone 3 Exercises
Create Organization for Shipyard
1. Type +O in the Spotlight Search and select Organization
2. Type MarsInterstellarShipyardOrg in the Name field
3. Start typing M in the Project field and select MarsInterstellarShipyardProject
4. Click Save on top of the screen
5. Click the Edit button on top of the screen to go back to edit mode
6. Click Visibility in the ThingWorx Explorer bar on the left side of the screen
7. Click the Add Org/Org Units button
8. Start typing M in the field next to the picker
9. Select MarsInterstellarShipyardOrg from the Search Result dialog box.
10. Click the Add Entire Organization button
11. Click Done
12. Click Save
13. Keep the MarsInterstellarShipyardOrg entity open

Create Organization for Power & Shipyard Administrators


14. Select Organization from the ThingWorx Explorer bar on the left side of the screen
15. Click the green + button underneath the MarsInterstellarShipyardOrg in the Organization chart in
the middle of the screen
16. Type Power in the Name field
17. Click Done
18. Click the green + button to the right of Power on the right side of the screen
19. Type Shipyard in the Name filed
20. Click Done
21. Click Save

Create User Entities


22. Click New Entity on the ThingWorx header
23. Select User from the drop-down window
24. Type klee in the Name field
25. Start typing M in the Project Name field and select MarsInterstellarShipyardProject
26. Click the Change Password button
27. Type ptc in the Enter New Password field
28. Type ptc in the Retype Password field.
29. Click the Change Password button
30. Click User Extensions in the ThingWorx Explorer bar on the left side of the screen
31. Type Karen in the First Name field
32. Type Lee in the Last Name field

Model 1 Exercises Workbook |2


33. Type your email address in the Email Address field
34. Type your cellphone in the SMS Address field
35. Click Save
36. Click New Entity on the ThingWorx header
37. Select User from the drop-down window
38. Type hconrad in the Name field
39. Start typing M in the Project Name field and select MarsInterstellarShipyardProject
40. Click the Change Password button
41. Type ptc in the Enter New Password field
42. Type ptc in the Retype Password field.
43. Click the Change Password button
44. Click User Extensions in the ThingWorx Explorer bar on the left side of the screen
45. Type Hector in the First Name field
46. Type Conrad in the Last Name field
47. Type your email address in the Email Address field
48. Type your cellphone in the SMS Address field
49. Click Save

Create User Groups


50. Type +U in the Spotlight Search and select User Group from the pop-out window
51. Type PowerAdminGrp in the Name field
52. Start typing M in the Project Name field and select MarsInterstellarShipyardProject
53. Click Save
54. Type +U in the Spotlight Search and select User Group from the pop-out window
55. Type ShipyardAdminGrp in the Name field
56. Start typing M in the Project Name field and select MarsInterstellarShipyardProject
57. Click Save

Adding Users to User Groups


58. Click the Edit Members button for the ShipyardAdminGrp group
59. Start typing h in the Filter field
60. Drag hconrad to the right panel
61. Click Save
62. Select the PowerAdminGrp tab on top of the screen
63. Click the Edit Members button
64. Drag klee from the right panel to the left panel
65. Click Save

Create Role-Based Groups


66. Type +U in the Spotlight Search and select User Group from the pop-out window
67. Type Power.Admin in the Name field
68. Start typing M in the Project field, then select MarsInterstellarShipyardProject

Model 1 Exercises Workbook |3


69. Click Save
70. Click Edit Members on the top of the screen
71. Drag PowerAdminGrp from the left panel to the right panel
72. Click Save
73. Type +U in the Spotlight Search and select User Group from the pop-down window
74. Type Power.Write in the Name field
75. Start typing M in the Project field, then select MarsInterstellarShipyardProject from the pop-up
window
76. Click Save
77. Click Edit Members on the top of the screen
78. Drag Power.Admin from the left panel to the right panel
79. Click Save
80. Type +U in the Spotlight Search and select User Group from the pop-down window
81. Type Power.General in the Name field
82. Start typing M in the Project field, then select MarsInterstellarShipyardProject from the pop-up
window
83. Click Save
84. Click the Edit Members button on top of the screen
85. Drag Power.Write from the left to the right panel

Adding Role-Based Groups to Organizations


86. Select the MarsInterstellarShipyardOrg tab
87. Click the Power box in the Organization chart
88. Start typing p in the field under Members
89. Select Power.General
90. Click the Shipyard box in the Organization chart
91. Start typing s in the field under Members
92. Select ShipyardAdminGrp
93. Click Save

*This concludes Milestone 3 Exercise*

Model 1 Exercises Workbook |4


Milestone 5 Exercises
Create Thing: Shipyard
1. Click New Entity on the ThingWorx header
2. Select Thing from the drop-down window
3. Type Shipyard in the Name field
4. Start typing M in the Project Name field and select MarsInterstellarShipyardProject
5. Start typing ti in the Thing Template field and select Timer_Simple
6. Click Visibility in the ThingWorx Explorer bar
7. Click Add Org/Org Units
8. Start typing M in the Search Organizations field and select MarsInterstellarShipyardOrg
9. Click the Shipyard Organization unit
10. Click Done
11. Click Save

Create Thing Shape: Power Producer


12. Type +T in the Spotlight Search and select Thing Shape from the pop-out window
13. Type PowerProducerTS in the Name field
14. Start typing M in the Project field and select MarsInterstellarShipyardProject
15. Click Visibility in the ThingWorx Explorer bar
16. Click the Add Org/Org Units button
17. Start typing M in the Search Organizations field
18. Select MarsInterstellarShipyardOrg
19. Click the Power box in the Organization chart
20. Click the Shipyard box in the Organization chart
21. Click Done
22. Click Save

Create Template: Solar Collector


1. Click New Entity on the ThingWorx header
2. Select Thing Template from the drop-down window
3. Type SolarCollectorTT in the Name filed
4. Start typing M in the Project Name field and select MarsInterstellarShipyardProject
5. Start typing rem in the Base Thing Template field and select RemoteThingWithFileTransfer
6. Start typing p in the Implemented Shapes field and select PowerProducerTS
7. Click Visibility in the ThingWorx Explorer bar
8. Click the Add Org/Org Units button
9. Start typing M in the Search Organizations field
10. Select MarsInterstellarShipyardOrg
11. Click the Power box in the Organization chart

Model 1 Exercises Workbook |5


12. Click the Shipyard box in the Organization chart
13. Click Done
14. Click Visibility Instance on the ThingWorx Explorer bar
15. Click Add Org/Org Units
16. Start typing M in the Search Organizations field
17. Select MarsInterstellarShipyardOrg
18. Click the Power box in the Organization chart
19. Click the Shipyard box in the Organization chart
20. Click Done
21. Click Save

Create Thing: Solar Collector


22. Verify that the SolarCollectorTT tab is selected
23. Click More on the top right side of the screen
24. Select Create Thing from the pop-out window
25. Type SolarCollector-1 in the Name field
26. Start typing M in the Project field
27. Select MarsInterstellarShipyardProject
28. Click Save

NOTE: In the following steps we will verify that our visibility works the way we want by logging as the users
Karen Lee and Hector Conrad

29. Click the User icon on the top right corner of the ThingWorx Composer
30. Select Log Out from the drop-down window
31. Click the Go Back to ThingWorx Explorer link
32. Log in as Karen Lee:
a. Username: klee_username
b. Password: ptc
c. Click Log In

NOTE: Remember that in order to log in successfully as Karen Lee or Hector Conrad, you must include
_username next to the character username

33. Click Things on the ThingWorx Explore bar on the left side of the screen

NOTE: Note that Karen Lee can only see SolarCollect-1 Thing as expected

34. Click the User icon on the top right corner of the ThingWorx Composer
35. Select Log Out from the drop-down window
36. Click the Go Back to ThingWorx Explorer link
37. Log in as Hector Conrad:
a. Username: hconrad_username
b. Password: ptc

Model 1 Exercises Workbook |6


c. Click Log In
38. Click Things on the ThingWorx Explorer bar on the left side of the screen

NOTE: Note that Hector has visibility to both the Shipyard thing and instance visibility to all solar collectors,
including SolarCollector-1

39. Click the User icon on the top right corner of the ThingWorx Composer
40. Select Log Out from the drop-down window
41. Click the Go Back to ThingWorx Explorer link
42. Log in with your username and password

Duplicate Thing: Solar Collector


43. Click the Home tab on the top left side of the screen
44. Click Things on the ThingWorx Explorer tab
45. Select the checkbox for SolarCollector-1
46. Click Duplicate on top of the screen
47. Type SolarCollector-2 in the Name field
48. Click Save

Create Thing Shape: Power Consumer


49. Click the Home tab
50. Click Thing Shapes on the ThingWorx Explorer bar
51. Select the checkbox next to PowerProducerTS
52. Click Duplicate on top of the screen
53. Type PowerConsumerTS in the Name field
54. Click Save

Iterate Things: Mars Rover


55. Start typing Bas and select BaseRoverTemplate from the pop-out window
56. Type p in the Implemented Shapes field and select PowerConsumerTS
57. Type p in the Implemented Shapes field and select PowerProducerTS
58. Click Visibility in the ThingWorx Explorer bar
59. Click Add Org/Org Units
60. Start typing m in the Search Organizations field
61. Select MarsInterstellarShipyardOrg
62. Click the Add Entire Organization button
63. Click Done
64. Click Visibility Instance in the ThingWorx Explorer bar
65. Click Add Org/Org Units
66. Start typing m in the Search Organizations field
67. Select MarsInterstellarShipyardOrg
68. Click the Add Entire Organization button

Model 1 Exercises Workbook |7


69. Click Done
70. Click Save
71. Open the MarsInterstellarShipyardProject project
72. Click the Edit Entities button
73. Select all rover related entities and drag them to the right side

NOTE: All rover entities are all the entities that include the word rover on their name

74. Click Save

Create Thing: Power Storage


75. Click New Entity on the ThingWorx header
76. Select Thing from the drop-down window
77. Type PowerStorage in the Name filed
78. Start typing M in the Project Name field and select MarsInterstellarShipyardProject
79. Start typing rem in the Thing Template field and select RemoteThing
80. Click Visibility in the ThingWorx Explorer bar
81. Click Add Org/Org Units
82. Start typing M in the Search Organizations field
83. Select MarsInterstellarShipyardOrg
84. Click the Add Entire Organization button on top of the screen
85. Click Done
86. Click Save

*This concludes Milestone 5 Exercise*

Model 1 Exercises Workbook |8


Milestone 6 Exercises
Creating Properties: Power System
1. Start typing Pow in the Spotlight Search on top of the screen
2. Select the PowerStorage thing
3. Click Properties on the ThingWorx Explorer bar
4. Click the Add My Property button and create a property as follows:
a. Name: PowerStored
b. Base Type: NUMBER
c. Units: kWh
d. Min Value: 0
e. Max Value: 500000000 (eight zeros)
f. Persistent: true
g. Logged: true
h. Change Threshold: 100
i. Click Done
5. Click General Information in the ThingWorx Explorer bar
6. Start typing V in the Value Stream field
7. Select VS from the pop-down window
8. Click Run Time in the ThingWorx Explorer bar
9. Start typing p in the field under All Properties, Events, and Services
10. Select Power.General
11. Start typing s in the field under All Properties, Events, and Services
12. Select ShipyardAdminGrp
13. Set the Property Read permission for both groups to green
14. Click Save
15. Click Properties in the ThingWorx Explorer bar
16. Click the Set button for the PowerStored property on the right side of the My Properties table
17. Type 11000 in the pop-up window, click Set
18. Click the Set button for the PowerStored property on the right side of the My Properties table
19. Type 10000 in the pop-up window, click Set
20. Click the Set button for the PowerStored property on the right side of the My Properties table
21. Type 10003 in the pop-up window, click Set
22. Click Services on the ThingWorx Explorer Bar
23. Expand the Generic Services section
24. Find the QueryPropertyHistory service
25. Click the Test button for the QueryPropertyHistory service
26. Click the Execute Service button in the pop-up window
27. Click Close
28. Start typing Pow in the Spotlight Search and click the PowerProducerTS thing shape

Model 1 Exercises Workbook |9


29. Click Properties on the ThingWorx Explorer bar
30. Click the Add My Property button and create a property as follows:
a. Name: PowerProduced
b. Base Type: NUMBER
c. Units: kW
d. Min Value: 0
e. Persistent: true
f. Logged: true
g. Click Done
31. Click Run Time Instance on the ThingWorx Explorer bar
32. Start typing p in the field under All Properties, Events, and Services
33. Select Power.General
34. Set the Property Read permission to green
35. Click Save
36. Start typing Sol in the Spotlight Search and click the SolarCollectorTT thing template
37. Start typing V in the Value Stream field on the right side of the screen
38. Select VS from the pop-down window
39. Click Save
40. Start typing Pow in the Spotlight Search and click the PowerConsumerTS thing shape
41. Click Properties on the ThingWorx Explorer bar
42. Click the Add My Property button and create a property as follows:
a. Name: PowerConsumed
b. Base Type: NUMBER
c. Units: kW
d. Min Value: 0
e. Persistent: true
f. Logged: true
g. Click Done
43. Click Run Time Instance on the ThingWorx Explorer bar
44. Start typing p in the field under All Properties, Events, and Services
45. Select Power.General
46. Set the Property Read permission to green
47. Click Save
48. Start typing Base in the Spotlight Search and click the BaseRoverTemplate thing template
49. Start typing V in the Value Stream field on the right side of the screen
50. Select VS from the pop-down window
51. Click Save
52. Start typing Crew in the Spotlight Search and click the CrewRover1 thing
53. Click Properties on the ThingWorx Explorer bar
54. Click the Set button for the PowerConsumed property on the right side of the My Properties table
55. Type 5 in the pop-up window , click Set

Model 1 Exercises Workbook | 10


56. Again, click the Set button for the PowerConsumed property on the right side of the My Properties
table
57. Type 2 in the pop-up window , click Set
58. Click Services on the ThingWorx Explorer bar
59. Expand the Generic Services drop-down
60. Click the Test button for the QueryPropertyHistory service
61. Click Execute Service
62. Click Close
63. Click Save

Wrapped Services: Power System


64. Start typing +T in the Spotlight Search and select +Thing
65. Type PowerSystemServices in the Name field
66. Start typing g in the Thing Template field and select GenericThing
67. Start typing M in the Project field and select MarsInterstellarShipyardProject
68. Click Visibility on the ThingWorx Explore bar
69. Click the Add Org/Org Units button
70. Type and select MarsInterstellarShipyardOrg in the Search Organization field
71. Click the Power button
72. Click the Shipyard button
73. Click Done
74. Select Services on the ThingWorx Explorer bar
75. Click Add My Service
76. Type GetPowerProducers in the Name field
77. Select the Inputs/Outputs tab
78. In the Outputs section, select INFOTABLE in the Base Type field
79. Select the Entities tab
80. Start typing p in the Search Entities bar
81. Select PowerProducerTS
82. Start typing getim in the Filter field to search the GetImplementingThingsWithData service
83. Click the blue arrow to the right of the service name to add the snippet for the service
84. Click the Check Syntax button
85. Click Done
86. Click Save
87. Click the Test button for the GetPowerProducers service
88. Click Execute Service
89. Click the Create Data Shape from Result button
90. Type GetPowerProducersDS in the Name field
91. Start typing M in the Project field
92. Select MarsInterstellarShipyardProject
93. Click Save
94. Go back to the PowerSystemServices thing

Model 1 Exercises Workbook | 11


95. In edit mode, click the Edit button for the GetPowerProducers service
96. On the Inputs/Outputs tab, under Outputs start typing g in the Data Shape field
97. Select GetPowerProducersDS
98. Click Done
99. Click Save
100. Click Add My Service
101. Type GetPowerConsumers in the Name field
102. Select the Inputs/Outputs tab
103. Under the Output section, select INFOTABLE
104. Select the Entities tab
105. Start typing p in the Search Entities field
106. Select PowerConsumerTS
107. Start typing getim in the Filter field to search the GetImplementingThingsWithData service
108. Click the blue arrow to the right of the service name to add the snippet for the service
109. Click the Check Syntax button
110. Click Done
111. Click Save
112. Click the Test button for the GetPowerConsumers service
113. Click Execute Service
114. Click the Create Data Shape from Result button
115. Type GetPowerConsumersDS in the Name field
116. Start typing M in the Project field
117. Select MarsInterstellarShipyardProject
118. Click Save
119. Go back to the PowerSystemServices thing
120. Verify you are on edit mode
121. Go to Services on the ThingWorx Explorer bar
122. Click the Edit button for the GetPowerConsumers service
123. Under the Inputs/Outputs tab, start typing g in the Data Shape field
124. Select GetPowerConsumersDS
125. Click Done
126. Click Save
127. Navigate to the PowerSystemServices thing
128. Click Run Time on the ThingWorx Explorer bar
129. Start typing getp in the Property, Service, or Event Overrides field
130. Select GetPowerProducers
131. Start typing p in the Add a User or Group field
132. Select Power.General
133. Set the Service Execute permission to green
134. Start typing getp in the Property, Service, or Event Overrides field
135. Select GetPowerConsumers

Model 1 Exercises Workbook | 12


136. Start typing p in the Add User or Group field
137. Select Power.General
138. Set the Service Execute permission to green
139. Click Save
140. Start typing +A in the Spotlight Search and select +Application Key
141. Type adminAppKey in the Name field
142. In the User Name Reference field, type your username and select it from the pop-up window
143. Click Save
144. Copy the generated keyId into a text editor such as Notepad
145. Create another Application Key
146. Type kleeAppKey in the Name field
147. In the User Name Reference field type and select klee
148. Click Save
149. Copy the generated keyId into a text editor such as Notepad
150. Create another Application Key
151. Type hconradAppKey in the Name field
152. In the User Name Reference field type and select hconrad
153. Click Save
154. Copy the generated keyId into a text editor such as Notepad
155. Open POSTMAN
156. On the drop-down menu next to the Enter request URL field, select POST
157. Back on the ThingWorx Composer copy the ThingWorx URL up to /Thingworx
158. On POSTMAN, enter the following:

[copied URL]/ThingShapes/PowerProducerTS_<your username>/Services/GetImplementingThingsWithData

159. Add the following information to the header:


a. appKey: [adminAppKey keyId copied in Notepad]
b. Content-type: application/json
c. Accept: text/html
160. Click Send on the top right of the screen
161. Click Preview under the Body section

NOTE: If everything goes right, you should be able to see a list of entities under the Preview tab

162. Next, replace the Administrators AppKey with Karens AppKey and click Send

NOTE: You should get a 401 unauthorized message. This is expected since the
GetImplementingThingsWithData is part of the internal API, therefore Karen is not able to execute it.

163. Replace Karens AppKey with Hectors AppKey and click Send

NOTE: You should get the same result as with Karens API because Hector cannot execute services in the
internal API either

Model 1 Exercises Workbook | 13


164. Replace Hectors AppKey with the Administrators key again and change the URL as follows:

[copied URL]/Things/PowerSystemServices_<your username>/Services/GetPowerProducers

165. Click Send

NOTE: Since GetPowerProducers just calls GetImplementingThingsWithData, the result is the same as
before

166. Replace the Administrators AppKey with Karens AppKey


167. Click Send

NOTE: Karen can execute GetPowerProducers because she has role-based group permissions as part of the
Power.General group.

168. Replace Karens AppKey with Hectors AppKey


169. Click Send

NOTE: Hector cannot execute this service. The only group that has permission s the Power.General group
and Hector is not a member of that group. It is important to remember that Hector only needs aggregate
power data, not data on individual assets, like this service provides.

170. Return to the ThingWorx Composer


171. Click Monitoring on the right side of the screen
172. Under Logs, click Application
173. On the User field select hconrad from the drop-down list

NOTE: ThingWorx generates logs about attempted REST API calls that are unauthorized. By default, the
application shows entries originating from the user who is logged on. The error was not generated by the
user that is currently logged on but by hconrad, that is why we pick him from the drop-down list.

Aggregating Properties
174. Open the Shipyard thing in edit mode
175. Click Properties on the ThingWorx Explorer bar
176. Click Add My Property and create a property as follows:
a. Name: PowerConsumed
b. Base Type: NUMBER
c. Units: kW
d. Persistent: true
e. Logged: true
f. Data Change Type: Value
g. Click Done and Add and
177. Create a second property as follows:
a. Name: PowerProduced
b. Base Type: NUMBER

Model 1 Exercises Workbook | 14


c. Units: kW
d. Persistent: true
e. Logged: true
f. Data Change Type: Value
g. Click Done and Add and
178. Create a third property as follows:
a. Name: PowerStored
b. Base Type: NUMBER
c. Units: kWh
d. Persistent: false
e. Logged: true
f. Data Change Type: Value
g. Change Threshold: 100
h. Click Done
179. Click Visibility on the ThingWorx Explorer bar
180. Click the Add Org/Org Units button
181. Select MarsInterstellarShipyardOrg in the Search Organization field
182. Click the Power button
183. Click Done
184. Click Save
185. Click Run Time on the ThingWorx Explorer field
186. Start typing Shi in the Add a User or Group field underneath the All Properties, Events and Services
heading and select ShipyardAdminGrp
187. Set the Property Read permission to green
188. Add PowerConsumed to the Property, Service or Event Overrides list
189. Start typing Pow in the Add a User or Group field under PowerConsumed
190. Select Power.General
191. Set the Property Read permission to green for the Power.General group
192. Add PowerProduced to the Property, Service or Event Overrides list
193. Start typing Pow in the Add a User or Group field under PowerProduced
194. Select Power.General
195. Set the Property Read permission to green for the Power.General group
196. Add PowerStored to the Property, Service or Event Overrides list
197. Start typing Pow in the Add a User or Group field under PowerStored
198. Select Power.General
199. Set the Property Read permission to green for the Power.General group
200. Click Done
201. Click Save

Model 1 Exercises Workbook | 15


Binding Properties
202. Open your Shipyard thing
203. On the ThingWorx Explorer bar click Properties
204. Click Manage Bindings on top of the screen
205. In the Search Thing field, on the left side of the screen start typing p
206. Select PowerStorage from the list
207. Drag the PowerStored property for the PowerStorage thing to the PowerStored property for the
Shipyard thing
208. Click Done
209. Click Save

Aggregator Service
210. On top of the screen, click +New Entity and select Data Shape
211. In the Name field, type RollupDS
212. In the Project field, start typing M and select MarsInterstellarShipyardProject
213. On the ThingWorx Explore bar, click Field Definitions
214. Click Add on top of the screen and add the field as follows:
a. Name: powerProduced
b. Base Type: Number
c. Units: kW
215. Click Done and Add and add another field as follows:
a. Name: powerConsumed
b. Base Type: Number
c. Units: kW
216. Click Done and Add and add the following field a follows:
a. Name: powerStored
b. Base Type: Number
c. Units: kWh
217. Click Save
218. Open your Shipyard thing
219. On the ThingWorx Explorer bar, click Services
220. Click Add My Service
221. Add a service as follows:
a. Name: Rollup
b. Click the Inputs/Outputs tab
c. Base Type: INFOTABLE
d. Select RollupDS in the Data Shape field
e. Download the RollupDS.txt file from the instructor notes, open the file, copy the code and paste
the code into the script editor in ThingWorx
f. In the Script area, type &&& into the Search Script field
g. Type _<your username> in the Find and Replace field

Model 1 Exercises Workbook | 16


h. Click Replace All (total of 4 replacements)
i. Click Check Syntax
222. Click Done
223. Click Save
224. Go to the PowerSystemServices thing
225. On the ThingWorx Explorer bar select Services
226. Click the Test button for the GetPowerProducers service
227. Click Execute Service
228. Click Close
229. Go to the SolarCollector-1 thing
230. On the ThingWorx Explorer bar select Properties
231. Set the PowerProduced property to 1000
232. Go to the SolarCollector-2 thing
233. On the ThingWorx Explorer bar select Properties
234. Set the PowerProduced property to 1000
235. Go to the PowerSystemServices thing
236. On the ThingWorx Explorer bar select Services
237. Click the Test button for the GetPowerConsumers service
238. Click Execute Service
239. Click Close
240. Go to the PowerStorage thing
241. On the ThingWorx Explorer bar select Properties
242. Verify that the value for the PowerStored property is 1003

NOTE: We already set up the PowerStored property to 1003. If not, set up the PowerStored of the
PowerStorage thing to 1003

243. Go to the Shipyard thing


244. On the ThingWorx Explorer bar select Services
245. Click the Test button for the Rollup service
246. Click Execute Service
247. Click Close
248. On the ThingWorx Explorer bar select Properties
249. Under My Properties, click the Refresh button on the Value field of the properties table

NOTE: The service does not only generate an Infotable but it also sets the property values for the Shipyard.

Subscribing to a Timer
250. Open your Shipyard thing
251. On the ThingWorx Explorer bar select Configuration
252. Type 10000 in the Update Rate field
253. On the ThingWorx Explorer bar select Subscriptions
254. Click Add My Subscription

Model 1 Exercises Workbook | 17


255. Under the Subscription Info tab, on the Event drop-down list select Timer
256. Select the Enabled checkbox
257. Go to the Me tab
258. In the left side of the tab, select -Uncategorized- under Categories
259. Click the blue arrow pointing right next to the Rollup service
260. Click Done
261. Click Save
262. Open your PowerStorage thing
263. On the ThingWorx Explorer bar select Properties
264. Set PowerStored to 12000
265. Open your SolarCollector-1 thing
266. On the ThingWorx Explorer bar select Properties
267. Set PowerProduced to 300
268. Open your CrewRover1 thing
269. On the ThingWorx Explorer bar select Properties
270. Set PowerConsumed to 150
271. Open your Shipyard thing
272. On the ThingWorx Explorer bar select Properties
273. Wait 10 seconds, then click the Refresh button next to the Value field under My Properties

Creating Properties
274. Open your Shipyard thing
275. On the ThingWorx Explorer bar select Properties
276. Add a Low Power State property as follows:
a. Name: LowPowerState
b. Base Type: Boolean
c. Persistent: true
d. Logged: true
e. Click Done and Add
277. Add a No Low Power State Until property as follows:
a. Name: NoLowPowerStateUntil
b. Base Type: DATETIME
c. Persistent: true
d. Logged: true
278. Click Done
279. Click Save
280. Open your PowerConsumerTS thing shape
281. On the ThingWorx Explorer bar select Properties
282. Add a High Priority property as follows:
a. Name: HighPriority
b. Base Type: Boolean
c. Persistent: true

Model 1 Exercises Workbook | 18


d. Logged: true
283. Click Done
284. Click Save
285. Open your Shipyard thing
286. On the ThingWorx Explorer bar select Run Time
287. Add LowPowerState to the Property, Service or Event Override list
288. Start typing Pow in the Add a User or Group field under LowPowerState
289. Select Power.General
290. Set the Property Read permission to green for the Power.General group
291. Start typing Pow in the Add a User or Group field under LowPowerState
292. Select Power.Write
293. Set the Property Write permission to green for the Power.Write group
294. Add NoLowPowerStateUntil to the Property, Service or Event Override list
295. Start typing Pow in the Add a User or Group field under LowPowerState
296. Select Power.General
297. Set the Property Read permission to green for the Power.General group
298. Start typing Pow in the Add a User or Group field under NoLowPowerState
299. Select Power.Write
300. Set the Property Write permission to green for the Power.Write group
301. Click Save

Writing Services
302. Open your PowerConsumerTS thing shape
303. On the ThingWorx Explorer bar, click Services
304. Click Add My Service
305. In the Name field type Shutdown
306. In the Description field type This is a generic service intended to be overridden by the thing template
or thing that implements the PowerConsumerTS thing shape. It is designed to shut down the power in a
safe way to conserve power.
307. Select the Allow Override checkbox
308. Select the Async checkbox
309. Click the Inputs/Outputs tab

NOTE: This is an asynchronous service; therefore, it requires no input and there is no output. Also, it does
not require any code in the script area. For more information, go back to the Exercise video.

310. Click Done


311. Click Save
312. Open your BaseRoverTemplate thing template
313. On the ThingWorx Explorer bar, go to Services
314. Under the PowerConsumerTS thing shape services, click the Override and Edit button
315. Select the Me tab

Model 1 Exercises Workbook | 19


316. Click Properties
317. Click the blue arrow to the right of the Destination property
318. Alter the end of the code so it reads:
me.Destination = Charging Station;
319. Click Done
320. Click Save
321. Open your CrewRover1 thing
322. Click the Test button for the Shutdown service
323. Click Execute Service
324. Click Close
325. Click Properties on the ThingWorx Explorer bar
326. Click the Refresh button for the CrewRoverTemplate table of properties
327. Set the Destination property to Something Else
328. Open the PowerSystemServices thing
329. On the ThingWorx Explorer bar, go to Services
330. Click Add My Service
331. Add a service as follows:
a. Name: EstHrsToPowerOutage
b. Click the Inputs/Outputs tab
c. Base Type: NUMBER
d. Download the EstHrsToPowerOutage.txt file from the instructor notes, open the file, copy the
code and paste the code into the script editor in ThingWorx
e. In the Script area, type &&& into the Search Script field
f. Type _<your username> in the Find and Replace field
g. Click Replace All (total of 4 replacements)
h. Click Check Syntax
332. Click Done
333. Click Save
334. Set the property value for the following things:

Thing Name Property Name Property Value


PowerStorage PowerStored 12000
CrewRover1 PowerConsumed 2000
CrewRover2 PowerConsumed 0
CrewRover3 PowerConsumed 0
SolarCollector-1 PowerProduced 1000
SolarCollector-2 PowerProduced 0

335. Open your PowerSystemServices thing


336. Click Services on the ThingWorx Explorer bar
337. Click the Test button for the EstHrsToPowerOutage service

Model 1 Exercises Workbook | 20


338. Click Execute Service
339. Click Close
340. Click Add My Service
341. Add a service as follows:
a. Name: ExitLowPowerState
b. Click the Inputs/Outputs tab
c. Click Add next to Inputs
d. Type hrsNoLowPowerState in the Name field
e. Base Type: NUMBER
f. Click Done
g. Back in the Inputs/Outputs tab
h. Under Outputs, set a STRING Base Type
i. Download the ExitLowPowerState.txt file from the instructor notes, open the file, copy the code
and paste the code into the script editor in ThingWorx
j. In the Script area, type &&& into the Search Script field
k. Type _<your username> in the Find and Replace field
l. Click Replace All (total of 4 replacements)
m. Click Check Syntax
342. Click Done
343. Click Save
344. Click the Test button for the ExitLowPowerState service
345. Type 0 in the hrsNoLowPowerState input parameter
346. Click the Execute Service button
347. Click Close
348. Open your Shipyard thing
349. Click the Set button for the LowPowerState property and set it to true (select checkbox)
350. Open the PowerSystemServices thing
351. Click Services on the ThingWorx Explorer bar
352. Click the Test button for the ExitLowPowerState service
353. Type 0 in the hrsNoLowPowerState input parameter
354. Click the Execute Service button

NOTE: Notice the date and time listed in the result message, it should match the property in the Shipyard
thing

355. Open your Shipyard thing


356. On the ThingWorx Explorer bar, click Properties
357. Click the Refresh button next to the Value field for the My Properties table

NOTE: Verify that the LowPowerState property is false and the NoLowPowerStateUntil property matches the
results of the service execution

358. Open your PowerSystemServices thing

Model 1 Exercises Workbook | 21


359. Click Services on the ThingWorx Explorer bar
360. Click Add My Service
361. Add a service as follows:
a. Name: EnterLowPowerState
b. Go to the Inputs/Outputs tab
c. Under Outputs, set a STRING Base Type
d. Download the EnterLowPowerState.txt file from the instructor notes, open the file, copy the
code and paste the code into the script editor in ThingWorx
e. In the Script area, type &&& into the Search Script field
f. Type _<your username> in the Find and Replace field
g. Click Replace All (total of 3 replacements)
h. Click Check Syntax
362. Click Done
363. Click Save
364. Click the Test button for the EnterLowPowerState service
365. Click Execute Service
366. Click Close
367. Click the Test button for the ExitLowPowerState service
368. Type 1 in the hrsNoLowPowerState field
369. Click Execute Service
370. Click Close
371. Click the Test button for the EnterLowPowerState service
372. Click Execute Service

NOTE: The result should be a message saying that you cannot enter low power state

373. Click Close


374. Click the Test button for the ExitLowPowerState service
375. Type 0 in the hrsNoLowPowerState field
376. Click Execute Service

NOTE: The result should be a message saying that you attempted to exit low power state while shipyard is
not in a low power state

377. Click Close


378. On the ThingWorx Explorer bar, click Run Time
379. Start typing es in the Property, Service or Event Overrides field
380. Select EstHrsToPowerOutage
381. Start typing p in the Add a User or Group field under EstHrsToPowerOutage
382. Select Power.General
383. Set Service Execute to green
384. Start typing s in the Add a User or Group field under EstHrsToPowerOutage
385. Select ShipyardAdminGrp

Model 1 Exercises Workbook | 22


386. Set Service Execute to green
387. Start typing en in the Property, Service or Event Overrides
388. Select EnterLowPowerState
389. Start typing p in the Add a User or Group field under EnterLowPowerState
390. Select Power.Admin
391. Set Service Execute to green
392. Start typing ex in the Property, Service or Event Overrides field
393. Select ExitLowPowerState
394. Start typing p in the Add a User or Group field under ExitLowPowerState
395. Select Power.Admin
396. Set Service Execute to green
397. Click Save

Events and Subscriptions


398. Go to the Home tab on the top left side of the screen
399. Click Data Shapes on the ThingWorx Explore bar
400. Select the RollupDS data shape by clicking the checkbox next to the entity
401. Click Duplicate on top of the screen
402. Type LowPowerEmergencyDS in the Name field
403. Click Field Definitions in the ThingWorx Explorer bar
404. Click the Add button
405. Type estHrsToPowerOut in the Name field
406. Select NUMBER in the Base Type field
407. Click Done
408. Click Save
409. Open your Shipyard thing
410. Click Events on the ThingWorx Explorer bar
411. Click Add My Event
412. Type LowPowerEmergency in the Name field
413. Select LowPowerEmergencyDS in the Data Shape field
414. Click Done
415. Click Save
416. Click Subscriptions on the ThingWorx Explorer bar
417. Click Add My Subscription
418. Select DataChange in the Event field
419. Select PowerStored in the Property field
420. Select the Enabled checkbox
421. Download the PowerStoredSubscription.txt file from the instructor notes, open the file, copy the code
and paste the code into the script editor in ThingWorx
422. In the Script area, type &&& into the Search Script field
423. Type _<your username> in the Find and Replace field
424. Click Replace All (total of 1 replacement)

Model 1 Exercises Workbook | 23


425. Click Done
426. Click Save
427. Go to your PowerStorage thing
428. Click Properties on the ThingWorx Explorer bar
429. Set the PowerStored property to 13000
430. Go to your CrewRover1 thing
431. Click Properties on the ThingWorx Explorer bar
432. Set the PowerConsumed property to 2000
433. Go to your PowerSystemServices thing
434. Click Services on the ThingWorx Explorer bar
435. Click the Test button for the GetPowerConsumers service
436. Click Execute Service
437. Click Close
438. Open your CrewRover2 thing
439. Click Properties on the ThingWorx Explorer bar
440. Set the HighPriority property of the TestPowerConsumerTS to true (checked)
441. Go to your SolarCollector-1 thing
442. Click Properties on the ThingWorx Explorer bar
443. Set the PowerProduced property to 1000
444. Go to your SolarCollector-2 thing
445. Click Properties on the ThingWorx Explorer bar
446. Set the PowerProduced property to 0
447. Go to your Shipyard thing
448. Click Properties on the ThingWorx Explorer bar
449. Set the LowPowerState property to false (unchecked)
450. Set the NoLowPowerStateUntil property to some time yesterday
451. Go to your PowerSystemServices thing
452. Click Services on the ThingWorx Explorer bar
453. Click the Test button for the EstHrsToPowerOutage service
454. Click Execute Service
455. Click Close
456. Go to your PowerStorage thing
457. Click Properties on the ThingWorx Explore bar
458. Set the PowerStored property to 10000
459. Go to your Shipyard thing
460. Click Properties on the ThingWorx Explorer bar
461. Click the Refresh button next to the Value field under the My Properties table
462. Open your PowerConsumerTS thing shape
463. Click Subscriptions on the ThingWorx Explorer bar
464. Click Add My Subscription
465. Select your Shipyard thing in the Source field

Model 1 Exercises Workbook | 24


466. Select LowPowerEmergency in the Event field
467. Select the Enabled check box
468. Type the following code to the Script area

if (me.HighPriority == false) {
me.Shutdown();
}

469. Click Done


470. Click Save
471. Open your PowerStorage thing
472. Click Properties on the ThingWorx Explorer bar
473. Set the PowerStored property to 13000
474. Open your PowerSystemServices thing
475. Click Services on the ThingWorx Explorer bar
476. Click the Test button for the ExitLowPowerState service
477. Type 0 in the hrsNoLowPowerState field
478. Click Execute Service
479. Open your Shipyard thing
480. Click Properties on the ThingWorx Explorer bar
481. Click the Refresh button next to the Value field in the My Properties table
482. Open your PowerStorage thing
483. Click Properties on the ThingWorx Explorer bar
484. Set the PowerStored property to 10000
485. Open your CrewRover1 thing
486. Click Properties on the ThingWorx Explorer bar
487. Click the Refresh button next to the Value field for the properties table under the
CrewRoverTemplate
488. Open your CrewRover2 thing
489. Click Properties on the ThingWorx Explorer bar
490. Click the Refresh button next to the Value field for the properties table under the
CrewRoverTemplate
491. Open your CrewRover3 thing
492. Click Properties on the ThingWorx Explorer bar
493. Click the Refresh button next to the Value field for the properties table under the
CrewRoverTemplate

*This concludes Model 1 Exercises*

Model 1 Exercises Workbook | 25

S-ar putea să vă placă și