I
I
Ilya2019-10-10 18:49:42
Python
Ilya, 2019-10-10 18:49:42

How to receive data from Serial and give it to the web server?

UART data comes from Arduino to Onion Omega2+ (OpenWRT microcomputer), I need to store data from UART and send it to web server when requested.
Bottle is used as a web framework, since the storage is only 22mb.
Separately, there is no problem to perform these actions, this is how I send data to web clients:

from bottle import route, run

@route('/')
def main():
    return "Test"

run(host='0.0.0.0', port=8080, debug=True)

This is how I get data:
import serial

ser = serial.Serial('/dev/ttyS1', 115200, timeout=0, parity=serial.PARITY_EVEN, bytesize=serial.EIGHTBITS)

while True:
    bytesArr = ser.read(5)
    if bytesArr:
        buffer = bytesArr.decode("ascii", "ignore")
        print(buffer)  # send this string

The problem is that after run() nothing is executed, how do I send a buffer when requested from a client?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question