Getting Started with ThingWorx > Programming for the IoT
Programming for the IoT
Programming Rules and Business Logic
In the Internet of Things (IoT), rules and business logic are programmed differently than in traditional procedural programming models that use SQL and database queries. Procedural programming moves through the code from beginning to end with logic controls transferred to other parts of the application. Systems were designed to support processes like the following:
1. Dump data into a database.
2. Every night, run queries against the new data and apply business logic.
3. Dump the output of the batch operation into a database.
4. Run a report explaining what happened.
This process doesn't work well in the fast-paced world of the IoT. The store-then-query approach is not flexible or timely enough. You must react to events in real time.
Your IoT Application Enablement Platform (AEP), ThingWorx, provides an event-driven architecture that allows you to set up alerts based on threshold criteria and provides a scripting facility to apply business logic as events occur. For more information, see Events and Subscriptions.
The Need for Analytics
You must consider the massive amount of data in the IoT and therefore, your approach to analytics.
An If This, Then That (IFTTT) pattern expects you to know how to react to events. However, there are many possible reactions to IoT events, and you may not know which action to take. You may not know if an event is a signal or just noise. You want to know what can be used as insight from the petabytes of data generated by your Things.
In short, If This, Then What (IFTTW)?
IFTTW looks for answers to questions like the following:
Is it time to do maintenance?
Is it time to order consumables?
Is it time to send a repair technician?
Should I adjust the configuration of my product?
When you use an analytics engine with your IoT solution, you not only get a historical log of events, but you also get a predictive view of the future based on an analytical model that was informed by that history.
The Thing model adds asset context to your analytics. It allows you to train your analytics engine based on classes of equipment as defined in your model. It provides a semantic interface to generate alerts or issues for assets based on near real-time data analysis. For more information, see Data Analysis Definition.
Thing-Centric Semantic Layer
ThingWorx provides a semantic layer in its model, which is not meant to be consumed in a traditional programmatic way. You need to consider your Things and the characteristics of those Things that are needed for your solution. Using the object-oriented ThingWorx Model, you can break down common functionality into higher level objects, encapsulate business logic and capabilities in base objects, and inherit those base objects in your digital Thing. This process creates a semantic layer (a business representation of data that helps end users access data autonomously using common terms, such as product, customer, or revenue) that allows you to ask questions like “Thing123, what is your temperature and location history for the last two hours?”
The semantics of your model are exposed as a strongly-typed, well-understood set of REST APIs.
See Thing-Centric vs. Traditional Query Approaches.
Visual Application Builders
Visual application builders provide the final piece for consuming the results of the Thing-centric semantic model and provide for rapid application development. There are many types of user interface (UI) renderers on the market. To maximize the speed and flexibility to build your IoT solution, you must use a solution that understands the semantic layer of the data model and adjusts as your data model changes.
To quickly leverage the power of your model, you can use the ThingWorx Mashup Builder, which provides a layer over the edge, the cloud, and your Thing model. It provides visual widgets designed for the IoT that can be pre-wired to your Thing model. Using the ThingWorx Mashup Builder, you can use drag and drop to create user interface pages without coding. The Rapid Application Development (RAD) environment allows you to iterate on UI faster. The unique value of the ThingWorx AEP is that it uses the semantic layer of properties, services, and events to quickly and intuitively create modern applications for desktop and mobile devices. The power of ThingWorx allows you to address the hundreds of millions of applications needed by billions of connected devices.
See Model-View-Controller (MVC).