Package: teleinforeader
TeleInfo ReaderApplication used to read the user data transmitted by Linky meter system (TeleInfo) from Enedis. The application then
provides the data using a socket server to connected clients and also publish it to a local database. The application
runs on a Raspberry Pi Zero and is used only to collect the user data from the meter equipment, the monitoring is done
with another application which connects to the Raspberry Pi and plot all the gathered information (see TeleInfoMonitor
application).Hardware DescriptionMaterialRaspberry Pi Zero
W (Buy one)PiTInfo shield for Linky user
interface (Buy one)Raspberry Pi ZeroBoard version:$cat/proc/device-tree/model
RaspberryPiZeroWRev1.1OS version:$cat/etc/os-releasePRETTY_NAME="Raspbian GNU/Linux 10 (buster)"Serial Link ConfigurationThe acquisition of the user data frame (TeleInfo) is done using the serial link provided by Enedis meter equipment. On
the Raspberry Pi, the reception of the serial data is done using a hardware module called PiTInfo, which is connected on
the GPIOs of the Raspberry Pi board.How to plug the PiTInfo moduleThe PiTInfo module should be plugged on GPIO pins {1..10} like in below picture:For information, the full mapping of GPIOs can be found here:model-zerow-rev1Pin 8 and 10, respectively GPIO 15 and 16 corresponds to the UART, which means where we get the serial data from Linky
meter.Serial Link ConfigurationDisable serial console (in order to use the serial link device for Linky reception):Edit /boot/cmdline.txtRemove line:console=serial0,(...)Disable bluetooth module(so it doesn't use UART):Edit /boot/config.txtAdd line:dtoverlay=pi3-miniuart-btReboot raspberryHow to test serial link$sudostty-F/dev/ttyAMA01200saneevenpparenbcs7-crtscts
$sudochmod666/dev/ttyAMA0
$sudocat/dev/ttyAMA0This should output the data collected from Linky. If nothing returned, then serial link is probably not well configured.How to create database on RaspberryThe application collects the TeleInfo frames and stores them into a local database calledteleinfodb. This database
should be created and configured manually on the Raspberry Pi.Install MariaDB server locally$sudoaptupdate
$sudoaptupgrade
$sudoaptinstallmariadb-server
$sudoaptinstalllibmariadbclient-dev# For python bindings$sudoaptinstalllibmariadb3libmariadb-dev# For python3 mariadb connectorsFor Windows, in order to install mariadb python package, it is required to install:MariaDB's connectors, which can be
foundhereMicrosoft Visual C++ 14.0 or greater:Download Microsoft Build ToolshereSelect custom installation and install "MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest)"Create and configure databaseCreationSecure and configure mysql:$sudomysql_secure_installation# Say yes to all$sudomysql-uroot-pCreate database (replace<user>,<password>and<remote-ip-address>by your own):NB:  is the IP address of the remote client from where it'll try to connect to the Raspberry
Pi.CREATE DATABASE teleinfodb;
CREATE USER '<user>'@'<remote-ip-address>' IDENTIFIED BY '<password>';
GRANT ALL PRIVILEGES ON teleinfodb.* TO '<user>'@'<remote-ip-address>';
FLUSH PRIVILEGES;ConfigurationEnable remote access to database (in order for a third party tool to connect to the database on the Raspberry Pi):In file/etc/mysql/mariadb.conf.d/50-server.cnf, change linebind-address = 127.0.0.1tobind-address = *Restart mysql:$sudoservicemysqlrestartTo connect remotely:$mysql-u<user>-p-h<raspberry-ip-address>Creating the DB schema and tablecreate schema teleinfodb;
use teleinfodb;
create table teleinfoframes
(
    timestamp                    timestamp default current_timestamp() not null on update current_timestamp() comment 'Frame timestamp in format YYYY-MM-DD HH:mm:ss.zzzzzz'
        primary key,
    meter_identifier             char(12)                              not null comment 'Identifier of Enedis telemeter',
    subscription_type            char(4)                               not null comment 'Customer subscription mode',
    subscription_power_in_a      tinyint unsigned                      not null comment 'Power in amperes',
    total_base_index_in_wh       int unsigned                          not null comment 'Total base index in W.h',
    current_pricing_period       char(4)                               not null comment 'Current period if using peak/off-peak pricing',
    instantaneous_intensity_in_a smallint unsigned                     not null comment 'Current intensity in amperes',
    intensity_max_in_a           smallint unsigned                     not null comment 'Maximum intensity in amperes',
    power_consumption_in_va      mediumint unsigned                    not null comment 'Power consumption in V.A',
    peak_off_peak_schedule       char                                  not null comment 'Peak/Off-peak time schedule',
    meter_state_code             char(6)                               null comment 'Error code returned by telemeter'
)
    comment 'Table containing the teleinfo frames' collate = utf8mb4_general_ci;Get size of databaseSELECT table_schema                                            'teleinfodb',
       SUM(data_length + index_length)                         'Size in Bytes',
       ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) 'Size in MiB'
FROM information_schema.tables
WHERE table_schema = 'teleinfodb'
GROUP BY table_schema;How to create TeleInfoReader daemon serviceHere we describe how to configure a Linux service for the application in order to automatically start after the
Raspberry Pi boot sequence.Copyteleinforeader.servicefile into/lib/systemd/system/Use below commands to enable the service:$sudosystemctldaemon-reload# To reload available services$sudosystemctlstartteleinforeader.service
$sudosystemctlstatusteleinforeader.service# To check if it worked$sudosystemctlenableteleinforeader.service# To enable service at boot$sudosystemctldisableteleinforeader.service# To disable the service at bootProgram should run automatically at next rebootProject ManagementHow to publish project on PypiSeepackaging-projectsSeepublishing-to-testpypiTest publish using TestPyPi (from host):Pre-requisites:Create an account on TestPypiCreate file ~/.pypirc containing the PyPi API token$python-mpipinstall--upgradepipsetuptoolswheelbuild
$python-mpipinstall--upgradetwinePublishing:$poetryversionpatch# To increment the version number$poetrybuild# To generate distribution packages for the package$poetryconfigrepositories.test-pypihttps://test.pypi.org/legacy/
$poetrypublish--build-rtest-pypi--username__token__--password<api-token>New version checklistCreate a pre-release tagUpdate project version:$poetryversionpatch
$poetrybuildUpdate Changelog.md fileRun tests locallyCommit new version with commentUpdate version to vX.Y.ZIf CI is passed, create a new pre-release tagvX.Y.Z_pre-releasePush the new tag -> pre-release workflow should be executedIf pre-release passed, then project is available on TestPyPiUpdate application on Raspberry Pi and test it<style>
  h2 {margin-left: 10px}
  h3 {margin-left: 20px}
  h4 {margin-left: 30px}

  body {counter-reset: h1}
  h1 {counter-reset: h2}
  h1:before {counter-increment: h1; content: counter(h1) ". "}
  h2:before {counter-increment: h2; content: counter(h1) "." counter(h2) " "}
</style>