Open Spiritdude opened 8 years ago
http://Kore.io would be a good candidate for the programming framework, all in C and portable, I'm using it in other embedded projects and works fine and is well documented. I am not aware of the status of higher language interpreters implementations in termux.
This is exactly what I was planning to do with this API! But I don't know C so I'll try to do it in nodejs
If you're using node js you can throw something like this together in literally a few minutes with node-red. Install / run, drag an http node onto the canvas, and use the exec node to execute commands.
Sounds like a good suggestion! We could create a termux-api-server
package, which can depend on what's needed (perl/node/...). Perl is a bit heavyweight as a dependency. Something in go would be nice (as it compiles to a executable without runtime dependencies), but node is fine too.
I gave it a go https://github.com/imikod/termux-api-server
I like to make/have termux-api available via REST, for example:
Android:
PC:
retrieves JPEG direct
retrieves JSON
etc. essentially
http://x.x.x.x:port/(\w+)?(.+)
->termux-$1 $2
(with some proper argument parsing)Question: what would be the easiest way (programming framework) to implement this lightweight http server providing the functionality?
I quickly coded (2hr) perl script which implements basic web-server which calls termux- (with simple argument parsing) and takes output to return to http GET request, yet, it might be more suitable to use termux-api.c direct and put a small web-server into it, which connects to the internal API instead via termux- -> termux-api -> am -> tcp.
I like to probe multiple android phones for battery info (actually the battery temperature is what I care about) and take photos via REST, turning Android smartphones into IoT devices.
My quick hack does this, accessing http://192.168.2.100:8091/ gives an overview of the services:
with
Content-Type: text/html
, each service listed is a link.and http://192.168.2.100:8091/battery-status:
with
Content-Type: application/json
and CORS set so XHR JavaScript requests can be made.