Rest.begin problem - cannot get contact with webpage


#1

I have a problem with the following code. (Only the important code is shown)

The code works when I’m on localhost (using the IP address) but when going to an external web page I get the text “No answer”

I do not have a fixed IP only the URL of the webpage and my web supplier cannot give me a fixed IP on the homepage.

Any good advice would be appreciated, as I’m stuck with 20 rev 2 Cactus micros if there is no solution!

The code is build on your example.

.
.
void wificonnect(MyObject customVar) {

  esp.enable();
  delay(500);
  esp.reset();
  delay(500);

  debugTekst("ARDUINO: setup rest client");

  while (!esp.ready());

  Serial.println("ARDUINO: setup rest client");
  //if (!rest.begin("yourapihere-com-r2pgihowjx7x.runscope.net")) {

  if (!rest.begin("http://www.klokken10.com")) {
    debugTekst("ARDUINO: failed to setup rest client");
    while (1);
  }

  /*setup wifi*/
  debugTekst("ARDUINO: setup wifi");
  esp.wifiCb.attach(&wifiCb);
  esp.wifiConnect(customVar.ssid, customVar.pass);
  debugTekst(customVar.ssid);
  debugTekst(customVar.pass);
  debugTekst("ARDUINO: system started");
}
.
.
.
void wifi() {
  char response[266];

  esp.process();

  if (digitalRead(pirPort)) {
    debugTekst("PIR alarm wifi?");
    if (wifiConnected) {
      debugTekst("PIR alarm");
      rest.get("/test.php");
     
      if (rest.getResponse(response, 266) == HTTP_STATUS_OK) {

        debugTekst("ARDUINO: GET successful");
        debugTekst(response);

        blink(4);

      } else {
        debugTekst("No answer");
      }
      delay(12000);
    }
  }
}
.
.

The output looks like this
.
.
add 0
aid 2
pm open phy2,type:2 0 0
cnt

connected with jip:192.168.0.19,mask:255.255.255.0,gw:192.168.0.1
WIFI CONNECTED
PIR alarm wifi?
PIR alarm
No answer


#2

What result is the command line?

ping www.klokken10.com

I can’t get any response.


#3

Pinging klokken10.com [77.66.117.80] with 32 bytes of data:
Reply from 77.66.117.80: bytes=32 time=21ms TTL=57
Reply from 77.66.117.80: bytes=32 time=12ms TTL=57
Reply from 77.66.117.80: bytes=32 time=11ms TTL=57
Reply from 77.66.117.80: bytes=32 time=16ms TTL=57

Ping statistics for 77.66.117.80:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 11ms, Maximum = 21ms, Average = 15ms


#4

try to edit this line

  if (!rest.begin("http://www.klokken10.com")) {

to

  if (!rest.begin("www.klokken10.com")) {

#5

Thanks for your fast response.

I have tried www.klokken10.com without luck as well as klokken10.com.

I have even tried to use URL’s which are not mine and the result are always the same.


#6

Will it work?

  if (!rest.begin("77.66.117.80")) {

#7

No it will not work.

If I enter 77.66.117.80 in a browser I’ll not get klokken10.com

The result is:

SORRY!
If you are the owner of this website, please contact your hosting provider: webmaster@77.66.117.80
It is possible you have reached this page because:


#8

is test.php same with the file when you are on localhost?


#9

Yes _ I have just changed the code on localhost and on the webpage so they are alike.

The code is very simple:

</head>
<body>
    <?php			
	  echo "Hello world";
	?>
</body>

#10

The solution was:

!rest.begin(“www.klokken10.com”,80,false)

Thank you for your support


#11

I’m glad you resolved the problem yourself. I learned more.