Control ESP8266 Over the Internet (from Anywhere)

278,061

699

122

Introduction: Control ESP8266 Over the Internet (from Anywhere)

There are but a few things better than (succesfully) programming and using your Arduino. Surely one of those things is using your ESP8266 as an Arduino with WiFi!

In this instructable I will show you an EASY way to get the ESP8266 working as a web server AND accessing that server from anywhere (over the internet)

Also if you find this instructable interesting, perhaps you'll like some of my others:

EASY Arduino OLED sensor data display

How to make a high voltage power supply

How to send data from Arduino to excel (and plot it)

How to display Arduino sensor readings on Nokia 5110 display

Step 1: What You'll Need:

Since the esp8266 NodeMcu is so cheap, I highly recommend buying one. You can simply plug it into your PC and use it as an Arduino. No weird commands or anything "unknown".

Step 2: Arduino IDE+ESP8266:

-Open up the Arduino IDE

-Go to File->Preferences->Additional Boards Manager URLs: http://arduino.esp8266.com/stable/package_esp8266c... ->click OK

-Close the IDE and open it up again

-Go to Tools->Board (where you'd select your version of Arduino)->Boards Manager, find the ESP8266 and click Install

You now should be able to use the ESP8266 as an Arduino. Simply select the NODEMCU 1.0 as your board and you should be ready to code. (if it doesn't work, try the 0.9 version)

Step 3: "Arduino" Code:

Since the code gets messed up when pasted, I have included it as an txt file. Download it and paste it into your Arduino IDE.

The code is commented, so you should have no trouble understanding what to change to suit your needs.

Step 4: Access From Anywhere:

First you need to go to www.whatsmyip.org and copy your IP.

You should now open up your router settings. (google how to do this for your router) Open up your browser and type in the address for your router. There you will find some settings, including something along the lines of Forwarding or port forwarding.

The important thing to note here is the "Service port" and the "IP address".

In "Service port", you should type the port that you specified in your Arduino code. (mine was 301)

In "IP Address", you should type: IP(from whatsmyip) : ServicePort

so it should look something like xxx.xxx.xx.xx:301

Just leave the other settings on Default. (or check how to port forward for your router)

Step 5: What Now???

Now...just type the xxx.xxx.xx.xx:301 into your browser and you should have a basic webpage with two buttons on it. I'm sure you can figure out how to use those.

You can type the address into your cellphone while away from home and access the ESP8266 that way. Perhaps instead of turning an LED on and off, try telling it to turn on your AC on those hot summer days.

If you enjoyed this Instructable, consider visiting my Fundrazr page here. And of course, share.

5 People Made This Project!

Recommendations

  • Fabric Challenge

    Fabric Challenge
  • Meatless Challenge

    Meatless Challenge
  • Eggs Challenge

    Eggs Challenge

122 Comments

0
letuantam96
letuantam96

Question 4 years ago

please help. i follow the instruction but nothing happen

when i try connect to the xxx.xxx.xx.xx:301 it say: "This site cant be reached!"

thanks very much!

Screenshot_20180408-175829_LI.jpg
0
j-marct
j-marct

Reply 7 days ago

bonjour
utilise le port 80 sa fonctionne trés bien

0
PraveenS90
PraveenS90

Answer 4 years ago

when u say whats mi IP, this value will changed everyday, since it is dynamic IP . if you want to have same IP every time then go for static IP by simple paying little to ISP provider/internet provider.

0
MANMOHANS9
MANMOHANS9

Answer 4 years ago

Follow the below setting

1 Make sure you have forwarded the right port, double check that you mentioned same port number in sketch and Router setting as well.

2 Check that you mentioned the correct IP address of your wemos in router setting

Lets say Wemos IP address is 192.168.0.323

and port number you mentioned in sketch is 301

so set them in router setting according to following way:

Service port 301

internal port 301

IP address 192.168.0.323

protocol all

status enable

after completion of these settings check the wan ip address of the router which also can be found by writing "what is my IP address" on Google

After finding that copy this IP address and paste to browser followed by semicolon and port number

lets say you found 34.56.23.67

Then paste it like 34.56.23.67:301

I hope it will help you

0
letuantam96
letuantam96

Answer 4 years ago

my Virtual Server setting:

Untitled.png
0
j-marct
j-marct

Question 7 days ago on Step 4

bonjour
comment changer la taille du text sur le site web
dans le programme arduino
merci d'avance

0
RossRobotics
RossRobotics

7 months ago

This tutorial only enables you to access the ESP8266 over a closed network. It does NOT let you control it from the internet. Notice the IP address in 'Step 4...', that is a network IP, not an internet IP. Not sure why he blacked out the last number since you can't access it anyway.

0
Crtekkk
Crtekkk

Reply 7 months ago

Nope. That's the whole point. From anywhere=any network, anywhere

0
J MUKUNTH
J MUKUNTH

Question 1 year ago

Do I want to enter my laptop IP or ESP IP..?

0
Jugaad it yourself
Jugaad it yourself

2 years ago

I have a questions,will this work on dynamic IP?

0
phanhuyvinh858
phanhuyvinh858

3 years ago

Hi, I tried to use the IP address from whatsmyip to fill in the IP address blank but I received an error. how can i fix itError code: 26106The IP address is not in the same subnet with LAN IP address.

0
BackwardsDave
BackwardsDave

Reply 2 years ago

He made a mistake. You are meant to put in the IP address of your ESP8266. For me it was 10.1.1.172. After you've uploaded the code to your device, you should be able to find your device's IP address in the drop-down when you start typing the IP address (start with the first few digits of your router's IP address). Otherwise look for a section called "connected devices" to find your device's IP address. Then when you try to access http://<your public IP address>:301 it should forward the HTTP requests to your device.

0
ofekpl
ofekpl

Tip 3 years ago

Instead of forwarding ports to a static chosen IP, you can use the package TinyUPnP from the Arduino Library Manager (from within the Arduino IDE).
Code base: https://github.com/ofekp/TinyUPnP.
Hope it helps somebody.

0
sachitha_bandara
sachitha_bandara

Reply 2 years ago

Hi, its seems the link is not working now. could you please update it?

0
mostafa00hammad
mostafa00hammad

Question 2 years ago on Step 4

i didn`t understanding this point ... please help me!!

0
MahdiSK
MahdiSK

2 years ago

Thanks a lot for this lesson. I have a problem. I need to receive and send data in a same time. can anyone you help me?
Thanks a lot dear Friends.