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

MQTT Example - About Broker's IP

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

  • Amazon EC2 for Mosquitto Broker (v 1.4.9)

I downloaded the MQTT publisher example and with Keil, the code was loaded to the PCA10040 successfully.

I also installed radvd and Distributed a global IPv6 prefix.

I did connect the PCA10040 and the RPi3; I observed that the LED 1 stopped blinked after typing this.

# Connect to the device.
echo "connect 00:AA:BB:XX:YY:ZZ 1" > /sys/kernel/debug/bluetooth/6lowpan_control

(Followed this link)

However, the LED didn't change when I pressed Button 1.

In other words, the publishing has failed.

static const ipv6_addr_t               m_broker_addr ={
.u8 =
{0x20, 0x01, 0x0D, 0xB8,
 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x01}};

The example used this IPv6 broker address.

As far as I know, the Amazon EC2 instances do not support IPv6.

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

I lack much knowledge of IPv6 so I hope for your understandings.

Suppose my EC2 instance's public IP address is 11.22.33.44.

I think I shouldn't set the variable m_broker_addr to the public IP address.

In this case, what configuration is needed to set the broker's address?

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

Edited 2016.07.14

Wireshark

The host name (IP address of Amazon EC2) starts with 52.

My PCA10040's address is 00:8D:55:3F:20:A2.

In the picture, A) is shown due to Eclipse Paho's MQTT Publisher example.

This example doesn't use user name nor password. It also uses 1883 port.

I executed the Eclipse Paho's MQTT Publisher example and those packets were captured. With this example, I published data sucessfully.

After that, B) I terminated Eclipse Paho's MQTT Publisher example and executed the Linux commands to connect PCA10040 with RPi3.

I pressed Button 1 from PCA10040.

However, no packets were captured like situation A.

#define APP_MQTT_BROKER_PORT                1883

 case BSP_BUTTON_0:
        {
            if (m_connection_state == false)
            {
                mqtt_client_init(&m_app_mqtt_client);

                memcpy(m_app_mqtt_client.broker_addr.u8, m_broker_addr.u8, IPV6_ADDR_SIZE);
                m_app_mqtt_client.broker_port          = APP_MQTT_BROKER_PORT;
                m_app_mqtt_client.evt_cb               = app_mqtt_evt_handler;
                m_app_mqtt_client.client_id.p_utf_str  = (uint8_t *)m_client_id;
                m_app_mqtt_client.client_id.utf_strlen = strlen(m_client_id);
                m_app_mqtt_client.p_password           = NULL;
                m_app_mqtt_client.p_user_name          = NULL;
                m_app_mqtt_client.transport_type       =  MQTT_TRANSPORT_NON_SECURE /*MQTT_TRANSPORT_SECURE*/ ;
                m_app_mqtt_client.p_security_settings  = NULL /*&m_tls_keys*/ ;

                uint32_t err_code = mqtt_connect(&m_app_mqtt_client);
                // err_code was 0, but the LED 2 didn't turned on.

The err_code value was 0 when I pressed Button 1.

Edited 2016.07.15

This is strange. As you suggested, I sniffed the BT0 interface in Wireshark.

Wireshart BT0

You can download the captured packets to see them in detail; sniff.pcapng.

The red line (packet No. 7 and 11) was created when I pressed Button 1 from PCA10040.

I followed the instruction to configure the non secure port as you mentioned in the comments.

That corresponds to the code part which I posted above.

By the way, this is the result when I checked what command is actually running.

grep

Added 2016.08.10

Wireshark Payload

Received payload.

-Best Regards, Mango

Parents Reply
    1. It is on your RPi3. You can use the ip address the way you describe. The command is correct.

    2. Because no matter what the destination ip address is, the 6tunnel will forward every packet arriving on port 1883 to the ip address you specify in the 6tunnel command.

    Remember that the MQTT example uses secure connections and port 8883 as default. You can read here on how to not use secure connections and port 1883 instead. (Or you can use secure connections and 6tunnel with port 8883 instead. But it might require some extra setup on the EC2 side.)

Children
No Data
Related