Show Posts
Pages: [1] 2
1  Using Arduino / Interfacing w/ Software on the Computer / Reading Multiple Times from PHP file Problem on: June 25, 2013, 12:30:21 am
Hello, I am having some difficulties with reading from a php file. The code for the PHP file and the Arduino is below

PHP Code
Code:
<?php

sleep
(10);
echo 
"Hello World";

?>


Arduino Code
Code:
#include <Ethernet.h>
  #include <SPI.h>
 
  byte mac[] = {  0x90, 0xA2, 0xDA, 0x00, 0x7E, 0xAE };
  IPAddress server(192,168,1,223);
  IPAddress ipAddress(192,168,1,224);
  IPAddress myDNS(8,8,8,8);
  IPAddress myGateway(192,168,1,1);
  IPAddress mySubnet(255,255,255,0);
 
  EthernetClient client;
 
  void setup()
  {
    Serial.begin(9600);
    Ethernet.begin(mac, ipAddress, myDNS, myGateway, mySubnet);
   
    delay(1000);
    Serial.println("connecting...");
   
    if(client.connect(server, 80))
    {
      Serial.println("Connected");
      client.println("GET /print.php");
      client.println("HTTP/1.1");
      client.println("Host: /localhost");
      client.println("user-agent: arduino/somethingorother");
      client.println();
      delay(1000);
    }
  }
 
  void loop()
  {
       
   
      if(client.available())
      {
         
          char c = client.read();
          Serial.print(c);
          delay(500);
      }
      else
      {
        Serial.println("Disconnecting");
        client.stop();
        delay(1000);
      }
     
      delay(1000);
  }

The php file waits for 10 seconds and then echos "Hello World". When I run the code in the Arduino and check the Serial Monitor I get "Disconnecting" and after 10 seconds passed I still get "Disconnecting". Now if I want the Arduino to get the updates that happened in the PHP file what do I do? Do I make multiple HTTP Requests?

Thank You
2  Using Arduino / Programming Questions / Re: Function doesn't get executed on: June 15, 2013, 02:45:20 pm
Thanks, everything is working fine
3  Using Arduino / Programming Questions / Function doesn't get executed on: June 15, 2013, 01:41:26 pm
Hello, I am having troubles with my code. The following code is:
Code:
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x7E, 0xAE };
IPAddress server ( 192, 168, 1, 223 );
IPAddress ipAddress ( 192, 168, 1, 224 );
IPAddress myDNS ( 8, 8, 8, 8 );
IPAddress myGateway ( 192, 168, 1, 1 );
IPAddress mySubnet ( 255, 255, 255, 0 );

EthernetClient client;

char c;

int bulb = 8;

void setup()
{
   pinMode( bulb, OUTPUT);
   digitalWrite(bulb, LOW);

   Serial.begin(9600);
   Ethernet.begin(mac, ipAddress, myDNS, myGateway, mySubnet);

   delay(1000);
   Serial.println("Connecting....");
}

void loop()
{
void connectToServer();
void readFromServer();
void characterPrint();
delay(500);
}

void connectToServer()
{
   if( client.connect(server, 80) )
   {
Serial.println("Connected");
client.println("GET /print.php");
client.println("HTTP/1.1");
client.println("Host: /localhost");
client.println("user-agent: arduino/somethingorother");
client.println();
delay(1000);
   }
   else
   {
Serial.println();
Serial.println("Unable to Connect");
client.stop();
   }
}

void readFromServer()
{
   if( client.available() )
   {
c = client.read();
delay(500);
   }
   else
   {
Serial.println("Unable To Read From Client");
Serial.println("Disconnecting");
Serial.println();
client.stop();
   }
}

void characterPrint()
{
   Serial.println(c);
}

When I upload it to the Arduino, I just prints "connecting...." and it doesn't execute the functions that I have called in the "void loop()". Any suggestions on what is wrong with the code? Thank You
4  Using Arduino / Programming Questions / Re: [SOLVED] Ethernet Connection with Arduino on: June 12, 2013, 06:42:04 pm
Hello, I have solved the problem. Here is the Software and Hardware information:
Software
  • Windows Server 2003
  • WAMP Server (latest version)
Hardware
  • Arduino UNO
  • Ethernet Sheild

Code for the Arduino
Code:
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //needs to be replaced with your own Ethernet shield mac address
//The following is based on your configuration of the DNS and the DHCP of the Windows Server 2003, you have to change the data below
//according to your configurations

IPAddress server { 192,168,1,100};
IPAddress ipAddress {192,168,1,101};
IPAddress myDNS {8,8,8,8};
IPAddress myGateway {192,168,1,1};
IPAddress mySubnet {255,255,255,0};

EthernetClient client;

void setup()
{
     Ethernet.begin(mac, ipAddress, myDNS, myGateway, mySubnet);
     Serial.begin(9600);

     delay(1000);
     Serial.println("Connecting");

     if(client.connect(server, 80))
     {
          Serial.println("Connected");
          client.println("GET /print.php");
          client.println("HTTP/1.1");
          client.println("Host: /localhost");
          client.println("user-agent: arduino/somethingorother");
          client.println();
          delay(1000);
     }
}

void loop()
{
    if(client.available())
    {
            char c = client.read();
            Serial.print(c);
            delay(1000);
    }
    else
    {
           Serial.println("Cannot Connect");
           delay(1000);
    }
}

Code for the php file (I named mine "print.php" and you will place it in the www directory of the WAMP)
Code:
<?php
echo "Hello World";
?>


There is only one thing left. If you uploaded the code in the Arduino and created the php file, it will give you the following error "client denied by server configuration: C:/wamp/www/print.php" (The C drive is where I installed the WAMP Sever also this depends on where you installed your WAMP Server). In order to solve this problem you need to find the httpd.conf file and look for the following:
<Directory  "c:/wamp/www"

onlineofflinetag tag - don't remove
Order Deny Allow
Deny from all
Allow from 127.0.0.1

</Directory>

You will only need to adjust the line of "Deny from all" to "Allow from all" (without quotes). All of the above worked fine for me, I hope this would be helpful for others. Thanks
5  Using Arduino / Programming Questions / Re: Ethernet Connection with Arduino on: June 12, 2013, 03:52:26 pm
I just made one minor change is change the name of the php file to print.php but it basically does the same thing. I also removed the "?name=Mahmoud"" Just to make sure everything is working fine.

I've opened the Apache access.log here is what I found in it:
"192.168.1.224  -  - [12/Jun/2013:23:33:05  +0300]   "GET  /print.php  HTTP/1.1"  400  226"

I've also opened the Apache apache_error.log I found in it:
"[Wed Jun 12  23:33:05  2013] [error] [client 192.168.1.224] client sent HTTP/1.1 request without hostname (see RFC2616 section 14.23): /print.php"
6  Using Arduino / Programming Questions / Re: Ethernet Connection with Arduino on: June 12, 2013, 10:10:55 am
@PaulS

When I try to test my PHP files. I place the files in xampp/htdocs/xampp. Then I go to Google Chrome Web Browser and type in http://localhost/xampp/filename. After that it executes the PHP script in the file. I have tried now
Code:
client.println("GET /rec.php?name=Mahmoud HTTP/1.1");
which is still giving me a HTTP/1.1 400 Bad Request in my Serial Monitor. The Arduino is connects to the XAMPP Server fine and it prints that in the Serial Monitor. My PHP file that I want to access and read from with the Arduino is located at /xampp/htdocs/xampp/. Any other suggestions?
7  Using Arduino / Programming Questions / Re: Ethernet Connection with Arduino on: June 12, 2013, 09:48:42 am
@PaulS

Hello, I am a newbie in the Arduino Ethernet. Please explain more your suggestion. Here are some information. I am using XAMPP Server on Windows 2003 Server. I store my php file in /xampp/htdocs/xampp. And I test run these files with my Google Chrome Web Browser and they work. Now I really don't understand how to make a good request, and how I wrote that request it is written in the Arduino Ethernet Example http://arduino.cc/en/Tutorial/WebClient. Could you please type how a good request is made? Thank you.
8  Using Arduino / Programming Questions / Re: Ethernet Connection with Arduino on: June 12, 2013, 09:20:45 am
@wildbill @surferTim

I have done as suferTim suggested, I put a "Serial.println("Connection Close\r\n");" in the HTTP request and it worked fine, I checked if the client is available and it was available. Now I have another error "HTTP/1.1 Request 400 Bad Request". Any suggestions on how to solve that problem, and I am using the GET Method.

Thank You
9  Using Arduino / Programming Questions / Re: Ethernet Connection with Arduino on: June 12, 2013, 05:25:41 am
@wildbill

All of my IPAddress variables are fine. When I connect the Arduino and the XAMPP server is online everything is fine and it prints that it is connected. The problem is why isn't the client available, is there some extra code I should write to make my client available? Any ideas on how to solve the problem? Thank You
10  Using Arduino / Programming Questions / Ethernet Connection with Arduino on: June 11, 2013, 06:13:34 pm
Hello, I am having trouble with my Arduino Ethernet Board. I am trying to connect to my XAMPP Server and trying to retrieve data from a php file that I have created.

Code:
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0x7E, 0xAE}
IPAddress server { 192, 168, 1, 223 };
IPAddress ipAddress { xxx,xxx,xxx,xxx };
IPAddress myDNS {8,8,8,8};
IPAddress myGateway{192,168,1,1};
IPAddress mySubnet{255,255,255,0};

EthernetClient client;

void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ipAddress, myDNS, myGateway, mySubnet);

delay(1000);
Serial.println("connecting");

if(client.connect(server, 80))
{
    Serial.println("Connected");
    client.println("GET /localhost/xampp/rec.php?name=Mahmoud HTTP/1.1");
}
else
    Serial.println("Not Connected");

if(client.avialable())
{
    Serial.println("Client Connected");
}
else
    Serial.println("Not Connected");

}

void loop()
{

}

Now when I run that code I get on my serial monitor Not Connected, I need to know why the arduino doesn't connect to my XAMPP Server. I am running Windows Server 2003. Thank You

11  Using Arduino / Networking, Protocols, and Devices / Re: Connecting to the Arduino through Ethernet Shield on: May 21, 2013, 12:31:15 am
Hello Zoomkat,

I have tried the code you have provided but its not working. I have tried another code from the bildr.org website and it worked fine, here is the following code:

Code:
//ARDUINO 1.0+ ONLY
//ARDUINO 1.0+ ONLY
#include <Ethernet.h>
#include <SPI.h>

////////////////////////////////////////////////////////////////////////
//CONFIGURE
////////////////////////////////////////////////////////////////////////
byte server[] = { 174,123,231,247 }; //ip Address of the server you will connect to

//The location to go to on the server
//make sure to keep HTTP/1.0 at the end, this is telling it what type of file it is
String location = "/~bildr/examples/ethernet/ HTTP/1.0";


// if need to change the MAC address (Very Rare)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
////////////////////////////////////////////////////////////////////////

EthernetClient client;

char inString[32]; // string for incoming serial data
int stringPos = 0; // string index counter
boolean startRead = false; // is reading?

void setup(){
  Ethernet.begin(mac);
  Serial.begin(9600);
}

void loop(){
  String pageValue = connectAndRead(); //connect to the server and read the output

  Serial.println(pageValue); //print out the findings.

  delay(5000); //wait 5 seconds before connecting again
}

String connectAndRead(){
  //connect to the server

  Serial.println("connecting...");

  //port 80 is typical of a www page
  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.print("GET ");
    client.println(location);
    client.println();

    //Connected - Read the page
    return readPage(); //go and read the output

  }else{
    return "connection failed";
  }

}

String readPage(){
  //read the page, and capture & return everything between '<' and '>'

  stringPos = 0;
  memset( &inString, 0, 32 ); //clear inString memory

  while(true){

    if (client.available()) {
      char c = client.read();

      if (c == '<' ) { //'<' is our begining character
        startRead = true; //Ready to start reading the part
      }else if(startRead){

        if(c != '>'){ //'>' is our ending character
          inString[stringPos] = c;
          stringPos ++;
        }else{
          //got what we need here! We can disconnect now
          startRead = false;
          client.stop();
          client.flush();
          Serial.println("disconnecting.");
          return inString;

        }

      }
    }

  }

}

My question is why either your code or my code is working? and do I have to put the read character into an array of String?
Thank You
12  Using Arduino / Networking, Protocols, and Devices / Connecting to the Arduino through Ethernet Shield on: May 19, 2013, 10:46:57 pm
Hello, I am having a problem with my Ethernet Shield. Here is the situation, I have a PC that I have installed on it Windows Server 2003, with DNS, DHCP, and XAMPP. Now my Arduino UNO is connected to the Ethernet Shield and connected to the internet as well as my PC. I am making my Arduino a Client. What I want to do is let the Arduino read a text file from the XAMPP directory and display it on the Serial Monitor. I have written the following code:
Code:
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //This is not my Arduino Shield MAC Address.
IPAddress server(XXX,XXX,XXX,XXX);
IPAddress ipAddress(XXX,XXX,XXX,XXX);
IPAddress myDNS(8,8,8,8);
IPAddress myGateway(XXX,XXX,XXX,XXX);
IPAddress mySubnet(255,255,255,0);

EthernetClient client;

void setup()
{
  Serial.begin(9600);
  Ethernet.begin(mac, ipAddress, myDNS, myGateway, mySubnet );

  delay(1000);
  Serial.println("connecting...");

  if (client.connect(server, 80)) {
    Serial.println("connected");
  }
  else {
    Serial.println("connection failed");
  }
}

void loop()
{
Serial.println("Your Connected");
client.println("GET http://localhost/xampp/text.txt HTTP/1.1");
if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
}

When I run it, it prints on the Serial Monitor, Connecting, then prints Connected, then it prints symbols and it doesn't print any text. I am having trouble reading from the server. Any idea on how to solve that problem? I also wanted to know if I want to send to the Arduino data do I have to send them through the GET method?  Please keep your answers simple.

Thank You
13  Using Arduino / Networking, Protocols, and Devices / Connecting the Arduino to the Internet on: February 13, 2013, 10:59:00 am
Hello, I have installed Windows 2003 and I have configured the DNS and the DHCP and tested if I am able to connect to the internet and I am able to. I have connected the Arduino with the Ethernet Shield and I have written the following code (you will find in the attachment). When I open the serial monitor it says connecting then it says connection failed any suggestion on how to connect to the internet with the arduino.

Thank You
14  Using Arduino / Networking, Protocols, and Devices / Re: Serial Communication on: November 15, 2012, 02:07:10 am
Thank you Rob for replying back, I know how to use the serial of the Arduino but I had some problems with sending HEX numbers through the Arduino. Thank you again for your reply it helped alot
15  Using Arduino / Networking, Protocols, and Devices / Serial Communication on: November 13, 2012, 11:35:15 pm
Hello, I know how to use the serial communication of the Arduino. I have this 12 Byte Hexadecimal number I want to send through the serial of the Arduino and I don't how to do so. The number is AA0Dh, 00h, 00h, 00h, 00h. Any suggestions on how to do so?

Thank You
Pages: [1] 2