Pages: [1]   Go Down
Author Topic: Why I can't connect  (Read 818 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, well I am new here, and have a question about why I can't connecto to 000webhost via ethernet shield this is my code.
Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte gateway[] = { 192, 168, 1, 254 };
byte subnet[] = { 255, 255, 255, 0 };
IPAddress server( 192,168,1,65 );
int s[20];
EthernetClient client;

void setup(){
  Ethernet.begin(mac, gateway, subnet);
  delay(1000);
  Serial.begin(9600);
}
void loop(){
  for(int a=0;a<20;a++){
    s[a]=random(10, 15);
  }
  mysql_ins();
}
void mysql_ins(){
  if (client.connect(server, 80)) {
    client.print("GET /arduino/read.php?s1=");
    client.print(s[0]);
    for(int a=1;a<20;a++){
      client.print("&s");
      client.print(a+1);
      client.print("=");
      client.print(s[a]);
     
    }
    client.println(" HTTP/1.1");
    client.println("Host: localhost");
    client.println();
    Serial.println("ARDUINO: HTTP message sent");
    delay(3000);
    if(client.available()){
      Serial.println("ARDUINO: HTTP message received");
      Serial.println("ARDUINO: printing received headers and script response...\n");

      while(client.available()){
        char c = client.read();
        Serial.print(c);
      }
    }else{
      Serial.println("ARDUINO: no response received / no response received in time");
    }
    client.stop();
  }else{
    Serial.println("connection failure");
  }
}
When I do it in my local computer I can acces but, I cant in 000webhost I set the server ip as it show me in the Cpanel.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46214
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What response do you get from the server?
What do the server's logs show?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I cant see the server log... and how can I know the error?

I am trying to access by the ip 31.170.160.96/home/a9451348 but I can't. In the cpanel show me that ip to acces...
« Last Edit: February 09, 2013, 06:29:22 pm by foca » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46214
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
In the cpanel show me that ip to acces...
What is this cpanel (or Cpanel) that you are talking about?

Quote
I am trying to access by the ip 31.170.160.96/home/a9451348
How does 31.170.160.96 relate to 192.168.1.65? Your source code shows that the server you are trying to access is at 192.168.1.65, not 31.170.160.96.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello I'm back again, the cpanel it's the control paranel from my webSite and I get this data:
Access your websitehttp://arduinosensor.hostzi.com
Access your website with www.http://www.arduinosensor.hostzi.com
Website IP address31.170.160.99
Server nameserver35.000webhost.com
and my code is this:
Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte gateway[] = { 192, 168, 1, 254 };
byte subnet[] = { 255, 255, 255, 0 };
IPAddress server( 31,170,160,99 );
int s[20];
EthernetClient client;

void setup(){
  Ethernet.begin(mac, gateway, subnet);
  delay(1000);
  Serial.begin(9600);
}
void loop(){
  for(int a=0;a<20;a++){
    s[a]=random(10, 15);
  }
  mysql_ins();
}
void mysql_ins(){
  if (client.connect(server, 80)) {
    client.print("GET /arduino/read.php?s1=");
    client.print(s[0]);
    for(int a=1;a<20;a++){
      client.print("&s");
      client.print(a+1);
      client.print("=");
      client.print(s[a]);
     
    }
    client.println(" HTTP/1.1");
    client.println("Host: localhost");
    client.println();
    Serial.println("ARDUINO: HTTP message sent");
    delay(3000);
    if(client.available()){
      Serial.println("ARDUINO: HTTP message received");
      Serial.println("ARDUINO: printing received headers and script response...\n");

      while(client.available()){
        char c = client.read();
        Serial.print(c);
      }
    }else{
      Serial.println("ARDUINO: no response received / no response received in time");
    }
    client.stop();
  }else{
    Serial.println("connection failure");
  }
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46214
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
    client.println("Host: localhost");
localhost is the computer that the code is running on (the Arduino). Have you really figured out a way to get PHP to run on your Arduino?
Logged

Pages: [1]   Go Up
Jump to: