Communication between Android app and Arduino with ESP8266-01

Hi all,

I would like to build an Adroid app (with MIT App Inventor) to send and receive some data to and from an Arduino project i have running. I have some ESP826-01 WiFi boards wich i would like to use for this communication.
I woud be happy to use this in my local WiFi network for now, but eventualy i would like to be able to communicate with the Arduino through the internet. But i guess that is a problem for later on.

The probem i have is that i know a bit of electronics, i can program the arduino (with help of tutorials and examples) and i can program a bit in MIT App Inventor (again with help of tutorials and examples). But i'm not able to set up the ESP8266-01 to do the job i need, i just don't know where to start or what the best approach would be.

I have done a lot of searching forums and google and there is a lot of information out there, i have made some progress but i seem to be stuck at the moment (probably using the wrong things to search for)...

So far i have things working one way (from the Arduino to the Android app) but i have no clue how to get some data back from the Addroid app to the Arduino. Again this is probably because i'm using the wrong methode or i am overthinking the whole thing.

At the moment i have the ESP8266 connected to anArduino Nano (clone) , i have the Arduino set up a webserver on the ESP8266 andd send a plain text http page to the ESP8266. When i open the webpage on my laptop i can see the string i send and in the Android app i can read that string and display it there. I'm just not able to have the Android app change the web page on the server so the Arduino can get the new data (if this is possible at all).
For this i used the "Webserver" example from the "WifiEsp" library, i have only remarked out most of the webpage so i can send just the plain text.

The Arduino project is a chicken coop door.
There is one LDR and when it gets dark enough, the door closes, the next morning the door opens when it is light enough. There are 3 led's for door open, door closed and door error.

I would like the Android app to be able to show me if the door is open, closed or in error and the current vallue of the LDR and the LDR-vallue i have set to close the door.
Then i would like the Android app to be able to send the command to manualy close or open the door now and set a new vallue for the LDR for when to close the door.
So i think i need the Arduino to send 4 and receive 3 variables to the android app and the other way around for the Android app.
I think i can just send and receive 1 string back and forth with all variables in there like (1:25:364) and cut them up in the code of the Arduino and Android.

I have no experience with wireless communication or internet protocall (if i'm using the correct words here?!?), exept for a very simple and basic HTTP webpage i once made many-many years ago. So i think i'm overthinking this problem and there should be a much simpler solution for this.

Can someone please point me in the right direction to set up things to be able to send and receive data at both ends?
Maby give me some keywords to use to search for a solution?
I did find some solutions for this but they all use a cloud service or something but i do not want to depend on exteral services if this can be avoided.

Thank you for reading this and if you need any more information or details, please let me know.

Hi Ome,

if you are willing to invest €8,50 into a almost ready to use App you could use the pfod app
pfod stand for Protocol For Operations Discovery

http://forward.com.au/pfod/index.html

The controlling App is €8,50. The pfod-design-App is for free

In the design-App you can define the design of the screen that will be shown when you connect to the arduino
All the sending back and forth between your android-device and the arduino (in this case called a pfod-device) is handled by the libraries

The pfod-design-App creates the arduino-code that is the interface to your own arduino-code.
So pretty much the same as using any kind of library. You connect your Wifi-device to your local WLAN and voila
data can be exchanged between your android-device and your arduino-device.

This app allows only one device beeing connected to the arduino-device at a time.
Another approach might be using the telegram interface described by randon nerd tutorials

usually I ddon't advertise a certain product but this one I make an exception.
If somebody else is aware of a similar product please feel free to post it.

best regards Stefan

Thanks for the plug @StefanL38.
As the author of pfodApp, I can offer advise if you need help using pfodDesigner / pfodApp

Thank you for your reply and the two options Stefan
I will look these over to see if I can use this.
But to be honest, I would rather build something myself so I can learn how this works and I can re-use this for future projects.

@OmelJozz,
Suggest you skip the MIT App Inventor and just use web pages from a browser.
Use POST, have a look at the PostServer example that comes with ESP8266 install.

Thank you for your reply drmpf,

I think a browser will have to do for now, it seems like the most usable option at the moment.

I just keep thinking that there must be a simple way to do what i need:
Have an Android app send or request a string from the ESP8266, and have the Arduino do the same.

Would it be possible to flash a webserver (or a small database or something like that) on the ESP8266 in a way that both the Android and the Arduino can use this to exchange information?
Because like i have this setup now only the Arduino can manipulate the website on the ESP8266.
Just thinking out loud here...

Thanks

I just got a crazy idea, it might be a bit of a work around, but this just might give me the result i would like.

I just found a turorial for filling in a form on a website and even to click a button with a little java script.
I think i will try to see if i can build a simple website on the ESP8266 (through the Arduino) with some text input boxes and maby even a button and have the Arduino fill in these boxes with the data i would like to send to the Android.
Then build an app wich can read and write to and from these textboxes. I wil probably add 1 box for a number 0 or 1 to indicate if the information in the textboxes was send by the Android app or the Arduino.
Then (i still have to find out if and how i can do this last bit) Have the Arduino get the information back from the website.
This way i have the communication i need (i think).

Does this sound like something that could work or am i missing something here?

Thanks.

That is tried and true method and if you search you will find many examples of implementations.
For example look at my project Cheap/Simple Wifi Shield which includes a configuration webpage that collects network SSID and password from the user to connect to the network.

Just to make sure that you are programing the ESP-01 directly from the IDE using the ESP8266 core, and not using the nano for anything more than a USB programmer. If you are using AT commands on the ESP, forget it.

Would it be possible to flash a webserver (or a small database or something like that) on the ESP8266 in a way that both the Android and the Arduino can use this to exchange information?
Because like i have this setup now only the Arduino can manipulate the website on the ESP8266.
Just thinking out loud here...

Ah there is my answer. Yes you can flash a sizable website onto the ESP-01, you will have to install the core in the IDE, there is loads of space. question is really do you need to communicate with the arduino at all ? how many data pins do you need ? Regardless of that, your ESP should be the master (or well your android device should be the master, but the arduino should be the slave if it is anything unless you need either the SPI or the UART, but i don't think you do) and you should create a webserver on it. You can then either just log onto it and use a browser to visit the page (no need for any App) and/or create an App that does the browsing for you. (which can look more slick but is more work)

@drmpf,
Thank you for the example in the link you provided. I will have to take some time to read through this. I still have very little knowledge of of things like xml, Java, tcp/ip and more because I haven't worked with these things before. It's probably easier then I think, just need a little practice..

@Deva_Rishi,
Thanks for your reply.
Like I wrote above, I really need to learn more about communication with websites and servers but I'm trying to get there...
I think I still need the Arduino, as far as I know there are only 2 IO pins on the ESP8266-01. I have 3 led's, 1 LDR, 1 motor driver, 1 button and 2 ir sensors (for detecting the end points of the door) and maby want to expend on this in the future. So I'm afraid I will still need the Arduino.
And the app I want to build is indeed to make it look nicer. Not an absolute must have, but for the looks (and practice to learn even more).
I still don't understand every detail I get in this forum but it does give me some pointers what I can search for.

I have a bit of a busy life at the moment working for my boss and at home so it will take me a while to make the time to see where your information leeds me.

Thanks so far for the help, I'll let you know if I get where I want to be.

There are other ESP8266 boards that have more pins available. I use an Adafruit HUZZAH ESP8266 because it is easy to program via normal usb cable

Yes, I already got the feeling I was a little too cheap to go for the ESP8266-01 boards. I think I, ll look into some bigger models for future projects.
Only most bigger ESP boards I have seen usually have only 1 analog port. No problem for this project, but it does limit the options I think.

Only most bigger ESP boards I have seen usually have only 1 analog port. No problem for this project, but it does limit the options I think.

Not just most, but all of them have only 1 ADC, since the MCU only has one Analog pin (which on the ESP-01 isn't even exposed)The normal way to use it is to power the device that you want to get an analog reading, using a digital pin. (or enable it using a digital pin)

as far as I know there are only 2 IO pins on the ESP8266-01.

There are 4 pins, but you are using 2 of them for the UART. If you would only need 4 pins, you could forfeit the use of the UART.

So I'm afraid I will still need the Arduino.

Yep or a nodeMCU would do the trick, but i think you will manage with your current hardware. Mainly i suggest to let the ESP be in charge of controlling the Arduino and not vice versa. The ESP has a lot more memory and processing power. It will anyway take care of the UI. It can send and request values from the Arduino, and control variables that are only used by the Arduino itself, like that doorstoppers, can of course still be processed by the Arduino alone. I suggest you focus first on setting up a webserver on the ESP using ESP8266Webserver.h and the establish Serial communication between the 2 boards.

Thank you for the extra information Deva_Rishi.
I will start messing with the ESP and see where It gets me.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.