Upload the Sample Device Models

To complete the Oracle Internet of Things Cloud Service samples, the humidity and temperature sensor device models must be uploaded to your Oracle Internet of Things Cloud Service instance.

The humidity sensor device model sends a humidity reading every 5 seconds. When the maximum threshold is set, the maximum threshold value and the humidity level are included in subsequent data messages. When the default maximum humidity threshold of 60% is reached or exceeded, an alert is sent.

The temperature sensor device model sends a temperature reading every 5 seconds. The minimum and maximum temperature values are included with the outgoing data message, when the device is turned on, and whenever a value changes. When the maximum or minimum temperature thresholds are set, the maximum and minimum threshold values and the current temperature are included in subsequent data messages. When the minimum or maximum temperature thresholds are reached or exceeded, a tooCold or tooHot alert is sent. Optionally, the threshold values can be included in the alert message (the default is NO). The default thresholds for the minimum and maximum temperature are 0 and 65 degrees.

When a REST call is invoked, the minimum and maximum temperature values are reset to the current temperature. When a device is turned off, data and alert messages are not sent until it is turned on.

  1. Open a text editor.
  2. Copy and paste this text into the text editor for the humidity sensor device model:
    {
        "urn": "urn:com:oracle:iot:device:humidity_sensor",
        "name": "Humidity Sensor",
        "description": "Device model for sensor that measures humidity.",
        "attributes": [
            {
                "name": "humidity",
                "description": "Measures humidity between 0% and 100%",
                "type": "INTEGER",
                "range": "0,100"
            },
            {
                "name": "maxThreshold",
                "description": "Maximum humidity threshold",
                "type": "INTEGER",
                "range": "60,100",
                "writable": true,
                "defaultValue":80
            }
        ],
        "formats": [
            {
                "urn": "urn:com:oracle:iot:device:humidity_sensor:too_humid",
                "name": "tooHumidAlert",
                "description": "Sample alert when humidity reaches the maximum humidity threshold",
                "type": "ALERT",
                "value": {
                    "fields": [
                        {
                            "name": "humidity",
                            "type": "INTEGER",
                            "optional": false
                        }
                    ]
                }
            }
        ]
    }
  3. Save the file as HumiditySensor.json and then close the text editor.
  4. Open a command prompt and then run this curl command to upload the humidity sensor device model to your Oracle Internet of Things Cloud Service instance:
    curl -k -u "<username>:<password>" https://<your_Oracle_IoT_CloudService_instance>:<instance_port_number>/iot/api/v2/deviceModels -X POST -d @HumiditySensor.json -H "Content-Type:application/json" -H "Accept:application/json"
    Replace <username>, <password>, and <your_Oracle_IoT_CloudService instance>, and <instance_port_number> variables with the values for your environment. For example:
    curl -k -u "joeuser@xyz.com:password" https://myiotserver.com:7105/iot/api/v2/deviceModels -X POST -d @HumiditySensor.json -H "Content-Type:application/json" -H "Accept:application/json"
  5. Open a text editor.
  6. Copy and then paste this text into the text editor for the temperature sensor device model:
    {
        "urn": "urn:com:oracle:iot:device:temperature_sensor",
        "name": "Temperature Sensor",
        "description": "Device model for sensor that measures temperature.",
        "attributes": [
            {
                "name": "temp",
                "description": "Measures temperature value between -20 and +80 Cel",
                "range": "-20,80",
                "type": "NUMBER"
            },
            {
                "name": "unit",
                "description": "Measurement unit, such as Cel for Celsius.",
                "type": "STRING",
                "defaultValue":"C"
            },
            {
                "name": "minTemp",
                "alias": "minimumTemperature",
                "description": "The minimum value measured by the sensor since power ON or reset",
                "type": "NUMBER"
            },
            {
                "name": "maxTemp",
                "alias": "maximumTemperature",
                "description": "The maximum value measured by the sensor since power ON or reset",
                "type": "NUMBER"
            },
            {
                "name": "minThreshold",
                "description": "The minimum temperature threshold",
                "type": "INTEGER",
                "range": "-20,0",
                "writable": true,
                "defaultValue":0
            },
            {
                "name": "maxThreshold",
                "description": "The maximum temperature threshold",
                "type": "INTEGER",
                "range": "65,80",
                "writable": true,
                "defaultValue":70
            },
            {
                "name": "startTime",
                "description": "The time (measured in EPOCH) at which the system was powered ON or reset",
                "type": "DATETIME"
            }
        ],
        "actions": [
            {
                "name": "reset",
                "description": "Reset the minimum and maximum measured values to current value"
            },
            {
                "name": "power",
                "description": "Turns system ON or OFF",
                "argType": "BOOLEAN"
            }
        ],
        "formats": [
            {
                "urn": "urn:com:oracle:iot:device:temperature_sensor:too_hot",
                "name": "tooHotAlert",
                "description": "Temperature has reached the maximum temperature threshold",
                "type": "ALERT",
                "value": {
                    "fields": [
                        {
                            "name": "temp",
                            "type": "NUMBER",
                            "optional": false
                        },
                        {
                            "name": "unit",
                            "type": "STRING",
                            "optional": false
                        },
                        {
                            "name": "maxThreshold",
                            "type": "NUMBER",
                            "optional": true
                        }
                    ]
                }
            },
            {
                "urn": "urn:com:oracle:iot:device:temperature_sensor:too_cold",
                "name": "tooColdAlert",
                "description": "Temperature has reached the minimum temperature threshold",
                "type": "ALERT",
                "value": {
                    "fields": [
                        {
                            "name": "temp",
                            "type": "NUMBER",
                            "optional": false
                        },
                        {
                            "name": "unit",
                            "type": "STRING",
                            "optional": false
                        },
                        {
                            "name": "minThreshold",
                            "type": "NUMBER",
                            "optional": true
                        }
                    ]
                }
            }
        ]
    }
  7. Save the file as TemperatureSensor.json and then close the text editor.
  8. Open a command prompt and then run this curl command to upload the temperature sensor device model to your Oracle Internet of Things Cloud Service:
    curl -k -u "<username>:<password>" https://<your_Oracle_IoT_CloudService_instance>:<instance_port_number>/iot/api/v2/deviceModels -X POST -d @TemperatureSensor.json -H "Content-Type:application/json" -H "Accept:application/json"
    Replace the <username>, <password>, and <your_Oracle_IoT_CloudService instance>, and <instance_port_number> variables with the values for your environment. For example:
    curl -k -u "joeuser@abc.com:password" https://myiotserver.com:7105/iot/api/v2/deviceModels -X POST -d @TemperatureSensor.json -H "Content-Type:application/json" -H "Accept:application/json"