Code Monkey home page Code Monkey logo

bbb-sht21-multithreaded-http-server's Introduction

Multithreaded HTTP Server for the BeagleBone Black

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.


JSON Structure

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>
}

Env Variables

Both the server's port number and the timeout for the ExpireCache can be adjusted in http-server.properties

Circuit

Setup, Building, and Flashing

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

Running the server

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

Details about the BBB and the OS

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

Yet another project with this damn SHT21 sensor?

Yes, mainly because:

  1. it's cheap and easy to find;
  2. I got to know it quite well;
  3. it's straightforward to connect and use;
  4. 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.

ASIDE: The walrus...

The nice cartoon sketch is offered by Pixabay users under their generous free license.

bbb-sht21-multithreaded-http-server's People

Contributors

dehre avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.