diff --git a/SARA/SSL/prepareUspotProfile.py b/SARA/SSL/prepareUspotProfile.py index 5a02b7a..933e92e 100644 --- a/SARA/SSL/prepareUspotProfile.py +++ b/SARA/SSL/prepareUspotProfile.py @@ -119,9 +119,19 @@ try: print(response_SARA_5) time.sleep(1) + #step 4: set url + print("****") + print("SET PORT") + command = f'AT+UHTTP=1,5,443\r' + ser_sara.write((command + '\r').encode('utf-8')) + response_SARA_55 = read_complete_response(ser_sara) + print(response_SARA_55) + time.sleep(1) + + #step 4: set url to SSL print("****") - print("SET URL") + print("SET SSL") command = f'AT+UHTTP=1,6,1,2\r' ser_sara.write((command + '\r').encode('utf-8')) response_SARA_5 = read_complete_response(ser_sara) diff --git a/loop/1_NPM/send_data.py b/loop/1_NPM/send_data.py index 1855b95..ebcebef 100755 --- a/loop/1_NPM/send_data.py +++ b/loop/1_NPM/send_data.py @@ -67,6 +67,8 @@ import time import busio import re import os +import traceback + import RPi.GPIO as GPIO from adafruit_bme280 import basic as adafruit_bme280 @@ -473,25 +475,27 @@ try: if send_uSpot: print(">>>>>>>>") print("SEND TO MICRO SPOT:") - print(payload_json) + + payload_string = json.dumps(payload_json) # Convert dict to JSON string # Write Data to saraR4 # 1. Open sensordata_csv.json (with correct data size) - size_of_string = len(payload_json) + size_of_string = len(payload_string) 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) - #if need_to_log: - #print("Open JSON:") - #print(response_SARA_1) + print("Open JSON:") + print(response_SARA_1) time.sleep(1) #2. Write to shell - ser_sara.write(payload_json.encode()) + + + ser_sara.write(payload_string.encode()) response_SARA_2 = read_complete_response(ser_sara) if need_to_log: print("Write to memory:") - print(response_SARA_2) + print('
'+response_SARA_2+'
') #3. Send to endpoint (with device ID) command= f'AT+UHTTPC=1,4,"nebuleair?token=2AFF6dQk68daFZ","server_response2.txt","sensordata_json.json",4\r' @@ -531,15 +535,6 @@ try: print("Operation not allowed. This may require a different configuration.") # Actions spécifiques pour ce type d'erreur - # Clignotement LED en cas d'erreur - GPIO.output(23, GPIO.LOW) # Éteindre la LED définitivement - for _ in range(4): - GPIO.output(23, GPIO.HIGH) # Allumer la LED - time.sleep(0.1) - GPIO.output(23, GPIO.LOW) # Éteindre la LED - time.sleep(0.1) - GPIO.output(23, GPIO.LOW) # Turn off the LED - else: # 2.Si la réponse contient une réponse HTTP valide # Extract HTTP response code from the last line @@ -552,21 +547,8 @@ try: if len(parts) == 3 and parts[-1] == '0': # The third value indicates success print("*****") print('ATTENTION: HTTP operation failed') - update_json_key(config_file, "SARA_R4_network_status", "disconnected") print("*****") - print("resetting the URL (domain name):") - print("Turning off the blue LED...") - for _ in range(4): # Faire clignoter 4 fois - GPIO.output(23, GPIO.HIGH) # Allumer la LED - time.sleep(0.1) # Attendre 100 ms - 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' - ser_sara.write((command + '\r').encode('utf-8')) - response_SARA_31 = read_complete_response(ser_sara) - if need_to_log: - print(response_SARA_31) + # 2.2 code 1 (HHTP succeded) else: @@ -607,4 +589,5 @@ try: except Exception as e: - print(f"Error reading the JSON file: {e}") \ No newline at end of file + print("An error occurred:", e) + traceback.print_exc() # This prints the full traceback \ No newline at end of file