I wrote a script to flash device but forgot to flash soft-ap suffix name.
I got several hundred device with same soft-ap suffix.
I want to generate soft-ap suffix base device id.
Is that possible to make it a standard feature then I do not have to hack the absolute address.
init_ap_name() will set the soft-ap name and if the name is the same as it already saved in flash no System.set() will be called.
START_UP(init_ap_name());
uint32_t get_prefix_base(void)
{
#define DCT_BASE1 0x0004000
#define DCT_BASE2 0x0008000
uint8_t flag1[2];
uint8_t flag2[2];
flag1[0] = *((uint8_t *)(DCT_BASE1 + 8));
flag1[1] = *((uint8_t *)(DCT_BASE1 + 9));
flag2[0] = *((uint8_t *)(DCT_BASE2 + 8));
flag2[1] = *((uint8_t *)(DCT_BASE2 + 9));
if (flag1[0] == 0x00 && flag1[1] == 0x01) {
return (0x80064B8 - 26);
}
if (flag2[0] == 0x00 && flag2[1] == 0x01) {
return (0x800A4B8 - 26);
}
return 0;
}
void read_ap_name_suffix(char *suffix)
{
char *suffix_add = ((char *)(26 + get_prefix_base()));
strncpy(suffix, suffix_add, 5);
Serial.printf("suffix %s \r\n", suffix);
}
void read_ap_name_prefix(char *prefix)
{
char *prefix_add = ((char *)(1 + get_prefix_base()));
strncpy(prefix, prefix_add, 6);
Serial.printf("prefix %s \r\n", prefix);
}
bool is_same_data(char *s1, char *s2, int32_t num)
{
for (int32_t i = 0; i < num; i++) {
if (s1[i] != s2[i]) {
return false;
}
}
return true;
}
void init_ap_name(void)
{
/*char m_c[62] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
};*/
char m_c[62] = { '8', '9', 'C', 'D', '6', '7', 'y', 'z', 'A', 'B', '2', '3', 'm', 'n', 'a', 'b', '0', '1', 'c', 'd', '4', '5', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'S', 'T', 'U', 'V', 'w', 'x', 'W', 'X', 'O', 'P', 'Q', 'R', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'Y', 'Z', 'o', 'p', 'q', 'r', 'u', 'v', 's', 't',};
String id = System.deviceID();
char suffix[6];
char prefix[26] = {'a', 'e', 'r', 'i', 's', '\0'};
suffix[4] = '\0';
uint8_t u_id[24];
for (int32_t i = 0; i < 24; i++) {
u_id[i] = id.charAt(i);
}
uint32_t suffix_index[4];
suffix_index[0] = (u_id[0] ^ u_id[1] ^ u_id[2] ^ u_id[23] ^ u_id[22] ^ u_id[21]) % sizeof(m_c);
suffix_index[1] = (u_id[3] ^ u_id[4] ^ u_id[5] ^ u_id[20] ^ u_id[19] ^ u_id[18]) % sizeof(m_c);
suffix_index[2] = (u_id[6] ^ u_id[7] ^ u_id[8] ^ u_id[17] ^ u_id[16] ^ u_id[15]) % sizeof(m_c);
suffix_index[3] = (u_id[9] ^ u_id[12] ^ u_id[15] ^ u_id[14] ^ u_id[13] ^ u_id[12]) % sizeof(m_c);
suffix[0] = m_c[suffix_index[0]];
suffix[1] = m_c[suffix_index[1]];
suffix[2] = m_c[suffix_index[2]];
suffix[3] = m_c[suffix_index[3]];
char cur_prefix[26];
char cur_suffix[6];
read_ap_name_suffix(cur_suffix);
read_ap_name_prefix(cur_prefix);
if (!is_same_data(cur_suffix, suffix, 5)) {
System.set(SYSTEM_CONFIG_SOFTAP_SUFFIX, suffix);
Serial.printf("suffix is not the same %s %s\r\n", cur_suffix, suffix);
} else {
Serial.printf("suffix is the same\r\n");
}
if (!is_same_data(cur_prefix, prefix, 5)) {
Serial.printf("prefix is not the same %s %s\r\n", cur_prefix, prefix);
System.set(SYSTEM_CONFIG_SOFTAP_PREFIX, "aeris");
} else {
Serial.printf("prefix is the same\r\n");
}
}