Send the CPU usage data to SAP IoT Application Enablement

Details

You will learn

You will learn how to use Python script to send sensor data to SAP Cloud Platform. If you get stuck with this you can skip to the next chapter and use someone else’s device to show its sensor data in your app.

Save the file. On a PC save the file to the folder where you installed python.

Step 3: Update the code and run the program

Update deviceid and authtoken variables in the code with IDs you copied in the previous tutorial when creating the thing for your computer.

Run the script with the command.

python computer_iotdevice_cpu.py

If all mentioned prerequisites have been satisfied, then you should see outcome like:

The return code 200 means that the message was received and processed by the IoT service in SAP Cloud Platform.

The return code 202 means that the message was received and queued for processing by the IoT service in SAP Cloud Platform or that the message does not fit the message type requirements.

Codes 4xx and 5xx mean errors.

If you are in a corporate network you might have to put your laptop into another network (e.g. your mobile phone hot spot) to not be hindered by a corporate proxy.

You can press control-c to stop sending data.

Step 4: Check posted values in the Thing Modeler

Go back to the Thing Modeler application from the previous tutorial. Make sure you have the proper package computeriotdevice selected and find your computer on the list of Things.

Go to Measured Values and expand resource_sensors to the cpu_usage. You should see the value (like 22.2 on the screen shot). It is updated only once a minute, so you may need to wait a bit for it to appear and then to change.

You can find corresponding value in the output of the Python’s script as well.

Step 5: Check posted values in the API

The power of SAP IoT Application Enablement is in its rich set of APIs available to build powerful customer applications on top of data from devices.