Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ESP8266 wemos d1 suddenly not reachable through wifi

Status
Not open for further replies.
A very strange problem ...

So, i am currently running 3 ESP8266 wemos d1 boards, each controling its own system. They do certain tasks and also run a server so i can access their data through wifi. All worked great for almost a year.

Yesterday i was playing around with wifi settings to see if i can improve transfer between phone and computer over the home network. So i changed a few settings, wasn't happy with them so i did a hard reset of the modem/router, reseting to ISPs defaults, which appear to be what i had to begin with, when i got the modem/router.

What confuses me is that i suddenly cannot access the ESP8266 servers anymore. The code is simply so i have no idea what could cause this. Also what is really funny is ... i can suddenly see all 3 ESP8266 boards on my mobile phone as access points - i can actualy connect to them. I dont know if that was like this before but i never noticed it.

Here is the code, not sure it has anything to do with the situation though since its been working for a year.

Code:
void connectToWifi() {

  Serial.begin(9600);
  
  WiFi.begin("SSID", "PASSWORD"); 

  for(int i=0;i<30;i++) {

     if(WiFi.status() == WL_CONNECTED) break;
     delay(30); 
    
  }
    
  server.on("/", handleRootPath);
  server.on("/data.html", handleRootPath);     
  server.begin();
  IPAddress ip(192,168,64,51);   
  IPAddress gateway(192,168,64,1);   
  IPAddress subnet(255,255,255,0);   
  WiFi.config(ip, gateway, subnet);  
      
}

Let me again state that this worked for a year. I tried different channels. What is strange though is that right now my router/modem is on channel 6, while those ESP8266's are on channel 1, at least that is what the wifi analyzer on my phone shows me. I tried changing router/modem to channel 1, does't make any difference.

I left the ESP8266's turned off over the night, same with router/modem - made no difference. The only other thing i can note is .. i tried changing the wifi bandwidth on modem/router. The problem is, i cant remember what the default value was. It gives me options auto, 20 or 40. Right now it is set to 20 and even if i change it to auto or 40, it still remains on 20.
 
You reset the routers name and password when you reset the router. That name and password were hard coded into the esp8266 board in the line (WiFi.begin("SSID", "PASSWORD"); )

Reset the name to the old name & PW or reprogram the boards to the new name and PW.
 
Sadly no, if it were that simple i wouldn't bother writing here. When you reset the router it resets to ISPs defaults, meaning SSID and password becomes the password that the ISP supplied. Either that OR ... since modem/router is connected to optical line, it is possible that after you reset the router/modem, the ISP sends the default data to it.

Another problem is that i cannot directly manipulate the router/switch, it is locked out. The only way i can change things is go to my ISPs webpage and use their interface to change things. But like i said, after i reset it, it defaulted to values that came when the ISP guys came to install the router. SSID and password is the same, i can connect to it with other devices no problem, my computers see eachother, etc. It simply makes no sense.
 
Just to let everyone know and maybe help someone ...

My SSID has 9A1EF4 in its name. And in all 3 ESP8266 boards, i set it as such. But it seems that the default SSID of modem/router actualy has 9a1ef4 in it, that is, small letters. I checked the documentation from ISP and there are small letters also.

Sadly i cannot remember what the SSID was when i got the router/modem, was it small or big letters. It IS possible that during the time of usage of modem/router, i tried to set some custom SSID and then wrote back the default one and used big letters instead of small ones. I remember once setting the custom SSID and i remember ESPs obviously wouldnt connect so i said i wont bother changing their code and just set it back to default. But that would mean i set it to the same one i got ...

So it is possible that the router/modem that i got had big letters in them, but the default software on modem/router was with big letters.

Anyway, at least now i know SSID is case sensitive, i wasn't sure before. And another thing i learned ... if in your code of ESP8266 you write a SSID that doesn't exist, then the ESP8266 will just make its own wifi network. I was able to connect to it with my mobile phone. So i was wondering, could i somehow use this to my advantage ? So i could connect to ESP8266 directly over wifi without needing to use the microusb cable to connect ?
 
The reason the ESP8266s are visible to your phone is that they have been programmed to act as access points when they can't log into a network (i.e., the SSID and PW are incorrect).

Connect to of them with your phone. Your phone will complain that this connection doesn't have internet access. Log in anyway.

After you're logged in, type

192.168.4.1

into your browser and chances are good that you'll see a screen asking for network SSID and PW.

If you entered in correct info, the ESP8266 will disappear as an access point and will connect to your wifi network. If not, it will show up as an access point again.

Repeat the same process for all of them.
 
Just to let everyone know and maybe help someone ...

My SSID has 9A1EF4 in its name. And in all 3 ESP8266 boards, i set it as such. But it seems that the default SSID of modem/router actualy has 9a1ef4 in it, that is, small letters. I checked the documentation from ISP and there are small letters also.

Sadly i cannot remember what the SSID was when i got the router/modem, was it small or big letters. It IS possible that during the time of usage of modem/router, i tried to set some custom SSID and then wrote back the default one and used big letters instead of small ones. I remember once setting the custom SSID and i remember ESPs obviously wouldnt connect so i said i wont bother changing their code and just set it back to default. But that would mean i set it to the same one i got ...

So it is possible that the router/modem that i got had big letters in them, but the default software on modem/router was with big letters.

Anyway, at least now i know SSID is case sensitive, i wasn't sure before. And another thing i learned ... if in your code of ESP8266 you write a SSID that doesn't exist, then the ESP8266 will just make its own wifi network. I was able to connect to it with my mobile phone. So i was wondering, could i somehow use this to my advantage ? So i could connect to ESP8266 directly over wifi without needing to use the microusb cable to connect ?

Yes, it is called station mode and you can create a private network (not connected to the internet) or a combination private mesh network plus one or more units in the mesh that connect to the internet when needed.

set up a backyard weather station or security system. So many possibilities.
Also, many, many commercial IoT devices already use esp8266 in various modes. Light switches, security systems, door locks, ...
 
I will play around with that.

Btw ... i am working on another project using esp8266 wemos d1 and using arduino IDE. And i am working with strings and printing them on server. It has been a while since i used c language doing any serious work, probably about 6 years ago in college.

Anyway, i am working with string and i remember from those c lessons that it was a hassle with strings in c, wasn't as simple as in java for instance. So i went browsing a bit how i could optimise my code and found some esp8266 pages or rather arduino pages with some very clean code. Alright so i went around and implemented it, so i did something like this:


C:
String myString =

    "Temperature1: " +
        String(sensor1_temperature) + "C" +
        "\nHumidity 1: " +
        String(sensor1_humidity) +  "%";

Do you see where i am going with this ? Only after i wrote it i realised that this certanly isn't pure c. C as i remember it, simply does not have the ability to concat strings using + sign. And that String() method for converting ints and floats into strings, i dont remember that either. I completely forgot about it but, isn't it along the lines that arduino ide actualy uses some custom c that is friendlier ? Google returns that it supports c and c++, but that it also has custom rules. Would anyone care to elaborate a bit on that ? I would love to know what i am actualy using. I can't belive i was able to make a few not so small projects without even knowing what exactly i am using, the programming language that is.
 
If you use strings in Arduino then you are using the C++ string class. If you want to stick to C then you can use sprintf().

E.G.
Code:
  char str[1024];
  float Temp = 25.4,Humid = 45.6;
  sprintf(str,"Temperature: %f\nHumidity: %.2f\n",Temp,Humid);
  Serial.print(str);
This will print
Code:
Temperature: 25.400000
Humidity: 45.60

HTH.

Mike.
Edit, note the number of decimal places.
 
Thank you, that is how i used to do it before, only yesterday i tried using strings and plus sign. But you said, if you want to stick to using C .. i am having a bit of a trouble understanding .. esp8266 with arduino ide supports both ? Because i didnt change the setting to either C or C++ anywhere, i left it all at default. And its kind of amazing that you can just mix programming languages like this and it still works ..
 
I avoid the string class as I've read in various locations that it is leaky - doesn't release all the memory it reserves. So I stick to good old fashioned C strings when I can and assume that the various libraries I use clean up after themselves. Most of C is a subset of C++ and so it appears that you can use both but some C syntax will not compile in C++. Also, the Arduino has a precompiler that fixes some of the syntax - E.G. it builds the prototypes so you don't have to.

Mike.
 
Thank you, that is how i used to do it before, only yesterday i tried using strings and plus sign. But you said, if you want to stick to using C .. i am having a bit of a trouble understanding .. esp8266 with arduino ide supports both ? Because i didnt change the setting to either C or C++ anywhere, i left it all at default. And its kind of amazing that you can just mix programming languages like this and it still works ..

You're not 'mixing' programming languages - C++ is backwards compatible with C - so no need to change settings at all.

The only 'problem' is the other way, C isn't compatible with C++ - and I've spent a LOT of time and effort converting various Arduino libraries to standard C so as to use them with PIC's. There's so much Arduino stuff out there it's much easier to convert an Arduino C++ library, rather than get the datasheet for the chip you're wanting to use and try and write it from scratch.
 
Status
Not open for further replies.

Latest threads

Back
Top