Remote Client installed on a Raspberry Pi
Before continuing, please make sure both prerequisites are fulfilled! If you need help, please feel free to open a support ticket: https://help.xki.cloud/hc/en-us/requests/new
Once the Raspberry Pi Client has been installed an activated as described in the documentation https://docs.xki.cloud/documentation/install-the-remote-client-on-a-raspberry-pi , the Device 'Raspi' is now active in the Dashboard. Please note that the name of the device depends on your previous setup. In this tutorial we will work with the device name 'Raspi'.
We can list our current devices by opening the Cloud Dashboard and going to Device Management >> All Devices .
Let's add a new Sensor Group.
Click the “Manage Sensors” button in the row of the device 'Raspi' and add a Sensor Group to the device. Add a sensor name you wish to use for the sensor group such as “SenseHATOne” and a sensor type such as “SenseHAT” to allow an easy overview if many sensors are added.
In the Sensor Group List, click “Configure” to manage the Sensor Attributes.
On the right side, click “Add Attribute” to add a new attribute. Fill out the form with the following details:
Name: temp Direction: input Type: double Frequency: 05 sec ( will be measured every 5 sec)
Add a second attribute by clicking the “Add Attribute” button:
Name: letter Direction: output Type: string Frequency: “Event Driven” (will be set automatically, cannot be edited) .
On the Raspberry Pi, click the “Refresh” button in the Remote Client. The attributes added previously in the Cloud Dashboard will now be visible.
Now we will be adding the Python scripts that run on the device to take measurements and forward them to the cloud.
In the “temp” row, click the “Script” button.
Click the “Edit” button. Then, from the “Load Template” dropdown, select the “readTemperature (Sense HAT)” template.
Our custom logic will be therefore as follows: If the temperature is above 38 degrees, show the letter H (for HOT) on the display. If the temperature is below 38 degrees, show the letter C (for COLD) on the display.
Then, click “Validate”.
The script will run once as soon as “Validate” is clicked.
The current reading from the temperature sensor on the senseHAT is around 40.25 celsius.
Then, click “Back to Dashboard”.
The “Script State” for the temp sensor is now Valid.
For the attribute “letter”, the steps will be similar .
Click “Script” and then “Edit”.
Load the template “showLetter (Sense HAT) “
For attributes of type “output”, a test Parameter is required for validation.
Enter the parameter “X”
and click the "Validate" button.
On the Raspberry itself, the SenseHAT will show the letter “X”. The script has been validated and the script ran once for testing purpose.
Click “Save” and return to the Dashboard on the Raspberry Pi.
The configuration on the Raspberry Pi is now finished.
Now that both scripts on the Raspberry Pi are valid, open the Cloud Dashboard and go to Device Management >> All Devices
If you had the page open previously, please click “Refresh” in the overview.
The sensor attributes can now be activated.
For each attribute, click “Activate”.
The “temp” sensor will start reading values as soon as it is activated.
To check the readings, go to Device Management >> All Sensor Groups and in the row "SenseHATOne" click the “History” button.
Click on any data point or select multiple values to get more information about the values.
Now we will add an Event with custom logic.
Go to Event Management >> Add Event in the menu.
Previously, we saw that the average temperature was around 40 Celsius.
Therefore, we will add a custom logic as follows:
If the temperature measured on the raspberry pi “temp” sensor is above 38 degrees, show the letter “H” (for Hot) on the SenseHAT led display (controlled by the sensor attribute “letter”)
Let's set the Event Source as follows:
Then, the Event Action:
Add an event name such as “TempAbove38”.
Click “Add” to save.
Let’s start reacting to events: click “Activate” for the “TempAbove38” event created previously.
Now on the Raspberry Pi Hardware, the letter “H” will be shown.
Great! The event is working.
At this point, the event will be fulfilled as soon as the first value received from the “temp” sensor is above 38 degrees. The event will trigger the value “H” to be sent to the Raspberry Pi’s “letter” sensor which outputs the letter.
However, even if the temperature goes below 38 degrees again, the letter H will still stay. We want to change that behavior by adding a new, additional event.
This logic can be used by combining two separate events.
IF above -> letter H (created previously)
IF below -> letter C (new event)
The two separate events are necessary to make continuous observations and update the output value based on the newest temperature value.
Now we need to add an event that changes the letter on the Raspberry to “C” (for Cold) as soon as the temperature goes below 38 degrees.
Go to “Event Management” in the menu on the left side, click “Add Event”.
Configure the Event Source as follows:
Now the Event Action:
Add the Event Name “TempBelow38” :
And click “Add”.
Activate the Event “TempBelow38” .
We can test the event.
If all steps were carried out correctly, the value “H” will switch to “C” on the Raspberry as soon as cold air is being blown over it.
Great, it worked!
With the combination of the two events, as soon as the temperature value goes above 38 degrees, the displayed letter will switch back again to “H”. We can monitor the values that triggered the events by going to Device Management >> All Sensor Groups, then clicking “History” for the graph or "Overview" for other details.
Please do not forget to share if you liked this tutorial! If you have any questions, please feel free to open a support ticket: https://help.xki.cloud/hc/en-us/requests/new