Init v1.0
This commit is contained in:
@@ -1,92 +1,249 @@
|
||||
# Banc-ECS-Diehl
|
||||
# Banc ECS Diehl
|
||||
|
||||
Banc d'enregistrement des mesures faites avec un "[Compteur Energie Thermique DIEHL SHARKY 774 compact](https://www.compteur-energie.com/compteur-energie-thermique-clim-sharky-775.htm)" (Diehl - SHARKY 774 BI)
|
||||
|
||||
Ce banc est plus qu'inspiré du [banc-tempsurf-ds18b20](https://gitlab.lowtech.fr/pdm/projets/labo/pub/banc-tempsurf-ds18b20/) lui même plus qu'inspiré de [PvMonit](https://pvmonit.zici.fr/)
|
||||
|
||||
## Getting started
|
||||
* [Mode d'emploi](doc/Mode d'emploi banc ECS.pdf) pour ce banc ECS Diehl
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
## Pré-requis
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
* Un raspberry pi (0 ici mais un 2, 3, 4 fonctionnera) avec :
|
||||
* [Raspbian](https://raspberry-pi.fr/telechargements/) installé
|
||||
* Interface 1 Wire active (raspi-config) pour les sondes ds18b20
|
||||
* Interface SPI active (raspi-config) pour les amplificateurs thermocouples
|
||||
* [Compteur Energie Thermique DIEHL SHARKY 774 compact](https://www.compteur-energie.com/compteur-energie-thermique-clim-sharky-775.htm)"
|
||||
* [M-Bus Master Hat](https://www.packom.net/m-bus-master-hat/) (pour la communication entre le raspberry pi et le compteur d'énergie)
|
||||
|
||||
## Add your files
|
||||
## Carte SD prêt à l'emploi
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||
Une carte SD prêt à l'emploi [contactez nous](https://www.afpma.pro/contacts/).
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://gitlab.afpma.pro/tech/labomobile/banc-ecs-diehl.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
La notice pour l'usage de cette carte SD est dans le fichier **[doc/Deployer_image_carte_SD.md](doc/Deployer_image_carte_SD.md)**
|
||||
|
||||
## Sinon : installation
|
||||
|
||||
### Dépendance
|
||||
|
||||
```bash
|
||||
apt install python3 python3-pip
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
Lib Python ds18b20 : https://github.com/rgbkrk/ds18b20
|
||||
|
||||
- [ ] [Set up project integrations](https://gitlab.afpma.pro/tech/labomobile/banc-ecs-diehl/-/settings/integrations)
|
||||
```bash
|
||||
pip3 install ds18b20 ConfigParser
|
||||
```
|
||||
|
||||
## Collaborate with your team
|
||||
Lib Python pour thermocouple MAX31855 : https://github.com/adafruit/Adafruit_CircuitPython_MAX31855
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||
```bash
|
||||
pip3 install adafruit-circuitpython-max31855
|
||||
```
|
||||
|
||||
## Test and Deploy
|
||||
### Récupération des sources
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
Récupération du code source :
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
```bash
|
||||
cd /opt/
|
||||
git clone https://gitlab.lowtech.fr/pdm/projets/labo/bancs-acqusition/banc-mesure-temp-surface-DS18B20.git
|
||||
cd banc-mesure-temp-surface-DS18B20
|
||||
```
|
||||
|
||||
***
|
||||
### Installation de l'interface web (option)
|
||||
|
||||
# Editing this README
|
||||
Option pratique pour les "non geek"
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||

|
||||
|
||||
## Suggestions for a good README
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
Rendre le fichier de configuration accessible en écriture pour l'interface web :
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
```bash
|
||||
chmod 777 /opt/banc/config.ini
|
||||
chmod 777 /opt/banc/releves -R
|
||||
# ou
|
||||
chown www-data:www-data /opt/banc/config.ini
|
||||
chown www-data:www-data /opt/banc/releves -R
|
||||
```
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
Installation des dépendances :
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
```
|
||||
aptitude install lighttpd php-cgi php-xml php7.3-json
|
||||
lighttpd-enable-mod fastcgi
|
||||
lighttpd-enable-mod fastcgi-php
|
||||
```
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
On change la configuration de lighttpd :
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
```
|
||||
service lighttpd stop
|
||||
```
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
Configuration du serveur http, avec le fichier /etc/lighttpd/lighttpd.conf :
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
```diff
|
||||
- server.document-root = "/var/www/html/"
|
||||
+ server.document-root = "/opt/banc/"
|
||||
```
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
On applique la configuration :
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
```
|
||||
service lighttpd start
|
||||
```
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
Télécharger la dernière version de [ttyd](https://github.com/tsl0922/ttyd/releases) (pour un raspberry pi c'est la version ARM) pour la placer dans le /opt :
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
```bash
|
||||
wget -O /opt/ttyd https://github.com/tsl0922/ttyd/releases/download/1.7.2/ttyd.arm
|
||||
chmod +x /opt/ttyd
|
||||
```
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
Dans le fichier rc.local il faut ensuite ajouter le ttyd au démarrage du raspberry pi. Ajouter ceci avant "exit 0" :
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
```
|
||||
/opt/ttyd -p 8022 /opt/banc/start-menu.sh > /tmp/ttyd.log 2>/tmp/ttyd-error.log &
|
||||
```
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
C'est prêt, rdv sur http://IPdeVotrePi ou http://pi.local
|
||||
|
||||
## Configuration
|
||||
|
||||
Toute la configuration se trouve dans le fichier config.ini
|
||||
|
||||
### Général
|
||||
|
||||
Configuration général dans le fichier config.ini :
|
||||
|
||||
```ini
|
||||
[general]
|
||||
# Répertoire de stockage des relevés (en csv)
|
||||
csv_dir="releves"
|
||||
# Temps entre 2 mesures (en minute)
|
||||
delai=5
|
||||
# Nombre de messure
|
||||
nb_mesure=500
|
||||
# Note : la durée du test est donc = delai * nb_mesure
|
||||
```
|
||||
|
||||
## Test des sondes
|
||||
|
||||
Des scripts de tests se trouve dans le répertoire "tools" vous pouvez lancer :
|
||||
|
||||
* ds18b20-list.sh : pour lister les sondes avec leur ID + affichage de la température
|
||||
* test-max31855.py : pour tester la présence de thermocouple (attention il faut éditer le script et le code n'est plus identique à celui de l’acquisition, a prendre donc avec de la distance...)
|
||||
|
||||
## Lancement de l’acquisition
|
||||
|
||||
### Depuis l'interface web
|
||||
|
||||
/!\ il y a certaine difficulté sur Firefox, vous pouvez essayer sur Chromium ou Chrome si la mention "press < to reconnect" persiste...
|
||||
|
||||
Choix 1
|
||||
|
||||
Pour stopper : CTRL + C
|
||||
|
||||
### En ligne de commande
|
||||
|
||||
Pour lancer l’acquisition :
|
||||
|
||||
```
|
||||
python3 aquisition.py
|
||||
```
|
||||
|
||||
On peut stopper l’acquisition par un CTRL + C au besoin
|
||||
|
||||
Les résultats (sauf modification) sont à récupérer dans le dossier "releves"
|
||||
|
||||
Exemple :
|
||||
|
||||
```
|
||||
#############################################################################
|
||||
######## Banc de test / Aquisition des mesures
|
||||
#############################################################################
|
||||
|
||||
La configuration (config.ini) détermine :
|
||||
* que le fichier csv de relevé est : releves/2021-02-15_11-26.csv
|
||||
* qu'il y aura 500 messures
|
||||
* que l'interval entre 2 mesures sera de 5 minutes
|
||||
Le script d'aquisition est donc partie pour tourner 41.666666666666664 heures
|
||||
|
||||
Messure N° 0
|
||||
"tparoi 1" = 20.1
|
||||
t1 = 31.937
|
||||
t2 = 29.312
|
||||
"Vitre" = 33.0
|
||||
t4 = 30.187
|
||||
t5 = 27.375
|
||||
t6 = 30.125
|
||||
t7 = 32.0
|
||||
t8 = 29.562
|
||||
t9 = 30.187
|
||||
t10 = 31.312
|
||||
t11 = 29.375
|
||||
t12 = 28.875
|
||||
t13 = 30.187
|
||||
t14 = 27.062
|
||||
t15 = 30.0
|
||||
t16 = 31.375
|
||||
t17 = 30.375
|
||||
t18 = 31.125
|
||||
t19 = 28.562
|
||||
t20 = 29.687
|
||||
"Plancha" = 33.75
|
||||
"Foyer" = 45.75
|
||||
"Evac" = 32.75
|
||||
"tparoi 2" = 19.9
|
||||
"tair" = 20.4
|
||||
Fin de la mesure, on patiente 300 s
|
||||
-
|
||||
```
|
||||
|
||||
Vous devriez obtenir un fichier CSV de ce type :
|
||||
|
||||
> "temps_min",0,5
|
||||
>
|
||||
> "temps_sec",0,319
|
||||
>
|
||||
> "tparoi 1",20.1,20.1
|
||||
>
|
||||
> "t1",31.937,31.812
|
||||
>
|
||||
> "t2",29.312,29.187
|
||||
>
|
||||
> "t3",33.0,33.0
|
||||
>
|
||||
> "t4",30.187,30.062
|
||||
>
|
||||
> "t5",27.375,27.25
|
||||
>
|
||||
> "t6",30.125,30.062
|
||||
>
|
||||
> "t7",32.0,31.937
|
||||
>
|
||||
> "t8",29.562,29.437
|
||||
>
|
||||
> "t9",30.187,30.125
|
||||
>
|
||||
> "t10",31.312,31.187
|
||||
>
|
||||
> "t11",29.375,29.312
|
||||
>
|
||||
> "t12",28.875,28.812
|
||||
>
|
||||
> "t13",30.187,30.062
|
||||
>
|
||||
> ...
|
||||
|
||||
## Auteur
|
||||
|
||||
Association [AFPMA](https://www.afpma.pro/)
|
||||
|
||||
* [David Mercereau](https://david.mercereau.info/contact/) pour la partie développement logiciel
|
||||
* Damien Lehman pour la conception, test, documentation
|
||||
|
||||
## Licence AGPL v3
|
||||
|
||||
https://www.gnu.org/licenses/agpl-3.0.fr.htmlgnouse
|
||||
Executable
+117
@@ -0,0 +1,117 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Pour lire le .ini
|
||||
import configparser
|
||||
import json
|
||||
import subprocess
|
||||
# Pour faire des sleep
|
||||
import time
|
||||
# Pour la date
|
||||
from datetime import datetime
|
||||
# Pour le debug
|
||||
import pprint
|
||||
import csv
|
||||
import os.path
|
||||
import random
|
||||
|
||||
# ~ import RPi.GPIO as GPIO
|
||||
# ~ GPIO.setmode(GPIO.BCM)
|
||||
# ~ gpio_number = 25
|
||||
# ~ GPIO.setup(gpio_number, GPIO.OUT)
|
||||
# ~ print("GPIO no " + str(gpio_number) + ": " + str(GPIO.input(gpio_number)))
|
||||
|
||||
# On charge le config.ini
|
||||
config = configparser.RawConfigParser() # On créé un nouvel objet "config"
|
||||
config.read('config.ini') # On lit le fichier de paramètres
|
||||
|
||||
csvfile=config.get('general', 'csv_dir').strip('"') + '/' + time.strftime ('%Y-%m-%d_%H-%M') + '.csv'
|
||||
if (os.path.exists(csvfile)) :
|
||||
csvfile=config.get('general', 'csv_dir').strip('"') + '/' + time.strftime ('%Y-%m-%d_%H-%M') + str(random.randint(1, 100)) + '.csv'
|
||||
|
||||
print('#############################################################################')
|
||||
print('######## Banc AFPMA ECS / Aquisition des mesures')
|
||||
print('#############################################################################')
|
||||
print()
|
||||
print('La configuration (config.ini) détermine : ')
|
||||
print(' * que le fichier csv de relevé est : ',csvfile)
|
||||
print(' * que l\'interval entre 2 mesures sera de ', int(config.get('general', 'delai')), 'secondes')
|
||||
print()
|
||||
|
||||
# Init colonne CSV
|
||||
with open(csvfile, 'w', newline='') as fichier:
|
||||
# on déclare un objet writer
|
||||
ecrivain = csv.writer(fichier)
|
||||
# écrire une ligne dans le fichier:
|
||||
ecrivain.writerow(['T', 'DATE', 'ENERGY_WH', 'VOLUME_FLOW', 'POWER_W', 'FLOW_TEMPERATURE', 'RETURN_TEMPERATURE'])
|
||||
|
||||
fin = False
|
||||
now = datetime.now()
|
||||
chronoDepart=datetime.timestamp(now)
|
||||
prochainReleve=chronoDepart
|
||||
|
||||
while fin == False:
|
||||
now = datetime.now()
|
||||
nowTimestamp=datetime.timestamp(now)
|
||||
if (nowTimestamp >= prochainReleve):
|
||||
print("Relevé " + str(now))
|
||||
prochainReleve=nowTimestamp+float(config.get('general', 'delai'))
|
||||
|
||||
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
|
||||
temps_sec=round(datetime.timestamp(now)-chronoDepart, 0)
|
||||
data = [temps_sec, dt_string]
|
||||
print('T='+str(temps_sec), end=" ")
|
||||
print('DATE='+str(dt_string), end=" ")
|
||||
## Récupérer les données :
|
||||
result = subprocess.Popen(["/usr/bin/python3", "/opt/banc/mbus-serial-request-data.py", "/dev/ttyAMA0"], stdout=subprocess.PIPE)
|
||||
result_request_data = result.communicate()[0]
|
||||
return_code = result.returncode
|
||||
|
||||
try:
|
||||
#convert string to object
|
||||
request_data_object = json.loads(result_request_data)
|
||||
except ValueError:
|
||||
return_code = 255
|
||||
|
||||
if (return_code == 0):
|
||||
## Parse des données
|
||||
for records in request_data_object['body']['records']:
|
||||
if (records['type'] == 'VIFUnit.ENERGY_WH'):
|
||||
try:
|
||||
if (records['device'] != None):
|
||||
# On ne récupère pas si le device est rensigné
|
||||
pass
|
||||
except KeyError as ke:
|
||||
print('ENERGY_WH='+str(round(records['value'], 2)), end=" ")
|
||||
data.append(round(records['value'], 2))
|
||||
elif (records['type'] == 'VIFUnit.VOLUME_FLOW'):
|
||||
print('VOLUME_FLOW='+str(round(records['value'], 2)), end=" ")
|
||||
data.append(round(records['value'], 2))
|
||||
elif (records['type'] == 'VIFUnit.POWER_W'):
|
||||
print('POWER_W='+str(round(records['value'], 2)), end=" ")
|
||||
data.append(round(records['value'], 2))
|
||||
elif (records['type'] == 'VIFUnit.FLOW_TEMPERATURE'):
|
||||
print('FLOW_TEMPERATURE='+str(round(records['value'], 2)), end=" ")
|
||||
data.append(round(records['value'], 2))
|
||||
elif (records['type'] == 'VIFUnit.RETURN_TEMPERATURE'):
|
||||
print('RETURN_TEMPERATURE='+str(round(records['value'], 2)), end=" ")
|
||||
data.append(round(records['value'], 2))
|
||||
print("");
|
||||
else:
|
||||
print('Erreur : aucune communicatoin avec le compteur d\'énergie')
|
||||
data.append('Erreur')
|
||||
data.append('Erreur')
|
||||
data.append('Erreur')
|
||||
data.append('Erreur')
|
||||
data.append('Erreur')
|
||||
# ouverture en écriture (w, première lettre de write) d'un fichier
|
||||
with open(csvfile, 'a', newline='') as fichier:
|
||||
# on déclare un objet writer
|
||||
ecrivain = csv.writer(fichier)
|
||||
# écrire une ligne dans le fichier:
|
||||
ecrivain.writerow(data)
|
||||
print('... Fin de la mesure, on patiente', int(config.get('general', 'delai')), 's')
|
||||
print('... Pour quiter, appuyer sur CTRL + C')
|
||||
print("");
|
||||
time.sleep(float(config.get('general', 'sleep')))
|
||||
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
[general]
|
||||
; Répertoire de sauvegardes
|
||||
csv_dir="releves"
|
||||
; Temps entre 2 mesures (en secondes)
|
||||
delai=180
|
||||
; Temps de repos dans la boucle (en s)
|
||||
sleep=0.5
|
||||
Executable
+97
@@ -0,0 +1,97 @@
|
||||
# Déployer l'image de la carte SD prêt à l'emploi
|
||||
|
||||
Note : Il s'agit d'une image qui a été généré à partir du modèle de PvMonit ([create](https://pvmonit.zici.fr/doc/fr:image:create)/[deployer](https://pvmonit.zici.fr/doc/fr:image:deployer))
|
||||
|
||||
Pré-requis : carte SD de 4Go
|
||||
|
||||
Pour télécharger l'image
|
||||
|
||||
Une fois télécharger déployer l'image comme si c'était une Raspbian “normal”
|
||||
|
||||
- Linux : https://www.raspberrypi.org/documentation/installation/installing-images/linux.md
|
||||
- Mac OS : https://www.raspberrypi.org/documentation/installation/installing-images/mac.md
|
||||
- Windows : https://www.raspberrypi.org/documentation/installation/installing-images/windows.md
|
||||
- Chrome OS : https://www.raspberrypi.org/documentation/installation/installing-images/chromeos.md
|
||||
|
||||
## Se connecter
|
||||
|
||||
### Hotspot
|
||||
|
||||
Depuis la version 1.1 de l'image, le raspberry pi est un "hotspot" ([configuré comme ça](https://les-enovateurs.com/hotspot-wifi-raspberry-pi/)) vous pouvez donc vous y connecter directement.
|
||||
|
||||
Connectez vous au hotspot wifi "banc" qui n'est pas sécuriser (pas de clé WAP)
|
||||
|
||||
Si tout se passe bien vous pouvez joindre le raspberry a 192.168.0.1 :
|
||||
|
||||
* http://192.168.0.1/
|
||||
* ou http://pi.local
|
||||
|
||||
### Se connecter à un hotpost / box
|
||||
|
||||
Pour basculer en mode "connexion à une box" déposer un fichier wpa_supplicant.conf dans la partition “boot” de la carte SD. Au démarrage celui-ci sera lu / déplacé dans le système avant un reboot.
|
||||
|
||||
*/!\ Bug sur la version 1.0 de la carte SD, [ce tips ne fonctionne pas.](https://gitlab.lowtech.fr/pdm/projets/labo/pub/banc-tempsurf-ds18b20/-/issues/8)*
|
||||
|
||||
Ce fichier wpa_supplicant.conf doit ressembler à ceci :
|
||||
|
||||
```
|
||||
country=fr
|
||||
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
|
||||
update_config=1
|
||||
network={
|
||||
ssid="<nom de votre connexion>"
|
||||
scan_ssid=1 # nécessaire quand le ssid n'est pas diffusé
|
||||
psk="<mot de passe de votre connexion>"
|
||||
}
|
||||
```
|
||||
|
||||
(plus de détail sur [ce fichier ici](https://debian-facile.org/doc:reseau:wpasupplicant#ajouter-un-profil-wifi))
|
||||
|
||||
Vous pouvez maintenant mettre la carte SD dans votre PI et le mettre sous tension.
|
||||
|
||||
Vous pouvez joindre votre raspberry pi avec son nom “**pi.local**”
|
||||
|
||||
Si pi.local ne répond pas vous pouvez chercher l'adresse IP de celui-ci avec https://angryip.org/download/#linux
|
||||
|
||||
Pour re-basculer de nouveau sur le mode "hotspot" en déposant un fichier hostapd.conf dans la partition “boot” de la carte SD. Au démarrage celui-ci sera lu / déplacé dans le système avant un reboot. Ce fichier hostapd.conf doit ressembler à ceci :
|
||||
|
||||
```
|
||||
interface=wlan0
|
||||
driver=nl80211
|
||||
ssid=banc
|
||||
hw_mode=g
|
||||
channel=6
|
||||
ieee80211n=1
|
||||
wmm_enabled=1
|
||||
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
|
||||
macaddr_acl=0
|
||||
auth_algs=1
|
||||
ignore_broadcast_ssid=0
|
||||
```
|
||||
|
||||
## Administrer votre raspberry pi
|
||||
|
||||
Les paramètres
|
||||
|
||||
- Hostname : pi.local ou 192.168.0.1 (pour le mode hotspot)
|
||||
- Port : 22 (standard)
|
||||
- Utilisateur : banc (ou root)
|
||||
- Mot de passe : banc
|
||||
|
||||
### En ligne de commande SSH
|
||||
|
||||
Avec un client (SSH) de votre choix : ssh pvmonit@pi.local
|
||||
|
||||
Ou avec un client type [putty](https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html) sous windows
|
||||
|
||||
### En graphique avec un client SSH SCP
|
||||
|
||||
[](https://pvmonit.zici.fr/doc/_media/fr:image:2020-04-17_19-20.png)
|
||||
|
||||
## Configurer
|
||||
|
||||
Le logiciel est installé dans /opt/banc
|
||||
|
||||
## Lancement
|
||||
|
||||
https://gitlab.lowtech.fr/pdm/projets/labo/bancs-acqusition/banc-mesure-temp-surface-DS18B20#lancement
|
||||
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Executable
BIN
Binary file not shown.
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
$page = null;
|
||||
if (isset($_GET['p'])) {
|
||||
$page = $_GET['p'];
|
||||
}
|
||||
if (isset($_POST['configfile'])) {
|
||||
file_put_contents('config.ini', $_POST['configfile']);
|
||||
header('Location: http://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']);
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
|
||||
<head>
|
||||
<title>Banc Test</title>
|
||||
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
|
||||
<meta name="generator" content="Geany 1.36" />
|
||||
<style>
|
||||
a {
|
||||
color: #3E3E7C;
|
||||
text-decoration: none;
|
||||
}
|
||||
#footer {
|
||||
position: fixed;
|
||||
bottom:0;
|
||||
right:0;
|
||||
}
|
||||
#menu li,
|
||||
#footer li {
|
||||
margin: 10px;
|
||||
display:inline;
|
||||
}
|
||||
.error {
|
||||
color: #B21E1E;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<?php
|
||||
$config_rw=true;
|
||||
$config = parse_ini_file('config.ini', true);
|
||||
if ($config == false) {
|
||||
echo '<div class="error">Erreur : Votre fichier config.ini n\'exsite pas ou comporte des erreurs/commentaires non lu par se programme.</div>';
|
||||
$page='config';
|
||||
} elseif (is_writeable('config.ini')) {
|
||||
echo '<div class="error">Erreur : Votre fichier config.ini n\'est pas accessible en écriture, vous ne pourez donc pas l\'éditer par cette interface.</div>';
|
||||
$config_rw=false;
|
||||
}
|
||||
?>
|
||||
<h1 id="title">banc-ecs-diehl</h1>
|
||||
<div id="menu">
|
||||
<ul>
|
||||
<li><a href="http://<?= $_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'] ?>">Aquisition</a></li>
|
||||
<li><a href="http://<?= $_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'] ?>?p=config">Editer la configuration</a></li>
|
||||
<li><a href="http://<?= $_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'] ?>?p=dl">Téléchargement des relevés</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<?php
|
||||
switch ($page) {
|
||||
case 'config':
|
||||
$content = file_get_contents('config.ini');
|
||||
echo '<form action="#" method="post">';
|
||||
echo '<p>Avant tout changement de configuration, bien <a href="https://gitlab.lowtech.fr/pdm/projets/labo/pub/banc-tempsurf-ds18b20#configuration">lire la documentation</a> : </p>';
|
||||
echo '<p><textarea name="configfile" id="configfile" rows="15" cols="70">'.$content.'</textarea></p>';
|
||||
if ($config_rw == true) {
|
||||
echo '<p><input type="submit" value="Enregistrer" /></p>';
|
||||
} else {
|
||||
echo '<p>Le fichier n\'est pas accessible en écriture, il ne peut être enregistré par cette interface.</p>';
|
||||
}
|
||||
echo '</form>';
|
||||
break;
|
||||
case 'dl':
|
||||
$cdir = scandir($config['general']['csv_dir']);
|
||||
echo '<p>Liste le répertoire <i>'.$config['general']['csv_dir'].'</i> : </p>';
|
||||
echo '<ul>';
|
||||
foreach ($cdir as $value) {
|
||||
if (!in_array($value,array(".",".."))) {
|
||||
echo '<li><a href="'.$config['general']['csv_dir'].'/'.$value.'">'.$value.'</a></li>';
|
||||
}
|
||||
}
|
||||
echo '</ul>';
|
||||
break;
|
||||
default:
|
||||
?>
|
||||
<iframe id="" allowtransparency="true" scrolling="auto" src="http://<?= $_SERVER['SERVER_NAME'] ?>:8022/" style="width:100%;height:300px;border:none;"></iframe>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<div id="footer">
|
||||
<ul>
|
||||
<!-- <li><a href="https://gitlab.lowtech.fr/pdm/projets/labo/pub/banc-tempsurf-ds18b20">Code source</a></li>-->
|
||||
<li>Auteur: <a href="https://david.mercereau.info/contact/">David Mercereau</a></li>
|
||||
<li>Licence <a href="https://www.gnu.org/licenses/agpl-3.0.fr.html">AGPL v3</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Executable
+167
@@ -0,0 +1,167 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import serial
|
||||
import time
|
||||
import os
|
||||
import stat
|
||||
import simplejson as json
|
||||
import yaml
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
try:
|
||||
import meterbus
|
||||
except ImportError:
|
||||
import sys
|
||||
sys.path.append('./pyMeterBus/')
|
||||
import meterbus
|
||||
|
||||
|
||||
def ping_address(ser, address, retries=5, read_echo=False):
|
||||
for i in range(0, retries + 1):
|
||||
meterbus.send_ping_frame(ser, address, read_echo)
|
||||
try:
|
||||
frame = meterbus.load(meterbus.recv_frame(ser, 1))
|
||||
if isinstance(frame, meterbus.TelegramACK):
|
||||
return True
|
||||
except meterbus.MBusFrameDecodeError as e:
|
||||
pass
|
||||
|
||||
time.sleep(0.5)
|
||||
|
||||
return False
|
||||
|
||||
def do_reg_file(args):
|
||||
with open(args.device, 'rb') as f:
|
||||
frame = meterbus.load(f.read())
|
||||
if frame is not None:
|
||||
print(frame.to_JSON())
|
||||
|
||||
def do_char_dev(args):
|
||||
address = None
|
||||
|
||||
try:
|
||||
address = int(args.address)
|
||||
if not (0 <= address <= 254):
|
||||
address = args.address
|
||||
except ValueError:
|
||||
address = args.address.upper()
|
||||
|
||||
try:
|
||||
ibt = meterbus.inter_byte_timeout(args.baudrate)
|
||||
with serial.serial_for_url(args.device,
|
||||
args.baudrate, 8, 'E', 1,
|
||||
inter_byte_timeout=ibt,
|
||||
timeout=1) as ser:
|
||||
frame = None
|
||||
|
||||
if meterbus.is_primary_address(address):
|
||||
if ping_address(ser, address, args.retries, args.echofix):
|
||||
meterbus.send_request_frame(ser, address, read_echo=args.echofix)
|
||||
frame = meterbus.load(
|
||||
meterbus.recv_frame(ser, meterbus.FRAME_DATA_LENGTH))
|
||||
else:
|
||||
print("no reply")
|
||||
|
||||
elif meterbus.is_secondary_address(address):
|
||||
if ping_address(ser, meterbus.ADDRESS_NETWORK_LAYER, args.retries, args.echofix):
|
||||
meterbus.send_select_frame(ser, address, args.echofix)
|
||||
try:
|
||||
frame = meterbus.load(meterbus.recv_frame(ser, 1))
|
||||
except meterbus.MBusFrameDecodeError as e:
|
||||
frame = e.value
|
||||
|
||||
# Ensure that the select frame request was handled by the slave
|
||||
assert isinstance(frame, meterbus.TelegramACK)
|
||||
|
||||
frame = None
|
||||
|
||||
meterbus.send_request_frame(
|
||||
ser, meterbus.ADDRESS_NETWORK_LAYER, read_echo=args.echofix)
|
||||
|
||||
time.sleep(0.3)
|
||||
|
||||
frame = meterbus.load(
|
||||
meterbus.recv_frame(ser, meterbus.FRAME_DATA_LENGTH))
|
||||
else:
|
||||
print("no reply")
|
||||
|
||||
if frame is not None and args.output != 'dump':
|
||||
recs = []
|
||||
for rec in frame.records:
|
||||
recs.append({
|
||||
'value': rec.value,
|
||||
'unit': rec.unit
|
||||
})
|
||||
|
||||
ydata = {
|
||||
'manufacturer': frame.body.bodyHeader.manufacturer_field.decodeManufacturer,
|
||||
'identification': ''.join(map('{:02x}'.format, frame.body.bodyHeader.id_nr)),
|
||||
'access_no': frame.body.bodyHeader.acc_nr_field.parts[0],
|
||||
'medium': frame.body.bodyHeader.measure_medium_field.parts[0],
|
||||
'records': recs
|
||||
}
|
||||
|
||||
if args.output == 'json':
|
||||
print(json.dumps(ydata, indent=4, sort_keys=True))
|
||||
|
||||
elif args.output == 'yaml':
|
||||
def float_representer(dumper, value):
|
||||
if int(value) == value:
|
||||
text = '{0:.4f}'.format(value).rstrip('0').rstrip('.')
|
||||
return dumper.represent_scalar(u'tag:yaml.org,2002:int', text)
|
||||
else:
|
||||
text = '{0:.4f}'.format(value).rstrip('0').rstrip('.')
|
||||
return dumper.represent_scalar(u'tag:yaml.org,2002:float', text)
|
||||
|
||||
# Handle float and Decimal representation
|
||||
yaml.add_representer(float, float_representer)
|
||||
yaml.add_representer(Decimal, float_representer)
|
||||
|
||||
print(yaml.dump(ydata, default_flow_style=False, allow_unicode=True, encoding=None))
|
||||
|
||||
elif frame is not None:
|
||||
print(frame.to_JSON())
|
||||
|
||||
except serial.serialutil.SerialException as e:
|
||||
print(e)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# meterbus.ADDRESS_NETWORK_LAYER
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Request data over serial M-Bus for devices.')
|
||||
parser.add_argument('-d', action='store_true',
|
||||
help='Enable verbose debug')
|
||||
parser.add_argument('-b', '--baudrate',
|
||||
type=int, default=2400,
|
||||
help='Serial bus baudrate')
|
||||
parser.add_argument('-a', '--address',
|
||||
type=str, default=meterbus.ADDRESS_BROADCAST_REPLY,
|
||||
help='Primary or secondary address')
|
||||
parser.add_argument('-r', '--retries',
|
||||
type=int, default=3,
|
||||
help='Number of ping retries for each address')
|
||||
parser.add_argument('-o', '--output', default="dump",
|
||||
help='Output format [dump,json,yaml]')
|
||||
parser.add_argument('--echofix', action='store_true',
|
||||
help='Read and ignore echoed data from target')
|
||||
parser.add_argument('device', type=str, help='Serial device, URI or binary file')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
meterbus.debug(args.d)
|
||||
|
||||
|
||||
try:
|
||||
mode = os.stat(args.device).st_mode
|
||||
if stat.S_ISREG(mode):
|
||||
do_reg_file(args)
|
||||
else:
|
||||
do_char_dev(args)
|
||||
except OSError:
|
||||
do_char_dev(args)
|
||||
|
||||
Executable
+150
@@ -0,0 +1,150 @@
|
||||
#!/bin/bash
|
||||
|
||||
# FIX for web interface
|
||||
chmod 777 /opt/banc/config.ini
|
||||
chmod 777 /opt/banc/releves -R
|
||||
# UP HAT MBUS
|
||||
if [ -f "/tmp/star-menu-first-launch" ]; then
|
||||
/usr/bin/gpio write 25 1
|
||||
fi
|
||||
|
||||
#### Initialisation des variables ####
|
||||
|
||||
#+ Mode normal
|
||||
RESETCOLOR="$(tput sgr0)"
|
||||
# "Surligné" (bold)
|
||||
SURLIGNE=$(tput smso)
|
||||
# "Non-Surligné" (offbold)
|
||||
NONSURLIGNE=$(tput rmso)
|
||||
|
||||
# Couleurs (gras)
|
||||
#+ Rouge
|
||||
ROUGE="$(tput bold ; tput setaf 1)"
|
||||
#+ Vert
|
||||
VERT="$(tput bold ; tput setaf 2)"
|
||||
#+ Jaune
|
||||
JAUNE="$(tput bold ; tput setaf 3)"
|
||||
#+ Bleu
|
||||
BLEU="$(tput bold ; tput setaf 4)"
|
||||
#+ Cyan
|
||||
CYAN="$(tput bold ; tput setaf 6)"
|
||||
|
||||
function cleanup {
|
||||
pkill -P $$
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
function autoaquisition {
|
||||
pkill -P $$
|
||||
cd /opt/banc
|
||||
clear
|
||||
python3 aquisition.py
|
||||
}
|
||||
trap autoaquisition TERM
|
||||
|
||||
function autolaunchaquisition()
|
||||
{
|
||||
sleep 1800
|
||||
#~ sleep 6
|
||||
if [ -f "/tmp/star-menu-first-launch" ]; then
|
||||
# Envoyer le signal pour lancer l'aquisition auto sur le programme primaire
|
||||
kill -TERM $$
|
||||
fi
|
||||
}
|
||||
|
||||
while [ 1 ]; do
|
||||
clear
|
||||
echo
|
||||
echo " ${JAUNE}AFPMA"
|
||||
echo -n ${RESETCOLOR}
|
||||
echo " Banc ECS"
|
||||
echo
|
||||
if [ -f "/tmp/star-menu-first-launch" ]; then
|
||||
echo -n ${ROUGE}
|
||||
echo "(Sans actio : lancement automatique de l'aquisition à +30min du démarrage)"
|
||||
echo -n ${RESETCOLOR}
|
||||
autolaunchaquisition &
|
||||
echo
|
||||
fi
|
||||
echo "Que voulez vous faire ?"
|
||||
echo " 1 - Lancer une aquisition de donnée"
|
||||
echo " 2 - Afficher la date et l'heure"
|
||||
echo " 3 - Changer la date et l'heure"
|
||||
echo " 4 - Tester un relevé sur le compteur d'énergie"
|
||||
echo " 5 - Allumer le HAT"
|
||||
echo " 6 - Eteindre le HAT"
|
||||
echo " 9 - Lancer l'invité de commande (bash) "
|
||||
|
||||
read -p "Enter votre choix : " menu
|
||||
|
||||
rm /tmp/star-menu-first-launch 2>/dev/null
|
||||
|
||||
if [[ "$menu" == "" ]] ; then
|
||||
continue
|
||||
elif ! [[ "$menu" =~ ^[1-6]$ ]] && ! [[ "$menu" == "9" ]] ; then
|
||||
echo "*** Erreur : Choix invalide *** "
|
||||
sleep 2
|
||||
continue
|
||||
fi
|
||||
|
||||
pkill -P $$
|
||||
|
||||
if [ "$menu" == "1" ]; then
|
||||
clear
|
||||
cd /opt/banc
|
||||
python3 aquisition.py
|
||||
elif [ "$menu" == "2" ]; then
|
||||
clear
|
||||
echo
|
||||
date
|
||||
echo
|
||||
echo "Retour dans 10s"
|
||||
sleep 10
|
||||
elif [ "$menu" == "3" ]; then
|
||||
clear
|
||||
echo
|
||||
echo "Entrée la date au format 'YYYY-MM-DD HH:MM:SS' "
|
||||
echo " * YYYY = année - MM = mois - DD = jour"
|
||||
echo " * HH = heure : MM = minute : SS = seconde"
|
||||
echo
|
||||
echo "Exemple pour la date le 12 janvier 2023 à 12:02"
|
||||
echo "Indiquez : 2023-01-12 12:02:00"
|
||||
echo
|
||||
read -p "Enter la date : " dateset
|
||||
timedatectl set-time "${dateset}"
|
||||
elif [ "$menu" == "4" ]; then
|
||||
clear
|
||||
echo "Attente des données..."
|
||||
echo -n ${BLEU}
|
||||
echo
|
||||
/usr/bin/python3 /opt/banc/mbus-serial-request-data.py /dev/ttyAMA0 &> /opt/banc/releves/test-releve.txt
|
||||
cat /opt/banc/releves/test-releve.txt
|
||||
echo
|
||||
echo -n ${RESETCOLOR}
|
||||
echo "Retrouvé le test de relevé dans 'Télécharger les relevés' > test-releve.txt"
|
||||
echo "Retour dans 30s"
|
||||
sleep 30
|
||||
elif [ "$menu" == "5" ]; then
|
||||
clear
|
||||
echo "Allumage du HAT (la LED rouge doit s'allumer)"
|
||||
echo -n ${BLEU}
|
||||
gpio write 25 1
|
||||
echo -n ${RESETCOLOR}
|
||||
echo "Retour dans 10s"
|
||||
sleep 10
|
||||
elif [ "$menu" == "6" ]; then
|
||||
clear
|
||||
echo "Extinction du HAT (la LED rouge doit s'éteindre)"
|
||||
echo -n ${BLEU}
|
||||
gpio write 25 0
|
||||
echo -n ${RESETCOLOR}
|
||||
echo "Retour dans 10s"
|
||||
sleep 10
|
||||
elif [ "$menu" == "9" ]; then
|
||||
clear
|
||||
/bin/bash
|
||||
else
|
||||
echo "Erreur choix inconnu"
|
||||
sleep 2
|
||||
fi
|
||||
done
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
screen -x start-menu
|
||||
if (($?)); then
|
||||
screen -A -m -d -S start-menu /opt/banc/start-menu.sh
|
||||
sleep 1
|
||||
screen -x start-menu
|
||||
fi
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -f /boot/hostapd.conf ]; then
|
||||
fs_mode=$(mount | sed -n -e "s/^.* on \/ .*(\(r[w|o]\).*/\1/p")
|
||||
if [ "$fs_mode" != "rw" ]; then
|
||||
mount -o remount,rw /
|
||||
fi
|
||||
cat /boot/hostapd.conf > /etc/hostapd/hostapd.conf
|
||||
cp /etc/dhcpcd.conf_hotspot /etc/dhcpcd.conf
|
||||
cp /etc/default/hostapd_hotspot /etc/default/hostapd
|
||||
rm /boot/hostapd.conf
|
||||
if ! (($?)); then
|
||||
/sbin/reboot
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Si l'utilisateur à déposé un fichier wpa_supplicant.conf dans boot
|
||||
if [ -f /boot/wpa_supplicant.conf ]; then
|
||||
fs_mode=$(mount | sed -n -e "s/^.* on \/ .*(\(r[w|o]\).*/\1/p")
|
||||
if [ "$fs_mode" != "rw" ]; then
|
||||
mount -o remount,rw /
|
||||
fi
|
||||
cp /etc/dhcpcd.conf_box /etc/dhcpcd.conf
|
||||
cp /etc/default/hostapd_box /etc/default/hostapd
|
||||
cat /boot/wpa_supplicant.conf > /etc/wpa_supplicant/wpa_supplicant.conf
|
||||
rm /boot/wpa_supplicant.conf
|
||||
if ! (($?)); then
|
||||
/sbin/reboot
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh -e
|
||||
#
|
||||
# rc.local
|
||||
#
|
||||
# This script is executed at the end of each multiuser runlevel.
|
||||
# Make sure that the script will "exit 0" on success or any other
|
||||
# value on error.
|
||||
#
|
||||
# In order to enable or disable this script just change the execution
|
||||
# bits.
|
||||
#
|
||||
# By default this script does nothing.
|
||||
if [ -f /opt/banc/tools/img-wpa_supplicant.sh ]; then
|
||||
/bin/bash /opt/banc/tools/img-wpa_supplicant.sh
|
||||
fi
|
||||
|
||||
# Print the IP address
|
||||
_IP=$(hostname -I) || true
|
||||
if [ "$_IP" ]; then
|
||||
printf "My IP address is %s\n" "$_IP"
|
||||
fi
|
||||
|
||||
touch /tmp/star-menu-first-launch
|
||||
screen -A -m -d -S start-menu /opt/banc/start-menu.sh
|
||||
if [ -x /opt/ttyd ]; then
|
||||
/opt/ttyd -p 8022 /opt/banc/start-ttyd.sh > /tmp/ttyd.log 2>/tmp/ttyd-error.log &
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user