Last active
August 29, 2015 14:05
-
-
Save toke/d75b8b1f22347ed40e54 to your computer and use it in GitHub Desktop.
Derive MAC adress from 1wire sensor address.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint8_t mac[] = { 0x02, 0xAD, 0x3A, 0x6E, 0xFE, 0xE1 }; // DEFAULT MAC | |
//... | |
if (sensors.count > 0) { | |
// Derive MAC address from OneWire Address | |
derive_mac(sensors.sensor[0].address, mac); | |
} | |
Ethernet.begin((uint8_t*)mac, ip); | |
//... | |
/* | |
Derive MAC address from OneWire serial | |
by using 6 bit of first byte and last 40 bits | |
of w1addr as mac address. | |
Bit 7+8 are zeroed to mark mac-address as | |
private. | |
*/ | |
void derive_mac(uint8_t * w1addr, uint8_t * mac) { | |
memcpy(mac, w1addr + 1, 6); | |
mac[0] = mac[0] | 0x02; | |
return; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment