Last active
November 30, 2018 08:21
-
-
Save Hermann-SW/fbedf1c6c4d9781ab7c897756bead886 to your computer and use it in GitHub Desktop.
Node.js script allowing for remote MicroPython command execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
Two related postings here:
https://forum.micropython.org/viewtopic.php?f=16&t=5572&p=32255#p32252