I want to write an app that receives data sent by ESP-01 8266 and that ESP-01 is connected to the same phone hotspot. What is best way to achieve this?
-
which data yhou want to receive? Can't you do it using regular connection to your esp-01 8266 IP? – Vladyslav Matviienko Dec 19 '16 at 08:45
-
@VladMatvienko actually the esp-01 sending the data of sensor(3 axis of accelerometer).but i can't understand what do you mean of regular connection. – Muhammad_08 Dec 19 '16 at 08:49
-
using which protocol does it send data? – Vladyslav Matviienko Dec 19 '16 at 08:50
-
@VladMatvienko by default we using http protocol. – Muhammad_08 Dec 19 '16 at 09:01
-
ok, in HTTP there is a client and a server. Which device is a server, and which is a client? Do you request data from that device, or it connects to the phone itself? – Vladyslav Matviienko Dec 19 '16 at 09:03
-
@VladMatvienko As mentioned in picture mobile is acting as receiver and Esp-01 acting as sender and no the app not requesting to device. – Muhammad_08 Dec 19 '16 at 09:07
-
that isn't possible with http I think. There always is a server and a client. Client initializes connection, server accepts connection. Client does request, server sends response – Vladyslav Matviienko Dec 19 '16 at 09:37
-
@VladMatvienko which protocol suitable for this application and that is also faster suggest me please. – Muhammad_08 Dec 19 '16 at 09:41
-
there is no *best protocol*. It's all up to which protocols does your `esp-01` support – Vladyslav Matviienko Dec 19 '16 at 09:42
-
@VladMatvienko esp-01 p2p and Tcp/ip protocol are supported – Muhammad_08 Dec 19 '16 at 09:57
3 Answers
First, you need to setup your ESP as a client (ST_MODE). If you don't know how to do it, you should read this ESP8266 module tutorial first. Then, on your Android device, you can install an application called Pushbullet. After that, setup an account free on pushbullet website, setup a new notification channel and start sending HTTP requests to that channel from your ESP8266-01. You should receive data sent from ESP8266 as notifications in real time on your smartphone. This is the fastest way :)

- 41
- 1
- 6
-
how can one use the cloud if the phone is the AP (nothing mentioned about tethers) – dandavis Dec 22 '16 at 03:57
I have used UDP to transmit data to apps from ESP8266. Using UDP means the data may get lost but the coding requirements are much easier (no hand shakes).
Have a look at this page which goes through all the steps. UDP on the ESP01
You wil lneed to change the section "UDP Receiver" as that shows code for a Windows UDP receiver and you would need to create an Android UDP receiver.

- 8,342
- 6
- 37
- 63
I have used a simple httprequest from Android phone to ESP8266. Open/close door application.
Android Java code detail as follow:
private void openCloseDoor(final String requestURL) {
reply = "";
new AsyncTask<Object, Void, String>() {
@Override
protected void onPreExecute() {
dialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
dialog.setMessage("Send command to door ...");
dialog.show();
}
@Override
protected String doInBackground(Object... params) {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(requestURL);
try {
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inputstream = entity.getContent();
BufferedReader bufferedreader =
new BufferedReader(new InputStreamReader(inputstream));
StringBuilder stringbuilder = new StringBuilder();
String currentline = null;
while ((currentline = bufferedreader.readLine()) != null) {
stringbuilder.append(currentline + "\n");
}
String result = stringbuilder.toString();
reply = result;
inputstream.close();
}
} catch (NetworkOnMainThreadException ne) {
String err = (ne.getMessage() == null) ? "Network" : ne.getMessage();
Log.e("openDoor", err);
reply = err;
} catch (MalformedURLException me) {
String err = (me.getMessage() == null) ? "Malform" : me.getMessage();
Log.e("openDoor", err);
reply = err;
} catch (ProtocolException pe) {
String err = (pe.getMessage() == null) ? "Protocol" : pe.getMessage();
Log.e("openDoor", err);
reply = err;
} catch (IOException ioe) {
String err = (ioe.getMessage() == null) ? "IOError" : ioe.getMessage();
Log.e("openDoor", err);
reply = err;
}
return reply;
}
@Override
protected void onPostExecute(String result) {
if (dialog.isShowing()) {
Log.v("openDoor", reply);
statust.setText(reply);
statust.setTextColor(getResources().getColor(R.color.lightGreen));
dialog.dismiss();
}
}
}.execute();
}
Call function example:
openCloseDoor("http://your domain or ip:port/command");
ESP8266 code:
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
const int LED_PIN = 16;
IPAddress ip(192, 168, 0, 32);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
WebServer server(9999);
void handleRoot();
void handleNotFound();
void handleRelay();
void setup(void){
WiFi.config(ip, gateway, subnet);
WiFi.begin("...","...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
server.on("/", HTTP_GET, handleRoot);
server.on("/<id>", HTTP_GET, handleDoor);
server.onNotFound(handleNotFound);
server.begin();
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
Serial.begin(115200);
}
void loop(void){
server.handleClient();
}
void handleDoor() {
digitalWrite(LED_PIN, HIGH);
// Send door code ....
server.send(200,"text/plan","OK");
delay(500);
digitalWrite(LED_PIN, LOW);
}
void handleRoot() {
digitalWrite(LED_PIN, HIGH);
server.send(200, "text/plain", "Ready");
digitalWrite(LED_PIN, LOW);
}
void handleNotFound(){
server.send(404, "text/plain", "404: Not found");
}

- 16