-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
3,745 additions
and
1,797 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.DS_Store | ||
.git/ | ||
.gitattributes | ||
.gitignore | ||
.pio/ | ||
.vscode | ||
README.md | ||
build/ | ||
buildall.sh | ||
cli.py | ||
data/ | ||
data_src/ | ||
docs/ | ||
lib/ | ||
platformio.ini | ||
prep_data_folder.py | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
|
||
project(tic) | ||
|
||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
set(CMAKE_CXX_STANDARD 14) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
||
option(DUMP_VARS "dump CMake variables" OFF) | ||
|
||
|
||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) | ||
find_package(gtest REQUIRED) | ||
else() | ||
set(GTEST_BOTH_LIBRARIES gtest gtest_main) | ||
endif() | ||
|
||
|
||
# Code Coverage Configuration | ||
add_library(coverage_config INTERFACE) | ||
|
||
option(CODE_COVERAGE "Enable coverage reporting" OFF) | ||
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") | ||
# Add required flags (GCC & LLVM/Clang) | ||
target_compile_options(coverage_config INTERFACE | ||
-O0 # no optimization | ||
-g # generate debug info | ||
--coverage # sets all required flags | ||
) | ||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) | ||
target_link_options(coverage_config INTERFACE --coverage) | ||
else() | ||
target_link_libraries(coverage_config INTERFACE --coverage) | ||
endif() | ||
endif() | ||
|
||
|
||
add_executable(tic | ||
test/test_teleinfo.cpp | ||
test/test_config.cpp | ||
test/test_tic.cpp | ||
test/test_sys.cpp | ||
test/test_filesystem.cpp | ||
test/test_support.cpp | ||
test/mock_time.cpp | ||
test/mock.cpp | ||
test/mock_support.cpp) | ||
|
||
target_include_directories(tic | ||
PRIVATE ${GTEST_INCLUDE_DIRS} | ||
PRIVATE src | ||
PRIVATE test/support) | ||
|
||
target_compile_options(tic PUBLIC -Wall -pedantic) | ||
|
||
if(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l) | ||
# https://github.com/nlohmann/json/issues/658 | ||
target_compile_options(tic PUBLIC -Wno-psabi) | ||
endif() | ||
|
||
target_link_libraries(tic | ||
PRIVATE ${GTEST_BOTH_LIBRARIES} pthread) | ||
|
||
target_link_libraries(tic PUBLIC coverage_config) | ||
|
||
|
||
enable_testing() | ||
add_test(NAME tic_test COMMAND tic) | ||
|
||
|
||
function(dump_cmake_variables) | ||
get_cmake_property(_variableNames VARIABLES) | ||
list(SORT _variableNames) | ||
foreach (_variableName ${_variableNames}) | ||
message(STATUS "${_variableName}=${${_variableName}}") | ||
endforeach() | ||
endfunction() | ||
if(DUMP_VARS) | ||
dump_cmake_variables() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM alpine:3.10 | ||
|
||
RUN apk add --no-cache gcc g++ gdb make cmake musl-dev gtest-dev vim wget curl bash perl \ | ||
&& wget -P /usr/local/include/nlohmann/ https://github.com/nlohmann/json/releases/download/v3.7.3/json.hpp | ||
|
||
RUN curl -slkL https://github.com/linux-test-project/lcov/releases/download/v1.14/lcov-1.14.tar.gz | tar -C /tmp -xzf - \ | ||
&& cd /tmp/lcov-1.14 \ | ||
&& make install \ | ||
&& cd / \ | ||
&& rm -rf /tmp/lcov-1.14 | ||
|
||
VOLUME /tic | ||
|
||
VOLUME /coverage | ||
|
||
WORKDIR /build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# WifInfo | ||
|
||
WifInfo est un module de consignation de la téléinformation des compteurs électriques avec serveur web embarqué. | ||
|
||
## Introduction | ||
|
||
Ce projet est la fusion de développements réalisés en vue du remplacement d'un [eco-devices](http://gce-electronics.com/fr/111-eco-devices) sur base de [ESP-01](https://fr.wikipedia.org/wiki/ESP8266) et de la une réécriture quasi complète - sauf la partie interface web - du projet homonyme de C-H. Hallard [LibTeleinfo](https://github.com/hallard/LibTeleinfo) avec des modifications notamment de [olileger](https://github.com/olileger/LibTeleinfo) et [Doume](https://github.com/Doume/LibTeleinfo). | ||
|
||
* Meilleure séparation des fonctions dans des fichiers sources différents | ||
* Homogénéisation du nommage, nettoyage du code source | ||
* Minimisation des allocations mémoire (nouvelle librairie teleinfo) | ||
* Server-sent event ([SSE](https://fr.wikipedia.org/wiki/Server-sent_events)) pour les mises à jour des index | ||
* Notifications HTTP sur changements HC/HP et dépasssement de seuils ou ADPS | ||
* Client en liaison série pour mise au point avec [SimpleCLI](https://github.com/spacehuhn/SimpleCLI) | ||
* Tests sur PC avec [Google Test](https://github.com/google/googletest) et couverture avec [lcov](http://ltp.sourceforge.net/coverage/lcov.php) | ||
* Client Python de simulation [cli.py](./cli.py) sur base de `miniterm.py` de [pySerial](https://pyserial.readthedocs.io/) | ||
* Compression et minimisation de la partie web avant écriture du filesystem (`data_src` ⇒ `data` au moment du build) | ||
* Serveur Python [Flask](https://www.palletsprojects.com/p/flask/) pour développement de la partie web | ||
* Utilisation de [PlatformIO](https://platformio.org) comme environnement de développement | ||
|
||
## Documentation | ||
|
||
Documentation ERDF sur la [téléinformation client](https://www.enedis.fr/sites/default/files/Enedis-NOI-CPT_02E.pdf) pour les compteurs électroniques et pour les compteurs [Linky](https://www.enedis.fr/sites/default/files/Enedis-NOI-CPT_54E.pdf). | ||
|
||
Module [PiTInfo](https://hallard.me/pitinfov12/) et explications pourquoi le montage avec uniquement optocoupleur et résistances ne suffit pas avec un esp8266. | ||
|
||
## Compilation | ||
|
||
Le projet est prévu pour PlatformIO sous macOS ou Linux, en conjonction avec [Visual Studio Code](https://code.visualstudio.com) et son l'extension [PlatformIO](https://marketplace.visualstudio.com/items?itemName=platformio.platformio-ide). | ||
L'IDE d'Arduino peut également être utilisé. | ||
|
||
La page HTML est compressée avec [html-minifier](https://github.com/kangax/html-minifier) et gzip. | ||
|
||
### PlatformtIO | ||
|
||
```bash | ||
platformio run -t uploadfs | ||
platformio run -t upload | ||
``` | ||
|
||
### IDE Arduino | ||
|
||
Cf. les nombreux tutos pour l'utilisation d'esp8266-arduino et l'upload de SPIFFS. | ||
|
||
Le répertoire `data` est préparé à l'aide du script suivant (nécessite python3, gzip, html-minifier) : | ||
|
||
```bash | ||
python3 prep_data_folder.py | ||
``` | ||
|
||
## Client de test/mise au point | ||
|
||
```bash | ||
pip3 install pySerial | ||
python3 cli.py [port] | ||
``` | ||
|
||
Pour activer le mode commande, il faut taper <TAB> puis la commande (ls, config, time, esp, ...). | ||
|
||
* `Ctrl-T` envoie une trame de téléinformation | ||
* `Ctrl-Y` bascule l'envoi automatique de trames | ||
* `Ctrl-P` bascule entre heures creuses et heures pleines | ||
* `Ctrl-C` sort du client | ||
|
||
## Tests unitaires | ||
|
||
Les tests unitaires et la couverture sont faites dans un conteneur Docker. | ||
|
||
Néanmoins, les logiciels et librairies suivants sont nécessaires: | ||
* [CMake](https://cmake.org) | ||
* [Google Test](https://github.com/google/googletest) | ||
* [nlohmann json](https://github.com/nlohmann/json) | ||
* [lcov](http://ltp.sourceforge.net/coverage/lcov.php) | ||
|
||
Préparation de l'image: | ||
```bash | ||
docker build -t tic . | ||
``` | ||
|
||
Lancement des tests et couverture: | ||
```bash | ||
docker run --rm -ti -v $(pwd):/tic:ro -v $(pwd)/coverage:/coverage tic /tic/runtest.sh | ||
``` | ||
|
||
La couverture est disponible dans `./coverage/index.html` | ||
|
||
|
||
## Développement web | ||
|
||
### Avec module simulé (aucun esp8266 requis) | ||
|
||
```bash | ||
pip3 install flask flask_cors | ||
python3 tools/srv.py | ||
``` | ||
L'interface est alors disponible à cette adresse: [http://localhost:5000/](http://localhost:5000/). | ||
|
||
### Avec module et partie web sur PC | ||
|
||
[nginx](http://nginx.org/en/) est utilisé en reverse proxy pour accéder aux pages dynamiques du module. | ||
|
||
```bash | ||
tools/httpdev.sh [adresse IP du module] | ||
``` | ||
L'interface alors sera disponible à cette adresse: [http://localhost:5001/](http://localhost:5001/), avec les requêtes dynamiques redirigées vers le module (qui doit donc être opérationnel et joignable). | ||
|
||
## Montage | ||
|
||
Le montage final utilise un ESP-01S avec le module [PiTInfo](http://hallard.me/pitinfov12-light/) - à acheter sur [tindie](https://www.tindie.com/products/Hallard/pitinfo/). L'alimentation est assurée par module USB. | ||
|
||
![teleinfo](docs/teleinfo.jpg) | ||
|
||
## Licence | ||
|
||
Compte-tenu de la diversité d'origine des sources, ce travail est publié avec la licence de [WifInfo](https://github.com/hallard/LibTeleinfo/tree/master/examples/Wifinfo). | ||
|
||
<div align="center"> | ||
|
||
[![Licence Creative Commons](https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png)](http://creativecommons.org/licenses/by-nc-sa/4.0/) | ||
|
||
</div> | ||
|
||
Ce(tte) œuvre est mise à disposition selon les termes de la [Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 4.0 International](http://creativecommons.org/licenses/by-nc-sa/4.0/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
#!/bin/sh | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
platformio run -t size | ||
platformio run -t buildfs | ||
|
||
mkdir -p test/build | ||
cd test/build | ||
cmake .. -DCMAKE_BUILD_TYPE=Debug | ||
make | ||
docker buildx build -t test . | ||
docker run --rm -ti \ | ||
-v $(pwd):/tic:ro \ | ||
-v $(pwd)/build:/build \ | ||
-v $(pwd)/coverage:/coverage \ | ||
test \ | ||
/tic/runtest.sh |
Oops, something went wrong.