Fastest way to check internet connection with ESP32 Arduino - arduino

Update:
I know, the WIFI AP is still on & active in this case and the chip should not know about the change, but the question is still open. How should I check the connectivity?
In my project, the internet connection is really important.
After some testing, I have experienced that if I plug out the ethernet cable from my router the ESP32 still thinks, that it is still connected to WIFI, even the
WiFi.status() == WL_CONNECTED
is always true in this case.
So, I have tried out pinging google.com to examine the connection. This works but takes ages to get back the result.
How should I check the connectivity with the lowest resource cost and time?

Even WiFi.status() is unreliable due to the not documented details by Espressif. The API is error prone as the issues on github show.So actually the question is . what do you really want to check? - in my definition internet connection means my line (or aerial) connectionto my ISP is unbroken. This includes
my AP
my router
the ISPs fiber converter in my basement,
the line itself and the
ISPs gateway
This is what I use to determine wether a connection is open. I ping the IP address of the ISP gateway server. So you save time (no DNS resolution, no hops over nodes on the internet. If you mean wether a certain service on a defined server is available, thats slow but then you are 100% sure.
Just a clarification: "ESP32 still thinks, that it is still connected to WIFI" - YES that has to be true because according to the API this ensures client to AP connection and not AP connection to some where else. Normally a good configured router informs its clients about connection loss (in this case the connected AP(s)) and these notify (depending on their config) their clients (or sometimes not or very late)

Technically that result is correct because you are still connected to wifi!
Just because you unplug the ethernet cable doesn't mean your wifi stops. All it means is that your wifi can't get to the internet.
You can try pinging your isp's dns server. It's a lot closer to you than Google is.
Just the ramblings of an old man...

Related

Local network blocks outgoing packets from devices occasionaly

My internet stops sending outgoing packets a lot of times during the day, and it lasts 8 to 13 seconds.
Example: in Discord I keep listening others, but they can't hear me. Other softwares have the same behavior.
In my house there are 4 routers, and 1 ISP Modem, all in the same subnet.
All routers have DHCP turned off, and the Modem is responsible por the DHCP.
Modem is 192.168.0.1, and the 4 routers from .2 to .5.
I would like to know if this could be a DHCP configuration problem, or a ISP problem! Any ideas?
I tried connecting my PC to all routers, and even the Modem, and the problem happened in all tries.
You have done your troubleshooting well. By observing the problem without any routers in the mix, you've shown that your trouble is in the modem or, more likely, the ISP network behind it.
One more thing to rule out: completely disconnect your routers from your modem, switch them off, and repeat your test directly connected, with Ethernet not WiFi, to the modem.
If you still have the problem you have proven the problem is with your machine, the modem, or the ISP network.
If the problem goes away in that situation it's possible that some other machine somewhere on your network is occasionally blasting data at the modem.
Four routers sounds like an overly complex setup. The typical modem connects to only one router. Routers actually route packets from an upstream network (your ISP) to a downstream network (your building's LAN). If there's confusion about which router is supposed to do that, frankly it's amazing that anything works. If three of your four are configured as WiFi access points that's OK.
The typical modem doesn't offer DHCP service to its downstream LAN network, because it doesn't know about a network behind it, only one device, your router.
Some ISPs provide combination modem / router boxes. Maybe that's what you have. You may want to review your network configuration.
Try tracert command in the command line to see if your packets are travelling through all these routers. Maybe it will solve the problem or at least displays if the problem is caused in the routing. Or try to see if the problem is caused in a wrong default gateway to the device.

Meaning of ICMPv6 packets?

I'm struggling to get an embedded platform with fairly standard IPV4 networking running. I have a working prototype which obtains an IP via DHCP without problem on a point to point connection (single cat5 cable) attached to a test laptop.
On my new hardware I get the link up but no DHCP request gets to the server (monitoring with wireshark). However what I do see, 100% repeatable, when those packets should be received, is a couple of ICMPv6 packets from the test laptop. This happens every time, there is no other activity on that link at any other time.
It seems to me that those packets are trying to tell me something, but what? Perhaps the DHCP request is going out but malformed for some reason?
(I can't post the actual packet from my phone, will make a copy and do so later.)
Seems to be something generated by the laptop when it sees the link comes up. Turned out to be unrelated to the issue I had (which was hardware related).

How does a network recognize a device?

I am person trying to learn networking. I understand that this may not be the best first step to take, but I am eager to try and understand how this takes place because it has been tearing up my mind for quite a while now.
My question is, how does a network recognize a device and automatically connect it to the network?(This is assuming, of course, that you have connected to the network previously and are connecting wirelessly.)
Does it store it on the routers side and then look for specific MAC Addresses and then connect it? Or is it stored somewhere on an encrypted file on your computer? Or is it none of these? Please forgive me if I am way off, I am only giving guesses from what I have so-far learned from networking.
'Connect it to the network' doesn't really mean anything, other than just plugging it in, or turning it on in the case of Wifi. What really happens is that the device broadcasts a DHCP request for an IP address, or else It already has an IP address in that subnet. From that point on it is discoverable by ARP, so other hosts in the subnet can send to it.

Is there a way to detect the number of connections active on a Wifi network?

If I want to detect the number of connections active on my home Wifi network, how should I go ahead doing it? This can be useful for building applications which would serve as monitoring unidentified/unrecognized people being fraudulently misusing a person's Wifi network.
How to know whether your neighbors or others are using your wireless network is rather complicated.
If your neighbors are experienced Wi-Fi hackers, you might not be able to tell at all.
If they're just stealing your Internet connection, you may be able to tell from the logs on your router.
To find out who's on your wireless network, you'll need to start by taking inventory of all the devices that are meant to be connected. Find out their MAC IDs and their IP addresses (if they're static).
To find out the MAC ID/IP address on a PC, click the Start menu and choose Run. Type cmd and click OK. In the screen that opens, type ipconfig /all and hit Enter. The MAC address will be shown as the physical address. Once you know the MAC addresses of each of the PCs on your network, you will recognize any addresses that don’t belong under the screen that shows the MAC addresses of current connections.
Check IP addresses
Likewise you may be able to see how many IP addresses have been dished out by the DHCP server. If you check the IP addresses of each of your PCs, you can see if other IP addresses have been served.
To find out your IP address from the Start menu, click Run. Then type in cmd and click OK. In the screen that comes up, type ipconfig which will display the IP address for that computer. (Bear in mind, however, that if the PC is set to auto detect settings, then the PC's IP address will change the next time the computer is rebooted or switched on. Sometimes previously served numbers have not yet expired, so you may think someone is connected when they are not.)
Dealing with intruders
If you do find someone using your connection, they may well not be doing so maliciously or even knowingly. Sometimes people can’t tell which is their own connection and they may honestly believe that they are using their Wi-Fi router rather than yours. The best way to deal with this is to set up your own security and maybe you can help them find their own router!
The optimal solution is to set up a strong password using WPA or WPA 2 of almost 20 to 30 digits and numbers. Once your network is functioning, you can switch off the SSID broadcast (which prevents it from advertising the name of your network) so it would effectively disappear as far as your neighbors are concerned, and the first you might hear of it is when someone complains that their Web connection has disappeared.
You could look for logs such as current LAN clients, connection or status log, or connected MAC addresses.
Be Happy :-)
Do you have access to the Access Point management ?
Look for MAC addresses and their filtering. Modern APs allow you to filter devices and or limit the timeframe during which devices can authenticate themselves, using a hardware button.
A link on how to secure your AP here, and a good start to know what to play with !
You can Either USE this Command... On your Router or Modem... Some Modem's have console for Ping and Commands like that....
ipconfig -all

Baffling networking query [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Bit of a random question (and I know a lot of the technology invovled is not described) but are there any networking gurus out there that can answer what is probably a simple M$ networking question that has me baffled?
Connected my laptop to the corporate network today in the same manner I do eveyday. I was allocated an IP address as per normal but unlike normal, I got no connectivity to the internet.
After a reboot and a ipconfig /release /renew the situation was the same. IP address but no connectivity.
So I called in the Techs who replaced my ethernet cable between my machine and the network port and everything sprung into life -- full connectivity restored.
My question: how did it get an IP address using that broken cable?
Most probably, your laptop assigned itself the last IP it was given by DHCP when it failed to get one from the DHCP server.
Which IP did you get? Windows computers get assigned dummy IPs when they do not get one from a DHCP server, starting with 169 if I recall correctly.
There's too many variables to keep a good educated guess. The best guess I can come up with the facts you've given is this:
The cable wasn't broken when it was initially plugged in. Maybe you were able to get an IP address before the cable broke.
As MrValdez already said, there are really to many unknowns to make a good guess. But one thing to keep in mind is, that just because one event follows another it is not necessarily caused by that event. This is also known as "Correlation does not imply causation".
It might well be, that the time to replace the cable was long enough that the real problem (router, ISP or some other thing along the path) could be solved by someone else (without knowing about your problem) or just vanished on its own.
If the cable was broken, you would get an error network "Not Connected" in the icon in the system tray. If you network connection was up, means the cable was OK.
If the cable was not of the right type, then you could have had connection up, but Ethernet negotiated to 10Mpbs/Half Duplex, which can cause a lot of pain to the use who's not aware of it, including symptoms like no connectivity, dropped packets and hence slow connection, etc.
After that, if you got an IP address beginning 169.184.X.X, that would mean that DHCP failed for whatever reason, and your laptop assigned itself a default configured IP address.
If the IP address you got was what you normally get in your LAN environment (the once with which you usually connect to the internet), then there might be some firewall issues, or something else wrong with your corporate network's router, which the Tech guys might not be too willing to share with you :-)
It's impossible to be sure but here are a few:
Network card driver: I've experienced very random things with HP laptops and ethernet cards. Usually a reboot fixes that. Green connectivity light doesn't always mean 'go', sometimes the drivers are responsible for turning the light on.
Loss of connectivity in the cable or the network plug in the compute.
Duplex negotiation problems between the switch and the computer
Maybe trying gigabit ethernet on a 4 wire cable?
If it was me I'd try an ethernet sniffer (like tcpdump or wireshark) if this happens again, see if you're getting anything in. Ping results would also be nice (to IP addresses, not hosts).
The cable and/or connectors were flaky. DHCP is done using very small UDP packets, and if enough of them are sent, eventually they'll get through. The DHCP retry mechanism is very robust, so I wouldn't be surprised if you lost 95% of the packets, and it was still enough to get an IP.
However, once you start sending larger packets for TCP/IP transactions you'll find that the 95% loss drops enough packets that even with durable TCP/IP, it's too tough to get anything useful through.

Resources