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
Add support for DNS name resolution #590
Comments
The ESP8266 has an API called When we look at the Espruino board specific interface to DNS resolution, we find the following in
As we see, we have a non obvious mapping between the two capabilities. This function is an indirection from the Gordon gave some excellent design guidance in this forum post. Following this, some of the basic DNS mapping was added such that the ESP8266 gethostbyname now calls the ESP API ... however ... I am having trouble. A call to JsNetwork gethostbyname is not passed the context of any sockets. What this means is that when a user JS app asks for a Action: Kolban to talk to Gordon. I believe that the correct story will be to either pass in a callback function to JSNetwork gethostbyname or else pass in context data to gethostbyname that can be used as a key. |
I think you could rely on the fact that
it's pretty evil though. Ideally there would be a better way of handling this, but it's probably better to get it working for now and to then worry about fixing the API later on. |
If I can make the assumption that gethostbyname is always linked to connect ... then yes ... I see that will work great ... however, that then removes the current hope to expose a gethostbyname API to the JS user. User @HyGy seems to have run into this as an issue ... see: |
I'll try it. But with virtual hosts it will not work... thx, |
Implemented a simple ESP8266WiFi.getHostByName() function. Documented in the user guide. Submitted a Pull Request. Uploaded firmware build that contains the code. |
What is the state of this in the esp8266 binaries? When will be included? And when it will incuded how can we use it? http.get({ or stg command, what can resolv the name? like thanks, |
Howdy HyGy ... the latest binaries have a class called "ESP8266". You can code:
I don't know when (if ever) we will be able to resolve hostnames by string without doing an explicit lookup. Our problem is that the Espruino internal architecture expects a "gethostbyname" function to be synchronous while on an ESP8266, the "gethostbyname" function is asynchronous. To change the logic would require a sign-off and participation by @gfwilliams as it will impact core and existing Espruino architecture rather than just implementation in the ESP8266 port. I am happy to partner with others on working on the implementation, but am nervous about attempting such radical surgery in the heart of Espruino without explicit agreement from all parties concerned ... and even then, ideally with their cooperation. |
Thanks!!!! Okay, that is good for me like this. I think it is usable, and not difficult. What if if the same ip address uses multiple host names (virtual hosts for 1 ip address)? How can I add the host name? Somehow in the header? |
The ESP8266 supplies an SDK that programmers can code against in C. This is what we are using inside the Espruino port. There is an API provided that takes a String as input (representing a hostname) and does a DNS lookup and asynchronously calls us back when an IP address is found. The callback supplied by the SDK returns only a single IP address. This seems to tell me that a hostname (at least as far as the SDK is concerned) can map to only a single IP address. |
So! here is the solution. (maybe I asked wrong) need to add a header "host", it is works for me my own apache server, i can get all the sites from the same address chainging the Host header in the request header. var http = require("http");
http.get({
host: ipAddress,
port: 80,
headers: { 'Host' : 'tingspeak.com', },
path: '/update?key=' + ApiKey + '&field1=' + press + '&field2=' + temp
} |
Ahhh ... now I see. Sorry ... I mis-understood the question. If that ever happens again, please be patient with me and keep asking using different words. I'll get it eventually :-) |
All my respect to you, you helpd me a lot, and U make a very great job about porting!!!! I think this can change the iot devices, couse js is easy, its close to real world events. I used c with arduino before, and other things but I think this is the fastest coding env, with js. And esp8266 is very cheap, so I can connect things together. Like a air quality mesurement, a power flow meter, gas meter, etc! So you are great! Please keep going!!! |
There appears to be problems when users specify a string hostname on TCP/IP based functions. We need to do better than just document not doing this ... even if it is to throw an exception. See the following thread. http://forum.espruino.com/conversations/277402/#comment12620455 |
The ESP8266 port does not yet have working support for DNS name resolution (i.e. taking a hostname and retrieving the IP address associated with it). This work items is being created to track the resolution of that omission.
The text was updated successfully, but these errors were encountered: