I am running the WebServer library and controlling LEDs simultaneously on a Photon. Whenever I hit the web server with my browser by typing in the ip address, the LED updates stop while the browser is updated, as expected.
However, I noticed the LEDs pause intermittently even if I don’t access the web server. I enabled WEBDUINO_SERIAL_DEBUGGING and it appears the web server is receiving GET requests from another device on my network, causing it to render the web content behind the scenes.
How can I identify where the request is coming from? I can’t find any way to access client ip address or agent-type.
Well, I was able to find the ip address of the offending client using remoteIP() and it is my router. Any thoughts on how to filter out these non-browser requests?
@Jerware, the bigger question is why is your router probing port 80 on your device! You should check if you have any port forwarding or virtual server ports setup on the router. Did you consider changing the port used by webduino to see if the probes stop?
I think it might be your router trying to cache the page.
In safari for instance you stop typing the url of the page and even before you hit enter, it gets called in the background to improve the appearance or perception of page loading performance.
Also you might want to put a known body (Json) on the request that the device can read to see if it’s a legit request and not a cache request. Of course this does not work if you want to turn on or off a light using a pure url call up in a browser.
If you don’t want to put a body in a get request you could try to see if the router cache ignores caching if the url has a query string like : ?led=on
I have to say that I haven’t seen a router do what you are describing so it is only pure speculation.
Thanks guys. I agree it’s surprising behavior for a router. For the record it’s the ASUS RT-AC68U.
There’s no port forwarding setup to my Photon’s ip address, and I assume changing the webduino port would solve the issue (I should verify though). The problem is that I’m writing this – potentially – for a number of my customers, and want them to access their device at the root URL, port 80. As rare as this issue may be, I’d like to solve it.
I was thinking of including some simple javascript to test the client, and if supported it would proceed to show the rest of the page. I just wish there was a faster way to do this than having the client submit a jquery form to signal successful javascript execution. I don’t want to delay page loads for legit users. I’m not a web monkey by any stretch, so if, @frlobo, your Json solution is simpler, perhaps you could show an example of how that works.
For testing purposes, it might be helpful to save/print/whatever the HTTP User-Agent header. Actually, that might also be a way to filter out non-browser requests for efficiency reasons. Not for security reasons, because the User-Agent is easily spoofed.
If you’re using the “WebServer” Library (the Webduino ported one) now that I look at it, it’s not exposed. But it should be just adding a few lines of code to WebServer.h in the WebServer::processHeaders() method.