Spark can't TCP connect to another device on the LAN

Recently I’ve been trying to connect to a webserver running on my Mac, using the HttpClient library, but for whatever reason TCPClient#connect is not working.

I’ve tested the connection from other remote computers using cURL, and all seem to work fine. I’ve switched and used a TCPServer on the Spark, and I can connect to the spark from my Mac just fine. Also, I am able to make a request to google’s IP just fine.

Doing something as simple as the attached isn’t even working:

TCPClient client;

void setup() {

void loop() {
    if (client.connect({192,168,1,181}, 4567)) {
    } else {
        Serial.println("Connection failed");

Anyone had any troubles with this? I am specifying the host via IP, so it’s not some DNS resolution issue. The Spark seems to stay breathing cyan the whole time too, so it’s not losing connection to the WiFi or anything.

Could you try to set your IP address up in a byte array an pass this into connect()?
Does it still behave the same way?

Previous examples were doing exactly this. I would set up an IPAddress with: IPAddress localIp({192, 168, 1, 181});. When I passed this to Serial.println it printed out perfectly, but TCPClient#connect still failed.

According to something that I read on this forum the cc3000 device can only support a very small number of concurrent tcp connections.

Your code above could potentially be using them up (and actually working) before you get the Serial port connected and stable. So all you’d be seeing are the ones that fail.

while (!Serial.available()) {

after the Serial.begin(); line and it will wait for you to connect using putty or similar. Then click any key to continue. It’s worth adding Serial.println(“Starting …”); immediately afterwards so that you know you are seeing the start of the debug.

Also, limit the number of attempts that you are making, either by increasing the delay(1) to delay(1000) or better still by using a counter and an if statement to stop after a few attempts. If nothing else the debug will stay on the screen rather than scroll off the top.

trying pinging the spark core from the mac, and re-try connecting, I found this was needed to make it work.

Hi timx,

I’ve tried both limited the number of connections and using a Spark.process loop and a SPARK_WLAN_Loop loop, but neither seemed to work. I’ve also verified this doesn’t work with another Spark. It’s very strange since I feel like this worked last week!

Hey mtnbrit,

Pinging the Spark just times out. And the connection continued to fail after leaving it pinging the Spark.

try increasing the both the delays to 20000 just for testing. that way you know that you get the first connection attempt. if it does connect make sure you flush and stop before trying to connect again. otherwise all attempts following will fail.

core is slow with this stuff… a 1ms delay is not long enough in the loop

right it doesn’t respond to the ping, but its enough to get layer2 arp working so the mac can see the spark and the spark can see the mac. worked for me. If its still not working, I would run tcpdump on the mac to see if you can see any traffic from the IP address of the spark.

I just reflashed the CC3000 following this README:, and then flashed my code through the DFU. That seemed to work. I’m not sure what was wrong, but looks like clearing the state worked! Thanks for the suggestions though!

1 Like

If you have Spark cli installed, the patch command in DFU-mode will be spark flash --usb cc3000 :wink:

Ah, I figured. I used the DFU command there, but have been using spark flash --usb for all the firmware files from the cloud compile. I feel like it’s a bit more reliable.

1 Like

I’ve run into this same issue. I followed the posts on this thread, including updating the cc3000 firmware, but the only thing that seems to make TCPClient work connecting to a local IP address on my network is to ping the Spark from another machine. This seems like a bug.

1 Like

Just tested this and pinging the core does fix the issue… strange bug and I do recall reading somewhere about the reason behind it. Maybe on the TI forum. I’ll see what I can find again

1 Like

I have the same problem I cannot ping or connect to a local Ip. unfortunately the pinging does not resolve the issue either. I also tried to apply the CC3000 firmware patch but it did not solve the problem