Cannot port forward to Spark outside Local Network

Using the webserver library, I flashed the “Hello World” sketch. The only fork I took was to change the default port from 80 to 9700. This was done to have a unique port number for the Spark from by other network connected “things”.

After the flash, I used a browser to access my spark using the URL:

“my DDNS domain”:9700

This worked great, the browser displayed “Hello, World” as expected.

This also worked from my smartphone, when it was connected to my home WIFI.

But when I disabled the WIFI, the Smartphone could not find the page. This is the same method I use to access my other SBCs, cameras, hubs at home.

Why does this not work with the Spark Core without a local WIFI connection?

Additional Information: I did set my router to port forward to my Spark Core all TCP requests to port 9700, the same as my other connected “things”.

Do you mean the wifi on your phone? When you set the port forwarding on your router did you set the forwarding port to 9700? Some routers will allow you to port an external port to a different internal port (eg. ext port 9700 to int port 80).

1 Like

When you turned off the wifi connection, what alternate route is there for the data?

Nomrally wifi is needed for your phone to connect to the router, and also for the spark to connect to the router.

@mdma, I think he turned off the wifi only on his phone so that he now goes through his carrier to the internet and to his router via DDNS. However if his port forwarding is not set right, the traffic won’t make it to the Spark. :smile:

1 Like

I have 6 webcams, a X10 webserver, and two other SBCs connected to my local home router. Using a DDNS service (lets call the domain “” for this example), “” points to the IP that my ISP has assigned to my home WAN connection. This DDNS service will always keep my domain name pointing to the currently assign IP of my WAN.

For the purpose of accessing the Spark, I set the webserver app to port 9700 and used the URL

All that is needed to gain access from the Internet (anywhere) is to configure my home router to forward port accesses (hence, the term port forwarding) to the device (webcam or other “thing”) that is configured to respond to a particular port.

Since this setup has been working, providing global access to my webcams and other devices for many years now, I was expecting this to work with the Spark Core.

What is difficult for me to understand is why the domain name resolves to my ISP assigned WAN IP with WIFI on but not when it is off (off on the Smartphone that is, WIFI on home network is still running).

This forces the phone to use the 4G network to find my WAN IP. In either case, it needs to find a DNS outside my local WIFI network to resolve the domain name.

It would seem that if the port forwarding will not work from an Internet access point outside my home network, then it should also not work inside the local network using the same domain name in both cases.

Just wondering if this is a Spark Core constraint. It also does not make sense to me. Does anyone understand how this could happen?

@surfnturf57, I’ve had weird problem with my phone browser (KitKat 4.4 w/Chrome) when I turn off my wifi WITH Chrome open. It does not seem to switch to the cell network properly. If I kill the app and restart it, then everything works as expected. Perhaps this could help? :wink:


Oh, of course! How silly of me! I live in small village in Norway, 4G LTE hasn’t made it here yet, so I sometimes forget some folks actually use their phone to access the internet! :slight_smile:

It was really bad here for a while - the best internet access we had was to send an SMS with the web page you wanted to the “internet man” in the village and he would type in the address into his browser and then send back a few SMSs with the page content. It was slow and unreliable.

Fortunately, it’s a lot better now. They got his brother working as well, so twice the bandwidth! :smiley:


Thanks @peekay123,

i reset my phone and even tried installing a different browser (Opera) so it would be clean of any history. Still no access :frowning:

I was just trying to fit the Spark in the same Webserver paradyn that has worked well with my other SBCs.

For me, since I have been unsuccessful to resolve this, It looks like I am going to have to use the Spark Cloud and expose variables and functions to control and monitor my “things” connected to the Spark. This will also require additional services such as “Parse” to store and retrieve JSON objects.

I know that this is supposed to be easier, but at least initially, it seems more difficult. And now we are vulnerable to the whims of the Spark Cloud “gatekeepers”.

I was hoping to sidestep the Spark Cloud, as my experience so far has been that it is very sloooow to respond.

Still evaluating the Spark Core…

Hi @surfnturf57

The other services like the web cams, X10 gateway and SBCs all work correctly from the same browser with the same resolved IP address? Can you try the IP address in the browser instead of the name?

Do you use a unique port number for any of the other services? For testing, can you switch to port 80 or 8080? A whole bunch of routers have to forward you packet from the your phone back to your home router, so there are lots of ways this can go wrong.

Thanks @bko,


  1. Same results when the IP address of my internet connection is entered instead of the domain name. This should not be a surprise since the domain name resolves to the IP address.

  2. Each service, webcam… MUST have unique port numbers for port forwarding from my internet connection IP to the appropriate device to work. All the other devices are accessible from any internet connected device anywhere on this planet.

My router has a configuration table to keep track of all the ports that are authorized to pass through my firewall to the appropriate local network device. The local port numbers are assigned to the same as the incoming port numbers.

The Spark Core that I have recently added to my network was configured in my router to forward port 9700 to the local Spark Core Device (identified by local network IP and device MAC).

  1. I changed the port to 80, same results.
1 Like

OK, thanks for trying! Does the above mean that you have your router giving the Spark core a locally static IP address based in’s MAC address? The core always does DHCP with the current firmware, so the only way for the local IP address to remain the same is for your router to handle it.


The router DHCP assigns an address. But once that initial IP/MAC combination is configure to port forward, the router will automatically adjust in the case that the IP assignment change, like when you power up the Spark.It appears to learn devices by MAC and then maintain an association with the dynamically assigned local IP.

As I noted, unless the Spark developers or the generous contributor of the webserver has an answer, I am moving forward with the Spark Cloud as my Internet API.

Have you used it yet?

I am still on the learning curve, ongoing as time permits.

I have many irons in the fire and the Spark Core currently presents itself to me as an obstacle that I can overcome much more quickly using my other SBCs that I am more familiar with.

Best Regards…

Hi @surfnturf57

Check out the tutorial category here in the forum. I have written a whole bunch of tutorials for Spark.publish(), Spark.variable(), and Spark.function().

If you have questions, just ask!

which webserver are you using? Given that the spark is running Berkley sockets, I really can’t see that this caused by something specific to the spark. If you want, I can try to replicate the situation here and see what it takes to access the spark with a port forwarded to the WAN IP on the router.

Thanks @mdma,

Any advise would be welcome and hopefully useful to others as well.

I simply created an app and included the library you see attached to my app.
I used the “Hello World” example for my App, with the only change being the port number in line 8 (80 to 9700).

The fact that I am able to port forward to the Spark with this App from a PC connected to my local network via WIFI but not from an externally connected device should be a clue, but what? The setup is the same as other connected devices in my network.

This might require a network sniffer like Wireshark to get to the root cause. I suspect a network switch/router guru would have some ideas, but that is not me.

Ah, you’re using that one! It was I who ported that library, so I can tell you there’s no magic going on - the web server just sits on top of a plain TCP server socket. I will try the same code as soon as I can and set up port forwarding here and try to access it from outside the LAN and report back what happens.


This appears to be some sort of timing or timeout issue. I noticed that if I reset the Spark (reset button),
I can indeed access the Spark (web URL one time, with a remote connection outside the LAN.

But the “Hello World!” is not returned and then another entry of the URL returns the “could not connect to” error…a reset fixes this for one access again.

Also noticed the Spark is inaccessible on the LAN after several accesses as well, reset correcting it. It seems that the issue, whatever it is, is more pronounce with the remote access (a longer round trip).


Is the source code for webserver.cpp open source available?

I seem to recall this being a problem with sockets “lingering” when the TCP connection is not properly closed.

This could be the socket close issue that I saw when porting the library

I thought I had fixed it by introducing a small delay, which made it more stable. (Naturally, that’s just a bandaid until we can uncover the real cause of the problem.) Could you please confirm again that this is working fine via your local net?

EDIT: ah, I saw now you said it times out locally too.