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/
sound_meter/moving_avg_minute.txt
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
port='/dev/'+parameter[0] # ex: ttyAMA2
endpoint = parameter[1] # ex: /pro_4G/notif_message.php
profile_id = parameter[2]
#get baudrate
def load_config(config_file):
@@ -37,7 +38,7 @@ ser = serial.Serial(
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'))
try:

View File

@@ -1,7 +1,7 @@
'''
Script to set the URL for a HTTP request
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
First profile id:
@@ -19,6 +19,7 @@ parameter = sys.argv[1:] # Exclude the script name
#print("Parameters received:")
port='/dev/'+parameter[0] # ex: ttyAMA2
url = parameter[1] # ex: data.mobileair.fr
profile_id = parameter[2] #ex: 0
#get baudrate
@@ -47,7 +48,7 @@ ser = serial.Serial(
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'))
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 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
#* * * * * /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

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") {
$port=$_GET['port'];
$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);
echo $output;
}
@@ -192,7 +193,8 @@ if ($type == "sara_sendMessage") {
$port=$_GET['port'];
$endpoint=$_GET['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);
echo $output;
}

View File

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

View File

@@ -96,7 +96,8 @@ payload_json = {
"sensordatavalues": [] # Empty list to start with
}
aircarto_profile_id = 0
uSpot_profile_id = 1
# Set up GPIO mode (for Blue LED: network status)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM) # Use Broadcom pin numbering
@@ -399,7 +400,7 @@ try:
#3. Send to endpoint (with device ID)
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'))
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
time.sleep(0.1) # Attendre 100 ms
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'))
response_SARA_31 = read_complete_response(ser_sara)
if need_to_log:
@@ -536,12 +537,11 @@ try:
print(">>>>>>>>")
print(">>>>>>>>")
print("SEND TO MICRO SPOT (HTTP):")
profile_id = 1
#step 4: set url (op_code = 1)
print("****")
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'))
response_SARA_5 = read_complete_response(ser_sara, wait_for_line="OK")
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)
print("****")
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'))
response_SARA_5 = read_complete_response(ser_sara, wait_for_line="OK")
print(response_SARA_5)
@@ -559,7 +559,7 @@ try:
#step 4: set PORT (op_code = 5)
print("****")
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'))
response_SARA_55 = read_complete_response(ser_sara, wait_for_line="OK")
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)
print("****")
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'))