circuitpython/supervisor/shared/web_workflow/static/serial.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
797 B
JavaScript
Raw Normal View History

2022-06-29 19:31:55 -04:00
var ws;
function onSubmit() {
var input = document.getElementById("input");
// You can send message to the Web Socket using ws.send.
ws.send(input.value);
2022-07-06 20:05:14 -04:00
// output("send: " + input.value);
2022-06-29 19:31:55 -04:00
input.value = "";
input.focus();
}
function onCloseClick() {
ws.close();
}
function output(str) {
var log = document.getElementById("log");
log.innerHTML += str;
}
// Connect to Web Socket
ws = new WebSocket("ws://cpy-f57ce8.local/cp/serial/");
// ws = new WebSocket("ws://127.0.0.1:9001")
// Set event handlers.
ws.onopen = function() {
2022-07-06 20:05:14 -04:00
console.log("onopen");
2022-06-29 19:31:55 -04:00
};
ws.onmessage = function(e) {
// e.data contains received string.
2022-07-06 20:05:14 -04:00
output(e.data);
2022-06-29 19:31:55 -04:00
};
ws.onclose = function() {
2022-07-06 20:05:14 -04:00
console.log("onclose");
2022-06-29 19:31:55 -04:00
};
ws.onerror = function(e) {
2022-07-06 20:05:14 -04:00
// output("onerror");
2022-06-29 19:31:55 -04:00
console.log(e)
};