Skip to content

Commit

Permalink
Fixes #12 - non-ASCII characters
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-ger committed Feb 23, 2020
1 parent c94f5fd commit ae8b9d2
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ The console understands the following command:
- unlock [password]: unlocks the config, requires password of the network AP
- scan: does a scan for APs

If you want to enter non-ASCII or special characters you can use HTTP-style hex encoding (e.g. "My%20AccessPoint") or, only on the CLI, as shortcut C-style quotes with backslash (e.g. "My\ AccessPoint"). Both methods will result in a string "My AccessPoint".

# Usage as AP
You can also turn the sides and make the ESP to work as AP - useful e.g. if you want to connect other devices to a RasPi that has no WiFi interface:

Expand Down
Binary file modified firmware/0x00000.bin
Binary file not shown.
Binary file modified firmware/0x10000.bin
Binary file not shown.
90 changes: 69 additions & 21 deletions user/user_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,77 @@ static os_timer_t ptimer;
// Similar to strtok
int ICACHE_FLASH_ATTR parse_str_into_tokens(char *str, char **tokens, int max_tokens)
{
char *p;
int token_count = 0;
bool in_token = false;
char *p, *q, *end;
int token_count = 0;
bool in_token = false;

p = str;
// preprocessing
for (p = q = str; *p != 0; p++)
{
if (*(p) == '%' && *(p + 1) != 0 && *(p + 2) != 0)
{
// quoted hex
uint8_t a;
p++;
if (*p <= '9')
a = *p - '0';
else
a = toupper(*p) - 'A' + 10;
a <<= 4;
p++;
if (*p <= '9')
a += *p - '0';
else
a += toupper(*p) - 'A' + 10;
*q++ = a;
}
else if (*p == '\\' && *(p + 1) != 0)
{
// next char is quoted - just copy it, skip this one
*q++ = *++p;
}
else if (*p == 8)
{
// backspace - delete previous char
if (q != str)
q--;
}
else if (*p <= ' ')
{
// mark this as whitespace
*q++ = 0;
}
else
{
*q++ = *p;
}
}

while (*p != 0) {
if (*p <= ' ') {
if (in_token) {
*p = 0;
in_token = false;
}
} else {
if (!in_token) {
tokens[token_count++] = p;
if (token_count == max_tokens)
return token_count;
in_token = true;
}
}
p++;
}
return token_count;
end = q;
*q = 0;

// cut into tokens
for (p = str; p != end; p++)
{
if (*p == 0)
{
if (in_token)
{
in_token = false;
}
}
else
{
if (!in_token)
{
tokens[token_count++] = p;
if (token_count == max_tokens)
return token_count;
in_token = true;
}
}
}
return token_count;
}


Expand Down

0 comments on commit ae8b9d2

Please sign in to comment.