Skip to content

Commit 2883e55

Browse files
committed
Implemented get mac address
Former-commit-id: e3d8e65
1 parent 6619217 commit 2883e55

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

libraries/WiFiS3/src/WiFi.cpp

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
/* -------------------------------------------------------------------------- */
55
CWifi::CWifi() : _timeout(50000){
6+
mak[0] = 0;
7+
mak[1] = 0;
8+
mak[2] = 0;
9+
mak[3] = 0;
10+
mak[4] = 0;
11+
mak[5] = 0;
612
}
713
/* -------------------------------------------------------------------------- */
814

@@ -186,11 +192,6 @@ void CWifi::end(void) {
186192

187193
}
188194

189-
/* -------------------------------------------------------------------------- */
190-
uint8_t* CWifi::macAddress(uint8_t* mac) {
191-
/* -------------------------------------------------------------------------- */
192-
return 0;
193-
}
194195

195196
static bool macStr2macArray(uint8_t *mac_out, const char *mac_in) {
196197
if(mac_in[2] != ':' ||
@@ -210,6 +211,37 @@ static bool macStr2macArray(uint8_t *mac_out, const char *mac_in) {
210211
}
211212

212213

214+
/* -------------------------------------------------------------------------- */
215+
uint8_t* CWifi::macAddress(uint8_t* mac) {
216+
/* -------------------------------------------------------------------------- */
217+
string res = "";
218+
modem.begin();
219+
if(modem.write(string(PROMPT(_MODE)),res, "%s" , CMD_READ(_MODE))) {
220+
if(atoi(res.c_str()) == 1) {
221+
if(modem.write(string(PROMPT(_MACSTA)),res, "%s" , CMD_READ(_MACSTA))) {
222+
macStr2macArray(mac, res.c_str());
223+
return mac;
224+
}
225+
}
226+
else if(atoi(res.c_str()) == 2) {
227+
if(modem.write(string(PROMPT(_MACSOFTAP)),res, "%s" , CMD_READ(_MACSOFTAP))) {
228+
macStr2macArray(mac, res.c_str());
229+
return mac;
230+
}
231+
}
232+
}
233+
234+
for(int i = 0; i < 6; i++)
235+
{
236+
mac[i] = mak[i];
237+
}
238+
239+
return mac;
240+
}
241+
242+
243+
244+
213245
/* -------------------------------------------------------------------------- */
214246
int8_t CWifi::scanNetworks() {
215247
/* -------------------------------------------------------------------------- */
@@ -355,9 +387,6 @@ static uint8_t Encr2wl_enc(string e) {
355387
}
356388
}
357389

358-
359-
360-
361390
/* -------------------------------------------------------------------------- */
362391
uint8_t CWifi::encryptionType(uint8_t networkItem) {
363392
if(networkItem < access_points.size()) {
@@ -367,10 +396,6 @@ uint8_t CWifi::encryptionType(uint8_t networkItem) {
367396
}
368397
/* -------------------------------------------------------------------------- */
369398

370-
371-
372-
373-
374399
/* -------------------------------------------------------------------------- */
375400
uint8_t* CWifi::BSSID(uint8_t networkItem, uint8_t* bssid) {
376401
if(networkItem < access_points.size()) {

libraries/WiFiS3/src/WiFi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CWifi {
3030
private:
3131
void _config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2);
3232
unsigned long _timeout;
33-
33+
uint8_t mak[6];
3434
vector<CAccessPoint> access_points;
3535

3636
public:

0 commit comments

Comments
 (0)