47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
|
#!/usr/bin/env python3
|
||
|
from flask import Flask, request, render_template
|
||
|
import requests
|
||
|
import json
|
||
|
import os
|
||
|
|
||
|
app = Flask(__name__)
|
||
|
|
||
|
# Charger le fichier JSON
|
||
|
with open('data.json', 'r') as json_file:
|
||
|
data = json.load(json_file)
|
||
|
|
||
|
@app.route('/', methods=['GET', 'POST'])
|
||
|
def index():
|
||
|
if request.method == 'POST':
|
||
|
# Récupérer les données du formulaire
|
||
|
capcode = request.form['capcode']
|
||
|
message = request.form['message']
|
||
|
# Trouver la fréquence correspondant au CapCode
|
||
|
frequency = get_frequency_by_capcode(capcode)
|
||
|
if frequency:
|
||
|
# Envoyer le message POCSAG à l'application
|
||
|
send_pocsag_message(frequency, capcode, message)
|
||
|
return "Message envoyé avec succès à la fréquence {}".format(frequency)
|
||
|
else:
|
||
|
return "CapCode non trouvé !"
|
||
|
else:
|
||
|
return render_template('index.html', data=data)
|
||
|
|
||
|
def get_frequency_by_capcode(capcode):
|
||
|
for item in data:
|
||
|
if item["CapCode"] == capcode:
|
||
|
return item["Freq"]
|
||
|
return None
|
||
|
|
||
|
def send_pocsag_message(frequency,capcode,message):
|
||
|
# Formatage de la commande shell avec les variables
|
||
|
command = f'sudo pocsag -f "{frequency}" -t 1 -r 1200 -b 3 -' # -n pour digital number
|
||
|
message_command = f'printf "{capcode}:{message}" | {command}'
|
||
|
print("le cmd=",message_command)
|
||
|
# Exécution de la commande
|
||
|
os.system(message_command)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
app.run(host='0.0.0.0', port=8080, debug=True)
|
||
|
|