Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main page #52

Merged
merged 7 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions IOT/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ topics = AM107/by-room/+/data,solaredge/blagnac/overview
sauvegarde = result.json

[donnees]
salles = C001,B105,B002,amphi1
salles = C001,B105,B002,amphi1,B103
temps = 60
donnees = co2,humidity,activity,tvoc,illumintation
donnees = co2,humidity,activity,pressure

[seuil]
humidity = 10,100
temperature = 18.0,22.3
co2 = 120.0,990.0
humidity = 0,100
temperature = 0.0,100.0
co2 = 0,100
tvoc = 0.0,100.0
activity = 0,100
illumination = 0.0,100.0
infrared_and_visible = 0.0,100.0
infrared = 0.0,100.0
pressure = 0,100

19 changes: 15 additions & 4 deletions JavaFxApp/JavaFxApp/appData.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"roomNames":["B103","E101","E207","E209","B111","B234","B113","E104","E006","E003","B112","B217","C002","E001","B108","C102","E007","B203","amphi1","E208","E210","E106","E004","B001","B202","C004","Foyer-personnels","Local-velo","B201","C001","B109","B002","Salle-conseil","Foyer-etudiants-entrée","C101","B105","E100","C006","hall-amphi","E102","E103","B110","hall-entrée-principale","B106","B005","E105","B107"],
"roomNames":["B103","E101","E207","E209","B111","B234","B113","E104","E006","E003","B112","B217","C002","E001","B108","C102","E007","B203","amphi1","E208","E210","E106","E004","B001","B202","C004","Foyer-personnels","Local-velo","B201","C001","B109","B002","Salle-conseil","Foyer-etudiants-entrée","C101","B105","E100","C006","hall-amphi","E102","E103","B110","hall-entrée-principale","B106","B005","E105","B107"],
"communes":{
"chosenData":["temperature", "humidity", "co2"],
"chosenRooms":["B103","E101","E207","E209","B111","B234","B113","E104","E006","E003","amphi1"],
"pathResultJson":"./../../IOT/result.json"
"pathResultJson":"./iot/result.json"
},
"config":{
"winiFilePath":"./../../IOT/config.ini"
"winiFilePath": "./iot/config.ini"
},
"traduction":{
"temperature" : "Température",
Expand All @@ -18,5 +18,16 @@
"infrared" : "Infrarouge",
"infrared_and_visible" : "Infrarouge et Visible",
"pressure" : "Pression"
}
},
"seuils": {
"tvoc": "0,300",
"activity": "0,300",
"illumination": "0,800",
"co2": "500,3000",
"temperature": "0, 300",
"humidity": "0, 100",
"infrared_and_visible": "0,1000",
"infrared": "0,300",
"pressure": "500,2000"
}
}
102 changes: 102 additions & 0 deletions JavaFxApp/JavaFxApp/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>JavaFxApp</artifactId>
<name>JavaFxApp</name>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer>
<mainClass>org.javafxapp.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>org.javafxapp.Main</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<argLine>--add-exports javafx.base/com.sun.javafx.event=org.controlsfx.controls</argLine>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>opentest4j</artifactId>
<groupId>org.opentest4j</groupId>
</exclusion>
<exclusion>
<artifactId>junit-platform-commons</artifactId>
<groupId>org.junit.platform</groupId>
</exclusion>
<exclusion>
<artifactId>apiguardian-api</artifactId>
<groupId>org.apiguardian</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>junit-platform-engine</artifactId>
<groupId>org.junit.platform</groupId>
</exclusion>
<exclusion>
<artifactId>apiguardian-api</artifactId>
<groupId>org.apiguardian</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.10.0</junit.version>
</properties>
</project>
22 changes: 22 additions & 0 deletions JavaFxApp/JavaFxApp/iot/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[adress]
broker = mqtt.iut-blagnac.fr
port = 1883
topics = AM107/by-room/+/data,solaredge/blagnac/overview
sauvegarde = result.json

[donnees]
salles = C001,B105,B002,amphi1,B103
temps = 60
donnees = co2,humidity,activity,pressure

[seuil]
humidity = 0.0,100.0
temperature = 0.0,100.0
co2 = 500.0,500.0
tvoc = 0.0,100.0
activity = 0.0,100.0
illumination = 0.0,100.0
infrared_and_visible = 0.0,100.0
infrared = 0.0,100.0
pressure = 500.0,500.0

121 changes: 121 additions & 0 deletions JavaFxApp/JavaFxApp/iot/iot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import configparser
import os

import paho.mqtt.client as mqtt
import json
import time
import threading

config = configparser.ConfigParser()
config.read('./iot/config.ini')

broker = config['adress']['broker']
port = config.getint('adress', 'port')
topics = config['adress']['topics'].split(',')

salles = set(config['donnees']['salles'].split(','))
donnees = config['donnees']['donnees'].split(',')
temps = int(config['donnees']['temps'])

seuil = {}
valeursFinal = {}

if (len(config['seuil']) != len(donnees)):
print("[WARNING] Seuil manquant dans le fichier de configuration")
else:
for do in donnees:
seuil[do] = config['seuil'][do].split(',')


def afficher_valeurs_final():
while True:
time.sleep(temps)
# Ouvrir le fichier en mode écriture avec os.open()
fd = os.open(config["adress"]["sauvegarde"], os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o644)

# Convertir le descripteur de fichier en un objet fichier avec os.fdopen()
with os.fdopen(fd, 'w', encoding='utf-8') as fichier:
json.dump(valeursFinal, fichier, indent=4, ensure_ascii=False)


def load_data():
global valeursFinal

file_path = config["adress"]["sauvegarde"]

if not os.path.exists(file_path):
# Si le fichier n'existe pas, le créer avec une structure vide (par exemple, un dictionnaire vide)
with open(file_path, 'w', encoding='utf-8') as fichier:
json.dump({}, fichier, indent=4, ensure_ascii=False) # Créer un fichier JSON vide (ou avec un contenu initial)

print(f"Le fichier {file_path} a été créé.")
valeursFinal = {}
else:
fd = os.open(file_path, os.O_RDONLY) # Utilisation de O_RDONLY pour la lecture
# Convertir le descripteur de fichier en un objet fichier
with os.fdopen(fd, 'r', encoding='utf-8') as fichier:
# Charger les données JSON du fichier
valeursFinal = json.load(fichier)

def on_connect(client, userdata, flags, rc):
print(f"Connecté avec le code de résultat {rc}")
load_data()
for topic in topics:
client.subscribe(topic.strip())


def on_message(client, userdata, msg):
global valeursFinal
data = json.loads(msg.payload.decode())
newMsg = msg.topic.split('/')[0]
if (newMsg == 'solaredge'):
print("----------------------------------")
print("Solar panel")
print(f"{data["lastUpdateTime"]}\nEnergie : {data["currentPower"]["power"]}")
if "solarpanel" not in valeursFinal:
valeursFinal["solarpanel"] = {}
else:
valeursFinal["solarpanel"][str(len(valeursFinal["solarpanel"]))] = data["currentPower"]["power"]
elif (newMsg == 'AM107'):
if (data[1]["room"] in salles):
print("----------------------------------")
print(f"Salle -> {data[1]["room"]}")
if data[1]["room"] not in valeursFinal:
valeursFinal[data[1]["room"]] = {}
newData = {}
for do in donnees:
newData[do] = float(data[0][do])
if float(data[0][do]) <= float(seuil[do][0]):
print(f"[ALERT] Seuil minimum dépassé -> {do} : {data[0][do]}")
elif float(data[0][do]) >= float(seuil[do][1]):
print(f"[ALERT] Seuil maximum dépassé -> {do} : {data[0][do]}")
else:
print(f"{do} : {data[0][do]}")
valeursFinal[data[1]["room"]][str(len(valeursFinal[data[1]["room"]]))] = newData

client = mqtt.Client()

client.on_connect = on_connect
client.on_message = on_message

try:
client.connect(broker, port, 60)
except Exception as e:
print(f"Erreur lors de la connexion au broker : {e}")
exit(1)


# Création d'un nouveau thread
thread = threading.Thread(target=afficher_valeurs_final)
thread.daemon = True
thread.start()

client.loop_start()

try:
while True:
pass
except KeyboardInterrupt:
print("\nDéconnexion...")
client.loop_stop()
client.disconnect()
8 changes: 8 additions & 0 deletions JavaFxApp/JavaFxApp/iot/result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"solarpanel": {
"0": 0,
"1": 0,
"2": 0,
"3": 0
}
}
Loading
Loading