From fd1d32a62b55834c73c9fe840969f01aace8842f Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 19 May 2025 10:26:27 +0200 Subject: [PATCH] udpate --- installation_part1.sh | 39 ++++++++++------------------- installation_part2.sh | 52 ++++++++++----------------------------- loop/SARA_send_data_v2.py | 39 ++++++++++++++++------------- 3 files changed, 48 insertions(+), 82 deletions(-) diff --git a/installation_part1.sh b/installation_part1.sh index b42bcb8..b859484 100644 --- a/installation_part1.sh +++ b/installation_part1.sh @@ -29,34 +29,21 @@ sudo apt update && sudo apt install -y git gh apache2 sqlite3 php php-sqlite3 py info "Installing Python libraries..." sudo pip3 install pyserial requests RPi.GPIO adafruit-circuitpython-bme280 crcmod psutil gpiozero ntplib pytz --break-system-packages || error "Failed to install Python libraries." -# Ask user if they want to set up SSH keys -read -p "Do you want to set up an SSH key for /var/www? (y/n): " answer -answer=${answer,,} # Convert to lowercase - -if [[ "$answer" == "y" ]]; then - info "Setting up SSH keys..." - - sudo mkdir -p /var/www/.ssh - sudo chmod 700 /var/www/.ssh - - if [[ ! -f /var/www/.ssh/id_rsa ]]; then - sudo ssh-keygen -t rsa -b 4096 -f /var/www/.ssh/id_rsa -N "" - success "SSH key generated successfully." - else - warning "SSH key already exists. Skipping key generation." - fi - - sudo ssh-copy-id -i /var/www/.ssh/id_rsa.pub -p 50221 airlab_server1@aircarto.fr || warning "Failed to copy SSH key. Please check the server connection." - - success "SSH setup complete!" -else - warning "Skipping SSH key setup." -fi - # Clone the repository (check if it exists first) REPO_DIR="/var/www/nebuleair_pro_4g" if [[ -d "$REPO_DIR" ]]; then - warning "Repository already exists. Skipping clone." + warning "Repository already exists. Will update instead of clone." + # Save current directory + local current_dir=$(pwd) + # Navigate to repository directory + cd "$REPO_DIR" + # Stash any local changes + sudo git stash || warning "Failed to stash local changes" + # Pull latest changes + sudo git pull || error "Failed to pull latest changes" + # Return to original directory + cd "$current_dir" + success "Repository updated successfully!" else info "Cloning the NebuleAir Pro 4G repository..." sudo git clone http://gitea.aircarto.fr/PaulVua/nebuleair_pro_4g.git "$REPO_DIR" || error "Failed to clone repository." @@ -98,6 +85,7 @@ if [[ -f "$REPO_DIR/sqlite/set_config.py" ]]; then else warning "Database creation script not found." fi + # Configure Apache info "Configuring Apache..." APACHE_CONF="/etc/apache2/sites-available/000-default.conf" @@ -140,7 +128,6 @@ success "I2C ports enabled." info "Creates sqlites databases..." /usr/bin/python3 /var/www/nebuleair_pro_4g/sqlite/create_db.py - # Completion message success "Setup completed successfully!" info "System will reboot in 5 seconds..." diff --git a/installation_part2.sh b/installation_part2.sh index c4475c0..ad2f154 100644 --- a/installation_part2.sh +++ b/installation_part2.sh @@ -27,8 +27,8 @@ fi info "Set up the RTC" /usr/bin/python3 /var/www/nebuleair_pro_4g/RTC/set_with_NTP.py -#Check SARA R4 connection -info "Check SARA R4 connection" +#Check SARA connection +info "Check SARA connection" /usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/sara.py ttyAMA2 ATI 2 #set up SARA R4 APN @@ -44,45 +44,19 @@ info "Connect SARA R4 to network" python3 /var/www/nebuleair_pro_4g/SARA/sara_connectNetwork.py ttyAMA2 20810 60 #Need to create the two service -# 1. master_nebuleair +# 1. start the scripts to set-up the services # 2. rtc_save_to_db -#1. Add master_nebuleair.service -SERVICE_FILE="/etc/systemd/system/master_nebuleair.service" -info "Setting up systemd service for master_nebuleair..." - -# Create the systemd service file (overwrite if necessary) -sudo bash -c "cat > $SERVICE_FILE" <START LOOP') - print(f'Modem version: {modem_version}') + #print(f'Modem version: {modem_version}') #Local timestamp #ATTENTION: # -> RTC module can be deconnected "" # -> RTC module can be out of time like "2000-01-01T00:55:21Z" - print("➡️Getting local timestamp") cursor.execute("SELECT * FROM timestamp_table LIMIT 1") row = cursor.fetchone() # Get the first (and only) row rtc_time_str = row[1] # '2025-02-07 12:30:45' ou '2000-01-01 00:55:21' ou 'not connected' - print(rtc_time_str) + print(f"➡️Getting local timestamp: {rtc_time_str}") + if rtc_time_str == 'not connected': print("⛔ Atttention RTC module not connected⛔") @@ -676,14 +676,14 @@ try: print("⛔ Attention: RTC has been reset to default date ⛔") rtc_status = "reset" else: - print("✅ RTC timestamp is valid") + #print("✅ RTC timestamp is valid") rtc_status = "valid" # Always convert to InfluxDB format # Convert to InfluxDB RFC3339 format with UTC 'Z' suffix influx_timestamp = dt_object.strftime('%Y-%m-%dT%H:%M:%SZ') rtc_status = "valid" - print(influx_timestamp) + #print(influx_timestamp) #NEXTPM # We take the last measures (order by rowid and not by timestamp) @@ -826,21 +826,22 @@ try: else: print("No data available in the database.") - print("Verify SARA R4 connection") + #print("Verify SARA connection (AT)") - # Getting the LTE Signal - print("➡️Getting LTE signal") + # Getting the LTE Signal (AT+CSQ) + print("➡️Getting SARA LTE signal") + command = f'AT+CSQ\r' ser_sara.write((command + '\r').encode('utf-8')) response2 = read_complete_response(ser_sara, wait_for_lines=["OK", "ERROR", "+CME ERROR","Socket:bind"]) + print('

') print(response2) print("

", end="") - #Here it's possible that the SARA do not repond at all or send a error message - #-> TO DO : harware reboot #-> send notification + #-> hardware reboot #-> end loop, no need to continue #1. No answer at all form SARA @@ -851,6 +852,12 @@ try: #Send notification (WIFI) send_error_notification(device_id, "SERIAL ISSUE ->no answer from sara") + #Hardware Reboot + hardware_reboot_success = modem_hardware_reboot() + if hardware_reboot_success: + print("✅Modem successfully rebooted and reinitialized") + else: + print("⛔There were issues with the modem reboot/reinitialize process") #end loop sys.exit() @@ -874,7 +881,7 @@ try: print("
") #Send notification (WIFI) send_error_notification(device_id, "SERIAL ISSUE -> Treck TCP/IP stack error") - #Software Reboot + #hardware reboot hardware_reboot_success = modem_hardware_reboot() if hardware_reboot_success: print("✅Modem successfully rebooted and reinitialized") @@ -932,7 +939,7 @@ try: print("Open JSON:") command = f'AT+UDWNFILE="sensordata_csv.json",{size_of_string}\r' ser_sara.write(command.encode('utf-8')) - response_SARA_1 = read_complete_response(ser_sara, wait_for_lines=[">"], debug=True) + response_SARA_1 = read_complete_response(ser_sara, wait_for_lines=[">"], debug=False) print('

') print(response_SARA_1) print("

", end="") @@ -942,10 +949,8 @@ try: #2. Write to shell print("Write data to memory:") ser_sara.write(csv_string.encode()) - response_SARA_2 = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=True) - print('

') - print(response_SARA_2) - print("

", end="") + response_SARA_2 = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=False) + print(f'

{response_SARA_2.strip()}

', end="") #3. Send to endpoint (with device ID) print("Send data (POST REQUEST):")