增加子设备密钥配置
This commit is contained in:
parent
8146508cb4
commit
d8ed14d14d
36
main.c
36
main.c
@ -157,7 +157,7 @@ int fd;
|
||||
int UPCASE=0;
|
||||
int count_value=0;
|
||||
int getPayloadTime=100*1000;//usecond
|
||||
char softwareVersion[16]="2.1.28";
|
||||
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",
|
||||
@ -2380,10 +2381,6 @@ void *thread_uart_recv_data(void *arg){
|
||||
while(1){
|
||||
int ret = uart_data_receive_data_back(&uartRecvData,&parmAck,&tagCodeHead,&tagCode,&tagSignal,&totalLen,&tagFeature,
|
||||
&count,&batteryV,&version,&ledCtrl,&signCode,&reserve,&lableParm);
|
||||
if(ret < 0) {
|
||||
usleep(100000); // 失败时延迟100ms
|
||||
continue;
|
||||
}
|
||||
|
||||
// 只在有效数据时才打印(tag不为0)
|
||||
if(tagCode != 0) {
|
||||
@ -2418,15 +2415,11 @@ void *thread_uart_recv_back(void *arg){
|
||||
//LOG_I("Before uart_data_receive_data_back call\n");
|
||||
int ret = uart_data_receive_data_back(&uartRecvBack,&parmAck,&tagCodeHead,&tagCode,&tagSignal,&totalLen,&tagFeature,
|
||||
&count,&batteryV,&version,&ledCtrl,&signCode,&reserve,&lableParm);
|
||||
if(ret < 0) {
|
||||
//LOG_I("uart_data_receive_data_back failed with ret=%d, sleeping 100ms\n", ret);
|
||||
usleep(100000); // 失败时延迟100ms
|
||||
continue;
|
||||
}
|
||||
|
||||
//LOG_I("After uart_data_receive_data_back call, ret: %d\n", parmAck);
|
||||
|
||||
// 只在有效数据且不是心跳时才打印
|
||||
if(tagCode != 0 && 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);
|
||||
}
|
||||
@ -3529,6 +3522,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){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user