IoTUModel1 Exercises
IoTUModel1 Exercises
IoTUModel1 Exercises
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
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
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
NOTE: All rover entities are all the entities that include the word rover on their name
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
NOTE: Since GetPowerProducers just calls GetImplementingThingsWithData, the result is the same as
before
NOTE: Karen can execute GetPowerProducers because she has role-based group permissions as part of the
Power.General group.
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.
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
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
NOTE: We already set up the PowerStored property to 1003. If not, set up the PowerStored of the
PowerStorage thing to 1003
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
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
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.
NOTE: Notice the date and time listed in the result message, it should match the property in the Shipyard
thing
NOTE: Verify that the LowPowerState property is false and the NoLowPowerStateUntil property matches the
results of the service execution
NOTE: The result should be a message saying that you cannot enter low power state
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
if (me.HighPriority == false) {
me.Shutdown();
}