update
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
Script to set the URL for a HTTP request and trigger the POST Request
|
||||
Ex:
|
||||
/usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/SSL/full_test_HTTPS_POST.py ttyAMA2 api-prod.uspot.probesys.net
|
||||
/usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/SSL/full_test_HTTPS_POST.py ttyAMA2 webhook.site
|
||||
/usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/SSL/full_test_HTTPS_POST.py ttyAMA2 aircarto.fr
|
||||
|
||||
|
||||
First profile id:
|
||||
@@ -96,7 +98,7 @@ ser_sara = serial.Serial(
|
||||
try:
|
||||
#step 1: import the certificate
|
||||
print("****")
|
||||
with open("/var/www/nebuleair_pro_4g/SARA/SSL/certificate/e6.der", "rb") as cert_file:
|
||||
with open("/var/www/nebuleair_pro_4g/SARA/SSL/certificate/isrgrootx1.der", "rb") as cert_file:
|
||||
certificate = cert_file.read()
|
||||
|
||||
size_of_string = len(certificate)
|
||||
@@ -104,7 +106,7 @@ try:
|
||||
print("\033[0;33m Import certificate\033[0m")
|
||||
# AT+USECMNG=0,<type>,<internal_name>,<data_size>
|
||||
# type-> 0 -> trusted root CA
|
||||
command = f'AT+USECMNG=0,0,"e6",{size_of_string}\r'
|
||||
command = f'AT+USECMNG=0,0,"isrgrootx1",{size_of_string}\r'
|
||||
ser_sara.write((command + '\r').encode('utf-8'))
|
||||
response_SARA_1 = read_complete_response(ser_sara)
|
||||
print(response_SARA_1)
|
||||
@@ -160,7 +162,7 @@ try:
|
||||
|
||||
# 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'
|
||||
command = f'AT+USECPRF={security_profile_id},3,"isrgrootx1"\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)
|
||||
@@ -190,8 +192,8 @@ try:
|
||||
#step 4: set url to SSL (op_code = 6) (http_secure = 1 for HTTPS)(USECMNG_PROFILE = 2)
|
||||
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'
|
||||
#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, wait_for_line="OK")
|
||||
@@ -257,9 +259,9 @@ try:
|
||||
print("****")
|
||||
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'
|
||||
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'
|
||||
#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
|
||||
|
||||
@@ -4,6 +4,7 @@ FONCTIONNE SUR data.nebuleair.fr
|
||||
FONCTIONNE SUR uSpot
|
||||
Ex:
|
||||
/usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/SSL/full_test_HTTP_POST.py ttyAMA2 api-prod.uspot.probesys.net
|
||||
/usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/SSL/full_test_HTTP_POST.py ttyAMA2 aircarto.fr
|
||||
|
||||
To do: need to add profile id as parameter
|
||||
|
||||
@@ -25,7 +26,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 = 1
|
||||
profile_id = 0
|
||||
|
||||
#get baudrate
|
||||
def load_config(config_file):
|
||||
@@ -82,19 +83,11 @@ try:
|
||||
print(response_SARA_5)
|
||||
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,0\r'
|
||||
ser_sara.write(command.encode('utf-8'))
|
||||
response_SARA_5 = read_complete_response(ser_sara)
|
||||
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,81\r'
|
||||
command = f'AT+UHTTP={profile_id},5,80\r'
|
||||
ser_sara.write((command + '\r').encode('utf-8'))
|
||||
response_SARA_55 = read_complete_response(ser_sara)
|
||||
print(response_SARA_55)
|
||||
@@ -163,10 +156,13 @@ 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},1,"/tests/test.php","http.resp"\r'
|
||||
command = f'AT+UHTTPC={profile_id},4,"/nebuleair?token=2AFF6dQk68daFZ","http.resp","sensordata_json.json",4\r'
|
||||
#AirCarto
|
||||
command = f'AT+UHTTPC={profile_id},1,"/tests/test.php","http.resp"\r'
|
||||
#command = f'AT+UHTTPC={profile_id},4,"/wifi.php","http.resp","sensordata_json.json",4\r'
|
||||
#command = f'AT+UHTTPC={profile_id},4,"/pro_4G/data.php?sensor_id=52E7573A","http.resp","sensordata_json.json",4\r'
|
||||
#command = f'AT+UHTTPC={profile_id},4,"/pro_4G/data.php?sensor_id=52E7573A","http.resp","sensordata_json.json",4\r'
|
||||
#AtmoSud
|
||||
#command = f'AT+UHTTPC={profile_id},4,"/nebuleair?token=2AFF6dQk68daFZ","http.resp","sensordata_json.json",4\r'
|
||||
|
||||
|
||||
ser_sara.write(command.encode('utf-8'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user