Preparation for ESP-Now code
Posted: Tue Jul 05, 2022 11:20 pm
In an example provided on the micropython site titled "— Support for the ESP-NOW protocol" for ESP-Now coding the following MAC Address format was suggested for a given peer:
peer = b'\xbb\xbb\xbb\xbb\xbb\xbb'
While I could simply add the MAC Address by hand as indicated above, I am able the read the MAC Address by code directly, but it doesn't appear to be in the correct format as seemingly required above.
Here is a code snippet:
mac1 = ubinascii.hexlify(net.config('mac')) #Retrieves MAC Address from device
print(mac1)
b'84cca8803d6b'
print(type(mac1))
<class 'bytes'>
print(len(mac1))
12
# Manual data input; as per example.
mac2 = b'\x84\xcc\xa8\x80\x3d\x6b'
print(mac2)
b'\x84\xcc\xa8\x80=k'
print(type(mac2))
<class 'bytes'>
print(len(mac2))
6
You will note the byte length difference 12 vs. 6. Also I don't understand the printed output of mac2 (b'\x84\xcc\xa8\x80=k') from the manual input. It appears to only display the first 3 MAC Address codes, and I have no idea what the "=k" means. But this is what follows from manually inputting the MAC Address as per the example posted.
If the manual input format is correct, I would like a suggestion as to how to format the 12 byte mac1 to the seemingly 6 byte format of mac2.
Thank MM.
peer = b'\xbb\xbb\xbb\xbb\xbb\xbb'
While I could simply add the MAC Address by hand as indicated above, I am able the read the MAC Address by code directly, but it doesn't appear to be in the correct format as seemingly required above.
Here is a code snippet:
mac1 = ubinascii.hexlify(net.config('mac')) #Retrieves MAC Address from device
print(mac1)
b'84cca8803d6b'
print(type(mac1))
<class 'bytes'>
print(len(mac1))
12
# Manual data input; as per example.
mac2 = b'\x84\xcc\xa8\x80\x3d\x6b'
print(mac2)
b'\x84\xcc\xa8\x80=k'
print(type(mac2))
<class 'bytes'>
print(len(mac2))
6
You will note the byte length difference 12 vs. 6. Also I don't understand the printed output of mac2 (b'\x84\xcc\xa8\x80=k') from the manual input. It appears to only display the first 3 MAC Address codes, and I have no idea what the "=k" means. But this is what follows from manually inputting the MAC Address as per the example posted.
If the manual input format is correct, I would like a suggestion as to how to format the 12 byte mac1 to the seemingly 6 byte format of mac2.
Thank MM.