Skip to content

Commit

Permalink
Allow chip-tool echo-ble to work along with credential passing (#1965)
Browse files Browse the repository at this point in the history
Prior to #1898, received bluetooth messages were echoed back
to the sender, and this facility is used by the command-line
`chip-tool echo-ble`. To restore that, this change adopts a
stricter format for WiFi credentials and treats anything else
as an echo request. (This too is temporary code, pending an
actual rendezvous implementation.)
  • Loading branch information
kpschoedel authored Aug 6, 2020
1 parent 90d3d88 commit a2a5622
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions examples/wifi-echo/server/esp32/main/RendezvousSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,25 @@ void RendezvousSession::HandleMessageReceived(Ble::BLEEndPoint * endPoint, Packe

ChipLogProgress(Ble, "RendezvousSession: Receive message: %s", msg);

char * ssid = strtok(msg, ":");
char * key = strtok(NULL, ":");
ChipLogProgress(Ble, "RendezvousSession: SSID: %s, key: %s", ssid, key);
SetWiFiStationProvisioning(ssid, key);
if ((bufferLen > 3) && (msg[0] == msg[1]) && (msg[0] == msg[bufferLen - 1]))
{
// WiFi credentials, of the form ‘::SSID:password:’, where ‘:’ can be any single ASCII character.
msg[1] = 0;
char * ssid = strtok(&msg[2], msg);
char * key = strtok(NULL, msg);
if (ssid && key)
{
ChipLogProgress(Ble, "RendezvousSession: SSID: %s, key: %s", ssid, key);
SetWiFiStationProvisioning(ssid, key);
}
else
{
ChipLogError(Ble, "RendezvousSession: SSID: %p, key: %p", ssid, key);
}
}
else
{
// Echo.
mEndPoint->Send(buffer);
}
}
2 changes: 1 addition & 1 deletion src/darwin/CHIPTool/CHIPTool/QRCode/QRCodeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ - (void)retrieveAndSendWifiCredentials

- (void)sendWifiCredentialsWithSSID:(NSString *)ssid password:(NSString *)password
{
NSString * msg = [NSString stringWithFormat:@"%@:%@", ssid, password];
NSString * msg = [NSString stringWithFormat:@"::%@:%@:", ssid, password];
NSError * error;
BOOL didSend = [self.chipController sendMessage:[msg dataUsingEncoding:NSUTF8StringEncoding] error:&error];
if (!didSend) {
Expand Down

0 comments on commit a2a5622

Please sign in to comment.