Research Breakthrough Possible @S-Logix pro@slogix.in

Office Address

Social List

How the Publisher Send Message to the Server in MQTT Contiki Cooja?

The publisher send message to server in MQTT contiki cooja

Contiki cooja steps for the publisher to send message to the server in MQTT

  • 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
    Run simulation
Output
  • Result of the cooja simulator
  • Publisher send the message to server