Photon sends to webserver in local network, but not to a remote webserver

This cannot work.

1 Like

I tried String hostname = “something.hopto.org”; and it is also not working

@asergio.branco, a non-blocking delay which calls Particle.process() looks like this:

unsigned long wait = millis();
while (millis() -  wait < 5000) Particle.process();  // Wait for 5 secs

Replace your delay(5000) with this code.

1 Like

You should debug the hostname part first. The form with “http://” will not work ever, so stop trying that.

Your code calls WiFi.resolve on the name and got a result: did you check that is was a valid and correct IP address? Why don’t you print the ip variable in setup to check?

Have tried substituting in the resolved external IP address for your “something.hopto.org” address? In other words, look up the correct IP address on a computer and then change your server array to be that IP address and try home_server mode.

Port 5000 is used for UPnP over TCP. Have you tried using a different port and making sure that is open in your router?

1 Like

@asergio.branco, when you say “not working”, does your server log the request in any way?

1 Like

The port 5000 is open in my router, no problem with that, like I said I can connect to it using a python tcp/ip client.

Also tried to use the direct IP, and not working either.

Nop, the server does not even says it received a request… but the server is receiving from another clients, like a computer etc…

Ok, I think I found the problem, and it is probably because of my home router, since the photon when requesting connects to the router and after that I believe my router my redirect the traffic to my home webserver. I tried print the response I get and is something like this:

@asergio.branco, do as @bko suggests and print the IP address from the resolve statement. It should match the IP you get from a ping something.hopto.org you do on your PC. Also, try using that IP in the client.connect() call:

if(client.connect(ip, port))

Serial.println(ip) works?? Because I tried it and it did not print any value, but the ip is not null because I put an if(ip){}else{} statement to give me an idea if it was null or not like it shows in the documentation

@asergio.branco, from the documentation:

Finally IPAddress can be used directly with print.

// PRINT THE DEVICE'S IP ADDRESS IN
// THE FORMAT 192.168.0.10
IPAddress myIP = WiFi.localIP();
Serial.println(myIP);    // prints the device's IP address

Your router will follow any server/port forwarding rules you have setup. You may need to create a rule for your specific port.

Well, it prints the ip it should, my router has the correct rules, changed the ports on my router, tried with WiFi.resolve… tried using the direct IP, checked iptable to see if rule is ok for my server, etc, not working, it connects but I do not receive anything

Well I do not know why, but passing the ipaddress to the function client.connect(ip, port) it does not connect, but is the correct ip, I connect with the same from my computer and is my server

@asergio.branco, so you say “it connects”. So now it comes down to the request. Perhaps it’s not properly formed or needs a second client.print("")? Is this a REST API call?

Well, I really do not understand what is happening, I only can connect with photon to my home server through port 80, (besides the port 9000 and 5000 are open and accessible)

What it may be?

Thanks

And no, the servers running in 5000 / 9000 ports are simply tcp/ip servers, they do not use GET or POST methods to receive and retrieve data… You simply send a text message and it should display it

That tends to indicate that the 5000 or 9000 port address is being blocked somewhere, possibly because these are being used by other protocols, as @bko pointed out. Try a non-standard port number.

1 Like