Node.js script allowing for remote MicroPython command execution
#!/usr/bin/env node | |
[scpt,pwd,host] = process.argv.slice(1); | |
cmd = process.argv.slice(4).join(" "); | |
out = 0; | |
last = ""; | |
if (process.argv.length < 5) { | |
console.log((require("path")).basename(scpt) + " pwd host cmd [...]"); | |
process.exit(1); | |
} | |
var ws = new (require('ws'))("ws://" + host + ":8266/"); | |
ws.onopen = function () { ws.send(pwd + "\r\n" + cmd + "\r\n"); } | |
ws.onmessage = function (ev) { | |
if ((last == "\r\n") && (ev.data == ">>> ")) { out = 0; ws.terminate(); } | |
if (out == 2) { process.stdout.write(ev.data); } | |
if (ev.data == "\r\nWebREPL connected\r\n>>> ") { out = 1; } | |
last = ev.data.slice(-2); | |
if ((out == 1) && (last == "\r\n")) { out = 2; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Two related postings here:
https://forum.micropython.org/viewtopic.php?f=16&t=5572&p=32255#p32252