cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f4 LwIP MQTT

voyvoda .
Senior

Hello,

I am able run successfully mqtt example on my stm32f4 MCU ​and on my local network.

I want to run the same code on a cloud platform. However there is a link provided by mqtt cloud pro​vider not an IP address like 192.168.0.10

​​

Can I directly use the below link instead of the IP address ? If not, then How can I ?

1f87a053302042c7a0ccb2dac5d1263b.s1.eu.hivemq.cloud

B​est Regards

1 ACCEPTED SOLUTION

Accepted Solutions

hello

This issue covered here.

In general, dns_gethostbyname() and dns_gethostbyname_addrtype() functions resolve hostname (hivemq.cloud) to address

View solution in original post

11 REPLIES 11

hello

This issue covered here.

In general, dns_gethostbyname() and dns_gethostbyname_addrtype() functions resolve hostname (hivemq.cloud) to address

@Vangelis Fortounas​  Thank you for your reply. I can only use dns_gethostbyname() with socket or netconn. So I need to use freertos. Is there any other way to use with RAW API functions ?

Or I migth use the web site http://domaintoipconverter.com/index.php to get the IP address directly.

In addition, How can I subscibe to a topic with lwip mqtt example.

I want to use second STM32 board to subscribe to the topic. In short, one board will publish and the other will subscribe(receive). "hivemq.cloud" will be the broker.

Those functions are parts of RAW API. Read the documentation:

https://www.nongnu.org/lwip/2_1_x/group__dns.html

of course it is. I need to just enbale DNS from CubeIDE.

Do I need use Multi Tread When I want to subscribe multiple topic in MQTT

@Vangelis Fortounas​ Hello My friend. I have enabled DNS in STM32cubeIDE

even if LWIP_DNS is set to 1 in "lwipopts.h", I see that LWIP_DNS is acting like not defined as 1 in dns.c file

I have manually redefine LWIP_DNS as 1

I have followed the steps. However I get IP as "32.0.0.0" in callback function.

dns_setserver(0, &dnsserver); // 8.8.8.8 as server IP

dns_init();

dns_gethostbyname(); 

What could be the problem ?

Hello

try to use as DNS server the default router's address or the gateway address that is set during initialization (netif_set_addr(..))

If dhcp is enabled , there is no need to set a DNS address

Why are you calling some API function before the related initialization function? Why are you calling dns_init() manually at all? It is not listed as an API in documentation because it is not meant to be called by user application. And for DNS to work, the IP/mask/gateway and DNS server must be configured, working and accessible.

voyvoda .
Senior

Hell @Vangelis Fortounas​ I am using static IP address.

Can you be more specific ? I did not understand what you mean.

Hello

Somewere in code, static address was set by calling netif_set_addr(...) function.

This function takes three parameters, static IP address, subnet mask and gateway(GW). (in cubeMX these parameters are set sequentially).

Usually the GW address is the IP address of the router that Ethernet cable is connected, also is the default DNS address. (eg 192.168.1.1).

I suggested to put as DNS server address (dns_setserver(...)) the default address of the router that is probably used also as gateway address.

I wrote "probably" because i don't know the exact network topology.