Example server application in Python
This tutorial shows how to set up a simple HTTP server with a database and configure an Efento Gateway to send measurement data to it. In the example, we use Python, Flask, and a PostgreSQL database, but the same concept can easily be implemented in other programming languages or with different databases.
Before you start
Before beginning, ensure that you have installed and configured the following components:
PyCharm or any Python 3 IDE
PostgreSQL database
Efento Gateway and Efento Bluetooth Low Energy loggers
PostgreSQL Database Setup
Create the database
After installing PostgreSQL, you will be prompted to create your first database during setup. By default, it will be created using the following credentials:
DATABASE_HOST = 'localhost'
DATABASE_USER = 'postgres'
DATABASE_PASSWORD = 'your_password'
DATABASE_NAME = 'postgres'You may change these values if needed. Be sure to write down your credentials, as they will be required later.
To check or modify database credentials, open pgAdmin, then navigate to: Object → Properties → General

Create the measurements table
To store measurements sent from the Efento Gateway, you must create a table. In this example, we create a very simple structure containing five columns, all of type text. This design is only for demonstration purposes - your production database should be structured according to your project needs.
You may create the table using pgAdmin’s interface or by running a SQL query.
In pgAdmin, select your database and navigate to: Tools → Query Tool

Insert the query below and click Execute (▶):
CREATE TABLE measurements (
measured_at text,
serial_number text,
low_battery text,
type text,
value text
);Running CREATE TABLE creates a new, initially empty table owned by the user who executed the command.
Python Server
The script you will create sets up a simple HTTP server. Efento Gateway sends data as JSON over REST, and a single message may contain multiple measurements.
When the server receives a request:
It parses the JSON payload.
It saves all measurements to the PostgreSQL database.
It returns HTTP 201 to confirm that the data was successfully processed.
If something goes wrong (e.g., database connection failure), the server returns HTTP 503, and the gateway will automatically retry sending the data later.

Configure Efento Gateway
Ethernet Gateway
Log in to the Efento Gateway web panel. Navigate to: Settings → Server settings
In Connection to Server, select Custom Settings.
Enter the server address (your PC/server IP or domain) in the Server Address field.
Set the Server Port to
5000.Switch TLS OFF for this tutorial.

When TLS is disabled, data is sent unencrypted. For production deployments, always upload your server certificate in the CA Certificate tab and enable encrypted HTTPS communication (TLS - ON).
For development or demonstration purposes you may use a self-signed certificate.
Results
Once the Python script is running, all data sent from the Efento Gateway will be saved in your PostgreSQL database.
To view measurements:
Open pgAdmin 4
Select your database
Go to Tools → Query Tool
Enter and execute:
You will now see all measurements received from the Efento Gateway stored in your database.

Last updated