External ipv4 MQTT broker error ETIMEDOUT #9456
-
Any kind of hint is appreciated since I am struggling a while with that. I am using two nrf52840-dks. I can ping and dns-resolve external ipv4. I used an empty nrf connect example and hard coded the openthread confs:
My border router seems to be setup correctly with NAT64 enabled. I am able to reach my MQTT broker: ot ping 20.23.192.248
Pinging synthesized IPv6 address: fd23:b6c6:7df7:2:0:0:1417:c0f8
16 bytes from fd23:b6c6:7df7:2:0:0:1417:c0f8: icmp_seq=1 hlim=112 time=46ms
1 packets transmitted, 1 packets received. Packet loss = 0.0%. Round-trip min/avg/max = 46/46.0/46 ms.
Done I tried many different samples but had problems why I boiled the sample code down to the following. Please note that I am using the ipv6 from the ping above: /*
* Copyright (c) 2020 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/net/socket.h>
#include <zephyr/net/mqtt.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/usb/usb_device.h>
#include <openthread/instance.h>
#include <openthread/thread.h>
#include <openthread/thread_ftd.h>
LOG_MODULE_REGISTER(openthead_mqtt, CONFIG_OT_COMMAND_LINE_INTERFACE_LOG_LEVEL);
#define MQTT_CLIENTID "zephyr_mqtt_client"
#define MQTT_USERNAME "BLA"
#define MQTT_PASSWORD "BLA"
#define SERVER_ADDR "fd23:b6c6:7df7:2:0:0:1417:c0f8"
#define APP_BMEM
#define APP_DMEM
/* Buffers for MQTT client. */
static APP_BMEM uint8_t rx_buffer[128];
static APP_BMEM uint8_t tx_buffer[128];
/* The mqtt client struct */
static APP_BMEM struct mqtt_client client_ctx;
/* MQTT Broker details. */
static APP_BMEM struct sockaddr_storage broker;
static APP_BMEM bool connected;
void mqtt_evt_handler(struct mqtt_client *const client,
const struct mqtt_evt *evt)
{
}
int main(void)
{
LOG_INF("Starting Openthread");
otInstance *instance = otInstanceInitSingle();
while (otThreadGetDeviceRole(instance) == (OT_DEVICE_ROLE_DISABLED || OT_DEVICE_ROLE_DETACHED))
{
k_sleep(K_MSEC(100));
LOG_INF("...");
}
LOG_INF("Openthread is running");
LOG_INF("Starting MQTT Client");
mqtt_client_init(&client_ctx);
/* broker init */
struct sockaddr_in6 *broker6 = (struct sockaddr_in6 *)&broker;
broker6->sin6_family = AF_INET6;
broker6->sin6_port = htons(1883);
zsock_inet_pton(AF_INET6, SERVER_ADDR, &broker6->sin6_addr);
/* MQTT client configuration */
struct mqtt_client *client = &client_ctx;
client->broker = &broker;
client->evt_cb = mqtt_evt_handler;
client->client_id.utf8 = (uint8_t *)MQTT_CLIENTID;
client->client_id.size = strlen(MQTT_CLIENTID);
client->password = MQTT_USERNAME;
client->user_name = MQTT_PASSWORD;
client->protocol_version = MQTT_VERSION_3_1_1;
/* MQTT buffers configuration */
client->rx_buf = rx_buffer;
client->rx_buf_size = sizeof(rx_buffer);
client->tx_buf = tx_buffer;
client->tx_buf_size = sizeof(tx_buffer);
client->transport.type = MQTT_TRANSPORT_NON_SECURE;
LOG_INF("Connecting ...");
/* MQTT buffers configuration */
int rc = mqtt_connect(client);
if (rc != 0)
{
LOG_INF("mqtt_connect: %d", rc);
}
return 0;
} The output is:
The zephyr docs says that 116 is connection time out. So I assume I am doing something wrong with the ip? Any kind of help is appreciated since I am very lost. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
I have set
|
Beta Was this translation helpful? Give feedback.
-
I found the following in one of the codelabs: OpenThread does not use the NAT64 well-known prefix 64:ff9b::/96. Instead, Thread Border Routers publish their dynamically generated NAT64 prefix used by the NAT64 translator in the Thread Network Data (as seen above, the n stands for NAT64). Thread End Devices must obtain this NAT64 prefix from the Thread Network Data and synthesize their own IPv6 addresses, see otNat64SynthesizeIp6Address(). This is automatically done in the CLI, but needs to be specifically implemented in custom applications. but I cannot find a sample implementation. |
Beta Was this translation helpful? Give feedback.
I switched from Mqtt to CoAP but run into the same problem with ipv4.
This did finally the trick: