增加子设备密钥配置

This commit is contained in:
zzh 2026-01-09 10:41:38 +08:00
parent b4d4043b5a
commit 89263932b2

33
main.c
View File

@ -157,7 +157,7 @@ int fd;
int UPCASE=0;
int count_value=0;
int getPayloadTime=100*1000;//usecond
char softwareVersion[16]="2.1.27";
char softwareVersion[16]="2.1.30";
//char stationsn[16]="d126ei4lj4cc00";//TJ250995217957
//char productid[8]="10045";
//char appSecret[64]="s3izIliw0CF48Pcsi16rjOmoFRf5WEt8";
@ -165,6 +165,7 @@ char stationsn[32]="90A9F73002CD";
char productid[16]="WcLightStrip";
char appKey[32]="fdhQmhqhvbL1cf1K9mUqt";
char appSecret[64]="RxU8NZjfZaxsKg2B3Dr6sx";
char subid[64]="EKmmjqyLRgghANEiQAA5LZ"; // 默认值,可从文件覆盖
char hostDomain[64]="auk-iot.test1.zservey.com";
int mqtt_port=1883;
//char hostDomain[64]="127.0.0.1";
@ -275,7 +276,7 @@ void report_lightbar_login(uint16_t tagCodeHead, uint32_t tagCode) {
subDeviceKey, subDeviceKey, "WcSubLightStrip", MQTT_ALGORITHM, timestamp_str);
// 使用HMAC-SHA1计算password
hmacsha1_hex("EKmmjqyLRgghANEiQAA5LZ", stringToSign, password, sizeof(password));
hmacsha1_hex(subid, stringToSign, password, sizeof(password));
// 构建topic
snprintf(topic, sizeof(topic), "/auk/iot/things/v1/sub/device/up/login/WcSubLightStrip/%s/%ld",
@ -286,8 +287,8 @@ void report_lightbar_login(uint16_t tagCodeHead, uint32_t tagCode) {
"{\"password\":\"%s\",\"timestamp\":%ld,\"signingAlgorithm\":\"%s\"}",
password, timestamp, MQTT_ALGORITHM);
//LOG_I("Lightbar login report - topic: %s\n", topic);
//LOG_I("Lightbar login report - payload: %s\n", payload);
LOG_I("Lightbar login report - topic: %s\n", topic);
LOG_I("Lightbar login report - payload: %s\n", payload);
// 发送MQTT消息
mqtt_utils_publish(&mqtt_config, topic, 0, payload, strlen(payload));
@ -636,7 +637,7 @@ void report_lightbar_logout(uint16_t tagCodeHead, uint32_t tagCode) {
subDeviceKey, subDeviceKey, "WcSubLightStrip", MQTT_ALGORITHM, timestamp_str);
// 使用HMAC-SHA1计算password
hmacsha1_hex("EKmmjqyLRgghANEiQAA5LZ", stringToSign, password, sizeof(password));
hmacsha1_hex(subid, stringToSign, password, sizeof(password));
// 构建topic (logout)
snprintf(topic, sizeof(topic), "/auk/iot/things/v1/sub/device/up/logout/WcSubLightStrip/%s/%ld",
@ -2430,8 +2431,12 @@ void *thread_uart_recv_data(void *arg){
while(1){
uart_data_receive_data_back(&uartRecvData,&parmAck,&tagCodeHead,&tagCode,&tagSignal,&totalLen,&tagFeature,
&count,&batteryV,&version,&ledCtrl,&signCode,&reserve,&lableParm);
// 只在有效数据时才打印tag不为0
if(tagCode != 0) {
LOG_I("recv_data:%04x,%04x,tag:%08x,%02x,%02x,%02x,%02x,battery:%02x,%04x,%02x,%04x,reserve:%04x,%08x\n",
parmAck,tagCodeHead,tagCode,tagSignal,totalLen,tagFeature,count,batteryV,version,ledCtrl,signCode,reserve,lableParm);
}
// 检查是否有待确认的亮灯任务如果tag匹配则上报亮灯成功
report_light_success(tagCodeHead, tagCode);
@ -2458,9 +2463,10 @@ void *thread_uart_recv_back(void *arg){
while(1){
uart_data_receive_data_back(&uartRecvBack,&parmAck,&tagCodeHead,&tagCode,&tagSignal,&totalLen,&tagFeature,
&count,&batteryV,&version,&ledCtrl,&signCode,&reserve,&lableParm);
//LOG_I("After uart_data_receive_data_back call, ret: %d\n", parmAck);
// 打印除心跳外的所有接收数据
if(tagFeature != 0xFF) {
// 只在有效数据且不是心跳时才打印
if(tagCode != 0) {
LOG_I("recv_back:%04x,%04x,tag:%08x,%02x,%02x,%02x,%02x,battery:%02x,%04x,%02x,%04x,reserve:%04x,%08x\n",
parmAck,tagCodeHead,tagCode,tagSignal,totalLen,tagFeature,count,batteryV,version,ledCtrl,signCode,reserve,lableParm);
}
@ -3646,6 +3652,19 @@ int main(int argc, char *argv[])
LOG_I("use default productid:%s\n",productid);
}
// 读取subid配置
readresult=file_to_buffer("/root/subid",&len);
if(readresult!=NULL){
trim_whitespace(readresult); // 先清理空白字符
memset(subid, 0, sizeof(subid));
strncpy(subid, readresult, sizeof(subid)-1);
free(readresult);
readresult = NULL;
LOG_I("saved subid:%s\n", subid);
} else {
LOG_I("subid file not found, using default:%s\n", subid);
}
// 读取appSecret配置
readresult=file_to_buffer("appSecret",&len);
if(readresult!=NULL){