This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

MQTT Example - Settings for publishing while subscribing?

Hi, I use the following.

  • Raspberry Pi 3 (RPi3 with Raspbian Jessie 4.4) as a router,

RPi3 is connected to a Wi-Fi router to access the Internet by using the built-in Wi-Fi BLE BCM43438 chip.

  • IoT SDK 0.9

  • MQTT Publisher Example

  • PCA10040 v1.1

  • Keil MDK 5.20

  • MQTT Broker = Mosquitto 1.4.9, hosted from Amazon EC2 instance which uses Ubuntu 14.

As far as I know, it is possible to publish while subscribing to topics.

I'm trying the IoT SDK's MQTT publish example.

Is it possible to publish while subscribing to topics with PCA10040?

If so, what settings should I add in the publish example?

/+++++++++++++++++++++++++++++++++++++++++++/

Edited : 2016.08.04

I tried the following code.

breakpoint

#define APP_MQTT_SUBSCRIPTION_PKT_ID        10                                                      /**< Unique identification of subscription, can be any unsigned 16 bit integer value. */
#define APP_MQTT_SUBSCRIPTION_TOPIC         "led/state"                                             /**< MQTT topic to which this application subscribes. */

static void button_init(void){
uint32_t err_code;

static app_button_cfg_t buttons[] =
{
    {BSP_BUTTON_0,        false, BUTTON_PULL, button_event_handler},
    {BSP_BUTTON_1,        false, BUTTON_PULL, button_event_handler},
    {BSP_BUTTON_2,        false, BUTTON_PULL, button_event_handler},
    {BSP_BUTTON_3,        false, BUTTON_PULL, button_event_handler}, // for testing subscribe
#ifdef COMMISSIONING_ENABLED // I didn't enabled it, the handler for BSP_BUTTON_3 is shown above
    {ERASE_BUTTON_PIN_NO, false, BUTTON_PULL, button_event_handler}
#endif // COMMISSIONING_ENABLED
}; // omitted other parts
}

void app_mqtt_evt_handler(mqtt_client_t * const p_client, const mqtt_evt_t * p_evt){
switch(p_evt->id){
   case MQTT_EVT_PUBLISH: // Publish event received when message is published on a topic client is subscribed to
   {
     if (p_evt->param.pub_message.message.payload.bin_strlen == 1){}
     if (p_evt->param.pub_message.message.topic.qos == MQTT_QoS_1_ATLEAST_ONCE){}
     break;
   }

-Best Regards, Mango

Related