#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 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 send the publisher send message to server in MQTT contiki cooja?
Description

Sender of the messages is called publisher in pub/sub pattern. Publish the topics periodically and also know about how to send the publish message to server in MQTT contiki cooja simulator.

Source code

Step 1: Open a file at location:contiki/ mqtt-sn-contiki/main_core.c
Define topics like this,
static char *topics_mqtt[] = {“/topic_1”, “/topic_2”, “/topic_3″”/topic_4”, “/topic_5”, “/topic_6”};

Step 2: Create socket to publish
mqtt_sn_init(); // initiation
size_t i;
for(i=0;i<ss(topics_mqtt);i++)
all_topics[i] = topics_mqtt[i];
all_topics[i] = topic_hw;
mqtt_sn_create_sck(mqtt_sn_connection,all_topics,ss(all_topics),mqtt_sn_callback);

Step 3: initiate broker and publish the message periodically
while(1) {
PROCESS_WAIT_EVENT();
sprintf(pub_test,”%s”,topic_hw);
mqtt_sn_pub(“/topic_1”,pub_test,true,0);
if (etimer_expired(&time_poll))
etimer_reset(&time_poll);
}

Step 4: contiki/ mqtt-sn-contiki/mqtt_sn.c
resp_con_t mqtt_sn_pub_send(char *topic, char *message, bool retain_flag, uint8_t qos). handles publish message to broker.

Step 5: Open cooja simulator

Run simulation

Output