Skip to main content
Question

JWTAuth error. Not able to find the Folder


Forum|alt.badge.img

I configured a raspberry pi 4 to be a cellular modem using the SixFab cellular modem kit The kit includes a SixFabBase Hat, LTE modem, antennas and a Sixfab core. I am using a in house sim card. The pi runs a python code to find the RSSI, RSRQ & SINR values every 5 minutes using Cron. Then another code to upload the text file to box every day. The issue I am facing here is that is that the JWTAuth is not working for me. Apparently, it doesn’t recognize my folder. It says it is it uploading the files to the root folder but I don’t see the file there as well. The codes are given below.

  1. Modem Signal Logger
import subprocess
import time
from datetime import datetime

def get_modem_signal_info():
    try:
        # Run the AT command using atcom and capture the output
        result = subprocess.run(['/home/genwave/.local/bin/atcom', '-p', '/dev/ttyUSB2', 'AT+QENG="servingcell"'],
                                capture_output=True, text=True)
        output = result.stdout.strip()
        return output
    except Exception as e:
        return f"Error: {e}"

def log_signal_info():
    # Get the current date for file naming
    current_date = datetime.now().strftime('%Y-%m-%d')  # Format date as YYYY-MM-DD

    # Create the file name with the date included
    file_name = f'/home/genwave/modem_signal_log_{current_date}.txt'

    # Get the current time for the log entry
    timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    # Get modem signal info
    signal_info = get_modem_signal_info()

    # Log the signal info to a text file with the date-based name
    with open(file_name, "a") as logfile:
        logfile.write(f"{timestamp} - Signal Info:\n")
        logfile.write(f"{signal_info}\n\n")

    return file_name  # Return the file name for later use

def main():
    try:
        log_signal_info()  # Log the signal information
        time.sleep(300)    # Sleep for 5 minutes (300 seconds)
    except KeyboardInterrupt:
        print("\nProgram interrupted by user. Exiting cleanly.")

if __name__ == "__main__":
    main()
  1. Upload to box code
from boxsdk import JWTAuth, Client
from datetime import datetime

auth = JWTAuth.from_settings_file('/home/genwave/scripts/1204742365_x6ntp8nl_config.json')

client = Client(auth)

current_date = datetime.now().strftime('%Y-%m-%d')
file_path = f'/home/genwave/modem_signal_log_{current_date}.txt'

folder_id = '287746897264'
folder = client.folder(folder_id).get()

with open(file_path, 'rb') as file_content:
    uploaded_file = folder.upload_stream(file_content, f'modem_signal_log_{current_date}.txt')

print(f'File "modem_signal_log_{current_date}.txt" uploaded successfully with File ID: {uploaded_file.id}')

 

0 replies

Be the first to reply!

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings