Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import serial
- import requests
- # Serial port configuration
- serial_port = '/dev/ttyUSB0' # Replace with the correct serial port
- baud_rate = 9600
- # API endpoint to retrieve node stats
- api_endpoint = 'http://localhost:3000/stats' # Replace with the correct API endpoint
- # Initialize serial connection
- ser = serial.Serial(serial_port, baud_rate)
- def display_stats(data):
- # Clear the screen
- ser.write(b'\x0C') # Send the clear screen command
- # Display the stats
- ser.write(f"Node Stats\n".encode())
- ser.write(f"---------------\n".encode())
- ser.write(f"Total Nodes: {data['total_nodes']}\n".encode())
- ser.write(f"Active Nodes: {data['active_nodes']}\n".encode())
- ser.write(f"Total Transactions: {data['total_transactions']}\n".encode())
- while True:
- try:
- # Retrieve node stats from the API
- response = requests.get(api_endpoint)
- data = response.json()
- # Display the stats on the eINK screen
- display_stats(data)
- # Wait for a few seconds before updating the stats
- time.sleep(10)
- except requests.exceptions.RequestException as e:
- print(f"Error: {e}")
- except KeyboardInterrupt:
- # Close the serial connection and exit the script
- ser.close()
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement