Problem for sending data trough url to wamp database

Hi everyone !

I use WampServer on my computer and i want to make my arduino card with ethernet shield put data in database named "automaplants".

My wamp use port 80 and i can access to data.php file from my phone, the port 80 is correctly accessible from anyone on my network but there are nothing appear in my database from my arduino.

When i write the url manually on my browser like :
"192.168.1.20:80/data.php?temperature=10.25&airhumidity=56.24$soilhumidity=0"
they work perfectly, the data has been entered in my db but nothing with my arduino card.

There is my code :

#include <DHT.h>
#include <Ethernet.h>

#define DHTPIN 2
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

int moistureSensorPin = A0;
int moistureSensorValue = 0;
String moistureSensorPercentage;

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 21);

IPAddress server(192, 168, 1, 20);

EthernetClient client;

void setup() {
  Serial.begin(115200);
  dht.begin();
  Ethernet.begin(mac, ip);
}

void loop() {
  float temp_hum_val[2] = {0};
  moistureSensorValue = analogRead(moistureSensorPin);

  if(moistureSensorValue < 95) {
    moistureSensorPercentage = "0";
  } else if(moistureSensorValue >= 95 && moistureSensorValue <= 190) {
    moistureSensorPercentage = "10";
  } else if (moistureSensorValue >= 190 && moistureSensorValue <= 285) {
    moistureSensorPercentage = "20";    
  } else if (moistureSensorValue >= 285 && moistureSensorValue <= 380) {
    moistureSensorPercentage = "30";
  } else if (moistureSensorValue >= 380 && moistureSensorValue <= 475) {
    moistureSensorPercentage = "40";
  } else if (moistureSensorValue >= 475 && moistureSensorValue <= 570) {
    moistureSensorPercentage = "50";
  } else if (moistureSensorValue >= 570 && moistureSensorValue <= 665) {
    moistureSensorPercentage = "60";
  } else if (moistureSensorValue >= 665 && moistureSensorValue <= 760) {
    moistureSensorPercentage = "70";
  } else if (moistureSensorValue >= 760 && moistureSensorValue <= 855) {
    moistureSensorPercentage = "80";
  } else if (moistureSensorValue >= 855 && moistureSensorValue <= 900) {
    moistureSensorPercentage = "90";
  } else {
    moistureSensorPercentage = "100";
  }

  if(client.connect(server, 80)) {
    Serial.println("Connected to Web Server");
    if(!dht.readTempAndHumidity(temp_hum_val)) {
      // Send data to localhost URL
      client.print("GET /data.php?");
      client.print("temperature=");
      client.print(temp_hum_val[1]);
      client.print("&airhumidity=");
      client.print(temp_hum_val[0]);
      client.print("&soilhumidity=");
      client.print(moistureSensorPercentage);
      client.println(" HTTP/1.1\r\n");
      // Print to serial monitor to survey returned value
      Serial.print("Temperature : ");
      Serial.print(temp_hum_val[1]);
      Serial.println("°C");
      Serial.print("Air humidity : ");
      Serial.print(temp_hum_val[0]);
      Serial.println("%");
      Serial.print("Soil humidity : ");
      Serial.print(moistureSensorPercentage);
      Serial.println("%");
    } else {
      Serial.println("Unable to fetch sensor value.");
    }
    // Close connnection to Web Server
    client.stop();
  } else {
    Serial.println("Connection to localhost failed.");
  }

  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }

  delay(2000);
}

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the Installation & Troubleshooting category.

What DHT libary do you use? In Adafruit library I don't see the method

dht.readTempAndHumidity

Sorry for this late response.
I find this code here : Grove - Temperature&Humidity Sensor Pro(DHT22) - Seeed Wiki

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.