Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to Subscribe the Message from Server in MQTT?

The Message from Server in MQTT

Contiki Cooja Steps to Subscribe The Message from Server in MQTT

Description:

   When a client publishes a message on a topic then the broker will distribute that message to any connected clients that have subscribed to that topic.

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)
{
Recived topic and message from server or broker
}

Step 4: Run the simulation

Publisher send the message to server
Output
subscribed successfully