8000 research project first commit · espressif/arduino-esp32@fbbba44 · GitHub
[go: up one dir, main page]

Skip to content

Commit fbbba44

Browse files
research project first commit
1 parent 884e417 commit fbbba44

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

libraries/WiFi/examples/WiFiSmartConfig/WiFiSmartConfig.ino

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
11
#include "WiFi.h"
2+
#include "mbedtls/md.h" //Included for generation of key
23

34
void setup() {
45
Serial.begin(115200);
56

67
//Init WiFi as Station, start SmartConfig
78
WiFi.mode(WIFI_AP_STA);
8-
WiFi.beginSmartConfig();
9+
10+
// --------------------------------------------------------------------
11+
char *prodKey = ""; //ProductKey = Per Vendor
12+
char *devID = ""; //DeviceID = Per IoT Device
13+
byte hmacResult[32];
14+
15+
mbedtls_md_context_t ctx;
16+
mbedtls_md_type_t md_type = MBEDTLS_MD_SHA256;
17+
18+
const size_t devIDLength = strlen(devID);
19+
const size_t prodKeyLength = strlen(prodKey);
20+
21+
mbedtls_md_init(&ctx);
22+
mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(md_type), 1);
23+
mbedtls_md_hmac_starts(&ctx, (const unsigned char *) prodKey, prodKeyLength);
24+
mbedtls_md_hmac_update(&ctx, (const unsigned char *) devID, devIDLength);
25+
mbedtls_md_hmac_finish(&ctx, hmacResult);
26+
mbedtls_md_free(&ctx);
27+
28+
//Serial.print("Hash: ");
29+
/*
30+
for(int i= 0; i< sizeof(hmacResult); i++){
31+
char str[3];
32+
33+
sprintf(str, "%02x", (int)hmacResult[i]);
34+
Serial.print(str);
35+
}
36+
*/
37+
38+
WiFi.beginSmartConfig(hmacResult); //Enter param (byte hmacResult[32])
39+
40+
// --------------------------------------------------------------------
941

1042
//Wait for SmartConfig packet from mobile
1143
Serial.println("Waiting for SmartConfig.");

libraries/WiFi/src/WiFiSTA.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ bool WiFiSTAClass::_smartConfigStarted = false;
621621
bool WiFiSTAClass::_smartConfigDone = false;
622622

623623

624-
bool WiFiSTAClass::beginSmartConfig() {
624+
bool WiFiSTAClass::beginSmartConfig(byte hmac_key[32]) {
625625
if (_smartConfigStarted) {
626626
return false;
627627
}

libraries/WiFi/src/WiFiSTA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class WiFiSTAClass
8787
static bool _autoReconnect;
8888

8989
public:
90-
bool beginSmartConfig();
90+
bool beginSmartConfig(byte hmac_key[32]); //Include param (byte hmacResult[32])
9191
bool stopSmartConfig();
9292
bool smartConfigDone();
9393

0 commit comments

Comments
 (0)
0