繁体   English   中英

通过python在Web浏览器上显示arduino串行数据

[英]Display arduino serial data on a web browser via python

我希望从网络浏览器中显示Arduino的串行数据。

首先,我使用json格式的python将数据放在本地主机上

from bottle import route, run
import serial

dic = {}
ser = serial.Serial(port='COM6',baudrate=9600,timeout=None)

@route('/test')
def test():
    c = ser.readline()
    c = (str(c)[2:-5]) #just to get rid of the extra characters
    dic["val"] = c
    return(dic)

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

然后我继续使用javascript阅读它

function getArduinoVals(){
    $.getJSON("http://localhost:8080/test", function(data){
        $('#vals').html(data.val);
    });
    t = setTimeout("getArduinoVals()",50);
    });
}
getArduinoVals();

但是,它似乎没有从本地主机加载(我测试了其他URL)。 我该怎么解决这个问题? 谢谢!

您可以使用p5.js的p5.serialport来获取Web浏览器上的串行数据。 但是你必须在后面运行节点服务器。 https://github.com/vanevery/p5.serialport您应该检查github repo以开始使用p5.serialport。 p5.j​​s与arduino代码风格非常相似,因此它比python更容易和方便。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM