smart-green-house-server-an.../how_to_use_mqtt/pub1_text.c

7 lines
411 B
C

1.mosquitto的库环境 mosquitto_lib_init();
2.mosquitto的服务端 struct mosquitto* client =
mosquitto_new(NULL, true, NULL);
3. mosquitto_connect_callback_set(client, connect_callback);
mosquitto_connect(client, "10.12.156.19", 1883, 60);
mosquitto_loop_start(client);
4. mosquitto_publish(client, &msg_id, topic, strlen(msg), msg, 1, true);