How to subscribe the message from server in MQTT?

Receiver of the message is called subscriber in pub/sub pattern. Client connect with broker and requests the topics, broker will publish the topics to subscriber.

+ Description

Receiver of the message is called subscriber in pub/sub pattern. Client connect with broker and requests the topics, broker will publish the topics to subscriber.

  • Step 1: Open a file at location:contiki/ mqtt-sn-contiki/main_core.c

    // To subscribe

    mqtt_sn_init(); // initiation

    char *topic =”/topic_1″;

    mqtt_sn_sub(topic,0); //subscribe

  • Step 2: Initiate the subscriber
    contiki/ mqtt-sn-contiki/mqtt_sn.c
    void init_sub(void *ptr)
    resp_con_t mqtt_sn_sub_send(char *topic, uint8_t qos)
    Subscribes the messages from broker.

  • Step 3: Function receives the topics.
    void mqtt_sn_callback(char *topic, char *message)
    {
    Reeived topic and message from server or broker
    }

  • Step 4: Run the simulation

u14a
+ Source code:
  • Step 1: Open a file at location:contiki/ mqtt-sn-contiki/main_core.c

    // To subscribe

    mqtt_sn_init(); // initiation

    char *topic =”/topic_1″;

    mqtt_sn_sub(topic,0); //subscribe

  • Step 2: Initiate the subscriber
    contiki/ mqtt-sn-contiki/mqtt_sn.c
    void init_sub(void *ptr)
    resp_con_t mqtt_sn_sub_send(char *topic, uint8_t qos)
    Subscribes the messages from broker.

  • Step 3: Function receives the topics.
    void mqtt_sn_callback(char *topic, char *message)
    {
    Reeived topic and message from server or broker
    }

  • Step 4: Run the simulation

u14a
Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit