Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By sreejitheg
#27680 Hi,

I am a newbie to ESP. I was successful reading data from DTH11 and post it to the ESP webserver with my esp acting as AP.
What am trying to achieve is to post the same data on to a webserver running on my PC Apache Server and ESP acting as a webclient in the system. Can anyone please refer me some example or idea for the same.
I have referred to the examples of posting data to internet (thingspeak.com). But am not able to figureout how to post to the local server(PC) in the network.

Thanks in advance :)
User avatar
By Touliloup
#27692 You could do a simple JSON Rest Service and simply post the data in JSON form to your service.
Plenty of example are available online on how to do a simple server. How you manage your data in the service depend on what you want to do with it.

http://crunchify.com/create-very-simple ... va-client/
User avatar
By LauBaz
#27728 I have done something similar.

ESP is reading a sensor, connecting to my wifi, connecting to Apache2 webserver on raspberry pi, transmit info, then shut down.

ESP sketch (transmit part):
Code: Select allvoid setup() {
  Serial.begin(115200);
  delay(10);

  // We start by connecting to a WiFi network

  //Serial.println();
  Serial.println("");
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected"); 
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}
void loop() {

// Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 8000;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
//temp variable is set with a function to check the temp of an DS18B20 sensor. Let me know if you need it
  String data = "temp1=" + (String)temp;
// "temp1=" is what is going to be sent using GET to the apache server, see code in add.php

  // We now create a URI for the request
  String url = "GET /add.php?" + data + " HTTP/1.1";
client.println(url);
  client.println("Host: 192.168.1.200");
  client.println("Connection: close");
  client.println();
  delay(500);
 
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
  client.stop(); //Stopping client
  ESP.deepSleep(60U*60*1000000); //U for unsigned
  delay(1000); //for above sleep
}


Apache2 to receive data (using GET)
Code: Select all<?php

$date = new DateTime();
$date = $date->format("d-M-Y  h:i:s  ");


if(!empty($_GET["temp1"]))
{
 $tempesp = "Temperature=";
 $tempesp .= ($_GET["temp1"]);
 file_put_contents("/media/USB/Temp.ESP", $date);
 file_put_contents("/media/USB/Temp.ESP", $tempesp, FILE_APPEND);
}


echo $tempesp;

?>


I use this so that my server writes the value of temp1, along with a timestamp, to a text file, which I then read with RPI-Monitor to display nice graphs and such.

Hope this helps