update
This commit is contained in:
@@ -119,9 +119,19 @@ try:
|
|||||||
print(response_SARA_5)
|
print(response_SARA_5)
|
||||||
time.sleep(1)
|
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
|
#step 4: set url to SSL
|
||||||
print("****")
|
print("****")
|
||||||
print("SET URL")
|
print("SET SSL")
|
||||||
command = f'AT+UHTTP=1,6,1,2\r'
|
command = f'AT+UHTTP=1,6,1,2\r'
|
||||||
ser_sara.write((command + '\r').encode('utf-8'))
|
ser_sara.write((command + '\r').encode('utf-8'))
|
||||||
response_SARA_5 = read_complete_response(ser_sara)
|
response_SARA_5 = read_complete_response(ser_sara)
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ import time
|
|||||||
import busio
|
import busio
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
from adafruit_bme280 import basic as adafruit_bme280
|
from adafruit_bme280 import basic as adafruit_bme280
|
||||||
@@ -473,25 +475,27 @@ try:
|
|||||||
if send_uSpot:
|
if send_uSpot:
|
||||||
print(">>>>>>>>")
|
print(">>>>>>>>")
|
||||||
print("SEND TO MICRO SPOT:")
|
print("SEND TO MICRO SPOT:")
|
||||||
print(payload_json)
|
|
||||||
|
payload_string = json.dumps(payload_json) # Convert dict to JSON string
|
||||||
|
|
||||||
# Write Data to saraR4
|
# Write Data to saraR4
|
||||||
# 1. Open sensordata_csv.json (with correct data size)
|
# 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'
|
command = f'AT+UDWNFILE="sensordata_json.json",{size_of_string}\r'
|
||||||
ser_sara.write((command + '\r').encode('utf-8'))
|
ser_sara.write((command + '\r').encode('utf-8'))
|
||||||
response_SARA_1 = read_complete_response(ser_sara)
|
response_SARA_1 = read_complete_response(ser_sara)
|
||||||
#if need_to_log:
|
print("Open JSON:")
|
||||||
#print("Open JSON:")
|
print(response_SARA_1)
|
||||||
#print(response_SARA_1)
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
#2. Write to shell
|
#2. Write to shell
|
||||||
ser_sara.write(payload_json.encode())
|
|
||||||
|
|
||||||
|
ser_sara.write(payload_string.encode())
|
||||||
response_SARA_2 = read_complete_response(ser_sara)
|
response_SARA_2 = read_complete_response(ser_sara)
|
||||||
if need_to_log:
|
if need_to_log:
|
||||||
print("Write to memory:")
|
print("Write to memory:")
|
||||||
print(response_SARA_2)
|
print('<p class="fw-bold">'+response_SARA_2+'</p>')
|
||||||
|
|
||||||
#3. Send to endpoint (with device ID)
|
#3. Send to endpoint (with device ID)
|
||||||
command= f'AT+UHTTPC=1,4,"nebuleair?token=2AFF6dQk68daFZ","server_response2.txt","sensordata_json.json",4\r'
|
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.")
|
print("Operation not allowed. This may require a different configuration.")
|
||||||
# Actions spécifiques pour ce type d'erreur
|
# 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:
|
else:
|
||||||
# 2.Si la réponse contient une réponse HTTP valide
|
# 2.Si la réponse contient une réponse HTTP valide
|
||||||
# Extract HTTP response code from the last line
|
# 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
|
if len(parts) == 3 and parts[-1] == '0': # The third value indicates success
|
||||||
print("*****")
|
print("*****")
|
||||||
print('<span style="color: red;font-weight: bold;">ATTENTION: HTTP operation failed</span>')
|
print('<span style="color: red;font-weight: bold;">ATTENTION: HTTP operation failed</span>')
|
||||||
update_json_key(config_file, "SARA_R4_network_status", "disconnected")
|
|
||||||
print("*****")
|
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)
|
# 2.2 code 1 (HHTP succeded)
|
||||||
else:
|
else:
|
||||||
@@ -607,4 +589,5 @@ try:
|
|||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error reading the JSON file: {e}")
|
print("An error occurred:", e)
|
||||||
|
traceback.print_exc() # This prints the full traceback
|
||||||
Reference in New Issue
Block a user