A common integration scenario is the inclusion of telemetry data retrieved from sensors in a smart contract. Based on data delivered by sensors, smart contracts could take informed actions and alter the state of the contract.
If a truck delivering medicine had its temperature soar to 110 degrees, it may impact the effectiveness of the medicine and may cause a public safety issue if not detected and removed from the supply chain.
If a driver accelerated his car to 100 miles per hour, the resulting sensor information could trigger a cancellation of insurance by his insurance provider. If the car was a rental car, GPS data could indicate when the driver went outside a geography covered by his rental agreement and charge a penalty.
The challenge is that these sensors can be delivering data on a constant basis and it is not appropriate to send all of this data to a smart contract.
A typical approach is to limit the number of messages sent to the blockchain while delivering all messages to a secondary store.
For example, deliver messages received at the only fixed interval, for example, once per hour, and when a contained value falls outside of an agreed upon range for a smart contract.
Checking values that fall outside of tolerances, ensures that the data relevant to the contracts business logic is received and executed.
Checking the value at the interval confirms that the sensor is still reporting. All data is sent to a secondary reporting store to enable broader reporting, analytics, and machine learning.
For example, while getting sensor readings for GPS may not be required every minute for a smart contract, they could provide interesting data to be used in reports or mapping routes.
On the Azure platform, integration with devices is typically done with IoT Hub. IoT Hub provides the ability to route messages based on content and enables the type of functionality described above.
The process above depicts a pattern for this is implemented:
- A device communicates directly or via a field gateway to IoT Hub.
- IoT Hub receives the messages and evaluates the messages against routes established that check the content of the message, for example. Does the sensor report a temperature greater than 50 degrees?
- The IoT Hub sends messages that meet the criteria to a defined Service Bus for the route.
- A Logic App or other code listens to the Service Bus that IoT Hub has established for the route.
- The Logic App or other code retrieves and transform the message to a known format.
- The transformed message, now in a standard format, is sent to the Service Bus for Azure Blockchain Workbench.
- Azure Blockchain Workbench is subscribed to events from the Service Bus and retrieves the message.
- Azure Blockchain Workbench initiates a call to the ledger, sending data from the external system to a specific contract.
- Upon receipt of the message, the contract evaluates the data and may change the state based on the outcome of that evaluation, for example, for a high temperature, change the state to Out of Compliance.
Azure Blockchain Workbench helps organizations build rich, integrated multi-party blockchain applications quickly and easily. Azure Blockchain Workbench REST API provides developers and information workers with a way to integrate to blockchain applications. For example, a developer can use the REST API to enable IoT devices to send data to a blockchain application. Or, an information worker can use the REST API and Power BI to create a visualization of blockchain data.