From aa3b4d238b2a7c12bb6c4e0e1b5b8f6ecbaaff29 Mon Sep 17 00:00:00 2001 From: PaulVua Date: Thu, 23 Jan 2025 14:19:46 +0100 Subject: [PATCH] update --- .gitignore | 3 ++- SARA/sara_sendMessage.py | 3 ++- SARA/sara_setURL.py | 5 +++-- cron_jobs | 5 +++-- html/launcher.php | 8 +++++--- html/saraR4.html | 7 ++----- loop/1_NPM/send_data.py | 16 ++++++++-------- 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 1c1b862..3c3c4a1 100755 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ config.json .ssh/ sound_meter/moving_avg_minute.txt wifi_list.csv -envea/data/*.txt \ No newline at end of file +envea/data/*.txt +*.lock \ No newline at end of file diff --git a/SARA/sara_sendMessage.py b/SARA/sara_sendMessage.py index 7fd5187..f5e3e95 100755 --- a/SARA/sara_sendMessage.py +++ b/SARA/sara_sendMessage.py @@ -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: diff --git a/SARA/sara_setURL.py b/SARA/sara_setURL.py index 8b44565..aae85df 100755 --- a/SARA/sara_setURL.py +++ b/SARA/sara_setURL.py @@ -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("****") diff --git a/cron_jobs b/cron_jobs index ae4f8f6..e6b633b 100755 --- a/cron_jobs +++ b/cron_jobs @@ -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 diff --git a/html/launcher.php b/html/launcher.php index bf21f6c..f2ced74 100755 --- a/html/launcher.php +++ b/html/launcher.php @@ -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; } diff --git a/html/saraR4.html b/html/saraR4.html index 832e846..fd1940d 100755 --- a/html/saraR4.html +++ b/html/saraR4.html @@ -172,10 +172,9 @@ - +
@@ -187,7 +186,6 @@
-
@@ -202,7 +200,6 @@
-
@@ -219,7 +216,7 @@
- + -->

Send message (test)

diff --git a/loop/1_NPM/send_data.py b/loop/1_NPM/send_data.py index f63c187..7d7b5d3 100755 --- a/loop/1_NPM/send_data.py +++ b/loop/1_NPM/send_data.py @@ -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'))