Created Wed, 30 Aug 2017 15:58:20 +0000 by aabfm
Wed, 30 Aug 2017 15:58:20 +0000
Hi Everyone, On my previous topic "chipkit mx7ck calling "hello world" from webserver" I manage to have my mx7ck calling a webserver and displaying the info, i.e. implementing a webclient. Now the next step is to identify my mx7ck (I actually have another one) in order to receive only the info that is related to it. In other words I want to contact my webserver which holds a php script, and this script is expecting the 'id' parameter sent via the POST method. It will then retrieve the info in xml format. My problem is to call the script located at:
sending the POST parameter 'id' with the value "abcde". 1st step: get the ip from the DNS server. Basically I want to be able to write the domain rather than the IP address of my webserver. On the previous post I was using the following code to connect to the server:
...
const char * server = "nnn.nnn.nnn.nnn";
unsigned short portServer = 80;
...
switch(state)
{
case CONNECT:
if(deIPcK.tcpConnect(server, portServer, tcpClient, &status))
{
state = WRITE;
}
break;
...
Does anyone know how to ? Thanks in advance.
Wed, 30 Aug 2017 16:17:40 +0000
The DIIPcK class contains the function "resolveDomainName(const char *name, IPv4& ip)" which you can use to look up a domain name.
IPv4 serverIP;
deIPcK.resolveDomainName("www.mywebserver.com", serverIP);
"serverIP" now should contain the IP address of the server.
Wed, 30 Aug 2017 16:30:00 +0000
I will try it straight away. Thx
Wed, 30 Aug 2017 16:35:56 +0000
I've just tried it as:
deIPcK.resolveDomainName("www.startpage.com", serverIP);
deIPcK.tcpConnect(serverIP, portServer, tcpClient);
but it hangs... Any ideas?
Wed, 30 Aug 2017 16:37:40 +0000
Maybe the DNS lookup is failing? I think the function will return a true
if it has worked, or false
if it fails.
Wed, 30 Aug 2017 16:45:34 +0000
Is there an option of forcing the DNS server to be something else such as OpenDNS IP? Note: OpenDNS ip is 208.67.222.222
Wed, 30 Aug 2017 16:51:57 +0000
Tried this one but it also doesn't work:
...
IPv4 opendns = {208,67,222,222};
...
deIPcK.setDNS(1, opendns);
deIPcK.resolveDomainName("www.google.com", serverIP);
deIPcK.tcpConnect(serverIP, portServer, tcpClient);
Wed, 30 Aug 2017 19:15:01 +0000
I've now tried both with and without DHCP but still the same response: none, it hangs... Any idea?
Wed, 30 Aug 2017 19:46:42 +0000
Both:
deIPcK.setDNS(1, opendns);
and
deIPcK.resolveDomainName("www.google.com", serverIP);
returned FALSE... :( Any ideas?
Wed, 30 Aug 2017 20:55:34 +0000
Latest test and... IT WORKED!!!! Apparently there was a problem with my router...
deIPcK.tcpConnect("www.mywebserver.com", portServer, tcpClient);
and the 2nd was also accomplished:
String message = "POST /test01/results.php HTTP/1.1\nHost: http://www.mywebserver.com\nConnection: close\nContent-Length: 8\nContent-Type: application/x-www-form-urlencoded\n\nid=abcde\n\n";
Nice!
Wed, 30 Aug 2017 21:13:40 +0000
Excellent!