Coder Social home page Coder Social logo

Hostname in localnetwork about esp_mqtt HOT 5 CLOSED

tuanpmt avatar tuanpmt commented on August 18, 2024
Hostname in localnetwork

from esp_mqtt.

Comments (5)

bcatalin avatar bcatalin commented on August 18, 2024

I think that you can use the API function described in the SDK doc as:

Err_t espconn_gethostbyname(struct espconn *pespconn, const char
*hostname, ip_addr_t *addr, dns_found_callback found) to find the IP
address of your broker

Parameters:
struct espconn *espconn——corresponding connected control block
structure const char *hostname——domain name string pointer
ip_addr_t *addr——ip address
dns_found_callback found——callback

Return:

Err_t——ESPCONN_OK
ESPCONN_INPROGRESS
ESPCONN_ARG

Example as follows. Pls refer to source code of IoT_Demo:
ip_addr_t esp_server_ip;
LOCAL void ICACHE_FLASH_ATTR
user_esp_platform_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
{
struct espconn *pespconn = (struct espconn *)arg;
os_printf("user_esp_platform_dns_found %d.%d.%d.%d\n",
*((uint8 *)&ipaddr->addr), *((uint8 *)&ipaddr->addr + 1),
*((uint8 *)&ipaddr->addr + 2), *((uint8 *)&ipaddr->addr + 3));
}
Void dns_test(void)
{
espconn_gethostbyname(pespconn,”iot.espressif.cn”,&esp_server_ip,user_es
p_platform_dns_found);
}

Havving the IP address we can use it to pass it to the MQTT connect
function

Catalin

On Fri, Feb 6, 2015 at 12:42 PM, Ânderson Ignácio da Silva <
[email protected]> wrote:

Hello,

I've been testing my mqtt network in a local network with fixed ip, but i
have a dhcp server in a apache running in this network and i would like to
know if is there a way to find the broker machine just with hostname in
this LAN.

tks.

#define MQTT_HOST "teste.local"


Reply to this email directly or view it on GitHub
#37.

from esp_mqtt.

PuceBaboon avatar PuceBaboon commented on August 18, 2024

Using the simple hostname ("teste"?) or the fully-qualified hostname (with the real domainname, such as "teste.example.com") will result in an automatic gethostbyname() lookup, which should work without any extra code.
Using the ".local" extension, as per your question, will probably not work unless you have something on your network which automatically responds to such requests with a real domain name.
If in doubt, an IP address should always work.

from esp_mqtt.

aignacio avatar aignacio commented on August 18, 2024

bcatalin 👍
I know this function, but the mqtt code from tuan already use this when you put the hostname from web, the problem is in the local network.

PuceBaboon:
Yes, it works for outside servers, but i`m using mDNS for my private network, and my broker does not has fixed ip. =/

from esp_mqtt.

PuceBaboon avatar PuceBaboon commented on August 18, 2024

aignaciors,

I'm not aware of any mDNS capabilities within the SDK (but then, I know almost nothing about anything in the SDK :-))

You might want to check out the Avahi daemon, though. It has the ability to "configure a unicast DNS server automatically from server data published on the LAN" and so should be able to automatically provide unicast answers to your multicast address request (I have a mixed environment here, with Macs co-existing in a mostly Un*x environment and Avahi works pretty well at handling the Mac mDNS traffic). Of course, this all depends upon what you actually have in your environment and, more importantly, what you have administration rights on.

from esp_mqtt.

tuanpmt avatar tuanpmt commented on August 18, 2024

contiki have implemented mDNS support resolve local domain, you can look through. This project focus only mqtt protocol.

from esp_mqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.