It is one of many examples of different devices supplying environmental sensor data (temperature, humidity) to SAP Cloud Platform (SCP). Here Raspberry Pi 3B device is used with connected Sense Hat. Sensor data will be send synchronously using HTTPS REST protocol.Prepare your Raspberry Pi device
In this project I am using Raspberry Pi 3B with Sense Hat connected to it. Sense Hat library is usually preinstalled on this model.
The code is executed with Python 3 and is using Requests library available from http://docs.python-requests.org/en/master/Make sure you have free developer account in SAP Cloud Platform
If you do not, please follow this tutorial first: https://www.sap.com/developer/tutorials/iot-part6-hcp-services.htmlConfigure virtual device for Raspberry Pi in SCP
Follow the tutorial https://www.sap.com/developer/tutorials/iot-part7-add-device.html and then create a separate virtual device for your raspberry Pi. Instead of "myDevice" you can call it "raspberrypi".
Note down technical ID of this raspberrypi virtual device and its assigned authorization token. You will need them in the next step.Modify the code
Modify attached Python code (at the bottom of this page). You will need to add your Message Type ID, Device ID, etc. The lines in particular you will need to modify are the following:
You should modify:
accountOwnerline to add your own SAP Cloud Platform Account User ID which starts with either an
msgtypeidis the ID of the message type you created, and not the name of the message type.
deviceidis the ID of the device you created, not to be confused with the
authtokenline contains the token of the device (not the device type!). You received it in the pop-up window after creating your device. But if missed it, then regenerate this token from Device screen once again.
Save the file as scpiot_neo_rpisensehat_http.pyRun the code and check the results
Once you have saved your file run the following command:
If everything is correct, then you should see output similar to this one. The loop reads and posts values every f and the green arrow flying through HAT's LEDs with every successful post to the SAP Cloud Platform.
You can preview received data in the cloud in Message Management Service Cockpit. There is the OData API link to now use this data in your applications!
Press Ctrl+C to stop the execution of the program.
Have a good weather!