update
This commit is contained in:
@@ -54,7 +54,9 @@ JSON PAYLOAD (Micro-Spot Servers)
|
||||
{"value_type":"latitude","value":"43.2964"},
|
||||
{"value_type":"longitude","value":"5.36978"},
|
||||
{"value_type":"state_npm","value":"State: 00000000"},
|
||||
{"value_type":"th_npm","value":"28.47 / 37.54"}
|
||||
{"value_type":"th_npm","value":"28.47 / 37.54"},
|
||||
{"value_type":"CAIRSENS_NO2","value":"54"},
|
||||
{"value_type":"CAIRSENS_H2S","value":"54"},
|
||||
]
|
||||
}
|
||||
"""
|
||||
@@ -72,8 +74,14 @@ from adafruit_bme280 import basic as adafruit_bme280
|
||||
# Record the start time of the script
|
||||
start_time = time.time()
|
||||
|
||||
url="data.nebuleair.fr"
|
||||
payload = [None] * 20
|
||||
url_nebuleair="data.nebuleair.fr"
|
||||
payload_csv = [None] * 20
|
||||
payload_json = {
|
||||
"nebuleairid": "82D25549434",
|
||||
"software_version": "ModuleAirV2-V1-042022",
|
||||
"sensordatavalues": [] # Empty list to start with
|
||||
}
|
||||
|
||||
|
||||
# Set up GPIO mode (for Blue LED: network status)
|
||||
GPIO.setwarnings(False)
|
||||
@@ -136,6 +144,8 @@ envea_sondes = config.get('envea_sondes', [])
|
||||
connected_envea_sondes = [sonde for sonde in envea_sondes if sonde.get('connected', False)]
|
||||
selected_networkID = config.get('SARA_R4_neworkID', '')
|
||||
|
||||
#update device id in the payload json
|
||||
payload_json["nebuleairid"] = device_id
|
||||
|
||||
ser_sara = serial.Serial(
|
||||
port='/dev/ttyAMA2',
|
||||
@@ -199,20 +209,25 @@ try:
|
||||
PM25 = int.from_bytes(byte_data[11:13], byteorder='big') / 10
|
||||
PM10 = int.from_bytes(byte_data[13:15], byteorder='big') / 10
|
||||
|
||||
payload[0] = PM1
|
||||
payload[1] = PM25
|
||||
payload[2] = PM10
|
||||
#Add data to payload CSV
|
||||
payload_csv[0] = PM1
|
||||
payload_csv[1] = PM25
|
||||
payload_csv[2] = PM10
|
||||
#Add data to payload JSON
|
||||
payload_json["sensordatavalues"].append({"value_type": "NPM_P0", "value": str(PM1)})
|
||||
payload_json["sensordatavalues"].append({"value_type": "NPM_P1", "value": str(PM10)})
|
||||
payload_json["sensordatavalues"].append({"value_type": "NPM_P2", "value": str(PM25)})
|
||||
|
||||
# Sonde BME280 connected
|
||||
if bme_280_config:
|
||||
#on récupère les infos du BME280 et on les ajoute au payload
|
||||
#on récupère les infos du BME280 et on les ajoute au payload_csv
|
||||
i2c = busio.I2C(board.SCL, board.SDA)
|
||||
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76)
|
||||
bme280.sea_level_pressure = 1013.25 # Update this value for your location
|
||||
|
||||
payload[3] = round(bme280.temperature, 2)
|
||||
payload[4] = round(bme280.humidity, 2)
|
||||
payload[5] = round(bme280.pressure, 2)
|
||||
payload_csv[3] = round(bme280.temperature, 2)
|
||||
payload_csv[4] = round(bme280.humidity, 2)
|
||||
payload_csv[5] = round(bme280.pressure, 2)
|
||||
|
||||
# Sonde Bruit connected
|
||||
if i2C_sound_config:
|
||||
@@ -224,10 +239,10 @@ try:
|
||||
content = file.read().strip()
|
||||
avg_noise, max_noise, min_noise = map(int, content.split())
|
||||
|
||||
# Append the variables to the payload
|
||||
payload[6] = avg_noise
|
||||
payload[7] = max_noise
|
||||
payload[8] = min_noise
|
||||
# Append the variables to the payload_csv
|
||||
payload_csv[6] = avg_noise
|
||||
payload_csv[7] = max_noise
|
||||
payload_csv[8] = min_noise
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"Error: File {file_path} not found.")
|
||||
@@ -245,7 +260,7 @@ try:
|
||||
if len(data_envea) >= 20:
|
||||
byte_20 = data_envea[19]
|
||||
byte_20 = byte_20 * coefficient
|
||||
payload[10] = byte_20
|
||||
payload_csv[10] = byte_20
|
||||
print(f"Data from envea {byte_20}")
|
||||
else:
|
||||
print("Données reçues insuffisantes pour extraire le 20ème octet.")
|
||||
@@ -261,13 +276,13 @@ try:
|
||||
if match:
|
||||
signal_quality = match.group(1)
|
||||
print("Signal Quality:", signal_quality)
|
||||
payload[12]=signal_quality
|
||||
payload_csv[12]=signal_quality
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
#Write Data to saraR4
|
||||
#1. Open sensordata.json (with correct data size)
|
||||
csv_string = ','.join(str(value) if value is not None else '' for value in payload)
|
||||
csv_string = ','.join(str(value) if value is not None else '' for value in payload_csv)
|
||||
size_of_string = len(csv_string)
|
||||
command = f'AT+UDWNFILE="sensordata.json",{size_of_string}\r'
|
||||
ser_sara.write((command + '\r').encode('utf-8'))
|
||||
@@ -364,7 +379,7 @@ try:
|
||||
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}"\r'
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user