From ee72d28dc7bb8f8c346e69c2f1f0ed073f80173b Mon Sep 17 00:00:00 2001 From: PaulVua Date: Tue, 21 Jan 2025 18:28:58 +0100 Subject: [PATCH] update --- SARA/SSL/certificate/e5.der | Bin 0 -> 696 bytes SARA/SSL/certificate/e5.pem | 17 ++ SARA/SSL/certificate/e6.der | Bin 0 -> 698 bytes SARA/SSL/certificate/e6.pem | 17 ++ SARA/SSL/certificate/isrg-root-x2.der | Bin 0 -> 543 bytes SARA/SSL/{ => certificate}/isrgrootx1.der | Bin SARA/SSL/certificate/isrgrootx1.pem | 31 ++++ SARA/SSL/certificate/r11.der | Bin 0 -> 1290 bytes SARA/SSL/certificate/r11.pem | 29 ++++ SARA/SSL/curl_script.sh | 35 ++++ SARA/SSL/full_test_HTTPS_POST.py | 200 +++++++++++++++++----- SARA/SSL/full_test_HTTP_POST.py | 1 - SARA/SSL/old/full_test_HTTPS.py | 18 +- SARA/SSL/open_ssl_script.sh | 5 + SARA/SSL/request.py | 45 +++++ 15 files changed, 352 insertions(+), 46 deletions(-) create mode 100644 SARA/SSL/certificate/e5.der create mode 100644 SARA/SSL/certificate/e5.pem create mode 100644 SARA/SSL/certificate/e6.der create mode 100644 SARA/SSL/certificate/e6.pem create mode 100644 SARA/SSL/certificate/isrg-root-x2.der rename SARA/SSL/{ => certificate}/isrgrootx1.der (100%) create mode 100644 SARA/SSL/certificate/isrgrootx1.pem create mode 100644 SARA/SSL/certificate/r11.der create mode 100644 SARA/SSL/certificate/r11.pem create mode 100755 SARA/SSL/curl_script.sh create mode 100644 SARA/SSL/open_ssl_script.sh create mode 100644 SARA/SSL/request.py diff --git a/SARA/SSL/certificate/e5.der b/SARA/SSL/certificate/e5.der new file mode 100644 index 0000000000000000000000000000000000000000..4e4adeef435ebfa31dd6df0ca18966b0202f6b1e GIT binary patch literal 696 zcmXqLV%lQR#ALmInTe5!NkAg6^vb&p3u6E3u25);l`}NpV&l+i^EhYA!pv;oZ^&)H z$;KSY!Y0fV8f>U(pbp}22`hN!m82HsrIsiJrzV#cWtLPb1f>?ICKe@UD7Y8pmlha` z8VG}wG7Ix~1_!w-1m)+KC`1?;$cghBnHU%w8XJH?6p(8U6S(&^MLL4VwHDhyjiF*y+}bu=ls>0AO*jWis%-R z>;n_lwZ1tJ=x7twUeD%x=oCV8;cu%7&Lx0-~&2P zmYp7p>y|T!B zs(}&Ad`3nVH3Jm`B^cj;sZA`Sq@=(~U%$dgFHVBs;~GT>li zOK;?1WMTxzuB<$Zf`OcY%mS$e63Dufk#!@b5$1FTgA^tM>0CWmM;TYUoAD+RCF#PI zyH;y%-6r7ItnStA>UX^Q{1*oU*~F#KWOA2G;GC4_=FMc_rYX^4Qnlyzy&KXuB$u;% mJze)ax8>%ozE|hW40bMR@X>jeAmqKWY}Je0sqVLmIC%gCLdv-S literal 0 HcmV?d00001 diff --git a/SARA/SSL/certificate/e5.pem b/SARA/SSL/certificate/e5.pem new file mode 100644 index 0000000..62c652d --- /dev/null +++ b/SARA/SSL/certificate/e5.pem @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE----- +MIICtDCCAjugAwIBAgIQGG511O6woF39Lagghl0eMTAKBggqhkjOPQQDAzBPMQsw +CQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJuZXQgU2VjdXJpdHkgUmVzZWFyY2gg +R3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBYMjAeFw0yNDAzMTMwMDAwMDBaFw0y +NzAzMTIyMzU5NTlaMDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNy +eXB0MQswCQYDVQQDEwJFNTB2MBAGByqGSM49AgEGBSuBBAAiA2IABA0LOoprYY62 +79xfWOfGQkVUq2P2ZmFICi5ZdbSBAjdQtz8WedyY7KEol3IgHCzP1XxSIE5UeFuE +FGvAkK6F7MBRQTxah38GTdT+YNH6bC3hfZUQiKIIVA+ZGkzm6gqs2KOB+DCB9TAO +BgNVHQ8BAf8EBAMCAYYwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMBMBIG +A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFJ8rX888IU+dBLftKyzExnCL0tcN +MB8GA1UdIwQYMBaAFHxClq7eS0g7+pL4nozPbYupcjeVMDIGCCsGAQUFBwEBBCYw +JDAiBggrBgEFBQcwAoYWaHR0cDovL3gyLmkubGVuY3Iub3JnLzATBgNVHSAEDDAK +MAgGBmeBDAECATAnBgNVHR8EIDAeMBygGqAYhhZodHRwOi8veDIuYy5sZW5jci5v +cmcvMAoGCCqGSM49BAMDA2cAMGQCMBttLkVBHEU+2V80GHRnE3m6qym1thBOgydK +i0VOx3vP9EAwHWGl5hxtpJAJkm5GSwIwRikYhDR6vPve2BvYGacE9ct+522E2dqO +6s42MLmigEws5mASS6l2quhtlUfacgkM +-----END CERTIFICATE----- diff --git a/SARA/SSL/certificate/e6.der b/SARA/SSL/certificate/e6.der new file mode 100644 index 0000000000000000000000000000000000000000..b241308648adaacc531c6a32d1a7e8fcde92871f GIT binary patch literal 698 zcmXqLV%lcV#ALI8nTe5!NsysoWwFP5^^BE|zwLHD@bj3a0T&yGR-4B;TNY+!1Ajwq z15P&PP!={}rqEzRO#^ihhf7$&Gp{7IC@-}{AviU;v?#NrQXwd{I5n{-IYYs{D8ID8 zP}D#eq?B2h$1^y{T_GqxzeFLz$Ush<*T}@c*wEMj45ENsb0F8q$k^1<)H2Gz2-QL{ z0}+UYygsQV>ctAKdC5hU1tl;=%)(5rW(H*j0&MJHCo?g!v1&K6Feou6F|geHIM1#9 zhhkyE3bogZf9-sAOLnKw@+)dL14T9_)|5`$uf%OBe|6tQF1J;>HeQ@9dixxvhQ5?^ zFi$IeYvfnX;`yVX`mn_FbKeUE{;esw!Eohmu1v9*vA`UwO|Np2zUgA*Y!%r{2C|w^MJF*HaJO*3_ z9BgdqjXaD@jNsUnm1j{fkTZ~3AhkdOS$8tBZlpBAoWWp_%4Corar(e!3#amc9Jj{? zk_}B488+8Xum5vkC!a+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>IK6h>?IL2pu+#PlHG2aFr!}i(E_dJ~+o?x-RXd~V3YLK~NWf5Pc zkc{CCJLT}Z%l#L8kZHVFE}wtx(#{o|nZ+6{z2}FnyOi~0^Zr*$ug>>geDa!g(Pyu3 zA**@*SbR@txSwZws&rw<6a77T;wPn+nr~e+YuB4E2TI-i%U8UJ44asyn|DvM@!GQK ztZ^x>`*hB|N^x@8aM*wChb?!QPtBao*)+9@H@PeAr)1HOt2;Xd9(B&(H2t|qX5XY@ i<&u|k<*!?N&1#7dIP`h>Bhxo^)~@Fa+=8+X8~^~rl=amB literal 0 HcmV?d00001 diff --git a/SARA/SSL/certificate/r11.pem b/SARA/SSL/certificate/r11.pem new file mode 100644 index 0000000..d6bdd38 --- /dev/null +++ b/SARA/SSL/certificate/r11.pem @@ -0,0 +1,29 @@ +-----BEGIN CERTIFICATE----- +MIIFBjCCAu6gAwIBAgIRAIp9PhPWLzDvI4a9KQdrNPgwDQYJKoZIhvcNAQELBQAw +TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh +cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMjQwMzEzMDAwMDAw +WhcNMjcwMzEyMjM1OTU5WjAzMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNTGV0J3Mg +RW5jcnlwdDEMMAoGA1UEAxMDUjExMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB +CgKCAQEAuoe8XBsAOcvKCs3UZxD5ATylTqVhyybKUvsVAbe5KPUoHu0nsyQYOWcJ +DAjs4DqwO3cOvfPlOVRBDE6uQdaZdN5R2+97/1i9qLcT9t4x1fJyyXJqC4N0lZxG +AGQUmfOx2SLZzaiSqhwmej/+71gFewiVgdtxD4774zEJuwm+UE1fj5F2PVqdnoPy +6cRms+EGZkNIGIBloDcYmpuEMpexsr3E+BUAnSeI++JjF5ZsmydnS8TbKF5pwnnw +SVzgJFDhxLyhBax7Q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mZsJgpWCDWOKZvkZcvjV +uYkQ4omYCTX5ohy+knMjdOmdH9c7SpqEWBDC86fiNex+O0XOMEZSa8DA +-----END CERTIFICATE----- diff --git a/SARA/SSL/curl_script.sh b/SARA/SSL/curl_script.sh new file mode 100755 index 0000000..1215a89 --- /dev/null +++ b/SARA/SSL/curl_script.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# to run this script ./curl_script.sh + +# URL to send the request +URL_microSpot="http://api-prod.uspot.probesys.net:81/nebuleair?token=2AFF6dQk68daFZ" +URL_microSpot_HTTPS="https://api-prod.uspot.probesys.net:443/nebuleair?token=2AFF6dQk68daFZ" +URL_airCarto_HTTPS="https://aircarto.fr/tests/test.php" +URL_webhook="https://webhook.site/6bee2237-099a-4ff4-8452-9f4126df7151" + +CERT_PATH="/var/www/nebuleair_pro_4g/SARA/SSL/certificate/e6.pem" +CIPHER="TLS_AES_256_GCM_SHA384" +#CIPHER="TLS_AES_256_GCM_SHA384" +#CIPHER="POLY1305_SHA256" + +# JSON payload to send +PAYLOAD='{ + "nebuleairid": "C04F8B8D3A08", + "software_version": "ModuleAir-V1-012023", + "sensordatavalues": [ + {"value_type": "NPM_P0", "value": "2.3"}, + {"value_type": "NPM_P0", "value": "3.30"}, + {"value_type": "NPM_P1", "value": "9.05"}, + {"value_type": "NPM_P2", "value": "20.60"}, + {"value_type": "NPM_N1", "value": "49.00"}, + {"value_type": "NPM_N10", "value": "49.00"}, + {"value_type": "NPM_N25", "value": "49.00"} + ] +}' + +# Perform the curl command +curl --http1.1 -v -X POST "$URL_microSpot_HTTPS" \ + --tlsv1.2 \ + --cacert "$CERT_PATH" \ + -d "$PAYLOAD" diff --git a/SARA/SSL/full_test_HTTPS_POST.py b/SARA/SSL/full_test_HTTPS_POST.py index e66eddb..a959794 100755 --- a/SARA/SSL/full_test_HTTPS_POST.py +++ b/SARA/SSL/full_test_HTTPS_POST.py @@ -22,8 +22,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 = 3 +profile_id = 2 #get baudrate def load_config(config_file): @@ -43,20 +42,45 @@ config = load_config(config_file) baudrate = config.get('SaraR4_baudrate', 115200) send_uSpot = config.get('send_uSpot', False) -def read_complete_response(serial_connection, timeout=2, end_of_response_timeout=2): +def color_text(text, color): + colors = { + "red": "\033[31m", + "green": "\033[32m", + "yellow": "\033[33m", + "blue": "\033[34m", + "magenta": "\033[35m", + "cyan": "\033[36m", + "white": "\033[37m", + } + reset = "\033[0m" + return f"{colors.get(color, '')}{text}{reset}" + +def read_complete_response(serial_connection, timeout=2, end_of_response_timeout=2, wait_for_line=None): response = bytearray() serial_connection.timeout = timeout end_time = time.time() + end_of_response_timeout - + start_time = time.time() + while True: + elapsed_time = time.time() - start_time # Time since function start if serial_connection.in_waiting > 0: data = serial_connection.read(serial_connection.in_waiting) response.extend(data) end_time = time.time() + end_of_response_timeout # Reset timeout on new data + + # Decode and check for the specific line + if wait_for_line: + decoded_response = response.decode('utf-8', errors='replace') + if wait_for_line in decoded_response: + print(f"[DEBUG] 🔎Found target line: {wait_for_line}") + break elif time.time() > end_time: + print(f"[DEBUG] Timeout reached. No more data received.") break time.sleep(0.1) # Short sleep to prevent busy waiting - + # Final response and debug output + total_elapsed_time = time.time() - start_time + print(f"[DEBUG] ⏱️ elapsed time: {total_elapsed_time:.2f}s. ⏱️") return response.decode('utf-8', errors='replace') ser_sara = serial.Serial( @@ -72,51 +96,105 @@ ser_sara = serial.Serial( try: #step 1: import the certificate print("****") - print("Add certificate") - with open("/var/www/nebuleair_pro_4g/SARA/SSL/isrgrootx1.der", "rb") as cert_file: + with open("/var/www/nebuleair_pro_4g/SARA/SSL/certificate/e6.der", "rb") as cert_file: certificate = cert_file.read() size_of_string = len(certificate) - command = f'AT+USECMNG=0,0,"myCertificate2",{size_of_string}\r' + print("\033[0;33m Import certificate\033[0m") + # AT+USECMNG=0,,, + # type-> 0 -> trusted root CA + command = f'AT+USECMNG=0,0,"e6",{size_of_string}\r' ser_sara.write((command + '\r').encode('utf-8')) response_SARA_1 = read_complete_response(ser_sara) - print("Write certificate metadata") print(response_SARA_1) - time.sleep(1) + time.sleep(0.5) + print("\033[0;33mAdd certificate\033[0m") ser_sara.write(certificate) response_SARA_2 = read_complete_response(ser_sara) - print("Write certificate data") print(response_SARA_2) - time.sleep(1) + time.sleep(0.5) + + #check certificate (List all available certificates and private keys) + print("\033[0;33mCheck certificate\033[0m") + command = f'AT+USECMNG=3\r' + ser_sara.write((command + '\r').encode('utf-8')) + response_SARA_5b = read_complete_response(ser_sara, wait_for_line="OK") + print(response_SARA_5b) + time.sleep(0.5) + + # ******************************* + # SECURITY PROFILE + # AT+USECPRF=[,[,]] + + + # op_code: 0 -> certificate validation level + # param_val : 0 -> Level 0 No validation; 1-> Level 1 Root certificate validation + security_profile_id = 0 + print("\033[0;33mSet the security profile (params)\033[0m") + command = f'AT+USECPRF={security_profile_id},0,0\r' + ser_sara.write((command + '\r').encode('utf-8')) + response_SARA_5b = read_complete_response(ser_sara, wait_for_line="OK") + print(response_SARA_5b) + time.sleep(0.5) + + # op_code: 1 -> minimum SSL/TLS version + # param_val : 0 -> any; server can use any version for the connection; 1-> LSv1.0; + print("\033[0;33mSet the security profile (params)\033[0m") + command = f'AT+USECPRF={security_profile_id},1,0\r' + ser_sara.write((command + '\r').encode('utf-8')) + response_SARA_5bb = read_complete_response(ser_sara, wait_for_line="OK") + print(response_SARA_5bb) + time.sleep(0.5) + + #op_code: 2 -> cipher suite + print("\033[0;33mSet cipher \033[0m") + command = f'AT+USECPRF={security_profile_id},2,0\r' + ser_sara.write((command + '\r').encode('utf-8')) + response_SARA_5cc = read_complete_response(ser_sara, wait_for_line="OK") + print(response_SARA_5cc) + time.sleep(0.5) + + # op_code: 3 -> trusted root certificate internal name + print("\033[0;33mSet the security profile (choose cert)\033[0m") + command = f'AT+USECPRF={security_profile_id},3,"e6"\r' + ser_sara.write((command + '\r').encode('utf-8')) + response_SARA_5c = read_complete_response(ser_sara, wait_for_line="OK") + print(response_SARA_5c) + time.sleep(0.5) + + # ************************* + # ************************* + #step 4: set url (op_code = 1) - print("****") - print("SET URL") + print("\033[0;33mSET URL\033[0m") command = f'AT+UHTTP={profile_id},1,"{url}"\r' ser_sara.write((command + '\r').encode('utf-8')) - response_SARA_5 = read_complete_response(ser_sara) + response_SARA_5 = read_complete_response(ser_sara, wait_for_line="OK") print(response_SARA_5) time.sleep(1) #step 4: set PORT (op_code = 5) - print("****") - print("SET PORT") - command = f'AT+UHTTP={profile_id},5,443\r' + print("\033[0;33mSET PORT\033[0m") + port = 443 + command = f'AT+UHTTP={profile_id},5,{port}\r' ser_sara.write((command + '\r').encode('utf-8')) - response_SARA_55 = read_complete_response(ser_sara) + response_SARA_55 = read_complete_response(ser_sara, wait_for_line="OK") print(response_SARA_55) time.sleep(1) #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,1\r' + print("\033[0;33mSET SSL\033[0m") + http_secure = 1 + command = f'AT+UHTTP={profile_id},6,{http_secure},{security_profile_id}\r' + #command = f'AT+UHTTP={profile_id},6,{http_secure}\r' + ser_sara.write(command.encode('utf-8')) - response_SARA_5 = read_complete_response(ser_sara) + response_SARA_5 = read_complete_response(ser_sara, wait_for_line="OK") print(response_SARA_5) time.sleep(1) @@ -162,53 +240,91 @@ try: # 1. Open sensordata_csv.json (with correct data size) payload_string = json.dumps(payload_json) # Convert dict to JSON string size_of_string = len(payload_string) + print("\033[0;33mOPEN JSON\033[0m") command = f'AT+UDWNFILE="sensordata_json.json",{size_of_string}\r' - ser_sara.write((command + '\r').encode('utf-8')) - response_SARA_1 = read_complete_response(ser_sara) - print("Open JSON:") + ser_sara.write(command.encode('utf-8')) + response_SARA_1 = read_complete_response(ser_sara, wait_for_line=">") print(response_SARA_1) - time.sleep(1) + time.sleep(0.5) #2. Write to shell + print("\033[0;33mWrite to Memory\033[0m") ser_sara.write(payload_string.encode()) - response_SARA_2 = read_complete_response(ser_sara) - print("Write to memory:") + response_SARA_2 = read_complete_response(ser_sara, wait_for_line="OK") print(response_SARA_2) #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},1,"/tests/test.php","https.resp"\r' - command = f'AT+UHTTPC={profile_id},4,"/nebuleair?token=2AFF6dQk68daFZ","https.resp","sensordata_json.json",4\r' + print("\033[0;33mPOST REQUEST\033[0m") + #AIRCARTO + #command = f'AT+UHTTPC={profile_id},4,"/tests/test.php","https.resp","sensordata_json.json",4\r' + #uSPOT + command = f'AT+UHTTPC={profile_id},4,"/nebuleair?token=2AFF6dQk68daFZ","https.resp","sensordata_json.json",4\r' + #AtmoSud + #command = f'AT+UHTTPC={profile_id},1,"/","https.resp"\r' + #Webhook + #command = f'AT+UHTTPC={profile_id},4,"/6bee2237-099a-4ff4-8452-9f4126df7151","https.resp","sensordata_json.json",4\r' + ser_sara.write(command.encode('utf-8')) # Wait for the +UUHTTPCR response print("Waiting for +UUHTTPCR response...") - response_received = False - while not response_received: - response = read_complete_response(ser_sara, timeout=5) - print(response) - if "+UUHTTPCR" in response: - response_received = True + response_SARA_3 = read_complete_response(ser_sara, timeout=5, end_of_response_timeout=30, wait_for_line="+UUHTTPCR") + + print("\033[0;34m") + print(response_SARA_3) + print("\033[0m") + + if "+UUHTTPCR" in response_SARA_3: + print("✅ Received +UUHTTPCR response.") + lines = response_SARA_3.strip().splitlines() + http_response = lines[-1] # "+UUHTTPCR: 0,4,0" + parts = http_response.split(',') + # code 0 (HTTP failed) + if len(parts) == 3 and parts[-1] == '0': # The third value indicates success + print("\033[0;31mATTENTION: HTTP operation failed\033[0m") + else: + print("\033[0;32m HTTP operation successful!!!\033[0m") + #READ REPLY print("****") - print("Read reply from server") + print("\033[0;33mREPLY SERVER\033[0m") ser_sara.write(b'AT+URDFILE="https.resp"\r') - response_SARA_7 = read_complete_response(ser_sara) + response_SARA_7 = read_complete_response(ser_sara, wait_for_line="OK") print("Reply from server:") + + print("\033[0;32m") print(response_SARA_7) + print("\033[0m") #5. empty json - print("Empty SARA memory:") + print("\033[0;33mEmpty Memory\033[0m") ser_sara.write(b'AT+UDELFILE="sensordata_json.json"\r') - response_SARA_8 = read_complete_response(ser_sara) + response_SARA_8 = read_complete_response(ser_sara, wait_for_line="OK") print(response_SARA_8) + # Get error code + print("\033[0;33mEmpty Memory\033[0m") + command = f'AT+UHTTPER={profile_id}\r' + ser_sara.write(command.encode('utf-8')) + response_SARA_9 = read_complete_response(ser_sara, wait_for_line="OK") + print(response_SARA_9) + ''' + +UHTTPER: profile_id,error_class,error_code + error_class + 0 OK, no error + 3 HTTP Protocol error class + 10 Wrong HTTP API USAGE + + error_code + 0 No error + 73 Secure socket connect error + ''' except serial.SerialException as e: print(f"Error: {e}") diff --git a/SARA/SSL/full_test_HTTP_POST.py b/SARA/SSL/full_test_HTTP_POST.py index 69c01cf..efb4d85 100755 --- a/SARA/SSL/full_test_HTTP_POST.py +++ b/SARA/SSL/full_test_HTTP_POST.py @@ -25,7 +25,6 @@ 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 = 1 #get baudrate diff --git a/SARA/SSL/old/full_test_HTTPS.py b/SARA/SSL/old/full_test_HTTPS.py index f1e6a70..aac6046 100755 --- a/SARA/SSL/old/full_test_HTTPS.py +++ b/SARA/SSL/old/full_test_HTTPS.py @@ -42,20 +42,32 @@ config = load_config(config_file) baudrate = config.get('SaraR4_baudrate', 115200) send_uSpot = config.get('send_uSpot', False) -def read_complete_response(serial_connection, timeout=2, end_of_response_timeout=2): +def read_complete_response(serial_connection, timeout=2, end_of_response_timeout=2, wait_for_line=None): response = bytearray() serial_connection.timeout = timeout end_time = time.time() + end_of_response_timeout - + start_time = time.time() + while True: + elapsed_time = time.time() - start_time # Time since function start if serial_connection.in_waiting > 0: data = serial_connection.read(serial_connection.in_waiting) response.extend(data) end_time = time.time() + end_of_response_timeout # Reset timeout on new data + + # Decode and check for the specific line + if wait_for_line: + decoded_response = response.decode('utf-8', errors='replace') + if wait_for_line in decoded_response: + print(f"[DEBUG] 🔎Found target line: {wait_for_line}") + break elif time.time() > end_time: + print(f"[DEBUG] Timeout reached. No more data received.") break time.sleep(0.1) # Short sleep to prevent busy waiting - + # Final response and debug output + total_elapsed_time = time.time() - start_time + print(f"[DEBUG] ⏱️ elapsed time: {total_elapsed_time:.2f}s. ⏱️") return response.decode('utf-8', errors='replace') ser_sara = serial.Serial( diff --git a/SARA/SSL/open_ssl_script.sh b/SARA/SSL/open_ssl_script.sh new file mode 100644 index 0000000..e84067b --- /dev/null +++ b/SARA/SSL/open_ssl_script.sh @@ -0,0 +1,5 @@ +#!/bin/bash +openssl s_client -connect aircarto.fr:443 -cipher TLS_AES_256_GCM_SHA384 +openssl s_client -connect aircarto.fr:443 -tls1_3 -ciphersuites TLS_AES_256_GCM_SHA384 +openssl s_client -connect api-prod.uspot.probesys.net:443 -tls1_2 -ciphersuites TLS_AES_256_GCM_SHA384 -CAfile /var/www/nebuleair_pro_4g/SARA/SSL/certificate/isrgrootx1.pem +openssl s_client -connect aircarto.fr:443 -tls1_2 -ciphersuites TLS_AES_256_GCM_SHA384 -CAfile /var/www/nebuleair_pro_4g/SARA/SSL/certificate/isrgrootx1.pem diff --git a/SARA/SSL/request.py b/SARA/SSL/request.py new file mode 100644 index 0000000..aea27da --- /dev/null +++ b/SARA/SSL/request.py @@ -0,0 +1,45 @@ +''' +/usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/SSL/request.py + +''' +import requests +import logging +import http.client as http_client + +# Enable HTTP and HTTPS verbose logging +http_client.HTTPConnection.debuglevel = 1 + +logging.basicConfig(level=logging.DEBUG) +logging.getLogger("http.client").setLevel(logging.DEBUG) +logging.getLogger("urllib3").setLevel(logging.DEBUG) +logging.getLogger("requests").setLevel(logging.DEBUG) + +# Suppress logging from unrelated libraries +logging.getLogger("chardet").setLevel(logging.INFO) +logging.getLogger("urllib3.connectionpool").setLevel(logging.INFO) + +url_microSpot = "https://api-prod.uspot.probesys.net/nebuleair?token=2AFF6dQk68daFZ" +url_aircarto = "https://aircarto.fr/tests/test.php" + +payload = { + "nebuleairid": "C04F8B8D3A08", + "software_version": "ModuleAir-V1-012023", + "sensordatavalues": [ + {"value_type": "NPM_P0", "value": "2.3"}, + {"value_type": "NPM_P0", "value": "3.30"}, + {"value_type": "NPM_P1", "value": "9.05"}, + {"value_type": "NPM_P2", "value": "20.60"}, + {"value_type": "NPM_N1", "value": "49.00"}, + {"value_type": "NPM_N10", "value": "49.00"}, + {"value_type": "NPM_N25", "value": "49.00"} + ] +} +cert_path = "/var/www/nebuleair_pro_4g/SARA/SSL/isrgrootx1.pem" + + +try: + response = requests.post(url_aircarto, json=payload, verify=cert_path) + print("Response Status Code:", response.status_code) + print("Response Text:", response.text) +except requests.exceptions.RequestException as e: + print("An error occurred:", e)