Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have a question. #2

Open
dbdbdee opened this issue Jan 8, 2024 · 2 comments
Open

I have a question. #2

dbdbdee opened this issue Jan 8, 2024 · 2 comments

Comments

@dbdbdee
Copy link

dbdbdee commented Jan 8, 2024

First of all, I am not good at English. Please understand.

I start pairing on Unifying software and when I connect the device, it works well until the device presses the key.

But when I disconnect and reconnect the device, it doesn't work.

Every time I reconnect the device, I have to make a new pairing to make the device work.

I want the device to work without pairing when I reconnect the device if it's already paired.

What should I do?

@decrazyo
Copy link
Owner

decrazyo commented Jan 8, 2024

A device gets a unique RF address and AES encryption key when it's paired to a receiver.
My example code will forget those values when it's powered off.

To fix this, you would have to save the RF address and AES encryption key to non-volatile memory, such as flash or EEPROM, after pairing and load those values back into memory when the device is rebooted.
The way you do that depends on what hardware you're using, which is why I didn't include that functionality in the example code.

I have added comments to the example code to indicate what needs to be done.

I would recommend looking at the Arduino EEPROM library to learn about saving and loading data.
https://docs.arduino.cc/learn/built-in-libraries/eeprom

@dbdbdee
Copy link
Author

dbdbdee commented Jan 9, 2024

Thank you for your answer.

if(err) {
uint8_t id = random();
uint16_t product_id = 0x1025;
uint16_t device_type = 0x0147;
uint32_t crypto = random();
uint32_t serial = 0xA58094B6;
uint16_t capabilities = 0x1E40;
char name[] = "Hacked";
uint8_t name_length = strlen(name);

err = unifying_pair(&state,
id,
product_id,
device_type,
crypto,
serial,
capabilities,
name,
name_length);
}

printf("Address : %d %d %d %d %d\n",address[0],address[1],address[2],address[3],address[4]);
printf("AesKey : %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n",aes_key[0],aes_key[1],aes_key[2],aes_key[3],aes_key[4],aes_key[5],aes_key[6],aes_key[7],aes_key[8],aes_key[9],aes_key[10],aes_key[11],aes_key[12],aes_key[13],aes_key[14],aes_key[15]);

for(int i = 0; i < 5; i++) {
EEPROM.write(i, address[i]);
}
for(int i =0; i <16; i++) {
EEPROM.write(i+5, aes_key[i]);
}

I modified the code like this at the bottom.

uint32_t aes_counter = random();
// TODO: Check if we have previously paired to a receiver.
// If so, load "address" and "aes_key" from non-volatile memory.
for(int i = 0; i < 5; i++) {
address[i]=EEPROM.read(i);
}
for(int i = 0; i <= 16; i++) {
aes_key[i]=EEPROM.read(i+5);
}
printf("Address : %d %d %d %d %d\n",address[0],address[1],address[2],address[3],address[4]);
printf("AesKey : %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n",aes_key[0],aes_key[1],aes_key[2],aes_key[3],aes_key[4],aes_key[5],aes_key[6],aes_key[7],aes_key[8],aes_key[9],aes_key[10],aes_key[11],aes_key[12],aes_key[13],aes_key[14],aes_key[15]);

I modified the code at the top like this.

But after the initial pairing was successful, it doesn't work when I remove and reconnect the device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants