Send data with ESP8266 to android app

As final year project im making an app that can read data from sensors that are connected with the arduino uno is it possible to send the data to the app with wifi and use the ESP8266?
Goes this directly?
Afterwards the data will be displayed on a map of google maps because every sensor
corresponds to a specific location on the map.
So you can always give some tips for programs to write this app to.
Thanks a lot!
PS is there also a possibility to use mobile internet instead of Wi-Fi?

If you go the WiFi route, consider dropping the Arduino part and connect your sensors straight to the ESP8266. Make your project a lot simpler.

Mobile Internet I suppose is possible - there are various GSM shields and GSM adapters out there, look into them.

I forgot the name, but recently on this forum a long-distance wireless network was mentioned. Covers most of Europe now. Low power, low speed, designed for projects that are installed in remote areas and need to regularly send out sensor data or so. This may be a good solution for your project, much cheaper and better coverage than mobile networks and you probably don’t need high speed network connections anyway.

Did you get any tutorial on how to send data with esp8266 to android app? I only found tutorials on sending data to website/internet. I just need to send the data only via local network. Thanks a lot in advance

You can easily set up a web server on the ESP8266 and then have the Android app request data from that server: just send a POST or GET request to the ESP and have its server handle the request, then send back the data, e.g. as JSON string in the body of the http response. This is pretty straightforward to set up, but note that you're not sending data from the ESP to the Android app, but it's the Android app requesting data from the ESP. A little Google should get you all the tutorials you need on how to set up the two sides.

If you really need the ESP to send data to the Android side, you'd have to open some kind of service on the Android that listens to incoming requests, then have the ESP send requests to that service. I've never tried doing it that way around, can't even suggest specific protocols. You'll have to do your own homework there.

If you want to send a lot of real-time sensor data over WiFi, consider using the WebSocket protocol. I've used it successfully for sending real-time controls to an ESP8266 vehicle and for receiving real-time wireless "oscilloscope" data from the analog input of the ESP. I had a team member write most of the java (Android Studio) code but I remember having trouble connecting at first. Specifying the protocol version ("Draft 17", IIRC) in the Android app solved it, and it worked great.

You could probably use cellular data, and set up a WiFi hotspot on the phone. Then have the ESP connect (as a station) to that hotspot. You'll have to check if Android apps have direct network access to stations connected to the hotspot. There's going to be some NAT involved.

A Beginner's Guide to the ESP8266


the post is some day ago but this “theme” is everlasting i guess - this is how i do this currently.

in my setup i have running severals ESP8266 ( node mcu lua )… the mcu´s are collecting lots of data.
Target is was to have this data in an MS SQL Database…This way other applications ( e.g. Desktop, Android APP,… ) easily can retrieve or access those data.

esp8266 - how to send this data to the implemented IIs Rest API:

here is the significant esp code ( sniplets ) to send Data to the rest API :

#include <Arduino.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include “WiFiManager.h”
#include <osapi.h>

const char* mySSID = “csfcdcc”;
const char* myLANpw = "mypojawoll;
String hostIP = “192.14.xxx7111.69”;
String myRESTapiCALL = “”;

int sendDataPack()


if (WiFi.status() !=
WL_CONNECTED) { // FIX FOR USING 2.3.0 CORE (only .begin if not connected)
WiFi.begin(mySSID, myLANpw); // connect to the network
Serial.println(“login into AP…”);
while (WiFi.status() != WL_CONNECTED) {
// Blink the LED
digitalWrite(2, ledStatus); // Write LED high/low
ledStatus = (ledStatus == HIGH) ? LOW : HIGH;
Serial.print("setup()/500erLoop/Waiting for connection/ new Wifi-State: ");

String jsonPayload = “”;
int httpCode = 0;

restArray[ri] = data4RestService;

// chunks are now ALL in the array and we loop through it

if (WiFi.status() == WL_CONNECTED) { // Check WiFi connection status
Serial.println(“WiFi.status(): WL_CONNECTED - OK”);
HTTPClient http; // Declare object of class HTTPClient

// now we need to chunk the payload into 1000 byte chunks
for (int i = 0; i <= ri; ++i) {
Serial.print("for(int i = 0; i <= ri; ++i) / LOOP / i = “);
jsonPayload = “{“data”:”” + restArray + “”}";
_ Serial.println(restArray*);_
http.begin(myRESTapiCALL); // Specify request destination*_
* http.addHeader(“Content-Type”, “application/json”);*
* httpCode = http.POST(jsonPayload);*
* if (httpCode >= 200 && httpCode <= 300) {*
* Serial.print("sendDataPack()/MobileDeviceData ok: OK…/ httpCode = ");*
* Serial.println(httpCode);*
* } else {*
* Serial.print("sendDataPack(): recursive Loop…call again sendDataPack() E R R O R - httpCode: ");*
* Serial.println(httpCode);*
* if (recursiveLoopCounter < 3) {*
* recursiveLoopCounter++;*
* ri = 0;*
* data4RestService = “”;*
* memset(restArray, 0, sizeof(restArray));*
* Serial.print( "sendDataPack(): recursive Loop…: recursiveLoopCounter= ");*
* Serial.println(recursiveLoopCounter);*
* delay(500);*
* sendDataPack();*
* } else {*
* ESP.restart();*
* }*
* }*
* http.end();*
* }*
* ri = 0;*
* data4RestService = “”;*
* memset(restArray, 0, sizeof(restArray));*
* } else {*
* Serial.print("Error in WiFi connection: ");*
* Serial.println(WiFi.status());*
* returnResult = WiFi.status(); // in case of failure …quick led flashing*
* }*
RESTapi written in VS … there are many option on how to setup a restService …Code from above with minimal adaption also can be unsed with a normal webService!
1. We set up the IIS on windows 10 …i followed just this video
How To Install IIS in Windows 10 - YouTube
2. I create this simple hallo world REST-API application / Rest1 - WAS so much helpful for me !!::
REST Intro - Data Model - Build a REST Service in Visual Studio 2015 Part 2 - YouTube
Now to your Question on How to access ESP8266 Data from an Android APP. Once the MCU-Data is Stored vis REST in the MS SQL-DB via REST - Access from Android is very easy and flexible:
Android APP / js + bootstrap + cordova
some important in index.html:
* *
* *
* *

* *
* *
…this is the snipplet on how to RETRIEVE DATA from the Rest-API-Service
// get Data from the WebPage from the iCounterBOX-AP…java-script…
// Make the actual CORS request. OK!! Arsch gerettet !! -
// Create the XHR object.
function createCORSRequest(method, url) {
** var xhr = new XMLHttpRequest();**
** if (“withCredentials” in xhr) {**
** // XHR for Chrome/Firefox/Opera/Safari.**
**, url, true);**
** } else if (typeof XDomainRequest !== “undefined”) {**
** // XDomainRequest for IE.**
** xhr = new XDomainRequest();**
**, url);**
** } else {**
** // CORS not supported.**
** xhr = null;**
** }**
** return xhr;**
function makeCorsRequest4WebPageData() {
** url = “http://” + “1xx.1xx.4.1/read”; //**
** var xhr = createCORSRequest(‘GET’, url);**
** if (!xhr) {**
** console.log(“CORS not supported”);**
** return;**
** }**
** // Response handlers.**
** xhr.onload = function () {**
** var text = xhr.responseText;**
** // empfangenen String etwas säubern CLEANING…**
** text = fkt.replaceAll(text, “\n”, “”); // !! REPLACE ersetzt immer NUR den zuerst gefundenen !! **
** text = text.replace("", “”);
text = text.replace("", “”);
text = text.replace("", “”);
text = text.replace("{", “”);_

text = fkt.getStringTillSubstr(text, “}”);**
** var index = text.indexOf(‘WAIT’);
if (index !== -1) {
// Noch keine Daten Da - Nichts machen…Nichts Speichern…
} else {_

fkt.setLoadMessage(text); // Bring this data into the RAW data TextAREA-LOG **
** //data is ok and we bring this into an ARRAY - would do this today with other? JSON functions!!
currentMACdevices = text.split("|");
var totalNrdeliveredCIs = currentMACdevices.length; // for some console.log and statistics
//document.getElementById(“apCounter”).innerHTML = totalNrdeliveredCIs; _

writeCounterBoxDataIntoDB_consolitated(currentMACdevices); // write 2 sqLite (Android )
** console.log(“xhr.responseText: \n” + text);

** xhr.onerror = function () {**
** console.log(“Woops, there was an error making the request (AP).”); **
** fkt.setLoadMessage(“xhr.onerror / AP request Fails / CORS(xHrsScan) /(AP) - Err getting data from iCounterBOX”); **
** };
return 0;

This was ESP 8266 — > REST ----> Android App
As always there are so many trails going to rome…
Your other question concerning GSM instead of wifi…have a look to

1 Like

Kina, check this line of code you posted compared to your actual line of code:

jsonPayload = "{\"data\":\"" + restArray + "\"}";

Is anything missing? I think it probably is. This is exactly why you should post code using code tags, according to the guidelines in the forum sticky post.