Commit ac2b0d67 authored by Hicham Brahimi's avatar Hicham Brahimi

First commit

parents

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
# Matches multiple files with brace expansion notation
# Set default charset
[*]
charset = utf-8
# Tab indentation (no size specified)
indent_style = tab
.DS_Store
application/cache/*
!application/cache/index.html
application/logs/*
!application/logs/index.html
!application/*/.htaccess
composer.lock
user_guide_src/build/*
user_guide_src/cilexer/build/*
user_guide_src/cilexer/dist/*
user_guide_src/cilexer/pycilexer.egg-info/*
/vendor/
# IDE Files
#-------------------------
/nbproject/
.idea/*
## Sublime Text cache files
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
*.sublime-workspace
*.sublime-project
/tests/tests/
/tests/results/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
import paho.mqtt.client as mqtt
import time
import sys
from random import randint
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to broker")
global Connected
Connected = True
else:
print("Connection failed")
Connected = False
client = mqtt.Client(transport="websockets")
client.on_connect = on_connect
client.connect("pil-09.univlehavre.lan", 9001, 60)
client.loop_start()
while Connected != True:
time.sleep(0.1)
try:
while True:
time.sleep(2);
client.publish("capteurs/capteurDegree", randint(26, 45));
client.publish("capteurs/capteurGo", randint(366, 455))
client.publish("capteurs/capteur10", randint(0, 10))
client.publish("capteurs/capteur100", randint(0, 100))
client.publish("capteurs/capteur1000", randint(0, 1000))
client.publish("map", str(randint(-90, 90))+","+ str(randint(-90, 90)))
print("messsage envoyee");
except KeyboardInterrupt:
client.disconnect()
client.loop_stop()
import MySQLdb
import paho.mqtt.client as mqtt
import time
import sys
db = MySQLdb.connect(host="pil-09.univlehavre.lan",
user="firediag",
passwd="firediag$!",
db="firediag");
global topics ; global frequenceSeuils; # frequenceSeuils => Map utilisee pour verifier l'effet de seuil
topics = []; frequenceSeuils = {};
topic_changeCapteur = "/system/changeCapteur";
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to broker");
client.subscribe(topic_changeCapteur);
global Connected;
Connected = True;
else:
print("Connection failed");
def on_message(client, userdata, msg):
global topics ; global frequenceSeuils ;
print(msg.topic + " Payload -> " +str(msg.payload));
message_topic = msg.topic;
message_valeur = msg.payload;
if message_topic == topic_changeCapteur: # Mise a jour des topics auxquelles on s'abonne
for topic in topics:
client.unsubscribe(topic);
update_capteur();
print("Update des topics => "+" ".join(topics));
else : # Arrivee d'une valeur d'un capteur
cursor = db.cursor();
cursor.execute('SELECT topic, id, idUser, nom, idGroupe FROM capteur WHERE visible = TRUE');
for capteur in cursor.fetchall():
if capteur[0] == message_topic:
try:
cursor.execute("INSERT INTO `valeur` (`temps`, `valeur`, `idCapteur`) VALUES ('"+
time.strftime('%Y-%m-%d %H:%M:%S')+"', '"+str(message_valeur)+"', '"+str(capteur[1])+"')");
print("Nouvelle valeur ('"+time.strftime('%Y-%m-%d %H:%M:%S')+"', '"+str(message_valeur)+"', '"+str(capteur[1])+"')");
if unicode(str(message_valeur).strip(), 'utf-8').isnumeric(): # Si c'est une valeur numerique
# Gestion des notifications des utilisateurs (ajout des alertes)
cursorNotif = db.cursor();
cursorNotif.execute('SELECT id, nom, valeur, regle, frequence FROM seuil WHERE idCapteur = '+str(capteur[1]));
for seuil in cursorNotif.fetchall():
frequence = int(seuil[0]);
if (seuil[3] == "sup" and int(message_valeur) > int(seuil[2])) or \
(seuil[3] == "inf" and int(message_valeur) < int(seuil[2])) or \
(seuil[3] == "eq" and int(message_valeur) == int(seuil[2])):
if frequence not in frequenceSeuils: # on ajoute le seuil a la map
frequenceSeuils[frequence] = 1;
else: # sinon on l'incremente
frequenceSeuils[frequence] = frequenceSeuils[frequence]+1;
# Si l'effet de seuil est depassee, on lance l'alerte
if frequenceSeuils[frequence] >= seuil[4]:
print(" Alerte \""+seuil[1]+"\" => "+message_valeur+" "+seuil[3]+" "+str(int(seuil[2])));
titre = "Alerte sur "+str(capteur[3]);
message = "Le seuil \""+str(seuil[1])+"\" a ete franchi ("+message_valeur ;
if seuil[3] == "sup" : message += " > " ;
elif seuil[3] == "inf" : message += " < " ;
else : message += " = " ;
message += str(int(seuil[2]))+")" ;
cursorNotif.execute("INSERT INTO `notification` (`temps`, `titre`, `message`, `idUser`, `idCapteur`, `vu`) VALUES ('"+
time.strftime('%Y-%m-%d %H:%M:%S')+"', '"+titre+"', '"+message+"', '"+str(capteur[2])+"', '"+str(capteur[1])+"', false)")
# notification du changement
client.publish("/system/notification/"+str(capteur[2]), str(capteur[4])+"/"+str(capteur[1]));
frequenceSeuils[frequence] = 0;
else:
frequenceSeuils[frequence] = 0;
db.commit();
except Exception as e:
db.rollback();
print("rollback ");
print(e);
def update_capteur():
global topics ;
topics = [];
cursor = db.cursor();
cursor.execute('SELECT topic FROM capteur WHERE visible = TRUE');
for capteur in cursor.fetchall():
topics.append(capteur[0]);
client.subscribe(capteur[0]);
db.commit();
Connected = False;
client = mqtt.Client(transport="websockets");
client.on_connect = on_connect;
client.on_message = on_message;
client.connect("pil-09.univlehavre.lan", 9001, 60);
client.loop_start() ;
while Connected != True:
time.sleep(0.1);
update_capteur();
try:
while True:
time.sleep(1);
except KeyboardInterrupt:
print "exiting";
client.disconnect();
client.loop_stop();
db.close();
import paho.mqtt.client as mqtt
import time
import sys
import subprocess
import os
import signal
from random import randint
# Pour couper le script :
# > ps -A | grep python
# > sudo kill -9 ...
global mqttTopic, errorDelay, lastMessageTime ;
global pid_MySQL, pid_Generation, client;
mqttTopic = "/system/mqtt";
errorDelay = 60; # On laisse 60 secondes au serveur avant de le redemmarer
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to broker");
global Connected;