0

am using Micropython to make a ESP webserver that can update my UART data live on the page. the page works good as long as there is no UART data. but when UART data is sent, the page stops loading. below is my code. any help would be appreciated.

try:
  import usocket as socket
except:
  import socket
  from machine import UART
  uart = UART(2,115200)
  uart.init(115200, bits = 8, parity = None, stop = 1)
  
def web_page():
    msg= uart.read()
    html = """<!DOCTYPE HTML>
<html>

    <title> sample title </title>
    

    <h2>Serial Debug Log:</h2>

                <h3>Received content:</h3>
                     <h1>""" + str(msg) + """<h1>
                 
    </html>"""
    return html


s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', 80))
s.listen(5)
 
while True:
  try:
    if gc.mem_free() < 102000:
      gc.collect()
    conn, addr = s.accept()
    conn.settimeout(3.0)
    print('Got a connection from %s' % str(addr))
    request = conn.recv(1024)
    conn.settimeout(None)
    request = str(request)
    response = web_page()
    conn.send('HTTP/1.1 200 OK\n')
    conn.send('Content-Type: text/html\n')
    conn.send('Connection: close\n\n')
    conn.sendall(response)
    conn.close()
  except OSError as e:
    conn.close()
    print('Connection closed')

can you please help with updating this uart live data on the webpage? Thankyou, Venky

Venky
  • 1

0 Answers0