This commit is contained in:
PaulVua
2025-01-31 17:31:14 +01:00
parent 456db5da98
commit ef2bd6b895
3 changed files with 22 additions and 21 deletions

View File

@@ -82,6 +82,9 @@ sudo chmod 777 /dev/i2c-1
Attention: sometimes activation with config.txt do not work, you need to activate i2c with `sudo raspi-config` and go to "Interface" -> I2C -> enable. Attention: sometimes activation with config.txt do not work, you need to activate i2c with `sudo raspi-config` and go to "Interface" -> I2C -> enable.
It is possible to manage raspi-config only with cli: `sudo raspi-config nonint do_i2c 0`
I2C addresses: use `sudo i2cdetect -y 1` to check the connected devices. I2C addresses: use `sudo i2cdetect -y 1` to check the connected devices.
### BME280 ### BME280

View File

@@ -12,6 +12,7 @@
"i2C_sound": false, "i2C_sound": false,
"i2c_BME": false, "i2c_BME": false,
"i2c_RTC": false, "i2c_RTC": false,
"local_storage": false,
"sshTunnel_port": 59228, "sshTunnel_port": 59228,
"npm1_status": "connected", "npm1_status": "connected",
"SARA_R4_general_status": "connected", "SARA_R4_general_status": "connected",

View File

@@ -185,6 +185,7 @@ i2C_sound_config = config.get('i2C_sound', False) #présence du capteur son
send_aircarto = config.get('send_aircarto', True) #envoi sur AirCarto (data.nebuleair.fr) send_aircarto = config.get('send_aircarto', True) #envoi sur AirCarto (data.nebuleair.fr)
send_uSpot = config.get('send_uSpot', False) #envoi sur MicroSpot () send_uSpot = config.get('send_uSpot', False) #envoi sur MicroSpot ()
npm_5channel = config.get('NextPM_5channels', False) #5 canaux du NPM npm_5channel = config.get('NextPM_5channels', False) #5 canaux du NPM
local_storage = config.get('local_storage', False) #enregistrement en local des data
envea_sondes = config.get('envea_sondes', []) envea_sondes = config.get('envea_sondes', [])
connected_envea_sondes = [sonde for sonde in envea_sondes if sonde.get('connected', False)] connected_envea_sondes = [sonde for sonde in envea_sondes if sonde.get('connected', False)]
@@ -236,7 +237,7 @@ if connected_envea_sondes:
def read_complete_response(serial_connection, timeout=2, end_of_response_timeout=2, wait_for_line=None): def read_complete_response(serial_connection, timeout=2, end_of_response_timeout=2, wait_for_line=None, debug=True):
response = bytearray() response = bytearray()
serial_connection.timeout = timeout serial_connection.timeout = timeout
end_time = time.time() + end_of_response_timeout end_time = time.time() + end_of_response_timeout
@@ -253,17 +254,17 @@ def read_complete_response(serial_connection, timeout=2, end_of_response_timeout
if wait_for_line: if wait_for_line:
decoded_response = response.decode('utf-8', errors='replace') decoded_response = response.decode('utf-8', errors='replace')
if wait_for_line in decoded_response: if wait_for_line in decoded_response:
print(f"[DEBUG] 🔎Found target line: {wait_for_line}") if debug: print(f"[DEBUG] 🔎Found target line: {wait_for_line}")
break break
elif time.time() > end_time: elif time.time() > end_time:
print(f"[DEBUG] Timeout reached. No more data received.") if debug: print(f"[DEBUG] Timeout reached. No more data received.")
break break
time.sleep(0.1) # Short sleep to prevent busy waiting time.sleep(0.1) # Short sleep to prevent busy waiting
# Final response and debug output # Final response and debug output
total_elapsed_time = time.time() - start_time total_elapsed_time = time.time() - start_time
print(f"[DEBUG] ⏱️ elapsed time: {total_elapsed_time:.2f}s. ⏱️") if debug: print(f"[DEBUG] ⏱️ elapsed time: {total_elapsed_time:.2f}s. ⏱️")
# Check if the elapsed time exceeded 10 seconds # Check if the elapsed time exceeded 10 seconds
if total_elapsed_time > 10: if total_elapsed_time > 10 and debug:
print(f"[ALERT] 🚨 The operation took too long🚨") print(f"[ALERT] 🚨 The operation took too long🚨")
print(f'<span style="color: red;font-weight: bold;">[ALERT] ⚠️{total_elapsed_time:.2f}s⚠</span>') print(f'<span style="color: red;font-weight: bold;">[ALERT] ⚠️{total_elapsed_time:.2f}s⚠</span>')
@@ -458,14 +459,14 @@ try:
print("Open JSON:") print("Open JSON:")
command = f'AT+UDWNFILE="sensordata_csv.json",{size_of_string}\r' command = f'AT+UDWNFILE="sensordata_csv.json",{size_of_string}\r'
ser_sara.write(command.encode('utf-8')) ser_sara.write(command.encode('utf-8'))
response_SARA_1 = read_complete_response(ser_sara, wait_for_line=">") response_SARA_1 = read_complete_response(ser_sara, wait_for_line=">", debug=False)
print(response_SARA_1) print(response_SARA_1)
time.sleep(1) time.sleep(1)
#2. Write to shell #2. Write to shell
print("Write data to memory:") print("Write data to memory:")
ser_sara.write(csv_string.encode()) ser_sara.write(csv_string.encode())
response_SARA_2 = read_complete_response(ser_sara, wait_for_line="OK") response_SARA_2 = read_complete_response(ser_sara, wait_for_line="OK", debug=False)
print(response_SARA_2) print(response_SARA_2)
#3. Send to endpoint (with device ID) #3. Send to endpoint (with device ID)
@@ -553,7 +554,7 @@ try:
print("Getting error code (11->Server connection error, 73->Secure socket connect error)") print("Getting error code (11->Server connection error, 73->Secure socket connect error)")
command = f'AT+UHTTPER={aircarto_profile_id}\r' command = f'AT+UHTTPER={aircarto_profile_id}\r'
ser_sara.write(command.encode('utf-8')) ser_sara.write(command.encode('utf-8'))
response_SARA_9 = read_complete_response(ser_sara, wait_for_line="OK") response_SARA_9 = read_complete_response(ser_sara, wait_for_line="OK", debug=False)
print('<p class="text-danger-emphasis">') print('<p class="text-danger-emphasis">')
print(response_SARA_9) print(response_SARA_9)
print("</p>") print("</p>")
@@ -590,7 +591,7 @@ try:
#4. Read reply from server #4. Read reply from server
print("Reply from server:") print("Reply from server:")
ser_sara.write(b'AT+URDFILE="server_response.txt"\r') ser_sara.write(b'AT+URDFILE="server_response.txt"\r')
response_SARA_4 = read_complete_response(ser_sara, wait_for_line="OK") response_SARA_4 = read_complete_response(ser_sara, wait_for_line="OK", debug=False)
print('<p class="text-success">') print('<p class="text-success">')
print(response_SARA_4) print(response_SARA_4)
print('</p>') print('</p>')
@@ -605,7 +606,7 @@ try:
#5. empty json #5. empty json
print("Empty SARA memory:") print("Empty SARA memory:")
ser_sara.write(b'AT+UDELFILE="sensordata_csv.json"\r') ser_sara.write(b'AT+UDELFILE="sensordata_csv.json"\r')
response_SARA_5 = read_complete_response(ser_sara, wait_for_line="OK") response_SARA_5 = read_complete_response(ser_sara, wait_for_line="OK", debug=False)
print(response_SARA_5) print(response_SARA_5)
''' '''
@@ -622,7 +623,7 @@ try:
print("SET URL") print("SET URL")
command = f'AT+UHTTP={uSpot_profile_id},1,"api-prod.uspot.probesys.net"\r' command = f'AT+UHTTP={uSpot_profile_id},1,"api-prod.uspot.probesys.net"\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, wait_for_line="OK") response_SARA_5 = read_complete_response(ser_sara, wait_for_line="OK", debug=False)
print(response_SARA_5) print(response_SARA_5)
time.sleep(1) time.sleep(1)
@@ -631,7 +632,7 @@ try:
print("SET SSL") print("SET SSL")
command = f'AT+UHTTP={uSpot_profile_id},6,0\r' command = f'AT+UHTTP={uSpot_profile_id},6,0\r'
ser_sara.write(command.encode('utf-8')) ser_sara.write(command.encode('utf-8'))
response_SARA_5 = read_complete_response(ser_sara, wait_for_line="OK") response_SARA_5 = read_complete_response(ser_sara, wait_for_line="OK", debug=False)
print(response_SARA_5) print(response_SARA_5)
time.sleep(1) time.sleep(1)
@@ -640,7 +641,7 @@ try:
print("SET PORT") print("SET PORT")
command = f'AT+UHTTP={uSpot_profile_id},5,81\r' command = f'AT+UHTTP={uSpot_profile_id},5,81\r'
ser_sara.write((command + '\r').encode('utf-8')) ser_sara.write((command + '\r').encode('utf-8'))
response_SARA_55 = read_complete_response(ser_sara, wait_for_line="OK") response_SARA_55 = read_complete_response(ser_sara, wait_for_line="OK", debug=False)
print(response_SARA_55) print(response_SARA_55)
time.sleep(1) time.sleep(1)
@@ -654,14 +655,14 @@ try:
size_of_string = len(payload_string) 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, wait_for_line=">") response_SARA_1 = read_complete_response(ser_sara, wait_for_line=">", debug=False)
print(response_SARA_1) print(response_SARA_1)
time.sleep(1) time.sleep(1)
#2. Write to shell #2. Write to shell
print("Write to memory:") print("Write to memory:")
ser_sara.write(payload_string.encode()) ser_sara.write(payload_string.encode())
response_SARA_2 = read_complete_response(ser_sara, wait_for_line="OK") response_SARA_2 = read_complete_response(ser_sara, wait_for_line="OK", debug=False)
print(response_SARA_2) print(response_SARA_2)
#step 4: trigger the request (http_command=1 for GET and http_command=1 for POST) #step 4: trigger the request (http_command=1 for GET and http_command=1 for POST)
@@ -680,7 +681,7 @@ try:
print("****") print("****")
print("Read reply from server") print("Read reply from server")
ser_sara.write(b'AT+URDFILE="http.resp"\r') ser_sara.write(b'AT+URDFILE="http.resp"\r')
response_SARA_7 = read_complete_response(ser_sara, wait_for_line="OK") response_SARA_7 = read_complete_response(ser_sara, wait_for_line="OK", debug=False)
print('<p class="text-success">') print('<p class="text-success">')
print(response_SARA_7) print(response_SARA_7)
print('</p>') print('</p>')
@@ -689,19 +690,15 @@ try:
#5. empty json #5. empty json
print("Empty SARA memory:") print("Empty SARA memory:")
ser_sara.write(b'AT+UDELFILE="sensordata_json.json"\r') ser_sara.write(b'AT+UDELFILE="sensordata_json.json"\r')
response_SARA_8 = read_complete_response(ser_sara, wait_for_line="OK") response_SARA_8 = read_complete_response(ser_sara, wait_for_line="OK", debug=False)
print(response_SARA_8) print(response_SARA_8)
# Calculate and print the elapsed time # Calculate and print the elapsed time
elapsed_time = time.time() - start_time_script elapsed_time = time.time() - start_time_script
print(f"Elapsed time: {elapsed_time:.2f} seconds") print(f"Elapsed time: {elapsed_time:.2f} seconds")
print("<hr>") print("<hr>")
except Exception as e: except Exception as e:
print("An error occurred:", e) print("An error occurred:", e)