Looking for guidance: Sending real-time samples from ESP8266 to Android Device - Page 1
Forum section: electronics / general

author: TimNJ
author_rank: Super Contributor
timestamp: December 01, 2016, 06:51:03 pm
content: Hi all,I'm not looking for a complete solution but rather some pointers to more information as I have almost no experience with networking. I'm going to be collecting data with an Arduino compatible board at about 1kSa/s @ 12-bits/Sa so I need around 12kb/s throughput. I have no interest in connecting to the Internet (for now), rather I just want a direct bi-directional wireless serial link between an Android device and an Arduino connected to an ESP8266. I'm choosing WiFi over Bluetooth for its range, larger bandwidth, and lower cost. I may also want to alter the project to have multiple sampling devices connect to a router at some point.The problem is, I'm not too sure how to go about this. For the last couple of weeks, I've been trying to learn more and more about networking and the ESP8266 in particular, but most examples are IoT related where a web server pings the client every so often for an update and the data gets sent to a website like Thingspeak. I know this is a pretty vague question, but I'm looking for some general thoughts or some pointers to projects or literature on the topic. Any ideas? Thank you.

author: EBRAddict
author_rank: Contributor
timestamp: December 01, 2016, 07:33:32 pm
content: If it was me, I would start with setting up a TCP (or maybe UDP) client on the Android device to receive TCP messages from the ESP8266.

author: TimNJ
author_rank: Super Contributor
timestamp: December 01, 2016, 08:34:57 pm
content: Quote from: EBRAddict on December 01, 2016, 07:33:32 pmThanks. I think I really need a crash course in the internet protocol suite.

author: Buriedcode
author_rank: Super Contributor
timestamp: December 01, 2016, 09:44:02 pm
content: I recommend websockets. Perhaps even node.js, but for the esp8266 side of things websockets can easily be implemented and I believe can stream data fairly efficiently.In terms of just sending it over wifi, you could just set up a basic server on the esp, and access it from your phone using a generic webpage or your own app. Doing it by a webpage makes the phone side much easier - you just connect to the device when its set up as a wifi AP, open up browser, enter the ip of the device, and there it is.

author: cravenhaven
author_rank: Contributor
timestamp: December 01, 2016, 11:08:30 pm
content: Quote from: TimNJ on December 01, 2016, 06:51:03 pmAs I understand it, Thingspeak gets sent data from the device rather than polling for it. I'm sure there would be a max data rate and max data storage for the service, but a paid registration would probably alleviate most of that for you.

author: TimNJ
author_rank: Super Contributor
timestamp: December 02, 2016, 04:08:14 am
content: Quote from: Buriedcode on December 01, 2016, 09:44:02 pmThank you. I found this brief Sparkfun tutorial regarding creating a soft AP server:https://learn.sparkfun.com/tutorials/esp8266-thing-hookup-guide/example-sketch-ap-web-server.Looks like they did it by using the ESP8266 addon for Arduino, allowing you to program an ESP8266 board in the Arduino IDE. A client (PC, phone, etc) can access the page hosted by the ESP8266 if you navigate to its IP address...but that's most definitely HTTP, not WebSockets. WebScockets's low overhead and low latency performance seems ideal.Found this project:http://www.whatimade.today/esp8266-on-websockets-mdns-ota-and-leds/Looks like someone made a WebSockets library for ArduinoStill so much to learn including how to use WebSockets in an Android app.Thanks to all. I really appreciate it.

author: Harvs
author_rank: Super Contributor
timestamp: December 02, 2016, 09:51:51 am
content: I guess I would go about this the other way.Set up the ESP in Station mode, and put a simple TCP socket server on it. Talking over sockets is similar to a serial port once they're connected.Then write your Android app to connect to the socket and do whatever you want to do.Fundamentally they're similar ways of achieving the same thing, neither is significantly more difficult than the other if you don't know either yet. Depends on whether you want the portability of a web app (i.e. it'll work on pretty much any system with a modern browser), or the system integration (and system resources) a native Android app offers.

author: TimNJ
author_rank: Super Contributor
timestamp: December 02, 2016, 02:14:12 pm
content: Quote from: Harvs on December 02, 2016, 09:51:51 amThanks. While I know sockets and WebSockets are fundamentally different (according to some answered questions on StackExchange), are you suggesting to use plain old TCP sockets instead of WebSockets?I can't say I'm well versed on either, but WebSockets seems like it would be a good idea. Any reasons why or why not?Thanks again.