fix(vd960DBN): iot_mqtt_srv compilation errors
- Add extern g_report_active (from tcp_json_srv.h) - Fix iot_make_topic call: 4-arg -> 5-arg (add NULL for 'status' sub) - Fix SOCK_INF field names: DestPort->DesPort, DestAddr->IPAddr - Fix struct _WCHNET_IPAddr -> uint8_t broker_ip[4] (type not available)
This commit is contained in:
@@ -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 uint32_t g_json_last_connect_ts; // Last client connect timestamp (ms)
|
||||||
extern uint8_t g_json_restart_count; // Auto-restart counter
|
extern uint8_t g_json_restart_count; // Auto-restart counter
|
||||||
extern uint32_t g_json_restart_cooldown; // Cooldown deadline (ms)
|
extern uint32_t g_json_restart_cooldown; // Cooldown deadline (ms)
|
||||||
|
extern uint8_t g_report_active; // 0=inactive 1=active report
|
||||||
|
|
||||||
/*===========================================================================
|
/*===========================================================================
|
||||||
* API
|
* API
|
||||||
|
|||||||
@@ -29,6 +29,9 @@
|
|||||||
/*===========================================================================
|
/*===========================================================================
|
||||||
* Global State
|
* 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
|
uint8_t g_iot_socket = 0xFF; // MQTT TCP socket ID
|
||||||
IotMqttState g_iot_state = IOT_STATE_DISCONNECTED;
|
IotMqttState g_iot_state = IOT_STATE_DISCONNECTED;
|
||||||
uint8_t g_iot_msg_id = 0; // MQTT packet identifier
|
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");
|
loop_ok[2] ? "true" : "false", loop_ok[3] ? "true" : "false");
|
||||||
|
|
||||||
char topic[IOT_MQTT_TOPIC_MAX_LEN];
|
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);
|
iot_mqtt_publish(topic, payload, strlen(payload), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,16 +477,16 @@ static void iot_send_heartbeat(void) {
|
|||||||
|
|
||||||
/* 连接到 MQTT Broker */
|
/* 连接到 MQTT Broker */
|
||||||
static void iot_connect_broker(void) {
|
static void iot_connect_broker(void) {
|
||||||
struct _WCHNET_IPAddr broker_ip;
|
uint8_t broker_ip[4];
|
||||||
SOCK_INF sock_inf;
|
SOCK_INF sock_inf;
|
||||||
uint8_t ret;
|
uint8_t ret;
|
||||||
|
|
||||||
// 解析 broker 地址
|
// 解析 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 地址
|
// 是 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",
|
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);
|
iot_net_info.mqtt_port);
|
||||||
} else {
|
} else {
|
||||||
PRINT("IOT: broker hostname=%s (DNS not implemented yet)\n",
|
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));
|
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.ProtoType = PROTO_TYPE_TCP;
|
||||||
sock_inf.RecvBufLen = RECE_BUF_LEN;
|
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);
|
ret = WCHNET_SocketCreat(&g_iot_socket, &sock_inf);
|
||||||
if (ret != WCHNET_ERR_SUCCESS) {
|
if (ret != WCHNET_ERR_SUCCESS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user