Search code examples
mqttcontiki

Mqtt subscribing to multiple topics in Contiki


I am starting to work with Mqtt in Contiki and found the mqtt-demo example very good as a starting point. I am having difficulties in finding the right way in Contiki to subscribe in multiple topics. My exact difficulty is to check when the first subscribe has finished to start the next one. I would expect that contiki would have some sort of mechanism or a "flag" that I can check to see if a subscribe is already finished. Also, is there a way to pool this "flag" in contiki without consuming all the processor? Code examples would help a lot.

Thank you in advance,


Solution

  • In the examples/cc2538-common/mqtt-demo.c (latest Contiki master branch) are shown the MQTT events triggered:

    static void
    mqtt_event(struct mqtt_connection *m, mqtt_event_t event, void *data)
    {
      switch(event) {
    
      (...)
    
      case MQTT_EVENT_SUBACK: {
        DBG("APP - Application is subscribed to topic successfully\n");
        break;
      }
      case MQTT_EVENT_UNSUBACK: {
        DBG("APP - Application is unsubscribed to topic successfully\n");
        break;
      }
    
      (...)
    }