This commit is contained in:
PaulVua
2025-01-23 14:19:46 +01:00
parent 838d6d7357
commit aa3b4d238b
7 changed files with 25 additions and 22 deletions

3
.gitignore vendored
View File

@@ -8,4 +8,5 @@ config.json
.ssh/ .ssh/
sound_meter/moving_avg_minute.txt sound_meter/moving_avg_minute.txt
wifi_list.csv wifi_list.csv
envea/data/*.txt envea/data/*.txt
*.lock

View File

@@ -10,6 +10,7 @@ import json
parameter = sys.argv[1:] # Exclude the script name parameter = sys.argv[1:] # Exclude the script name
port='/dev/'+parameter[0] # ex: ttyAMA2 port='/dev/'+parameter[0] # ex: ttyAMA2
endpoint = parameter[1] # ex: /pro_4G/notif_message.php endpoint = parameter[1] # ex: /pro_4G/notif_message.php
profile_id = parameter[2]
#get baudrate #get baudrate
def load_config(config_file): def load_config(config_file):
@@ -37,7 +38,7 @@ ser = serial.Serial(
timeout = 2 timeout = 2
) )
command= f'AT+UHTTPC=0,4,"{endpoint}","data.txt","sensordata.json",4\r' command= f'AT+UHTTPC={profile_id},4,"{endpoint}","data.txt","sensordata.json",4\r'
ser.write((command + '\r').encode('utf-8')) ser.write((command + '\r').encode('utf-8'))
try: try:

View File

@@ -1,7 +1,7 @@
''' '''
Script to set the URL for a HTTP request Script to set the URL for a HTTP request
Ex: Ex:
/usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/sara_setURL.py ttyAMA2 data.nebuleair.fr /usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/sara_setURL.py ttyAMA2 data.nebuleair.fr 0
To do: need to add profile id as parameter To do: need to add profile id as parameter
First profile id: First profile id:
@@ -19,6 +19,7 @@ parameter = sys.argv[1:] # Exclude the script name
#print("Parameters received:") #print("Parameters received:")
port='/dev/'+parameter[0] # ex: ttyAMA2 port='/dev/'+parameter[0] # ex: ttyAMA2
url = parameter[1] # ex: data.mobileair.fr url = parameter[1] # ex: data.mobileair.fr
profile_id = parameter[2] #ex: 0
#get baudrate #get baudrate
@@ -47,7 +48,7 @@ ser = serial.Serial(
timeout = 2 timeout = 2
) )
command = f'AT+UHTTP=0,1,"{url}"\r' command = f'AT+UHTTP={profile_id},1,"{url}"\r'
ser.write((command + '\r').encode('utf-8')) ser.write((command + '\r').encode('utf-8'))
print("****") print("****")

View File

@@ -2,11 +2,12 @@
@reboot /var/www/nebuleair_pro_4g/boot_hotspot.sh >> /var/www/nebuleair_pro_4g/logs/app.log 2>&1 @reboot /var/www/nebuleair_pro_4g/boot_hotspot.sh >> /var/www/nebuleair_pro_4g/logs/app.log 2>&1
@reboot sleep 30 && /usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/sara_setURL.py ttyAMA2 data.nebuleair.fr >> /var/www/nebuleair_pro_4g/logs/app.log 2>&1 @reboot sleep 30 && /usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/sara_setURL.py ttyAMA2 data.nebuleair.fr 0 >> /var/www/nebuleair_pro_4g/logs/app.log 2>&1
@reboot sleep 45 && /usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/SSL/prepareUspotProfile.py ttyAMA2 api-prod.uspot.probesys.net >> /var/www/nebuleair_pro_4g/logs/app.log 2>&1 @reboot sleep 45 && /usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/SSL/prepareUspotProfile.py ttyAMA2 api-prod.uspot.probesys.net >> /var/www/nebuleair_pro_4g/logs/app.log 2>&1
#* * * * * /usr/bin/python3 /var/www/nebuleair_pro_4g/loop/1_NPM/send_data.py >> /var/www/nebuleair_pro_4g/logs/loop.log 2>&1
* * * * * /usr/bin/python3 /var/www/nebuleair_pro_4g/loop/1_NPM/send_data.py >> /var/www/nebuleair_pro_4g/logs/loop.log 2>&1 * * * * * flock -n /var/www/nebuleair_pro_4g/loop/1_NPM/send_data.lock /usr/bin/python3 /var/www/nebuleair_pro_4g/loop/1_NPM/send_data.py >> /var/www/nebuleair_pro_4g/logs/loop.log 2>&1
0 0 */2 * * > /var/www/nebuleair_pro_4g/logs/loop.log 0 0 */2 * * > /var/www/nebuleair_pro_4g/logs/loop.log

View File

@@ -145,11 +145,12 @@ if ($type == "sara_connectNetwork") {
} }
#SET THE URL for messaging #SET THE URL for messaging (profile id 2)
if ($type == "sara_setURL") { if ($type == "sara_setURL") {
$port=$_GET['port']; $port=$_GET['port'];
$url=$_GET['url']; $url=$_GET['url'];
$command = '/usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/sara_setURL.py ' . $port . ' ' . $url; $profile_id = 2;
$command = '/usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/sara_setURL.py ' . $port . ' ' . $url . ' ' . $profile_id;
$output = shell_exec($command); $output = shell_exec($command);
echo $output; echo $output;
} }
@@ -192,7 +193,8 @@ if ($type == "sara_sendMessage") {
$port=$_GET['port']; $port=$_GET['port'];
$endpoint=$_GET['endpoint']; $endpoint=$_GET['endpoint'];
$endpoint = escapeshellcmd($endpoint); $endpoint = escapeshellcmd($endpoint);
$command = '/usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/sara_sendMessage.py ' . $port . ' ' . $endpoint; $profile_id = 2;
$command = '/usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/sara_sendMessage.py ' . $port . ' ' . $endpoint. ' ' . $profile_id;
$output = shell_exec($command); $output = shell_exec($command);
echo $output; echo $output;
} }

View File

@@ -172,10 +172,9 @@
</div> </div>
<!--
<h3>MQTT</h3> <h3>MQTT</h3>
<div class="row mb-3"> <div class="row mb-3">
<!-- Get CONFIG -->
<div class="col-sm-4"> <div class="col-sm-4">
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
@@ -187,7 +186,6 @@
</div> </div>
</div> </div>
<!-- MQTT LOGIN -->
<div class="col-sm-4"> <div class="col-sm-4">
<div class="card"> <div class="card">
@@ -202,7 +200,6 @@
</div> </div>
</div> </div>
<!-- Send MESSAGE -->
<div class="col-sm-4"> <div class="col-sm-4">
<div class="card"> <div class="card">
@@ -219,7 +216,7 @@
</div> </div>
</div> </div>
</div> </div>
-->
<h3>Send message (test)</h3> <h3>Send message (test)</h3>
<div class="row mb-3"> <div class="row mb-3">
<!-- SET URL --> <!-- SET URL -->

View File

@@ -96,7 +96,8 @@ payload_json = {
"sensordatavalues": [] # Empty list to start with "sensordatavalues": [] # Empty list to start with
} }
aircarto_profile_id = 0
uSpot_profile_id = 1
# Set up GPIO mode (for Blue LED: network status) # Set up GPIO mode (for Blue LED: network status)
GPIO.setwarnings(False) GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM) # Use Broadcom pin numbering GPIO.setmode(GPIO.BCM) # Use Broadcom pin numbering
@@ -399,7 +400,7 @@ try:
#3. Send to endpoint (with device ID) #3. Send to endpoint (with device ID)
print("Send data (POST REQUEST):") print("Send data (POST REQUEST):")
command= f'AT+UHTTPC=0,4,"/pro_4G/data.php?sensor_id={device_id}","server_response.txt","sensordata_csv.json",4\r' command= f'AT+UHTTPC={aircarto_profile_id},4,"/pro_4G/data.php?sensor_id={device_id}","server_response.txt","sensordata_csv.json",4\r'
ser_sara.write(command.encode('utf-8')) ser_sara.write(command.encode('utf-8'))
response_SARA_3 = read_complete_response(ser_sara, timeout=5, end_of_response_timeout=45, wait_for_line="+UUHTTPCR") response_SARA_3 = read_complete_response(ser_sara, timeout=5, end_of_response_timeout=45, wait_for_line="+UUHTTPCR")
@@ -494,7 +495,7 @@ try:
GPIO.output(23, GPIO.LOW) # Éteindre la LED GPIO.output(23, GPIO.LOW) # Éteindre la LED
time.sleep(0.1) # Attendre 100 ms time.sleep(0.1) # Attendre 100 ms
GPIO.output(23, GPIO.LOW) # Turn off the LED GPIO.output(23, GPIO.LOW) # Turn off the LED
command = f'AT+UHTTP=0,1,"{url_nebuleair}"\r' command = f'AT+UHTTP={aircarto_profile_id},1,"{url_nebuleair}"\r'
ser_sara.write(command.encode('utf-8')) ser_sara.write(command.encode('utf-8'))
response_SARA_31 = read_complete_response(ser_sara) response_SARA_31 = read_complete_response(ser_sara)
if need_to_log: if need_to_log:
@@ -536,12 +537,11 @@ try:
print(">>>>>>>>") print(">>>>>>>>")
print(">>>>>>>>") print(">>>>>>>>")
print("SEND TO MICRO SPOT (HTTP):") print("SEND TO MICRO SPOT (HTTP):")
profile_id = 1
#step 4: set url (op_code = 1) #step 4: set url (op_code = 1)
print("****") print("****")
print("SET URL") print("SET URL")
command = f'AT+UHTTP={profile_id},1,"api-prod.uspot.probesys.net"\r' command = f'AT+UHTTP={uSpot_profile_id},1,"api-prod.uspot.probesys.net"\r'
ser_sara.write((command + '\r').encode('utf-8')) ser_sara.write((command + '\r').encode('utf-8'))
response_SARA_5 = read_complete_response(ser_sara, wait_for_line="OK") response_SARA_5 = read_complete_response(ser_sara, wait_for_line="OK")
print(response_SARA_5) print(response_SARA_5)
@@ -550,7 +550,7 @@ try:
#step 4: set url to SSL (op_code = 6) (http_secure = 1 for HTTPS)(USECMNG_PROFILE = 2) #step 4: set url to SSL (op_code = 6) (http_secure = 1 for HTTPS)(USECMNG_PROFILE = 2)
print("****") print("****")
print("SET SSL") print("SET SSL")
command = f'AT+UHTTP={profile_id},6,0\r' command = f'AT+UHTTP={uSpot_profile_id},6,0\r'
ser_sara.write(command.encode('utf-8')) ser_sara.write(command.encode('utf-8'))
response_SARA_5 = read_complete_response(ser_sara, wait_for_line="OK") response_SARA_5 = read_complete_response(ser_sara, wait_for_line="OK")
print(response_SARA_5) print(response_SARA_5)
@@ -559,7 +559,7 @@ try:
#step 4: set PORT (op_code = 5) #step 4: set PORT (op_code = 5)
print("****") print("****")
print("SET PORT") print("SET PORT")
command = f'AT+UHTTP={profile_id},5,81\r' command = f'AT+UHTTP={uSpot_profile_id},5,81\r'
ser_sara.write((command + '\r').encode('utf-8')) ser_sara.write((command + '\r').encode('utf-8'))
response_SARA_55 = read_complete_response(ser_sara, wait_for_line="OK") response_SARA_55 = read_complete_response(ser_sara, wait_for_line="OK")
print(response_SARA_55) print(response_SARA_55)
@@ -588,7 +588,7 @@ try:
#step 4: trigger the request (http_command=1 for GET and http_command=1 for POST) #step 4: trigger the request (http_command=1 for GET and http_command=1 for POST)
print("****") print("****")
print("Trigger POST REQUEST") print("Trigger POST REQUEST")
command = f'AT+UHTTPC={profile_id},4,"/nebuleair?token=2AFF6dQk68daFZ","http.resp","sensordata_json.json",4\r' command = f'AT+UHTTPC={uSpot_profile_id},4,"/nebuleair?token=2AFF6dQk68daFZ","http.resp","sensordata_json.json",4\r'
ser_sara.write(command.encode('utf-8')) ser_sara.write(command.encode('utf-8'))