I try to send sensor data from Turta HAT on Raspberry PI 4 running Raspbian to either cloud or on premise Thinger server. I implemented code for getting data off the HAT in Python. I execute it from C via shell command and get the values, but cannot work out how to send them to the platform. Could anyone provide me an example C code? Thank you in advance.
Best regards
Artur
Hello Krukowa,
Have you deploy the Rb pi Thinger software client? can you provide us your code or anything else in order to help you? just with this little description it is impossible
best
Thanks for responding.
I provided the content of my main() function at the end. I used provided example as a base, adding custom code for communicating with the sensor HAT. I defined globally variables holding sensor values, as as error was flagged otherwise.
The resulting code executes the read once and needs to get re-executed to get new values. Following much appreciated suggestion from Alvaro (Thinger.io) I tried placing the sensor read commands from Step (2) within the thinger statement in Step (3). This resulted in the execution of the sensor read commands automatically every 60 seconds, but after some time the (cloud) platform stopped allowing connections, forcefully closing the socket after every successful authentication. This continued even after returning to the original code and re-executing it.
In both cases, accessing resources defined in Step (3) could not be done from the bucket and the dashboard. After clicking on the device (when connected) in settings of the bucket and dashboard (option to read from device resources) no resources could be found. Hence no data could be shown in the bucket and in the dashboard.
From searching various online docs related to other (supported) devices, my initial assessment is that the PI needs to be able to stream the resources to the platform in order to allow collection of data in the bucket and display in dashboard, but i cannot work out how this could be achieved.
I am out of idea at the moment and every suggestion would be much appreciated.
All the best,
Artur
======================== main() ========================
#include "thinger/thinger.h"
#include <stdio.h>
#define USER_ID "USER"
#define DEVICE_ID "DEVICE"
#define DEVICE_CREDENTIAL "PASSWORD"
float Temperature, Humidity, Pressure, Altitude, Resistance;
int main(int argc, char *argv[])
{
bool Debug;
thinger_device thing(USER_ID, DEVICE_ID, DEVICE_CREDENTIAL);
// Step (1) Execute python script to collect data from Turta HAT
// Data is returned as char[] containing floats separated with spaces
Debug = true;
if (!Debug) {
char command[]="python ../../IoTHAT-Python/IoT_RFSAT/IoT/getTemperature.py";
FILE *fp;
fp = popen(command,"r");
fscanf(fp,"%f %f %f %f %f", &Temperature, &Humidity, &Pressure, &Altitude, &Resistance);
fclose(fp);
}
else {
// Bypassing 'popen()'
Temperature = 23.0;
Humidity = 45.0;
Pressure = 1013.0;
Altitude = 800.0;
Resistance = 14.0;
}
// Step (2) Thing output resource definition (Turta IoT HAT)
thing["RASPI4Turta"] = [](pson& in, pson& out) {
out["Temperature"] = Temperature;
out["Humidity"] = Humidity;
out["Pressure"] = Pressure;
out["Altitude"] = Altitude;
out["Resistance"] = Resistance;
};
// Step (3) Start Thinger
thing.start();
// Step (4) Send property data to platform
thing.handle();
return 0;
}