harlequin-tech / WiFlyHQ

WiFly RN-XV Arduino Library
Other
110 stars 68 forks source link

Escape spaces in SSID, passphrase #13

Closed lonnon closed 11 years ago

lonnon commented 12 years ago

The WiFly commands for setting SSID and passphrase (`set wlan ssid

` and `set wlan phrase `, respectively) use a dollar sign ($) in place of the space character, presumably to work around limitations in its command parser. Most code I've seen that uses the WiFly RN-XV library works around this limitation simply by inserting dollar signs into the string that makes up the SSID and passphrase: const char mySSID[] = "here$be$spaces"; const char myPassword[] = "and$here$be$more"; This works fine for the password, because the only WiFly command that uses it is `set wlan phrase `. However, the SSID is used in two places in the various WiFly::join methods, once for setting the SSID (`set wlan ssid `) and once for joining the wireless network (`join `). The `join ` command does _not_ use dollar signs as space replacements; in fact, it expects to see space characters, and using dollar signs results in a failed connection to a network whose SSID contains spaces. Long story short, this commit works around the problem by replacing spaces with dollar signs where appropriate (when calling `set wlan ssid` and `set wlan phrase`), but passes the SSID intact to the `join` command. This means that code using the WiFly library can declare SSID and passphrase strings in a more readable fashion: const char mySSID[] = "here be spaces"; const char myPassword[] = "and here be more"; One caveat: if the passphrase actually contains dollar signs, this code will fail to connect, because it will replace them with spaces. However, the same thing will happen if you directly call the `set wlan phrase` command in the WiFly command mode; it swaps $ for space already, so this is known, if somewhat unexpected, behavior. Dollar signs aren't valid characters in an SSID, so it shouldn't be a problem there.
harlequin-tech commented 11 years ago

Hi Lonnon, sorry for the slow response. I pushed some code I had around for a while that handles replacing spaces with the substitute character. It has the WLAN passphrase supported, and I'll add the SSID also.

Thanks for your patch. I'd like to avoid using the string class because it allocates memory and is a bit bloated, and one of the goals for the WiFlyHQ library is to be really lean with memory use.

Cheers, Harlequin.

harlequin-tech commented 11 years ago

Added SSID space substitution code. Functionality matches Lonnon, without the use of C++ strings and mallocs.