Java Magazine, Sept/Oct 2016
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2016 33 internet of things For example IoTCS uses OAuth 20 tokening to implement much of its security model Using the REST APIs your device would need to read an SSL keystore Base64 encode the appropriate username and password send the proper OAuth 2 handshake messages and handle the responses all to activate an IoT device and have it communicate data Doing this with pure REST can be tedious However by using parts of the Oracle IoT Cloud Service Java Client Software Library the code to authenticate and activate an IoT device is reduced to whats shown in Listing 1 Listing 1 String url HttpClient httpClient new HttpClient server_ url uid pwd WebResource resource httpClient createHTTPClient true resource url TokenInputDetails tokenInputDetails new TokenInputDetails tokenInputDetails setTokenType TokenType TOKEN_ TYPE_ ACTIVATION tokenInputDetails setDeviceId endpointID tokenInputDetails setSharedSecret secret String deviceModelStr urn com acme conveyorbeltmodel String messageFormat urn com acme conveyorbeltmodel speed Authorization authorization new Authorization resource PrivateKey privateKey authorization activate tokenInputDetails In fact this code can be reduced further to the following using the oracle iot client device DirectlyConnectedDevice class from the IoTCS Client Software Library see Listing 2 Listing 2 DirectlyConnectedDevice device new DirectlyConnectedDevice if device isActivated device activate getDeviceModelURN When leveraging the cloud based development paradigm the key is understanding which aspects of an IoT solution to leave as cloud handled analytics and which to implement in code The goal is to alleviate tedious maintenance requirements by allowing the business to make changes without new software deployments To demonstrate I describe an IoT application scenario dive into the Java code and explore the Oracle IoT Cloud Service setup that makes this goal achievable Sample Application Monitoring Industrial Conveyor Belts In this sample IoT application a factory conveyor belt is implemented monitored and controlled using Java and IoTCS Although the belt motor is emulated here the Java code is written with the IoTCS Client Software Library to run on an actual device or on a gateway connecting the device to the cloud Its assumed that the conveyor belt in this scenario has the ability to connect to the internet directly to send Oracle provides a Java based Oracle IoT Cloud Service Client Software Library that facilitates device gateway and enterprise application development in Java
You must have JavaScript enabled to view digital editions.