Query RaspberryPi and display data on client side in HTML page

Viewed 29

I need to fetch data from RaspberryPi and display on the HTML page, so far I've managed to set up RaspberryPi (as server-wirelessly) and my laptop (as client) and fetch RaspberryPi's features. I want to display those features on a HTML page

I'm using Ubuntu terminal on my laptop to execute client side code

client.py

import socket

HOST = "192.168.1.1"  # The server's hostname or IP address
PORT = 65432  # The port used by the server

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    s.sendall(b"Hello, world")
    data = s.recv(1024)

print(f"Received {data!r}")
s.close()

server.py

import socket
from vcgencmd import Vcgencmd


HOST = "192.168.1.1"  # Standard loopback interface address (localhost)
PORT = 65432  # Port to listen on (non-privileged ports are > 1023)

core_volts = str(vcgm.measure_volts("core"))
#
    with conn:
        print(f"Connected by {addr}")
        while True:
            data = conn.recv(1024)
            if not data:
                break
            conn.sendall(core_volts.encode())

results

ms@G1g1-v0L1R:~/client$ python3 client.py
Received b"Aug  9 2022 13:44:40 0.88

0.88 is core volts fetched from RaspberryPi

I want HTML button Fetch Core Volts (it should execute client.py) and in turn fetch Core Volts from RaspberryPi and display on HTML page. Can this be done using flask? If so, how. Any other pointers, please suggest.

0 Answers
Related