Java Magazine, September/October 2016
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2016 36 internet of things String alertType payload getString format switch alertType case TEMP_ TOO_ LOW_ ALERT_ URN device set FAN_ SPEED_ ATTR OFF break case TEMP_ LOW_ ALERT_ URN device set FAN_ SPEED_ ATTR FAN_ LOW_ SPEED break case TEMP_ MED_ ALERT_ URN device set FAN_ SPEED_ ATTR FAN_ MED_ SPEED break case TEMP_ HIGH_ ALERT_ URN device set FAN_ SPEED_ ATTR FAN_ HIGH_ SPEED break case TEMP_ CRITICAL_ ALERT_ URN shutDownBelt device break With this IoTCS analytics based implementation changing the thresholds that indicate when the cooling fan speed needs to be increased or decreased doesnt require changes to the Java application The analytics can be set and adjusted instead by someone who understands the mechanical properties of the belt motor The alternative would be the much less satisfactory hard coding of values and limits using code such as shown in Listing 4 Listing 4 VirtualDevice device event getVirtualDevice int temp Integer namedValue getValue int coolingFanSpeed device get FAN_ SPEED_ ATTR Determine if action is needed based on new temp if temp 300 Shut things down device set BELT_ SPEED_ ATTR 0 else if temp 250 To receive notification that the monitoring application changed the belt or fan speed the device needs to register for appropriate attribute changes as shown in Listing 5 Listing 5 DeviceModel model device getDeviceModel CONVEYOR_ BELT_ MODEL_ URN VirtualDevice virtualDevice device createVirtualDevice device getEndpointId model virtualDevice setOnChange BELT_ SPEED_ ATTR new VirtualDevice ChangeCallback VirtualDevice public void onChange VirtualDevice ChangeEvent VirtualDevice e onBeltSpeedChange e
You must have JavaScript enabled to view digital editions.