[SOLVED] Ability to start in ANT AUTO but switch to ANT EXTERNAL if connected?

I find with ANT AUTO I see frequent disconnects (in older firmware, 0.7.0 and 0.8.0-rc4). The Photon is using an external antenna in an outdoor location. The disconnects are random (not consistently tied to any particular code running at the time) and last for about 10 seconds. After reading this post with this situation solved by specifying ANT EXTERNAL I tried it.

OK, so that does solve it (1 disconnect/day versus 73). However, I only assemble the external antenna at the end when completing the enclosure and perform testing prior to that. If my firmware specifies ANT EXTERNAL then the Photon will not connect with the internal antenna - voiding testing capability and eliminates ability for OTA flashes. I would prefer to only flash once, not once with a ‘testing’ version, and again with a production version.

My ideal is something like:
Set startup antenna to AUTO (in case there is no external antenna connected).
Have the Photon determine if an external antenna is present (regardless whether the external or internal has the stronger RSSI…within acceptable range), and if so, only then switch permanently and exclusively to the external antenna.

I guess this may be something that can be improved on the Particle firmware side with ANT AUTO’s dynamic rapid switching behavior…but until then anyone with suggestions on how to implement this on our side?

How close is the wifi when doing your setup? I’ve been able to use the external antenna, without it being attached, and still setup, claim, program, and test my products.

Interesting to know. The router is in the same room, yet it doesn’t come online. This was many months ago when I ran into that issue and since it blocked further OTA updates I’ve avoided it like the plague. It may be worth checking testing again.

1 Like

Since you have to select the antenna at startup, I’m not sure if you can call a function to change that.

The reason why the docs state you should select the antenna on startup is to ensure that you have reception right from the start, but you can change your mind during runtime.
This is also supported by this statement
https://docs.particle.io/reference/firmware/photon/#selectantenna-antenna-

@bloukingfisher, since the antenna selection is a sticky setting, you only need to set the desired selection once on demand (e.g. via a button - you can even use the onboard SETUP button for that, which is refered to by BTN in code).

1 Like

Thanks @ScruffR, I did not realize it can be used outside startup.
@Mjones it seems you are correct. Even with external antenna selected, in the same room as the router, I can program, etc. and it maintains a connection. That did not work for me before, but I have changed my router since those days.

Below is my code attempting to determine if an external is connected - and to use it, or, fall back to internal (or Auto).

However, in the console what I’m seeing is that it connects to external (returns a 0 for success) whether the external antenna is physically connected or not. So it doesn’t appear that the Photon can actually distinguish whether an antenna is plugged in (perhaps if the surface connector was removed it would know).

While running and I actually plug in an external I can see the signal quality improve.
FWIW, the RSSI when connected to internal is -41 to -46, with external connected -33 to -37, and in firmware connected to external but no actual external physically connected -51 to -61

STARTUP(WiFi.selectAntenna(ANT_AUTO)); //set it for AUTO, and in SETUP check if External is connected

void setup() {

delay(3000);
//WiFi.selectAntenna() returns 0 on success, or -1005 if the antenna choice was not found. 
//Other errors that may appear will all be negative values.

  if (WiFi.selectAntenna(ANT_EXTERNAL) != 0) 
  {
    WiFi.selectAntenna(ANT_INTERNAL);
    delay(3000);
    Particle.publish("Wifi antenna", "Switched to INTERNAL", PRIVATE);
    Particle.publish("WiFi signal", String(WiFi.RSSI()), 360, PRIVATE);
    
  }
  else
  {
    delay(3000);
    Particle.publish("Wifi antenna", "Connected successfully to EXTERNAL", PRIVATE);
    Particle.publish("WiFi signal", String(WiFi.RSSI()), 360, PRIVATE);
  }
  
  
}

void loop() {

delay(20000);
Particle.publish("WiFi signal", String(WiFi.RSSI()), 360, PRIVATE);
}

And in the Console:

I think for my purposes I can rest easy just specifying external and leaving it at that. The only workaround I can see for what I really wanted to achieve is to connect each antenna, measure the RSSI, compare which one has the stronger signal and selecting that one. The only real reason for that would be the “flaky” auto if it doesn’t seem to reliably switch and remain connected.

1 Like