Advertisement
Sweetening

eINK LFI > RFI

Feb 6th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import time
  2. import serial
  3. import requests
  4.  
  5. # Serial port configuration
  6. serial_port = '/dev/ttyUSB0' # Replace with the correct serial port
  7. baud_rate = 9600
  8.  
  9. # API endpoint to retrieve node stats
  10. api_endpoint = 'http://localhost:3000/stats' # Replace with the correct API endpoint
  11.  
  12. # Initialize serial connection
  13. ser = serial.Serial(serial_port, baud_rate)
  14.  
  15. def display_stats(data):
  16. # Clear the screen
  17. ser.write(b'\x0C') # Send the clear screen command
  18.  
  19. # Display the stats
  20. ser.write(f"Node Stats\n".encode())
  21. ser.write(f"---------------\n".encode())
  22. ser.write(f"Total Nodes: {data['total_nodes']}\n".encode())
  23. ser.write(f"Active Nodes: {data['active_nodes']}\n".encode())
  24. ser.write(f"Total Transactions: {data['total_transactions']}\n".encode())
  25.  
  26. while True:
  27. try:
  28. # Retrieve node stats from the API
  29. response = requests.get(api_endpoint)
  30. data = response.json()
  31.  
  32. # Display the stats on the eINK screen
  33. display_stats(data)
  34.  
  35. # Wait for a few seconds before updating the stats
  36. time.sleep(10)
  37.  
  38. except requests.exceptions.RequestException as e:
  39. print(f"Error: {e}")
  40.  
  41. except KeyboardInterrupt:
  42. # Close the serial connection and exit the script
  43. ser.close()
  44. break
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement