Compare commits
6 Commits
b4d4043b5a
...
10c9705078
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10c9705078 | ||
|
|
81ce05254e | ||
|
|
19a3506080 | ||
|
|
607035e912 | ||
|
|
450a267efb | ||
|
|
89263932b2 |
67
main.c
67
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.27";
|
||||
char softwareVersion[16]="2.2.0";
|
||||
//char stationsn[16]="d126ei4lj4cc00";//TJ250995217957
|
||||
//char productid[8]="10045";
|
||||
//char appSecret[64]="s3izIliw0CF48Pcsi16rjOmoFRf5WEt8";
|
||||
@ -165,7 +165,8 @@ char stationsn[32]="90A9F73002CD";
|
||||
char productid[16]="WcLightStrip";
|
||||
char appKey[32]="fdhQmhqhvbL1cf1K9mUqt";
|
||||
char appSecret[64]="RxU8NZjfZaxsKg2B3Dr6sx";
|
||||
char hostDomain[64]="auk-iot.test1.zservey.com";
|
||||
char subid[64]="7AyxtxSV96Kvt76dafvdzu"; // 默认值,可从文件覆盖
|
||||
char hostDomain[64]="auk-iot.zservey.com";
|
||||
int mqtt_port=1883;
|
||||
//char hostDomain[64]="127.0.0.1";
|
||||
//int mqtt_port=1884;
|
||||
@ -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 && tagFeature != 0xFF) {
|
||||
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);
|
||||
}
|
||||
@ -2472,7 +2478,7 @@ void *thread_uart_recv_back(void *arg){
|
||||
}else if(tagFeature==0xFD){
|
||||
LOG_I("key pressed from tag %08X\n", tagCode);
|
||||
|
||||
// 按键防抖:2秒内只处理一次
|
||||
// 按键防抖:3秒内只处理一次
|
||||
time_t now = time(NULL);
|
||||
pthread_mutex_lock(&keyDebounceMutex);
|
||||
bool shouldProcess = true;
|
||||
@ -2482,9 +2488,9 @@ void *thread_uart_recv_back(void *arg){
|
||||
for (int i = 0; i < keyDebounceCount; i++) {
|
||||
if (keyDebounceList[i].tagCode == tagCode && keyDebounceList[i].tagCodeHead == tagCodeHead) {
|
||||
debounceIndex = i;
|
||||
if (now - keyDebounceList[i].lastKeyTime < 2) {
|
||||
if (now - keyDebounceList[i].lastKeyTime < 3) {
|
||||
shouldProcess = false;
|
||||
LOG_I("Key debounce: ignoring key press from tag %08X (within 2s)\n", tagCode);
|
||||
LOG_I("Key debounce: ignoring key press from tag %08X (within 3s)\n", tagCode);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -3498,7 +3504,7 @@ int main(int argc, char *argv[])
|
||||
pthread_detach(pt_mqtt_recv);
|
||||
LOG_I("pthread_create mqtt_recv success\n");
|
||||
}
|
||||
|
||||
#if 0
|
||||
ret = pthread_create(&pt_removeduplicatetag,NULL,thread_remove_duplicate_tag,NULL);
|
||||
if(ret!=0){
|
||||
LOG_I("pthread_create remove duplicate tag send fail\n");
|
||||
@ -3515,7 +3521,7 @@ int main(int argc, char *argv[])
|
||||
LOG_I("pthread_create removelog success\n");
|
||||
pthread_detach(pt_removelog);
|
||||
}
|
||||
#if 0
|
||||
|
||||
ret = pthread_create(&pt_readqr,NULL,thread_readqr,NULL);
|
||||
if(ret!=0){
|
||||
LOG_I("pthread_create readqr fail\n");
|
||||
@ -3524,7 +3530,7 @@ int main(int argc, char *argv[])
|
||||
LOG_I("pthread_create readqr success\n");
|
||||
pthread_detach(pt_readqr);
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = pthread_create(&pt_reporttag,NULL,thread_reporttag,NULL);
|
||||
if(ret!=0){
|
||||
LOG_I("pthread_create reporttag fail\n");
|
||||
@ -3542,15 +3548,15 @@ int main(int argc, char *argv[])
|
||||
LOG_I("pthread_create keycheck success\n");
|
||||
pthread_detach(pt_keycheck);
|
||||
}
|
||||
|
||||
ret = pthread_create(&pt_station_heartbeat,NULL,thread_station_heartbeat,NULL);
|
||||
if(ret!=0){
|
||||
LOG_I("pthread_create station_heartbeat fail\n");
|
||||
system("reboot");
|
||||
}else{
|
||||
LOG_I("pthread_create station_heartbeat success\n");
|
||||
pthread_detach(pt_station_heartbeat);
|
||||
}
|
||||
#endif
|
||||
//ret = pthread_create(&pt_station_heartbeat,NULL,thread_station_heartbeat,NULL);
|
||||
//if(ret!=0){
|
||||
// LOG_I("pthread_create station_heartbeat fail\n");
|
||||
// system("reboot");
|
||||
//}else{
|
||||
// LOG_I("pthread_create station_heartbeat success\n");
|
||||
// pthread_detach(pt_station_heartbeat);
|
||||
//}
|
||||
|
||||
// 心跳检测线程移到MQTT连接成功后启动,避免MQTT未连接时上报失败
|
||||
// ret = pthread_create(&pt_heartbeat_check,NULL,thread_heartbeat_check,NULL);
|
||||
@ -3561,7 +3567,7 @@ int main(int argc, char *argv[])
|
||||
// pthread_detach(pt_heartbeat_check);
|
||||
// }
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
//ret = pthread_create(&pt_simulate_light,NULL,thread_simulate_light,NULL);
|
||||
//if(ret!=0){
|
||||
// LOG_I("pthread_create simulate_light fail\n");
|
||||
@ -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){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user