Go Down

Topic: Ethernet shiled + temperature sensor DHT11 + PHP + HTTP GET (Read 235 times) previous topic - next topic


Jul 04, 2016, 09:08 am Last Edit: Jul 04, 2016, 09:28 am by LukasCZE Reason: edit
Hi everyone,
I am not so experienced with Arduino and I would like to get some feedback for what I did. Some parts of my project might be usefull for others.

I decided to create another version of ethernet enabled temperature sensor (based on DHT11) that logs temperature into a log file on a webserver througth HTTP GET request. There are many versions of this project on the internet like [1] and [2]. But in my version the only requirement is that PHP is running on the server, database is not needed.

I tried to use POST method for „uploading" data to the server but I found some problems and I choosed rather to use GET. From some http documentation I understand it's not that secure but I don't care.
Things started working well after writing full http request that was constructed by [3] inserting by string
Code: [Select]
and HTML/1.1 and request type GET. I found on the internet some simplifications of the GET request but they didn't work for me. For example, I don't quite get what are the following lines actually used for:
Code: [Select]
   client.println("User-Agent: Web-sniffer/1.1.0 (+http://web-sniffer.net/)");
    client.println("Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7");
    client.println("Cache-Control: no-cache");
    client.println("Accept-Language: de,en;q=0.7,en-us;q=0.3");
    client.println("Referer: http://web-sniffer.net");

However, some simplifications of the request didn't work for me. For purposes of testing it's good idea to shorten upload interval from minutes to seconds. The huge advantage of the solution is that real time is provided on web server and you don't have to care about it. You just upload and the timestamp is given.

Full Arduino code:
Code: [Select]
#include <DHT.h>
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = {  0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
byte ip[] = {  192, 168, 0, 178};
byte gateway[] = { 192, 168, 0, 1 };
byte aaa[] = { 192, 168, 0, 1};

char server[] = "yoursite.wz.cz";

#define DHTPIN 2
#define DHTTYPE DHT11

void countDown(int n) {
  Serial.println("countdown " + String(n) + " seconds");
  while (n > 0) {

void phpUpload(float t, float h, String pokoj) {
  EthernetClient client;
  int uspech = client.connect(server, 80);
  if (uspech)

    client.print("GET /uploadDataVer2.php?");
    client.println(" HTTP/1.1");

    client.println("Host: yoursite.wz.cz");
    client.println("Connection: close");
    client.println("User-Agent: Web-sniffer/1.1.0 (+http://web-sniffer.net/)");
    client.println("Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7");
    client.println("Cache-Control: no-cache");
    client.println("Accept-Language: de,en;q=0.7,en-us;q=0.3");
    client.println("Referer: http://web-sniffer.net");

  } else {
    Serial.println("CONNECTION FAILED");

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

  if (!client.connected()) {

void setup() {
  int vystup = Ethernet.begin(mac);

void loop() {
  phpUpload(dht.readTemperature(), dht.readHumidity(), "sensor01");

The server side:
There are 3 simple files:
uploadDataVer2.php that captures GET request and adds timestamp. The output of script can be readed througth serial connection.
clear.php that clears/erases the log temp.log
parse.php creates slightly formatted table with visualisation using bars by equal sign „="

thx for commnets.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131