Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hostname in localnetwork #37

Closed
aignacio opened this issue Feb 6, 2015 · 5 comments
Closed

Hostname in localnetwork #37

aignacio opened this issue Feb 6, 2015 · 5 comments

Comments

@aignacio
Copy link

aignacio commented Feb 6, 2015

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"

@bcatalin
Copy link

bcatalin commented Feb 6, 2015

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 <
notifications@github.com> 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.

@PuceBaboon
Copy link

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.

@aignacio
Copy link
Author

aignacio commented Feb 6, 2015

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. =/

@PuceBaboon
Copy link

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.

@tuanpmt
Copy link
Owner

tuanpmt commented Feb 14, 2015

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

@tuanpmt tuanpmt closed this as completed Feb 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants