Why and How to run a web app on Android
Why run a web app on Android you might ask.
When I am travelling my second phone is always on and is capturing data (time, gps, ODB via bluetooth etc). Along with mobile I would love to have a couple of ESP8266/Sensor combo devices to capture data on the go. I don't want them to have any storage. Instead they push data to the network. But while on the go internet is extremely patchy. So best option would be to store on a local server and sync when required.
ESP8266 knows to talk HTTP. So the idea is to create a local network by enabling tethering on Android phone. Also run a simple restful api server on Android. Then all ESP8266s can connect and push data using standard HTTP. Best part is I know how to talk in HTTP. So its easy to code and maintain. Another advantage is Unlike Bluetooth or other protocols, HTTP server can receive/send data from multiple services simultaneously.
So all I need is an android app which would receive http requests and store the data in a database. It would be great if that app exposes the Android sensor api to the script.
So for example when a ESP8266/Temperature sensor sends a temperature data point on a web service to the Android App. App receives it, it also gathers Time-stamp, Location from Android api and stores it in DB. At the end of the trip I just download/export the DB. Makes sense?
Using an Android phone/App combination is easier than building a custom hardware.
The setup structure would be
I am still exploring the options. But the following two options are promising. They aren't perfect but they are close. If you know any app that does this well. Leave a comment.
Palapa Web Server
Palapa Web Server is a pre-configured single app LMP (Lighttpd, PHP, MySQL) stack for Android. It doesn't need root access.
It's a standard LAMP like stack. I did setup a very basic RESTFul API using ArrestDB. ArrestDB is a simple PHP frame-work to create RESTFul APIs based on database tables, in our case MySQL. The setup did survive the load testing.
There are a couple of issues with this setup. Lack of API access to android sensors is a big deal. Also running full stack AMP stack seems like an over kill for the job.
All I need is a long running python/lua script which can access sqlite and android sensors.
QPython
QPython - Python on Android. QPython includes Bottle framework as it's WEB framework. You can install it from QPypi. You can also install any pip package. It comes with sqlite support. It also includes standard SL4A API (Battery, Bluetooth, Camera, Location, Sensor, Media Player, Media Recorder, Wifi, Text To Speech, Speech Recognition etc).
QPython looks like something made for my requirement. For last few days I have run tests. I am quite happy until now. In the coming week I want to run load tests and actually check the life of the web thread. Next Tuesday I will write another post with the details. Until then have fun exploring.
1 Response
[…] and How to run a web app on Android thejeshgn.com/2015/09/30/why… via […]