-->
Page 1 of 2

NodeMcu 1.0 project from local network to internet

PostPosted: Fri May 19, 2017 2:26 pm
by SurtrTech
Hello,
I'm working on a project using NodeMcu v1.0, It works fine in local network using my router, the project is that I have a temperature sensor wired to the board, then I get the value on my Android App whenever I press a button (Get data...).
Now I want to be able to do this over the internet (even if my phone and my board aren't connected to the same router).
I have no idea where to start, at lease I want to be able to do it from a webpage for now.
Thanks

Re: NodeMcu 1.0 project from local network to internet

PostPosted: Sat May 20, 2017 3:53 am
by Luc Volders
It is not really very complicated, but involves some steps that are router dependend so I can only give you the general outlines.

I am doing the same using ESP-Basic.
Now ESP-Basic generally uses port 80 for communication with the outside world.
So that means that any command you send to the ESP (or from the ESP) is coming from the following local IP adress

XXX.XXX.XXX.XXX:80

now your local IP adress is not available from the outside world.

You can only find your global ip adress.
You can find that by pointing your web-browser at:
http://whatismyipaddress.com/

Now you have to dig into the setting pages from your router.
Look at something calledport-forwarding.

There open a new port for the outside world.

In my router I have to give it a name. Next I give it the IP adress of the ESP and the ESP's port number which is 80.
Next I instruct it to send all communication from router port no 8081 to the ESP's port.

The router will most likely ask for a starting port number and an ending port number for your local and global ports. In both cases use the same. So Start local 80, end local 80, start global 8085 and end global 8081. You can use many numbers for 8081 but there are some restrictions. This allows you to open many specific ports for all kinds of projects.

That is it.

Now the only thing left is to instruct your app or whatever you are using to crontrol the ESP to send or get the info from:
http://www.YYY.YYY.YYY.YYY:8081

The YYY part is off course the global internet adress

Be aware however that opening a port in your router might bring some security issuses as you are opening your router to the world.

This way I have controlled my ESP from my work or many adresses on hollidays be it from a ESP-Web-page or a dedicated App adressing the ESP.
I am devellopping my apps with MIT Appinventor which is dead-easy.

I will be publishing some stories about writing dedicated apps for your ESP on my weblog shortly.
http://lucstechblog.blogspot.nl/

Luc

Re: NodeMcu 1.0 project from local network to internet

PostPosted: Sat May 20, 2017 7:08 am
by SurtrTech
Hello Luc,
Thanks for the reply, but the problem is that I will be always far from the NodeMcu board, which means if the router reboots I will not know about the board IP adress, also my project is about a door lock, so if someone know the IP adress of the board and have the same app he could send a command or something to break the security.
I want something like "Blynk": the board connect to a server and have an API key then I use that key on the Blynk app to control the board from anywhere.

Re: NodeMcu 1.0 project from local network to internet

PostPosted: Sat May 20, 2017 4:15 pm
by Luc Volders
Hey SurtrTech,

SurtrTech wrote:Hello Luc,
Thanks for the reply, but the problem is that I will be always far from the NodeMcu board, which means if the router reboots I will not know about the board IP adress.


If you give your ESP a static IP adress (can be done in the router) then the board will always get the same IP adress even if the router reboots.

By building your own APP you can build in any security you want.
First they will have to know your IP adress. Second they will have to know which port is open. And then they will have to know your security code which you can build in. That is 3 steps....

Luc