Created
January 23, 2022 02:46
-
-
Save mattrude/062405e9dc1f3d8f74b662378ea14d6f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/python | |
# Python code for writing eeprom data to a 25AA128 | |
data = bytearray([ | |
# Set ABP Byte (1-byte) | |
0x01, | |
# TTN Device Address, 4 Bytes, MSB | |
0xCB, 0x4B, 0xCC, 0x18, # devaddr | |
# TTN Network Key, 16 Bytes, MSB | |
0xB8, 0xA8, 0x2B, 0xB4, 0xB9, 0x73, 0xDF, 0x26, 0x21, 0x6E, 0x20, 0x35, 0x88, 0x17, 0xF0, 0x3F, # nwkey | |
# TTN Application Key, 16 Bytes, MSB | |
0x3A, 0x89, 0x5B, 0x87, 0xF1, 0x00, 0x7F, 0xA5, 0x5C, 0x8A, 0x85, 0x5D, 0xBD, 0x61, 0xEC, 0x63, # appkey | |
]) | |
with open("lorawan-eeprom.bin", "wb") as out_file: | |
out_file.write(data) |
This file contains hidden or 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
#!/bin/python | |
# Python code for writing eeprom data to a 25AA128 | |
data = bytearray([ | |
# Set OTAA Byte (1-byte) | |
0x02, | |
# TTN DevID (MSB, 8-bytes) | |
0x00, 0x4A, 0x47, 0xA6, 0x46, 0x75, 0x2A, 0xAA, # DevID | |
# TTN AppEUI (MSB, 8-bytes) | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # AppEUI | |
# TTN AppKey (MSB, 16-bytes) | |
0xAA, 0x00, 0xDD, 0xB2, 0xA8, 0xD7, 0xD6, 0x83, 0xC6, 0x07, 0x22, 0x82, 0xEE, 0xD9, 0xC5, 0xCF, # AppKey | |
]) | |
with open("lorawan-eeprom.bin", "wb") as out_file: | |
out_file.write(data) |
This file contains hidden or 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
# Create library object using our bus i2c port for si7021 | |
i2c = busio.I2C(board.SCL, board.SDA) | |
# EEPROM Memory | |
import adafruit_24lc32 | |
eeprom = adafruit_24lc32.EEPROM_I2C(i2c) | |
type = eeprom[0] | |
if type == b'\x01': | |
print("LoRaWAN Type: ABP") | |
devaddr = eeprom[1:5] | |
nwkey = eeprom[5:21] | |
app = eeprom[21:37] | |
else: | |
print("LoRaWAN Type: Failed!!!") | |
ttn_config = TTN(devaddr, nwkey, app, country="US") | |
lora = TinyLoRa(spi, cs, irq, rst, ttn_config, channel=None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment