Comments (5)
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.
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.
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.
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.
contiki have implemented mDNS support resolve local domain, you can look through. This project focus only mqtt protocol.
from esp_mqtt.
Related Issues (20)
- program stack in function BOOL ICACHE_FLASH_ATTR MQTT_InitClient HOT 1
- free(outbound_message->data) wrong? HOT 2
- i have problem with WiFiClientSecure :(
- Problems building for "user/user_main.c" example.. HOT 4
- platformio support?
- Can use this ESP_MQTT to "iot.eclipse.org" , but can't for "test.mosquitto.org" . Why ?
- Support of SSL different algorithms HOT 1
- How disable automatic connect Wi-Fi network? HOT 1
- event->msg_id always 0 in MQTT_EVENT_DATA
- null check client pointer before deref
- Queue never getempty HOT 1
- compiling with esp8266 latest SDK version using virtual machine
- getting incorrect packet id for MQTT_MSG_TYPE_UNSUBSCRIBE from mqtt_get_id function in mqtt_msg.c since its type is not listed in switch case. HOT 1
- Why use of while in MQTT_* functions? HOT 2
- buffer corruption because of unterminated data HOT 2
- re-queue on error sending
- publish callback in wrong place for QOS > 0 HOT 3
- Race condition in all commands that expect a reply (sub/unsub/publish w QoS >0) HOT 7
- building user_main.c
- Unable to use ssl mode
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp_mqtt.