Photon cannot connect to hidden SSID

I have a Particle Photon with the most recent (0.6.2) firmware. I am trying to connect to an open (no security) WiFi network that does not broadcast its SSID. I do not have the ability to modify the network end of things (an enterprise level network managed by my employer). I have two Photons already connected to this network and happily reporting data. They are firmware 0.4.9 and I configured them using the CLI (particle serial wifi). I have tried rolling back the firmware of my newest Photon to this version, but it does not make a difference (I have since returned it to the current 0.6.2 firmware). If I setup a temporary WiFi network using my phone’s “hot spot” capability I am able to connect without a problem. Please help! I have two of these things already running smoothly and I was asked to deploy a third - I didn’t expect this to be a problem. Thank you in advance!

EDIT: My Photon LED behaves as follows: blinking green, blinking cyan, two orange blinks, blinking cyan, two orange blinks, blinking cyan, then it restarts blinking green. Aside from the orange blinks, the duration of each other color blinking is about 10 seconds. Prior to this, it was connected to my phone’s hot spot and breathing cyan with data coming in and reporting just fine. The code that is currently on it does nothing other than publish “TESTING” every 3 seconds, which worked fine when connected through my phone’s hot spot.

Thank you again! :slight_smile:

@jmativi
You can do this via USB serial, but choose not to scan for networks. It will ask for SSID and there is an “Unsecured” Security Type.

$ particle serial wifi
? Should I scan for nearby Wi-Fi networks? No
Attempting to configure Wi-Fi on /dev/cu.usbmodem1421
? SSID romswrf
? Security Type Unsecured
Done! Your device should now restart.

@cermak Thank you! I have already tried to configure the Photon this way, as it is how I configured the previous two that are working just fine. I was able to configure it, and it restarted, but it will not connect. Other devices (cell phone, laptop) are able to connect to this network without a problem. Any other ideas?

I was able to setup a hidden unsecured wireless AP here. The Photon connects to the cloud fine. This leads me to believe that the AP at your end is not sending sufficient network information to the Photon. Not sure which piece is missing. The tinker app may include logging to serial. Otherwise you can add this line to your code near the top to allow additional output via USB serial.

// Use primary serial over USB interface for logging output
SerialLogHandler logHandler;

After resetting the Photon, switch to serial monitor:

$ particle serial monitor  // With SSID broadcast on
Opening serial monitor for com port: "/dev/cu.usbmodem1421"
Serial monitor opened successfully:
0000003058 [system] INFO: CLR_WLAN_WD 1, DHCP success
0000003059 [system] INFO: Cloud: connecting
0000003059 [system] INFO: Read Server Address = type:1,domain:device.spark.io
0000003068 [system] INFO: Resolved host device.spark.io to 107.22.28.43
0000003234 [system] INFO: connected to cloud 107.22.28.43:5683
0000003234 [system] INFO: Cloud socket connected
0000003234 [system] INFO: Starting handshake: presense_announce=1
0000003235 [comm.sparkprotocol.handshake] INFO: Started: Receive nonce
0000003438 [comm.sparkprotocol.handshake] INFO: Encrypting handshake nonce
0000003485 [comm.sparkprotocol.handshake] INFO: Sending encrypted nonce
0000003485 [comm.sparkprotocol.handshake] INFO: Receive key
0000004159 [comm.sparkprotocol.handshake] INFO: Setting key
0000004348 [comm.sparkprotocol.handshake] INFO: Sending HELLO message
0000004348 [comm.sparkprotocol.handshake] INFO: Receiving HELLO response
0000004483 [comm.sparkprotocol.handshake] INFO: Completed
0000004484 [system] INFO: Send spark/hardware/max_binary event
0000004484 [system] INFO: spark/hardware/ota_chunk_size event
0000004485 [system] INFO: Send spark/device/last_reset event
0000004486 [system] INFO: Send subscriptions
0000004486 [comm.sparkprotocol] INFO: Sending TIME request
0000004487 [system] INFO: Cloud connected
0000004743 [comm.sparkprotocol] INFO: Received TIME response: 1497029895
0000005744 [comm.sparkprotocol] INFO: Sending A describe message
0000005876 [comm.sparkprotocol] INFO: Sending S describe message
0000196598 [comm.sparkprotocol] WARN: bytes recieved error -9
0000196598 [system] WARN: Communication loop error, closing cloud socket
0000196598 [system] INFO: Cloud: connecting
0000196599 [system] INFO: Read Server Address = type:1,domain:device.spark.io
0000196602 [system] ERROR: Cloud: unable to resolve IP for device.spark.io
0000196602 [system] WARN: Cloud socket connection failed: -1
0000196602 [system] WARN: Internet Test Failed!
0000196603 [system] WARN: Resetting WLAN due to 2 failed connect attempts
0000196603 [system] WARN: Handling cloud error: 2
0000196603 [system] WARN: Resetting WLAN due to SPARK_WLAN_RESET
0000196605 [hal.wlan] INFO: Using internal antenna
0000196607 [system] INFO: ARM_WLAN_WD 1

// Rebooting the AP with SSID in hidden mode 
0000196998 [system] INFO: ARM_WLAN_WD 4
0000196998 [system] INFO: ARM_WLAN_WD 4
0000218396 [system] INFO: ARM_WLAN_WD 2
0000218396 [system] INFO: ARM_WLAN_WD 2
0000218440 [system] INFO: ARM_WLAN_WD 2
0000218440 [hal.wlan] INFO: Bringing WiFi interface up with DHCP
0000219141 [system] INFO: CLR_WLAN_WD 1, DHCP success
0000219142 [system] INFO: Cloud: connecting
0000219142 [system] INFO: Read Server Address = type:1,domain:device.spark.io
0000219230 [system] INFO: Resolved host device.spark.io to 107.22.28.43
0000219343 [system] INFO: connected to cloud 107.22.28.43:5683
0000219344 [system] INFO: Cloud socket connected
0000219344 [system] INFO: Starting handshake: presense_announce=1
0000219344 [comm.sparkprotocol.handshake] INFO: Started: Receive nonce
0000219463 [comm.sparkprotocol.handshake] INFO: Encrypting handshake nonce
0000219511 [comm.sparkprotocol.handshake] INFO: Sending encrypted nonce
0000219511 [comm.sparkprotocol.handshake] INFO: Receive key
0000219650 [comm.sparkprotocol.handshake] INFO: Setting key
0000219839 [comm.sparkprotocol.handshake] INFO: Sending HELLO message
0000219840 [comm.sparkprotocol.handshake] INFO: Receiving HELLO response
0000219956 [comm.sparkprotocol.handshake] INFO: Completed
0000219956 [system] INFO: Send spark/hardware/max_binary event
0000219956 [system] INFO: spark/hardware/ota_chunk_size event
0000219957 [system] INFO: Send subscriptions
0000219957 [comm.sparkprotocol] INFO: Sending TIME request
0000219959 [system] INFO: Cloud connected
0000220190 [comm.sparkprotocol] INFO: Received TIME response: 1497030111
0000221216 [comm.sparkprotocol] INFO: Sending A describe message
0000221351 [comm.sparkprotocol] INFO: Sending S describe message

@cermak Thank you! What code are you running on your Photon to get that output? (Please assume I know nothing beyond that I will need Serial.begin(9600);). Once I have that code, I will try to let it connect and see what I learn! I assume I can just open a line in Putty and then watch while it tries to connect? Thank you again!

You don’t even need the Serial.begin(). Just the two lines above.

It can be an empty blob of code.

// Use primary serial over USB interface for logging output
SerialLogHandler logHandler;

void setup() {
   
}

void loop() {

}

@cermak Thank you again! I have taken a look at the serial output. It seems that this is were it is having trouble:

0000073563 [system] ERROR: connection failed to 107.22.156.56:5683, code=-2

Everything else works OK. Below is the full output. What is that code=-2?

0000062601 [hal.wlan] INFO: Bringing WiFi interface up with DHCP
0000068552 [system] INFO: CLR_WLAN_WD 1, DHCP success
0000068553 [system] INFO: Cloud: connecting
0000068553 [system] INFO: Read Server Address = type:1,domain:device.spark.io
0000068563 [system] INFO: Resolved host device.spark.io to 107.22.156.56
0000073563 [system] ERROR: connection failed to 107.22.156.56:5683, code=-2
0000073563 [system] WARN: Cloud socket connection failed: -2
0000078563 [system] WARN: Internet Test Failed!
0000078563 [system] WARN: Resetting WLAN due to 2 failed connect attempts
0000078563 [system] WARN: Handling cloud error: 2
0000078563 [system] WARN: Resetting WLAN due to SPARK_WLAN_RESET
0000078567 [hal.wlan] INFO: Using internal antenna
0000078569 [system] INFO: ARM_WLAN_WD 1
0000093407 [system] INFO: ARM_WLAN_WD 2

It looks like it is timing out trying to connect to the cloud.

Did you have to do anything special with opening up TCP port 5683 for the other Photons?

Maybe you got their MAC addresses whitelisted or similar?

That is much more useful information! I can’t immediately say what that means.
One of the Elites will know what the code is. I will do some digging until a reply is found.

@bko Thank you! I did have to get their MAC addresses registered with our IT department. However, I did that for this Photon as well, so that shouldn’t be the issue. It looks like it is getting an IP address (“DHCP success”) which would not be the case if its MAC weren’t registered. Any other ideas?

I currently have the IT guys looking into the state of that port, whether it’s blocked or not, etc. I am surprised that the older Photons don’t have this problem. Any ideas on why that might be?

It does look like DHCP is successful, but I was referring to whitelisting a particular device (via MAC address or other means) to enable access to TCP 5683.

I would ask the IT guys to look at the router logs when you try to connect to the cloud. That should tell you what is going on.

The address of the Particle cloud is not one, single IP address but like many modern things on the internet can be one of many host IP addresses due to geography or load balancing etc. This can be confusing for IP folks who may be used to the older notion that there is exactly one IP address for a given service.

So it could be that in the past the other Photons got a different IP address for device.spark.io whereas you now get 107.22.156.56. Could it be that they only opened up a particular host and port combination earlier?

Let’s see if it can ping www.google.com at port 80. This code will print out some other diagnostics too. It is curious why some things show up with information and other items report 0.0.0.0. I do call Particle.process().

// Use primary serial over USB interface for logging output
SerialLogHandler logHandler;
TCPClient client;
IPAddress ip;
int reading_content = 0;
int connected = 0;
String msg = "";

void setup() {

  // The WiFi module saves credentials!
  //WiFi.clearCredentials();

  delay(10000);

  waitUntil(WiFi.ready);
  
  byte mac[6];
  Particle.process();
  
  Log.info("System version: %s", System.version().c_str());
  Log.info("Wifi SSID: %s", WiFi.SSID());
  WiFi.BSSID(mac);
  Log.info("Mac address SSID: %02x:%02x:%02x:%02x:%02x:%02x", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
  WiFi.macAddress(mac);
  Log.info("Mac address: %02x:%02x:%02x:%02x:%02x:%02x", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
  ip = WiFi.dhcpServerIP();
  Log.info("DHCP Server IP: %u.%u.%u.%u", ip[0],ip[1],ip[2],ip[3]);
  ip = WiFi.localIP();
  Log.info("Assigned IP: %u.%u.%u.%u", ip[0],ip[1],ip[2],ip[3]);
  ip = WiFi.subnetMask();
  Log.info("Subnet Mask: %u.%u.%u.%u", ip[0],ip[1],ip[2],ip[3]);
  ip = WiFi.gatewayIP();
  Log.info("Gateway IP: %u.%u.%u.%u", ip[0],ip[1],ip[2],ip[3]);
  ip = WiFi.dnsServerIP();
  Log.info("DNS Server IP: %u.%u.%u.%u", ip[0],ip[1],ip[2],ip[3]);
  
  // Do a simple port 80 test to www.google.com to test for a firewall
  // Port 80 is generally open
  ip = WiFi.resolve("www.google.com");
  Log.info("Resolved IP for www.google.com: %u.%u.%u.%u", ip[0],ip[1],ip[2],ip[3]);
  
  if (client.connect(ip, 80))
  {
      Log.info("Connected...");
      client.println("GET /search?q=unicorn HTTP/1.0");
      client.println("Host: www.google.com");
      client.println("Content-Length: 0");
      client.println();
      connected = 1;
  } 
  else
  {
      Log.info("Connection failed.");
  }
}

void loop() 
{
    if (client.available()) {
        if (reading_content == 0) {
            Log.info("Reading content...");
        }
        reading_content++;
        char c = client.read();
        if (c > 0) {
            if (c == 10 || c == 13) {
                if (msg != "") {
                    Log.info("Web>%s", (const char *) msg);
                }
                msg = "";
            } else {
                msg.concat(c);
            }
        }
    }

    if (connected && !client.connected())
    {
        if (msg != "") {
           Log.info("Web>%s", (const char *) msg); 
        }
        Log.info("Disconnecting.");
        client.stop();
        connected = 0;
    }
}

Running this bit of code should log something similar. I put a delay in setup() so there is a better chance of capturing it in the log. Notice, you will see the header response right away. The body will not show up until Google drops the connection. I pulled the example from the docs.

$ particle serial monitor
Opening serial monitor for com port: "/dev/cu.usbmodem1421"
Serial monitor opened successfully:
0000007066 [system] INFO: CLR_WLAN_WD 1, DHCP success
0000007067 [system] INFO: Cloud: connecting
0000007067 [system] INFO: Read Server Address = type:1,domain:device.spark.io
0000007079 [system] INFO: Resolved host device.spark.io to 54.175.227.173
0000007189 [system] INFO: connected to cloud 54.175.227.173:5683
0000007190 [system] INFO: Cloud socket connected
0000007190 [system] INFO: Starting handshake: presense_announce=1
0000007190 [comm.sparkprotocol.handshake] INFO: Started: Receive nonce
0000007299 [comm.sparkprotocol.handshake] INFO: Encrypting handshake nonce
0000007346 [comm.sparkprotocol.handshake] INFO: Sending encrypted nonce
0000007347 [comm.sparkprotocol.handshake] INFO: Receive key
0000007470 [comm.sparkprotocol.handshake] INFO: Setting key
0000007659 [comm.sparkprotocol.handshake] INFO: Sending HELLO message
0000007659 [comm.sparkprotocol.handshake] INFO: Receiving HELLO response
0000007767 [comm.sparkprotocol.handshake] INFO: Completed
0000007768 [system] INFO: Send spark/hardware/max_binary event
0000007768 [system] INFO: spark/hardware/ota_chunk_size event
0000007768 [system] INFO: Send spark/device/last_reset event
0000007769 [system] INFO: Send subscriptions
0000007769 [comm.sparkprotocol] INFO: Sending TIME request
0000007771 [system] INFO: Cloud connected
0000009773 [comm.sparkprotocol] INFO: Received TIME response: 1497039148
0000010773 [comm.sparkprotocol] INFO: Sending A describe message
0000011788 [comm.sparkprotocol] INFO: Sending S describe message
0000017773 [app] INFO: System version: 0.6.2
0000017773 [app] INFO: Wifi SSID: romswrf
0000017773 [app] INFO: Mac address SSID: e4:ce:8f:69:28:d1
0000017773 [app] INFO: Mac address: 6c:0b:84:59:72:95
0000017774 [app] INFO: DHCP Server IP: 0.0.0.0
0000017774 [app] INFO: Assigned IP: 10.0.1.8
0000017774 [app] INFO: Subnet Mask: 255.255.255.0
0000017774 [app] INFO: Gateway IP: 10.0.1.1
0000017775 [app] INFO: DNS Server IP: 0.0.0.0
0000017779 [app] INFO: Resolved IP for www.google.com: 216.58.194.164
0000017845 [app] INFO: Connected...
0000018056 [app] INFO: Reading content...
0000018071 [app] INFO: Web>HTTP/1.0 200 OK
0000018108 [app] INFO: Web>Date: Fri, 09 Jun 2017 20:12:39 GMT
0000018121 [app] INFO: Web>Expires: -1
0000018156 [app] INFO: Web>Cache-Control: private, max-age=0
0000018201 [app] INFO: Web>Content-Type: text/html; charset=ISO-8859-1
0000018317 [app] INFO: Web>P3P: CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."
0000018330 [app] INFO: Web>Server: gws
0000018363 [app] INFO: Web>X-XSS-Protection: 1; mode=block
0000018392 [app] INFO: Web>X-Frame-Options: SAMEORIGIN
0000018637 [app] INFO: Web>Set-Cookie: NID=105=bJ_yDctGKuWmxU2GOCiuaavFg7SKhb7ra_Je_TPoPjXXDN0B7EFraChE7ZEa4TIRc2qXc6gV2JsAxUo0P6HlWkW1SUEZplicUj0T1aL7_Iseoq26y8yU9sSp1Ybyr-NAx65OKQ~
0000018659 [app] INFO: Web>Accept-Ranges: none
0000018682 [app] INFO: Web>Vary: Accept-Encoding
0000076760 [app] INFO: Web><!doctype html><html itemscope="" itemtype="http://schema.org/SearchResultsPage" lang="en"><head><meta content="text/html; charset=UTF-8" http-equiv="Cont~
0000078978 [app] INFO: Web>beast with a single large, pointed, spiraling horn projecting from its forehead.</span><br><div class="osl"><a href="/url?q=https://en.wikipedia.org/wiki/~
0000079064 [app] INFO: Web>impossible. Impossible is nothing. Under no circumstances, never ever, not ever, <br>
0000083314 [app] INFO: Web>at no&nbsp;...</span><br></div></div><div class="g"><h3 class="r"><a href="/search?q=unicorn&amp;ie=UTF-8&amp;prmd=ivns&amp;tbm=isch&amp;tbo=u&amp;source=~
0000084869 [app] INFO: Web>Cute <b>unicorn</b> and <b>Unicorn</b> drawing.</span><br></div></div><div class="g"><div><h3 class="r"><a href="/search?q=unicorn&amp;ie=UTF-8&amp;prmd=i~
0000087146 [app] INFO: Web>and <b>unicorn</b> mimosas to Starbucks&#39;s <b>Unicorn</b> Frappucino,&nbsp;...</span></div></div><div style="margin-top:4px"><a href="/url?q=http://www~
0000088280 [app] INFO: Web>unicorne, and their source, Latin &#363;nicornis, from unus (&#8220;one&#8221;) + cornu (&#8220;horn&#8221;).</span><br></div></div><div class="g"><h3 cla~
0000089346 [app] INFO: Web>of information systems and information and communication technologies.</span><br></div></div><div class="g"><h3 class="r"><a href="/url?q=http://fortune.c~
0000090790 [app] INFO: Web>billion-dollar technology startup was once the stuff of myth.</span><br></div></div><div class="g"><h3 class="r"><a href="/url?q=https://www.cbinsights.co~
0000092050 [app] INFO: Web>more.</span><br></div></div><div class="g"><h3 class="r"><a href="/url?q=https://www.wired.com/2015/02/fantastically-wrong-unicorn/&amp;sa=U&amp;ved=0ahUK~
0000103112 [app] INFO: Web>to capture one alive. It has the body of a horse, the head of a&nbsp;...</span><br></div></div></ol></div></div></div><div style="clear:both;margin-bottom~
0000103113 [app] INFO: Disconnecting.

@cermak @bko Thank you!

Here’s an update: I did get it to connect once. It will connect for about 30 seconds, then drop, and fail to reconnect. If I leave it unplugged and off for at least an hour and try again, it will do the same thing. If I leave it plugged in and on, it just tries to connect forever. Here’s the log:

Serial monitor opened successfully:
0000009808 [system] INFO: ARM_WLAN_WD 2
0000009808 [hal.wlan] INFO: Bringing WiFi interface up with DHCP
0000023560 [system] INFO: CLR_WLAN_WD 1, DHCP success
0000023561 [system] INFO: Cloud: connecting
0000023561 [system] INFO: Read Server Address = type:1,domain:device.spark.io
0000023616 [system] INFO: Resolved host device.spark.io to 52.90.98.3
0000023640 [system] INFO: connected to cloud 52.90.98.3:5683
0000023640 [system] INFO: Cloud socket connected
0000023641 [system] INFO: Starting handshake: presense_announce=1
0000023641 [comm.sparkprotocol.handshake] INFO: Started: Receive nonce
0000023662 [comm.sparkprotocol.handshake] INFO: Encrypting handshake nonce
0000023709 [comm.sparkprotocol.handshake] INFO: Sending encrypted nonce
0000023710 [comm.sparkprotocol.handshake] INFO: Receive key
0000026393 [comm.sparkprotocol.handshake] INFO: Setting key
0000026584 [comm.sparkprotocol.handshake] INFO: Sending HELLO message
0000026584 [comm.sparkprotocol.handshake] INFO: Receiving HELLO response
0000026603 [comm.sparkprotocol.handshake] INFO: Completed
0000026603 [system] INFO: Send spark/hardware/max_binary event
0000026604 [system] INFO: spark/hardware/ota_chunk_size event
0000026605 [system] INFO: Send spark/device/last_reset event
0000026605 [system] INFO: Send subscriptions
0000026606 [comm.sparkprotocol] INFO: Sending TIME request
0000026608 [system] INFO: Cloud connected
123.123.123.123 - Our IT department requires that I keep this address confidential, though it was a valid address.
ssid: [A valid SSID]
security: 0
cipher: 0
0000029609 [comm.sparkprotocol] INFO: Received TIME response: 1497288199
0000029610 [comm.sparkprotocol] INFO: Sending A describe message
0000054611 [comm.sparkprotocol] WARN: ping ACK not received
0000054611 [system] WARN: Communication loop error, closing cloud socket
0000054611 [system] INFO: Cloud: connecting
0000054612 [system] INFO: Read Server Address = type:1,domain:device.spark.io
0000054619 [system] INFO: Resolved host device.spark.io to 52.90.98.3
0000059619 [system] ERROR: connection failed to 52.90.98.3:5683, code=-2
0000059619 [system] WARN: Cloud socket connection failed: -2
0000064620 [system] WARN: Internet Test Failed!
0000064620 [system] WARN: Resetting WLAN due to 2 failed connect attempts
0000064620 [system] WARN: Handling cloud error: 2
0000064621 [system] WARN: Resetting WLAN due to SPARK_WLAN_RESET
0000064623 [hal.wlan] INFO: Using internal antenna
0000064626 [system] INFO: ARM_WLAN_WD 1
0000065525 [system] INFO: ARM_WLAN_WD 2
0000065525 [hal.wlan] INFO: Bringing WiFi interface up with DHCP

Thoughts? I have a suspicion the firewall here is letting it through once then blocking it? Is that possible? Or is there something that I’m missing on my end?

It does smell like a firewall problem since it works over the phone’s hot spot and not this hidden network.

It is conceivable that packets are sneaking through the (adaptive) firewall before the firewall sees it and shuts it down. That should be seen in the firewall log at this point.

Any luck?

There is one or two more things to try? When I was setting up the test hidden DHCP server, for some reason now matter how many times I tried to switch it back to my main network it would not switch. After running WiFi.clearCredentials();, I was able to finally reconfigure the Photon to the network I wanted.

When I had you try to manually set the SSID, etc, all those attempts are in the WiFi memory and maybe we need to clear that out? Just an idea. Although these networks did not have a password, they are still saved.

REF: Somewhat related. Another code snippet to try if you tried to assign a static ip?

clearCredentials()
This will clear all saved credentials from the Wi-Fi module’s memory. This will return true on success and false if the Wi-Fi module has an error.

@cermak Yes, finally some luck! The IT department here finally took a look at their firewall and the IPs of the Photon’s cloud were being blocked, as well as its port. They are going to add a rule to their ACL that should permit all my Photons to talk to their cloud. So, hopefully that works! Thank you!

1 Like