This commit is contained in:
PaulVua
2025-01-14 17:42:59 +01:00
parent b9c7caf624
commit 0894961abf
2 changed files with 25 additions and 32 deletions

View File

@@ -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('<p class="fw-bold">'+response_SARA_2+'</p>')
#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('<span style="color: red;font-weight: bold;">ATTENTION: HTTP operation failed</span>')
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}")
print("An error occurred:", e)
traceback.print_exc() # This prints the full traceback