-->
Page 1 of 2

Executing a program upon initial 192.168.4.1

PostPosted: Sat Dec 26, 2015 8:13 pm
by viscomjim
When the esp is powered up, if it has already connected to a network before, and sees that network again upon power up, it automatically connects to that network. This is good. However, is it possible to do the following...

If the unit is powered up and can't see the previous network, it will go into access point mode. When you enter 192.168.4.1 into the browser, instead of going to the menu bar, can you just execute a program right away that will display a webpage that asks for your network name and password only? And once you do that you hit a "connect" button and the unit connects to that network and continues executing the rest of the program without any other user interaction?

Or maybe another approach, I remember when using the AT commands, there was a command to list all available wifi networks. Would it be possible to, when the unit is powered up and it doesn't recognize the network it has been previously connected to that it could list the networks available when you enter 192.168.4.1 and you select one and enter the password in a text box and hit connect and then the rest of the program continues?

My goal is minimal "non technical" connection of the esp to the wifi network. And there will be no serial connection available so the user will have just a plain old turn the unit on, connect to your wifi and thats it.

Any ideas would be greatly appreciated!!!

Re: Executing a program upon initial 192.168.4.1

PostPosted: Sat Dec 26, 2015 9:16 pm
by TassyJim
A short routine at the beginning of the main program should work:

There is the IP() function which will give you the current IP.
If it is 192.168.4.1 you know that you have not connected to your network.
If that's the case, run a routine to ask for the network name and password.'then run the command to connect to that network.

If the IP is not 192.168.4.1, you should have connected OK so skip the ask for name/password bit.

Then continue on with the main program.

The bit I am not sure about is if the network name and password are remembered when you connect via program instead of setup.

An alternative might be to redirect the webpage to the setup page if the IP is not correct.


The next problem for your enduser will be explaining how to find the IP address by interrogating his/her modem/access point.

You could get it to send am email with the required address., but that requires setting up the correct mail server.
All these things are getting harder to do as ISP's tighten up their access rules.

Jim

Re: Executing a program upon initial 192.168.4.1

PostPosted: Sat Dec 26, 2015 10:20 pm
by viscomjim
Hi TassyJim, that is a good idea and I will give that a whirl. Would the test for that be like this...

x = ip()
if x = "192.168.4.1" then whatever

I will try this and report back. It will be interesting to see if the id and password are remembered this way...

I think, not sure, that when using the AT command set, that you could set up an access point and join your network at the same time. (AP and Station). This would be great if it could be done in the basic port. Then maybe you could report the ip address by accessing the access point. Again, not positive.

You are correct in that once it joins the network after you enter the ssid and password, how would you let the user know what the ip address is without the use of a serial port? Kind of chicken and egg problem. Right now, this doesn't pose a problem as all I want to do is make the little www clock and let the user join a network solely for checking the time and displaying it. But for more than this, one has to know the ip address.

Re: Executing a program upon initial 192.168.4.1

PostPosted: Mon Dec 28, 2015 9:47 pm
by forlotto
one easy way to do it is...

Have them run wirelessnetwatcher by NIRSoft http://www.nirsoft.net/utils/wireless_n ... tcher.html

Once you run this program. It should tell you what IP's are on your network and info about them.

Tell them to look for the one that says ESPXXXX the X's could be random numbers and letters.

Jot down the IP that is tied to it and access it that way.

Finally you could set a static IP ... So that it is easy for the user to know what the IP will be at all times.

In the code you can use.

connect ssid password staticip gateway subnet

the static IP is 192.168.x.x most of the time tell the user to give you his local ip if it is 192.168.1.34 then make the static IP 192.168.1.39 for instance if it was 192.168.2.22 then use 192.168.2.25 keeping the first 3 numbers the same. Now if it was 192.168.1.x then the gateway is normally 192.168.1.1 if it is 192.168.2.x then the gateway is normally 192.168.2.1...

subnet typically is 255.255.255.0 in most simple network setups if you have multiple routers it could get tricky with different subnets.

Code: Select allconnect "mywifiname" "mypassword" "192.168.1.39" "192.168.1.1" "255.255.255.0"


This would give you an idea of what the line for connecting would look like for static IP.

I do agree it would be cool to just somehow know the IP there is a way to do it you could print the IP and have it sent to thingspeak I'd bet somehow as data maybe!!! Just a thought. Have that be the start of your code.