i have small problem

what is mean <FILE_APPEND>

in the file.txt

…thank you for all …

thank you <> and <> for all

i try to exchange my (insert.php) file with (file.php) where file.php file is

<?php
date_default_timezone_set('Europe/london');
setlocale(LC_ALL, 'en_GB');

$var1 = $_GET['sensor1'];
$var2 = $_GET['sensor2'];
$var3 = $_GET['sensor3'];

$currTime = time();
$fileContent =  $currTime ."\t" .$var1 ."\t" .$var2 ."\t" .$var3 ."\n";

$fileStatus = file_put_contents('myFile.txt',$fileContent,FILE_APPEND);

if ($fileStatus != false) {
echo "OK";
} else {
echo "FAIL";
}
?>

and replace file.php instead of insert.php in arduino code :

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

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

IPAddress ip( 192,168,0,104 );

char server[] = "192,168,0,102";
   
   
EthernetClient cliente;

void setup() 
{ 
 Serial.begin(9600);
 Ethernet.begin(mac,ip);
   Serial.println(Ethernet.localIP());    
}

void loop() 
{
 if( cliente.connect (server,8095))
{  Serial.println("connected");
    
    
cliente.print("GET /sensores/file.php?sensor1=125&sensor2=17&sensor3=228 HTTP/1.0\r\nHost: 192,168,0,102\r\n");       
 

cliente.stop();


}else {Serial.println("disconnected");
cliente.stop();
} 

delay(10000);
}

but the myfile.txt don’t created in my server file (C:\AppServ\www\sensores)
wher i store file.php in (C:\AppServ\www\sensores)

but when i am write : ((http://localhost:8095/sensores/file.php?sensor1=11&sensor2=22&sensor3=33))
in browser the myfile.txt is created in(C:\AppServ\www\sensores)

PaulS:
Where do the echo statements go? The server returns all of the output from the script, along with other stuff, to the client. Why are you ignoring the server's response?

how to know the response of server ??

how to know the response of server ??

After making the request:

   while(client.connected())
   {
       while(client.available() > 0)
       {
           char c = client.read();
           // Do something with c, such as Serial.print() it
       }
   }

my dear<< paulS>> I tired you with me …

but i make the code as this :

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

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

IPAddress ip( 192,168,0,104 );

//char server[] = "192,168,0,102";
//IPAddress server(192,168,0,102); 
byte server[]={192,168,0,102};

EthernetClient cliente;

void setup() 
{ 
 Serial.begin(9600);
 Ethernet.begin(mac,ip);
   Serial.println(Ethernet.localIP());    
}

void loop() 
{
 if( cliente.connect (server,8095))
{  Serial.println("connected");
    
    
cliente.print("GET /sensores/file.php?sensor1=125&sensor2=17&sensor3=228 HTTP/1.0\r\nHost: 192,168,0,102\r\n");       

}else 
{Serial.println("disconnected"); 
}


if (cliente.available()) {
    char c = cliente.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!cliente.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    cliente.stop();

    // do nothing forevermore:
    while (true);
  }
 

delay(10000);
}

and the result is :
192.168.0.104
disconnected
disconnecting.

I think your issue might just be that you do

cliente.print("GET /sensores/file.php?sensor1=125&sensor2=17&sensor3=228 HTTP/1.0\r\nHost: 192,168,0,102\r\n");

instead of

cliente.print[color=red][b]ln[/b][/color]("GET /sensores/file.php?sensor1=125&sensor2=17&sensor3=228 HTTP/1.0\r\nHost: [color=red]192.168.0.102[/color]\r\n");

because a well formed HTTP request needs to end with a full empty line and you don’t serve that so it’s likely then having a timeout on the connection.

if that does not work:

let’s try something

  • install the script below that does the reporting on your server into insert.php in a sensores directory under the root of your web site

the script is as follow, name it insert.php, be careful non capital letters

<?php
date_default_timezone_set('Europe/London');
setlocale(LC_ALL, 'en_GB');

$var1 = $_GET['sensor1'];
$var2 = $_GET['sensor2'];
$var3 = $_GET['sensor3'];

$currTime = time();
$fileContent =  $currTime ."\t" .$var1 ."\t" .$var2 ."\t" .$var3 ."\n";

$fileStatus = file_put_contents('myFile.txt',$fileContent,FILE_APPEND);

if ($fileStatus != false) {
echo "SUCESS";
} else {
echo "FAILURE";
}
?>

In a web-browser type

http://[color=blue]192.168.0.104:8095[/color]/sensores/insert.php?sensor1=1&sensor2=2&sensor3=3

you should see “SUCESS” appear in your web browser and myFile.txt being created on your server in the sensors directory with a timestamp and then the number 1 2 3 separated by tabs.

if that does not work check that your web server address is really 192.168.0.104, check capitalization of the sensores/insert.php and ensure the port number is 8095. default web server port is 80… (in your URL above you did not provide the port number by the way)

Fix what needs to be fixed so that this works.

When that works you know you have a valid service on the server side, reachable from a computer on your network.

  • set your Arduino IDE serial console at 115200 bauds
  • upload this code.
  • tell us what you see in the console

if all goes well you should see on the server side the file being modified with a new line with a time stamp and 3 4 5 separated by tabs

and in the console

My IP address: 192.168.0.104
connected
HTTP/1.1 200 OK
Set-Cookie: startBAK=R3415743754; path=/; expires=Wed, 12-Oct-2016 21:40:27 GMT
Date: Wed, 12 Oct 2016 20:32:18 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
Set-Cookie: start=R118955113; path=/; expires=Wed, 12-Oct-2016 21:36:13 GMT
Server: Apache
X-Powered-By: PHP/7.0.10
Vary: Accept-Encoding

[color=green]SUCESS[/color]
disconnecting.

the arduino code to upload

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

// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

//the IP address for the shield:
byte ip[] = { 192, 168, 0, 104 };

EthernetClient client;

byte server[] = { 192, 168, 0, 102 };

//===============================================
//
//===============================================
boolean checkIPAddress()
{
  byte a, b, c, d;
  a = Ethernet.localIP()[0];
  b = Ethernet.localIP()[1];
  c = Ethernet.localIP()[2];
  d = Ethernet.localIP()[3];

  Serial.print("My IP address: ");
  Serial.print(a); Serial.print(".");
  Serial.print(b); Serial.print(".");
  Serial.print(c); Serial.print(".");
  Serial.println(d);

  return (a == ip[0]) && (b == ip[1]) && (c == ip[2]) && (d == ip[3]);
}

//===============================================
//
//===============================================
void setup() {
  Serial.begin(115200);

  // start the Ethernet connection:
  Ethernet.begin(mac, ip);
  if (!checkIPAddress()) {
    Serial.println("Failed to configure static IP address");
    while (1); // no point in carrying on, die here
  }

  if (client.connect(server, 8095)) { // are you sure about the server addres and PORT?
    Serial.println("connected");
    client.println("GET /sensores/insert.php?sensor1=4&sensor2=5&sensor3=6 HTTP/1.0\r\nHost: 192.168.0.102\r\nUser-Agent: Arduino\r\n");
  } else {
    Serial.println("connection failed");
  }
}


//===============================================
//
//===============================================
void loop() {
  if (client.available()) {
    int c = client.read();
    if (c != -1) Serial.print((char) c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    while (1); // no point in carrying on, die here
  }
}

my dear J-M-L

iam sure from my server ip where it taken from my pc (cmd>>ipconfig>>IPv4 Address)
and also sure from port

I install the php file and type this in browser :
http://192.168.0.102:8095/sensores/insert.php?sensor1=1&sensor2=2&sensor3=3

and i see "SUCESS" appear in my web browser and myFile.txt being created on my server in the sensors directory with a timestamp and then the number 1 2 3 separated by tabs.

but when install arduino code and execute it the result is

My IP address: 192.168.0.104
connection failed
disconnecting.

i think the problem is the connection between the arduino and server

This rubbish is hard to read:

void loop()
{
 if( cliente.connect (server,8095))
{  Serial.println("connected");
    
    
cliente.print("GET /sensores/file.php?sensor1=125&sensor2=17&sensor3=228 HTTP/1.0\r\nHost: 192,168,0,102\r\n");      

}else
{Serial.println("disconnected");

Compare that to this identical-in-functionality code:

void loop()
{
   if( cliente.connect (server,8095))
   {
      Serial.println("connected");
      cliente.print("GET /sensores/file.php?sensor1=125&sensor2=17&sensor3=228 HTTP/1.0\r\nHost: 192,168,0,102\r\n");      
   }
   else
   {
      Serial.println("disconnected");

When the curly braces line up, and stand out, the organization of the is easier to see and understand.

This code is in the wrong place:

if (cliente.available()) {
    char c = cliente.read();
    Serial.print(c);
  }

and is missing the while(client.connected()) statement and braces that I posted.

Put the code I posted EXACTLY AS I POSTED IT (well, except for adding an e on the end of client; Americans do not spell client your way) immediately after the line that sends the GET request (just like in the examples)..

I trust that you did not modify my code, right? Used as is on both sides?

Do you have DHCP working on your network? Could use this to try out your settings

Is your server the same as the machine you use to test the browser or do you have 2 different machines? Can you try the web browser connexion by connecting your PC to that Ethernet cable you are using?

Can you give us a link to your Ethernet shield?

PaulS:
Put the code I posted EXACTLY AS I POSTED IT (well, except for adding an e on the end of client; Americans do not spell client your way) immediately after the line that sends the GET request (just like in the examples)…

<>
where is the code that you posted it . do you mean this ??

if (cliente.available()) {
    char c = cliente.read();
    Serial.print(c);
  }

and where is the example talk about it do you mean the (webclient) in ethernet library??

with my respect

my sir J-M-L i modify the code as you request
and i only change this instuction that it write it in browser :

http://192.168.0.104:8095/sensores/insert.php?sensor1=1&sensor2=2&sensor3=3

by this :

http://192.168.0.102:8095/sensores/insert.php?sensor1=1&sensor2=2&sensor3=3

because my server ip is 192.168.0.102 instead of 192.168.0.104 where 192.168.0.104 is ip of ethernet shield

…and this code used it as you posted :

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

// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

//the IP address for the shield:
byte ip[] = { 192, 168, 0, 104 };

EthernetClient client;

byte server[] = { 192, 168, 0, 102 };

//===============================================
//
//===============================================
boolean checkIPAddress()
{
  byte a, b, c, d;
  a = Ethernet.localIP()[0];
  b = Ethernet.localIP()[1];
  c = Ethernet.localIP()[2];
  d = Ethernet.localIP()[3];

  Serial.print("My IP address: ");
  Serial.print(a); Serial.print(".");
  Serial.print(b); Serial.print(".");
  Serial.print(c); Serial.print(".");
  Serial.println(d);

  return (a == ip[0]) && (b == ip[1]) && (c == ip[2]) && (d == ip[3]);
}

//===============================================
//
//===============================================
void setup() {
  Serial.begin(115200);

  // start the Ethernet connection:
  Ethernet.begin(mac, ip);
  if (!checkIPAddress()) {
    Serial.println("Failed to configure static IP address");
    while (1); // no point in carrying on, die here
  }

  if (client.connect(server, 8095)) { // are you sure about the server addres and PORT?
    Serial.println("connected");
    client.println("GET /sensores/insert.php?sensor1=4&sensor2=5&sensor3=6 HTTP/1.0\r\nHost: 192.168.0.102\r\nUser-Agent: Arduino\r\n");
  } else {
    Serial.println("connection failed");
  }
}


//===============================================
//
//===============================================
void loop() {
  if (client.available()) {
    int c = client.read();
    if (c != -1) Serial.print((char) c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    while (1); // no point in carrying on, die here
  }
}

wallaa_alebady:
my sir J-M-L i modify the code as you request
and i only change this instuction that it write it in browser :

http://192.168.0.104:8095/sensores/insert.php?sensor1=1&sensor2=2&sensor3=3

by this :

http://192.168.0.102:8095/sensores/insert.php?sensor1=1&sensor2=2&sensor3=3

because my server ip is 192.168.0.102 instead of 192.168.0.104 where 192.168.0.104 is ip of ethernet shield

right - this was the correct thing to do, indeed my mistake there

can you comment on my other questions?

Do you have DHCP working on your network? Could use this to try out your settings
Is your server the same as the machine you use to test the browser or do you have 2 different machines? Can you try the web browser connexion by connecting your PC to that Ethernet cable you are using?
Can you give us a link to your Ethernet shield?

<>

i think i have DHCP and i by it make the ethernet ip (192.168.0.104) static ip in my router
are you mean this??

i am used apache server on my PC as server and i used the same PC to test the browser .

and what you are mean by :

J-M-L:
? Can you try the web browser connexion by connecting your PC to that Ethernet cable you are using?

??

and the ethernet shield used as this in this link:

i am used apache server on my PC as server and i used the same PC to test the browser .

OK so you can’t remove the cable from your PC then - I was wondering if there is an issue with routing on your network.

when you set the IP static in your DHCP router, did you allocate mac address “0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED” to 192.168.0.104 correctly?

can you remove that entry in your router and let DHCP work automagically for your set up and try with the following code that I hacked together without testing

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

// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

EthernetClient client;

byte server[] = { 192, 168, 0, 102 };

//===============================================
//
//===============================================
void displayIPAddress()
{
  byte a, b, c, d;
  a = Ethernet.localIP()[0];
  b = Ethernet.localIP()[1];
  c = Ethernet.localIP()[2];
  d = Ethernet.localIP()[3];

  Serial.print("My IP address: ");
  Serial.print(a); Serial.print(".");
  Serial.print(b); Serial.print(".");
  Serial.print(c); Serial.print(".");
  Serial.println(d);

}

//===============================================
//
//===============================================
void setup() {
  Serial.begin(115200);

  // start the Ethernet connection:

  if (! Ethernet.begin(mac)) {
    Serial.println("Failed to receive DHCP IP address");
    while (1); // no point in carrying on, die here
  }
  displayIPAddress();

  if (client.connect(server, 8095)) { // are you sure about the server addres and PORT?
    Serial.println("connected");
    client.println("GET /sensores/insert.php?sensor1=4&sensor2=5&sensor3=6 HTTP/1.0\r\nHost: 192.168.0.102\r\nUser-Agent: Arduino\r\n");
  } else {
    Serial.println("connection failed");
  }
}


//===============================================
//
//===============================================

void loop() {
  switch (Ethernet.maintain())
  {
    case 1:
      //renewed fail
      Serial.println("Error: renewed fail");
      break;

    case 2:
      //renewed success
      Serial.println("Renewed success");

      //print your local IP address:
      printIPAddress();
      break;

    case 3:
      //rebind fail
      Serial.println("Error: rebind fail");
      break;

    case 4:
      //rebind success
      Serial.println("Rebind success");

      //print your local IP address:
      printIPAddress();
      break;

    default:
      //nothing happened
      break;

  }

  if (client.available()) {
    int c = client.read();
    if (c != -1) Serial.print((char) c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    while (1); // no point in carrying on, die here
  }
}

and see what it does?

Also just as this is not a real arduino board but a clone, if you have a SD card on it let's make sure the SD card is not messing around with the Ethernet communication.

Usually pin 4 is the chip select pin for the SD card interface so add this to the top of the code:#define SS_SD_CARD  4 // chip select pin for SD card on Ethernet Shieldthen in the setup do the following

pinMode(SS_SD_CARD, OUTPUT);
digitalWrite(SS_SD_CARD, HIGH);  // SD Card not active

just to be on the safe side.

<>

there is error in code because << printIPAddress(); >> function don’t found …
are you mean << displayIPAddress(); >> is same ??

yep sorry - did not change the full code was just typing in the forum the code. make sure to match the function name

<>

i execute your last code :

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

#define SS_SD_CARD   4

// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

EthernetClient client;

byte server[] = { 192, 168, 0, 102 };

//===============================================
//
//===============================================
void displayIPAddress()
{
  byte a, b, c, d;
  a = Ethernet.localIP()[0];
  b = Ethernet.localIP()[1];
  c = Ethernet.localIP()[2];
  d = Ethernet.localIP()[3];

  Serial.print("My IP address: ");
  Serial.print(a); Serial.print(".");
  Serial.print(b); Serial.print(".");
  Serial.print(c); Serial.print(".");
  Serial.println(d);

}

//===============================================
//
//===============================================
void setup() {
  Serial.begin(115200);
  
  pinMode(SS_SD_CARD, OUTPUT);
  digitalWrite(SS_SD_CARD, HIGH);  // SD Card not active

  // start the Ethernet connection:

  if (! Ethernet.begin(mac)) {
    Serial.println("Failed to receive DHCP IP address");
    while (1); // no point in carrying on, die here
  }
displayIPAddress();

  if (client.connect(server, 8095)) { // are you sure about the server addres and PORT?
    Serial.println("connected");
    client.println("GET /sensores/insert.php?sensor1=4&sensor2=5&sensor3=6 HTTP/1.0\r\nHost: 192.168.0.102\r\nUser-Agent: Arduino\r\n");
  } else {
    Serial.println("connection failed");
  }
}


//===============================================
//
//===============================================

void loop() {
  switch (Ethernet.maintain())
  {
    case 1:
      //renewed fail
      Serial.println("Error: renewed fail");
      break;

    case 2:
      //renewed success
      Serial.println("Renewed success");

      //print your local IP address:
     displayIPAddress();
      break;

    case 3:
      //rebind fail
      Serial.println("Error: rebind fail");
      break;

    case 4:
      //rebind success
      Serial.println("Rebind success");

      //print your local IP address:
displayIPAddress();
      break;

    default:
      //nothing happened
      break;

  }

  if (client.available()) {
    int c = client.read();
    if (c != -1) Serial.print((char) c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    while (1); // no point in carrying on, die here
  }
}

and the result is :

My IP address: 192.168.0.100
connection failed
disconnecting.

so you are getting an IP address in the right range from your DHCP service, showing that your ethernet shield, ethernet cable and library do work.

The connection to the server though gets rejected. I'd be tempted to look at the logs of the web server to see why the connection is rejected.

do you have a smartphone and wifi active on that same network? if so can you use your smartphone, connected by Wifi to that network and type in the smartphone's browser

http://192.168.0.102:8095/sensores/insert.php?sensor1=1&sensor2=2&sensor3=3

if that fails then you know your server is rejecting external connections. that might be due to wrong network settings or ports being closed on your server computer or anti-virus software blocking incoming traffic etc... would suggest to check that