mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
#722 Updated to used improved MAC address string construction.
This commit is contained in:
parent
a35b05c4a9
commit
6f470b1608
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
*~
|
||||
*.tgz
|
||||
*.o
|
||||
*.elf
|
||||
*.hex
|
||||
@ -21,3 +22,4 @@ diffs/*
|
||||
.settings
|
||||
MDN_URLS.txt
|
||||
node_modules
|
||||
/build/
|
||||
|
||||
@ -769,10 +769,7 @@ static JsVar *getIPInfo(int interface) {
|
||||
|
||||
uint8 macAddr[6];
|
||||
wifi_get_macaddr(interface, macAddr);
|
||||
char macAddrString[6*2 + 1];
|
||||
os_sprintf(macAddrString, "%2x%2x%2x%2x%2x%2x",
|
||||
macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4], macAddr[5]);
|
||||
jsvObjectSetChildAndUnLock(jsIpInfo, "mac", jsvNewFromString(macAddrString));
|
||||
networkPutAddressAsString(jsIpInfo, "mac", macAddr, 6, 16, ':');
|
||||
return jsIpInfo;
|
||||
}
|
||||
|
||||
|
||||
@ -83,6 +83,17 @@ bool networkParseMACAddress(unsigned char *addr, const char *ip) {
|
||||
return i==5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a buffer of bytes pointed to by ip ... for a length of nBytes into a string where each
|
||||
* byte is separated by a separator character. The numeric base of the bytes is given by the base
|
||||
* value.
|
||||
*
|
||||
* For example, to create a dotted decimal string, one would use:
|
||||
* networkGetAddressAsString(ip, 4, 10, '.')
|
||||
*
|
||||
* To create a Mac address, one might use:
|
||||
* networkGetAddressAsString(mac, 6, 16, ':')
|
||||
*/
|
||||
JsVar *networkGetAddressAsString(unsigned char *ip, int nBytes, unsigned int base, char separator) {
|
||||
char data[64] = "";
|
||||
int i = 0, dir = 1, l = 0;
|
||||
@ -108,6 +119,17 @@ JsVar *networkGetAddressAsString(unsigned char *ip, int nBytes, unsigned int bas
|
||||
return jsvNewFromString(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a buffer of bytes pointed to by ip ... for a length of nBytes into a string member of an object where each
|
||||
* byte is separated by a separator character. The numeric base of the bytes is given by the base
|
||||
* value.
|
||||
*
|
||||
* For example, to create a dotted decimal string, one would use:
|
||||
* networkPutAddressAsString(myObject,"ip", ip, 4, 10, '.')
|
||||
*
|
||||
* To create a Mac address, one might use:
|
||||
* networkPutAddressAsString(myObject, "mac", mac, 6, 16, ':')
|
||||
*/
|
||||
void networkPutAddressAsString(JsVar *object, const char *name, unsigned char *ip, int nBytes, unsigned int base, char separator) {
|
||||
jsvObjectSetChildAndUnLock(object, name, networkGetAddressAsString(ip, nBytes, base, separator));
|
||||
}
|
||||
|
||||
@ -130,6 +130,28 @@ and
|
||||
|
||||
----
|
||||
|
||||
##wifi.getAPIP
|
||||
|
||||
`wifi.getIP()`
|
||||
|
||||
Returns an object that contains the details of the current access point IP address. The object contains:
|
||||
|
||||
* `ip` - The current IP address
|
||||
* `gw` - The current Gateway address
|
||||
* `netmask` - The current Netmask value
|
||||
* `mac` - The MAC Address of the access point interface.
|
||||
|
||||
Each of these properties are 32 bit integers (4 bytes corresponding to the IP address). To convert these
|
||||
into string dotted decimal format one can use the `ESP8266WiFi.getAddressAsString` function.
|
||||
|
||||
For example:
|
||||
|
||||
var wifi = require("wifi");
|
||||
var ipInfo = wifi.getAPIP();
|
||||
print("Wifi AP IP info: " + JSON.stringify(ipInfo));
|
||||
|
||||
----
|
||||
|
||||
##wifi.connect
|
||||
|
||||
Connect to a named access point.
|
||||
@ -229,6 +251,7 @@ Returns an object that contains the details of the current IP address. The obje
|
||||
* `ip` - The current IP address
|
||||
* `gw` - The current Gateway address
|
||||
* `netmask` - The current Netmask value
|
||||
* `mac` - The MAC Address of the station interface.
|
||||
|
||||
Each of these properties are 32 bit integers (4 bytes corresponding to the IP address). To convert these
|
||||
into string dotted decimal format one can use the `ESP8266WiFi.getAddressAsString` function.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user