diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/include/tcp_json_srv.h b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/include/tcp_json_srv.h index 382fec3..ec636e1 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/include/tcp_json_srv.h +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/include/tcp_json_srv.h @@ -70,6 +70,7 @@ extern uint32_t g_json_last_comm_ts; // Last communication timestamp (ms) extern uint32_t g_json_last_connect_ts; // Last client connect timestamp (ms) extern uint8_t g_json_restart_count; // Auto-restart counter extern uint32_t g_json_restart_cooldown; // Cooldown deadline (ms) +extern uint8_t g_report_active; // 0=inactive 1=active report /*=========================================================================== * API diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c index 8127f56..7d372e0 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c @@ -29,6 +29,9 @@ /*=========================================================================== * Global State *===========================================================================*/ + + +extern uint8_t g_report_active; // from tcp_json_srv.c, 0=inactive 1=active uint8_t g_iot_socket = 0xFF; // MQTT TCP socket ID IotMqttState g_iot_state = IOT_STATE_DISCONNECTED; uint8_t g_iot_msg_id = 0; // MQTT packet identifier @@ -464,7 +467,7 @@ static void iot_send_heartbeat(void) { loop_ok[2] ? "true" : "false", loop_ok[3] ? "true" : "false"); char topic[IOT_MQTT_TOPIC_MAX_LEN]; - iot_make_topic(topic, sizeof(topic), "dev", "status"); + iot_make_topic(topic, sizeof(topic), "dev", "status", NULL); iot_mqtt_publish(topic, payload, strlen(payload), 0); } @@ -474,16 +477,16 @@ static void iot_send_heartbeat(void) { /* 连接到 MQTT Broker */ static void iot_connect_broker(void) { - struct _WCHNET_IPAddr broker_ip; + uint8_t broker_ip[4]; SOCK_INF sock_inf; uint8_t ret; // 解析 broker 地址 - if (get_ipstr_to_array((char *)iot_net_info.remote_addr, broker_ip.a) == 0) { + if (get_ipstr_to_array((char *)iot_net_info.remote_addr, broker_ip) == 0) { // 是 IP 地址 - memcpy(broker_ip.a, iot_net_info.remote_addr, 4); + memcpy(broker_ip, iot_net_info.remote_addr, 4); PRINT("IOT: broker IP %d.%d.%d.%d:%d\n", - broker_ip.a[0], broker_ip.a[1], broker_ip.a[2], broker_ip.a[3], + broker_ip[0], broker_ip[1], broker_ip[2], broker_ip[3], iot_net_info.mqtt_port); } else { PRINT("IOT: broker hostname=%s (DNS not implemented yet)\n", @@ -492,10 +495,10 @@ static void iot_connect_broker(void) { } memset(&sock_inf, 0, sizeof(SOCK_INF)); - sock_inf.DestPort = iot_net_info.mqtt_port; + sock_inf.DesPort = iot_net_info.mqtt_port; sock_inf.ProtoType = PROTO_TYPE_TCP; sock_inf.RecvBufLen = RECE_BUF_LEN; - memcpy(sock_inf.DestAddr, broker_ip.a, 4); + memcpy(sock_inf.IPAddr, broker_ip, 4); ret = WCHNET_SocketCreat(&g_iot_socket, &sock_inf); if (ret != WCHNET_ERR_SUCCESS) {