A multithreaded HTTP server, running on the BeagleBone Black, that serves the current temperature and humidity to its clients in JSON format.
The server is built using the Poco C++ Libraries.
Data from the SHT21 temperature and humidity sensor is read through sysfs
using the pre-built LKM.
An ExpireCache
,
whose access is protected by a mutex,
prevents simultaneous http requests from concurrently accessing the sensor.
Last but not least, the server can be connected to a fat-client Qt desktop application, whose job is to retrieve the information and display it nicely to the user.
Data is served at /
.
Any other endpoint will serve a 404 response.
Here's how the JSON looks like if everything went fine:
{
"version": <number>,
"data": {
"temperature": <number>,
"humidity": <number>
}
}
For an error:
{
"version": <number>,
"error": <string>
}
Both the server's port number and the timeout for the ExpireCache
can be adjusted in http-server.properties
This document goes in detail about how I set up my machine for cross-compilation.
The project uses a global CMake file with different targets.
Dependencies are managed through Conan.
The file profile_crossbuild
tells the latter which platform we're generating binary files for.
To build:
#
# On the VM
#
mkdir build
cd build
conan install .. --build=missing --profile=../profile_crossbuild
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Build
cmake --build .
Finally sftp
the executable and the environment variables to the board:
#
# On the VM
#
sftp-bbb
> put build/bin/http-server
> put http-server.properties
The program expects the SHT21 LKM to be loaded before starting:
#
# On the BeagleBone
#
# get root permissions
sudo su
# verify that the sht21 kernel module exists
find "/lib/modules/$(uname -r)/kernel/drivers/hwmon" -name sht21.ko.xz
# load the module
modprobe sht21
# let the kernel know to which bus the sensor is connected
echo sht21 0x40 > /sys/bus/i2c/devices/i2c-2/new_device
# no need for root permissions anymore
exit
# start the server
./http-server
Processor: AM3358 ARM Cortex-A8
OS: Debian 10.3 Buster IoT (without graphical desktop)
Kernel release: 4.19.94-ti-r42
GCC version: 8.3.0
Link to the official docs here
Yes, mainly because:
- it's cheap and easy to find;
- I got to know it quite well;
- it's straightforward to connect and use;
- the pre-built LKM abstracts over many details.
Focus of this project was the combination of a remote sensor running on Linux with a fat-client GUI app.
Using the SHT21 has simply been the quickest way to get it done.
The nice cartoon sketch is offered by Pixabay users under their generous free license.