
Ask HN: Best way to input data to a RasPi, from browsers on the same LAN? - terrantech
I was originally thinking of making a Python&#x2F;Flask or PHP web app that can take form field inputs and then run a subprocess to run the command, with the inputted data as argument values.<p>Eg I can input &quot;microsoft.com&quot; into a form field (or passed in the URL like http:&#x2F;&#x2F;raspi&#x2F;pingapp&#x2F;microsoft.com), and the RasPi runs &quot;ping microsoft.com &gt; microsoft.txt&quot; in Raspbian (not that exact command obviously, but it&#x27;s the best way to explain it).<p>Ideally they&#x27;d then see the progress and output of the command in their browser, after submitting.<p>This won&#x27;t have public access, so auth&#x2F;security is not a concern. Pretend every user is 100% trusted, and data does not need to be cleaned or checked in any way.<p>I&#x27;m open to any language, tool, or framework. I just want it to be as light and reliable as possible.<p>Anyone got any ideas? Thanks.
======
chatmasta
If you want to run commands on the raspbi from the web, you have lots of
options. The question is if you want to send the commands literally to the
terminal, or have some preprocessing step in between?

If you want to have a preprocessing step, then you need an API to take the
commands, process them, run them, and then return the output. If you want to
stream the output, you should look into something like websockets. There are
also libraries built specifically for streaming logs to the browser, e.g. [0]

But might I suggest a simpler approach? How about a JS terminal emulator that
is SSHed into the raspberry pi? I've used a library called "wetty" [1]
successfully in the past. It's a node server + JS terminal emulator (based on
hterm, used in chromebooks). The node server SSH's into the target box on
behalf of the client, and then forwards the tty over the link `client <->
server <-> ssh <-> target`. All you need to do is install the node server on
the pi and have it SSH into localhost.

[0] [https://github.com/mthenw/frontail](https://github.com/mthenw/frontail)

[1]
[https://github.com/krishnasrinivas/wetty](https://github.com/krishnasrinivas/wetty)

~~~
terrantech
Thanks so much, I'll play with both of those options.

------
artpar
Hey I am building daptin. I have chosen golang so that it can run on raspi (or
any target).

I haven't personally tried it on raspi yet since I don't have one, but I
invite you to give this a try

If I understand correctly you should be able to run the arm7 static build
directly

You can find the docs here at [https://docs.dapt.in](https://docs.dapt.in)

There is a nice dashboard accessible over the web which you can completely
protect after signing up on it. Daptin is completely standalone and can work
offline (doesn't load any asset from internet as such, everything is packed
in). You can reach me out via my github profile.

[1]
[https://github.com/daptin/daptin/releases/tag/v0.6.8](https://github.com/daptin/daptin/releases/tag/v0.6.8)

edit:

a little bit more details of how you would build what you asked

\- create a subsite exposing html form

\- use js to call daptin api

\- daptin creates a sqlite db (unless configured otherwise)

\- share subsite address with users

\- take dump from admin dashboard

~~~
ultrasounder
This sounds very interesting and the timing couldn't be perfect. How does your
dashboard differ from the freeboard.io that was referenced below?

~~~
artpar
Don't see freebord referenced in this thread, but I just checked out what
freeboard is. Seems like freeboard can consume a data source and make graphs
out of it. It needs a data source to push data to it I guess. Freeboard looks
more in the direction of plotting readily available data from one source.

Daptin on the other hands manages your database, build REST/Graphql APIs which
you can use from any page and provides automation using actions/outcomes.

------
IpV8
I've done similar things with python/flask. My experienced tip, if you try to
do an ad hoc network and have people connect to that without passing the
internet through, prepare to get f'd by apple:
[https://discussions.apple.com/thread/7705927?page=3](https://discussions.apple.com/thread/7705927?page=3)

If you want to host it on the lan just play with IPtables to get your port
through and host a little web server. Shouldn't be too complicated. Look in to
gunicorn for a production capable flask server. I have used Monit to keep
gunicorn alive as a second line of defense. You could use init instead if you
prefer.

If this is over your head let me know and I can break it down to more detail.

------
h-c-c
Check out MQTT and Adafruit.io in particular. The cool thing about MQTT is
that your device is reachable behind NAT. I'm doing pretty much exactly what
you describe here with this IOT-lamp project.

[https://github.com/h-c-c/IOT-LAMP](https://github.com/h-c-c/IOT-LAMP)

I set up a 'util' feed for system commands and have implemented a shutdown
routine so far. I send my lamp commands with Google Assistant through IFTTT.

~~~
terrantech
That's really cool. Considering I just need the same command to run each time,
with a different value passed to it, I could see this working the same as this
(and the idea of being able to tell my Google Home to do it is pretty
awesome!). I'll have a play, thanks.

------
kejaed
I used Remi for a web based GUI on an rpi and it worked great.

[https://github.com/dddomodossola/remi/blob/master/README.md](https://github.com/dddomodossola/remi/blob/master/README.md)

------
icedchai
PHP. No framework is needed. Just use "system" and flush the output.

------
billconan
why not using [https://www.tecmint.com/cockpit-monitor-multiple-linux-
serve...](https://www.tecmint.com/cockpit-monitor-multiple-linux-servers-via-
web-browser/)

it has a terminal you can remotely run anything.

------
Petrakis
[https://github.com/jheising/HAPI](https://github.com/jheising/HAPI) or REST

~~~
terrantech
I thought about doing an API, but is that really the easiest way to run a
single command and get a single input? Seems like overkill.

~~~
Petrakis
Then Websockets. There are few python implementations of websockets module,
this is one of them
[https://pypi.org/project/websockets/](https://pypi.org/project/websockets/)

