Author Topic: Looking for guidance: Sending real-time samples from ESP8266 to Android Device  (Read 4966 times)

0 Members and 1 Guest are viewing this topic.

Offline TimNJTopic starter

  • Super Contributor
  • ***
  • Posts: 1656
  • Country: us
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.
 

Offline EBRAddict

  • Contributor
  • Posts: 26
  • Country: us
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.
 
The following users thanked this post: TimNJ

Offline TimNJTopic starter

  • Super Contributor
  • ***
  • Posts: 1656
  • Country: us
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.

Thanks. I think I really need a crash course in the internet protocol suite.
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1611
  • Country: gb
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.

 
The following users thanked this post: TimNJ

Offline cravenhaven

  • Contributor
  • Posts: 40
  • Country: au
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.

As 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.
 

Offline TimNJTopic starter

  • Super Contributor
  • ***
  • Posts: 1656
  • Country: us
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.


Thank 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 Arduino  :-+ Still so much to learn including how to use WebSockets in an Android app.

Thanks to all. I really appreciate it.
 

Offline Harvs

  • Super Contributor
  • ***
  • Posts: 1202
  • Country: au
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.
 
The following users thanked this post: TimNJ

Offline TimNJTopic starter

  • Super Contributor
  • ***
  • Posts: 1656
  • Country: us
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.

Thanks. 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf