上报灯条心跳离线
This commit is contained in:
parent
ab96125b3f
commit
adb6723a74
@ -133,8 +133,8 @@ SET(SRC_TX_SERVER
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/main.c
|
${CMAKE_CURRENT_LIST_DIR}/main.c
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_EXECUTABLE(jd_server ${SRC_TX_SERVER})
|
ADD_EXECUTABLE(mt_server ${SRC_TX_SERVER})
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(jd_server pthread dl "-L${CMAKE_CURRENT_LIST_DIR}/openssl/lib" "-lssl" "-lcrypto")
|
TARGET_LINK_LIBRARIES(mt_server pthread dl "-L${CMAKE_CURRENT_LIST_DIR}/openssl/lib" "-lssl" "-lcrypto")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
cp.sh
2
cp.sh
@ -4,7 +4,7 @@
|
|||||||
#sshpass -p "PddloTSecPwdOnly!" scp ./output/bin/tx_server root@192.168.0.148:/home/linaro/
|
#sshpass -p "PddloTSecPwdOnly!" scp ./output/bin/tx_server root@192.168.0.148:/home/linaro/
|
||||||
#sshpass -p "TxApPwd#2025!" scp ./output/bin/tx_server root@10.10.12.2:/root
|
#sshpass -p "TxApPwd#2025!" scp ./output/bin/tx_server root@10.10.12.2:/root
|
||||||
#sshpass -p "TxApPwd#2025!" scp ./*.zip root@10.10.12.4:/root/ota
|
#sshpass -p "TxApPwd#2025!" scp ./*.zip root@10.10.12.4:/root/ota
|
||||||
sshpass -p "TxApPwd#2025!" scp output/bin/jd_server root@10.10.12.2:/root
|
sshpass -p "TxApPwd#2025!" scp output/bin/mt_server root@10.10.12.2:/root
|
||||||
#sshpass -p "TxApPwd#2025!" scp tx_ota/*.bin root@10.10.12.4:/root/ota
|
#sshpass -p "TxApPwd#2025!" scp tx_ota/*.bin root@10.10.12.4:/root/ota
|
||||||
#sshpass -p "PddloTSecPwdOnly!" scp ./output/bin/tx_server root@10.10.12.4:/root/
|
#sshpass -p "PddloTSecPwdOnly!" scp ./output/bin/tx_server root@10.10.12.4:/root/
|
||||||
#sshpass -p "PddloTSecPwdOnly!" scp tx_ota/*.bin root@10.10.12.6:/root/ota
|
#sshpass -p "PddloTSecPwdOnly!" scp tx_ota/*.bin root@10.10.12.6:/root/ota
|
||||||
|
|||||||
@ -1,16 +1,16 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
cd /root
|
cd /root
|
||||||
filename=/root/ota/jd_server
|
filename=/root/ota/mt_server
|
||||||
filesize=`ls -l $filename | awk '{ print $5 }'`
|
filesize=`ls -l $filename | awk '{ print $5 }'`
|
||||||
maxsize=$((440000))
|
maxsize=$((440000))
|
||||||
if [ $filesize -gt $maxsize ]
|
if [ $filesize -gt $maxsize ]
|
||||||
then
|
then
|
||||||
echo "$filesize > $maxsize copy"
|
echo "$filesize > $maxsize copy"
|
||||||
cp $filename .
|
cp $filename .
|
||||||
chmod 777 jd_server
|
chmod 777 mt_server
|
||||||
./jd_server
|
./mt_server
|
||||||
else
|
else
|
||||||
echo "$filesize < $maxsize not copy"
|
echo "$filesize < $maxsize not copy"
|
||||||
./jd_server
|
./mt_server
|
||||||
fi
|
fi
|
||||||
|
|||||||
93
main.c
93
main.c
@ -86,6 +86,9 @@ char productid[16]="WcLightStrip";
|
|||||||
char appKey[32]="fdhQmhqhvbL1cf1K9mUqt";
|
char appKey[32]="fdhQmhqhvbL1cf1K9mUqt";
|
||||||
char appSecret[64]="RxU8NZjfZaxsKg2B3Dr6sx";
|
char appSecret[64]="RxU8NZjfZaxsKg2B3Dr6sx";
|
||||||
char hostDomain[64]="auk-iot.test1.zservey.com";
|
char hostDomain[64]="auk-iot.test1.zservey.com";
|
||||||
|
int mqtt_port=1883;
|
||||||
|
//char hostDomain[64]="127.0.0.1";
|
||||||
|
//int mqtt_port=1884;
|
||||||
char mqttRawPassword[64]="";
|
char mqttRawPassword[64]="";
|
||||||
char input_value[1024]={0};//94b4e39caf1d45ee9a071d701cc037b4
|
char input_value[1024]={0};//94b4e39caf1d45ee9a071d701cc037b4
|
||||||
char input_value_copy[1024]={0};
|
char input_value_copy[1024]={0};
|
||||||
@ -124,13 +127,98 @@ char lightsn28[7]={0};
|
|||||||
char lightsn29[7]={0};
|
char lightsn29[7]={0};
|
||||||
char lightsn30[7]={0};
|
char lightsn30[7]={0};
|
||||||
int lightsnNum=0;
|
int lightsnNum=0;
|
||||||
int mqtt_port=1883;
|
|
||||||
|
|
||||||
void hmacsha1_hex(char *key, char* data, char *signhex, int signhex_len);
|
void hmacsha1_hex(char *key, char* data, char *signhex, int signhex_len);
|
||||||
void *thread_mqtt_status_check(void *arg);
|
void *thread_mqtt_status_check(void *arg);
|
||||||
void *thread_station_heartbeat(void *arg);
|
void *thread_station_heartbeat(void *arg);
|
||||||
void *thread_heartbeat_check(void *arg);
|
void *thread_heartbeat_check(void *arg);
|
||||||
void update_lightbar_heartbeat(uint32_t tagCode);
|
void update_lightbar_heartbeat(uint32_t tagCode);
|
||||||
|
void report_lightbar_login(uint32_t tagCode);
|
||||||
|
void report_lightbar_logout(uint32_t tagCode);
|
||||||
|
|
||||||
|
/*================================================================================*/
|
||||||
|
// 上报灯条子设备登录
|
||||||
|
void report_lightbar_login(uint32_t tagCode) {
|
||||||
|
char subDeviceKey[32] = {0};
|
||||||
|
char topic[256] = {0};
|
||||||
|
char payload[512] = {0};
|
||||||
|
char password[64] = {0};
|
||||||
|
char stringToSign[256] = {0};
|
||||||
|
char timestamp_str[32] = {0};
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
// 构建subDeviceKey: AD10 + tagCode (十六进制)
|
||||||
|
snprintf(subDeviceKey, sizeof(subDeviceKey), "AD10%08X", tagCode);
|
||||||
|
|
||||||
|
// 获取当前时间戳(毫秒)
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
long timestamp = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||||
|
snprintf(timestamp_str, sizeof(timestamp_str), "%ld", timestamp);
|
||||||
|
|
||||||
|
// 构建待签名串: subDeviceKey + subDeviceKey + productKey + algorithm + timestamp
|
||||||
|
snprintf(stringToSign, sizeof(stringToSign), "%s%s%s%s%s",
|
||||||
|
subDeviceKey, subDeviceKey, "WcSubLightStrip", MQTT_ALGORITHM, timestamp_str);
|
||||||
|
|
||||||
|
// 使用HMAC-SHA1计算password
|
||||||
|
hmacsha1_hex("EKmmjqyLRgghANEiQAA5LZ", stringToSign, password, sizeof(password));
|
||||||
|
|
||||||
|
// 构建topic
|
||||||
|
snprintf(topic, sizeof(topic), "/auk/iot/things/v1/sub/device/up/login/WcSubLightStrip/%s/%ld",
|
||||||
|
subDeviceKey, timestamp);
|
||||||
|
|
||||||
|
// 构建JSON payload
|
||||||
|
snprintf(payload, sizeof(payload),
|
||||||
|
"{\"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);
|
||||||
|
|
||||||
|
// 发送MQTT消息
|
||||||
|
mqtt_utils_publish(&mqtt_config, topic, 0, payload, strlen(payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*================================================================================*/
|
||||||
|
// 上报灯条子设备登出
|
||||||
|
void report_lightbar_logout(uint32_t tagCode) {
|
||||||
|
char subDeviceKey[32] = {0};
|
||||||
|
char topic[256] = {0};
|
||||||
|
char payload[512] = {0};
|
||||||
|
char password[64] = {0};
|
||||||
|
char stringToSign[256] = {0};
|
||||||
|
char timestamp_str[32] = {0};
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
// 构建subDeviceKey: AD10 + tagCode (十六进制)
|
||||||
|
snprintf(subDeviceKey, sizeof(subDeviceKey), "AD10%08X", tagCode);
|
||||||
|
|
||||||
|
// 获取当前时间戳(毫秒)
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
long timestamp = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||||
|
snprintf(timestamp_str, sizeof(timestamp_str), "%ld", timestamp);
|
||||||
|
|
||||||
|
// 构建待签名串: subDeviceKey + subDeviceKey + productKey + algorithm + timestamp
|
||||||
|
snprintf(stringToSign, sizeof(stringToSign), "%s%s%s%s%s",
|
||||||
|
subDeviceKey, subDeviceKey, "WcSubLightStrip", MQTT_ALGORITHM, timestamp_str);
|
||||||
|
|
||||||
|
// 使用HMAC-SHA1计算password
|
||||||
|
hmacsha1_hex("EKmmjqyLRgghANEiQAA5LZ", stringToSign, password, sizeof(password));
|
||||||
|
|
||||||
|
// 构建topic (logout)
|
||||||
|
snprintf(topic, sizeof(topic), "/auk/iot/things/v1/sub/device/up/logout/WcSubLightStrip/%s/%ld",
|
||||||
|
subDeviceKey, timestamp);
|
||||||
|
|
||||||
|
// 构建JSON payload
|
||||||
|
snprintf(payload, sizeof(payload),
|
||||||
|
"{\"password\":\"%s\",\"timestamp\":%ld,\"signingAlgorithm\":\"%s\"}",
|
||||||
|
password, timestamp, MQTT_ALGORITHM);
|
||||||
|
|
||||||
|
LOG_I("Lightbar logout report - topic: %s\n", topic);
|
||||||
|
LOG_I("Lightbar logout report - payload: %s\n", payload);
|
||||||
|
|
||||||
|
// 发送MQTT消息
|
||||||
|
mqtt_utils_publish(&mqtt_config, topic, 0, payload, strlen(payload));
|
||||||
|
}
|
||||||
|
|
||||||
/*================================================================================*/
|
/*================================================================================*/
|
||||||
// 更新灯条心跳时间
|
// 更新灯条心跳时间
|
||||||
@ -154,6 +242,7 @@ void update_lightbar_heartbeat(uint32_t tagCode) {
|
|||||||
if (!lightbarHeartbeat[found].isOnline) {
|
if (!lightbarHeartbeat[found].isOnline) {
|
||||||
lightbarHeartbeat[found].isOnline = true;
|
lightbarHeartbeat[found].isOnline = true;
|
||||||
LOG_I("Lightbar %08X back online\n", tagCode);
|
LOG_I("Lightbar %08X back online\n", tagCode);
|
||||||
|
report_lightbar_login(tagCode);
|
||||||
}
|
}
|
||||||
} else if (lightbarHeartbeatCount < MAX_LIGHTBAR_NUM) {
|
} else if (lightbarHeartbeatCount < MAX_LIGHTBAR_NUM) {
|
||||||
// 添加新灯条
|
// 添加新灯条
|
||||||
@ -162,6 +251,7 @@ void update_lightbar_heartbeat(uint32_t tagCode) {
|
|||||||
lightbarHeartbeat[lightbarHeartbeatCount].isOnline = true;
|
lightbarHeartbeat[lightbarHeartbeatCount].isOnline = true;
|
||||||
lightbarHeartbeatCount++;
|
lightbarHeartbeatCount++;
|
||||||
LOG_I("New lightbar %08X registered, total: %d\n", tagCode, lightbarHeartbeatCount);
|
LOG_I("New lightbar %08X registered, total: %d\n", tagCode, lightbarHeartbeatCount);
|
||||||
|
report_lightbar_login(tagCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&heartbeatMutex);
|
pthread_mutex_unlock(&heartbeatMutex);
|
||||||
@ -185,6 +275,7 @@ void *thread_heartbeat_check(void *arg) {
|
|||||||
lightbarHeartbeat[i].isOnline = false;
|
lightbarHeartbeat[i].isOnline = false;
|
||||||
LOG_I("!!! Lightbar %06X OFFLINE - no heartbeat for %ld seconds (>%d sec)\n",
|
LOG_I("!!! Lightbar %06X OFFLINE - no heartbeat for %ld seconds (>%d sec)\n",
|
||||||
lightbarHeartbeat[i].tagCode, (long)elapsed, HEARTBEAT_TIMEOUT_SEC);
|
lightbarHeartbeat[i].tagCode, (long)elapsed, HEARTBEAT_TIMEOUT_SEC);
|
||||||
|
report_lightbar_logout(lightbarHeartbeat[i].tagCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -122,7 +122,7 @@ void mqtt_net_failure(int *failure_times){
|
|||||||
(*failure_times)++;
|
(*failure_times)++;
|
||||||
LOG_I("mqtt net failure_times = %d\n", *failure_times);
|
LOG_I("mqtt net failure_times = %d\n", *failure_times);
|
||||||
if(*failure_times >= 5){
|
if(*failure_times >= 5){
|
||||||
system("systemctl restart jd_server");
|
system("systemctl restart mt_server");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
start.sh
8
start.sh
@ -1,16 +1,16 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
cd /root
|
cd /root
|
||||||
filename=/home/linaro/jd_server
|
filename=/home/linaro/mt_server
|
||||||
filesize=`ls -l $filename | awk '{ print $5 }'`
|
filesize=`ls -l $filename | awk '{ print $5 }'`
|
||||||
maxsize=$((440000))
|
maxsize=$((440000))
|
||||||
if [ $filesize -gt $maxsize ]
|
if [ $filesize -gt $maxsize ]
|
||||||
then
|
then
|
||||||
echo "$filesize > $maxsize copy"
|
echo "$filesize > $maxsize copy"
|
||||||
cp $filename .
|
cp $filename .
|
||||||
chmod 777 jd_server
|
chmod 777 mt_server
|
||||||
./jd_server
|
./mt_server
|
||||||
else
|
else
|
||||||
echo "$filesize < $maxsize not copy"
|
echo "$filesize < $maxsize not copy"
|
||||||
./jd_server
|
./mt_server
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user