[ESP8266 NodeMCU Arduino] im trying to send my sensor varibles to internet page

Hi im still newb in programing trying to figure out how to send my DTH 22 (am2302) readings to a internet web page not local one
what i found after few days is this : ESP8266 Send Data To a Website (ESP-01/ESP-12) - YouTube
i have setted up a web page like in this toutorial with reciever.php and myfile.txt

my reciever.php file form that toutorial

<?php $var1 = $_GET['apples']; $var2 = $_GET['oranges']; $fileContent = "you have".$var1."apples, and".$var2." oranges.\n"; $fileStatus = file_put_contents('myfile.txt',$fileContent,FILE_APPEND); if($fileStatus != false) { echo "SUCCES: data written to file"; } else { echo "FAIL: culd not write to file"; } ?>

now what im trying to do is open url link mywebpage.com - This website is for sale! - mywebpage Resources and Information.
except to use my varible with sensor reading where the number 30 is using Arduino 1.8.1 sketch
iv`e allready have connected to wi-fi ,read my sensor and have it readings in varible just missing that part
is that even posible ? if yes and some one know how to do it please help me ! :smiley:

Thanks in advance and sorry for my bad english :slight_smile:

ok iv`e manage to figure out alot now i have another qestion can i put a varible inside a url adress i wanna use ,some how ?

heres my not working code

String url = (“http://mywebpage.xyz/reciver.php?apples="(celsiusTemp)"&oranges="(humidityTemp)"”;
HTTPClient http;
http.begin(url);
http.addHeader(“Content-Type”, “application/x-www-form-urlencoded”);
Serial.print(url);

i want (celsiusTemp) and (humidityTemp) be in one line with rest
so it will look like http://mywebpage.xyz/reciver.php?apples=50&oranges=60

Try:
String url = "mywebpage.xyz" + String(celsiusTemp) + "&oranges=" + String( humidityTemp);

Thanks ! :smiley:

String url = "mywebpage.com - This website is for sale! - mywebpage Resources and Information."+String(humidityTemp);

this works but

Serial.print(url);

gives:

mywebpage.com - This website is for sale! - mywebpage Resources and Information. 21.21&oranges= 28.10Client disconnected.

im hoping spaces wont mess up and also got other qestion ,how can i convert 22.20Celcius to 22celcius ? just change reading varibles from float to integer ?

switchet varible to diffrent and changet it to integer now it gives what it shud Thanks :slight_smile:

http://mywebpage/reciver.php?apples=27&oranges=22

but myfile.txt wont update with new data :frowning: maybe i used wrong command to open url link or my reciver.php got mistake in it

Does the file myfile.txt update when you issue this command in a web browser ?

http://mywebpage/reciver.php?apples=27&oranges=22

If not, then you have a problem with the PHP script named reciver.php (or reciever.php in the OP ).
The correct English is, incidentally, receiver.

yep it works coz i typed reciver in sketch and named file the same :stuck_out_tongue:

you have27apples, and22 oranges.

Im guessing i just need to write proper http.GET or http.POST reqest function in sketch
wich i cant figure how to and fighting with it all night lol

that Youtube.com video have commands in description

3.) Connec to website
AT+CIPSTART="TCP","esp8266.allaboutee.com",80\r\n

4.) Specify number of bytes you'll send

AT+CIPSEND=81\r\n

AT+CIPSEND=154\r\n

5.) Send GET Request

GET /receiver.php?apples=56&oranges=23 HTTP/1.1\r\nHost: esp8266.allaboutee.com\r\n\r\n

5.) send POST Request
POST /receiver.php HTTP/1.1\r\nHost: esp8266.allaboutee.com\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 20\r\n\r\napples=12&oranges=45\r\n\r\n

but hes using some diffrent language im guessing and i cant make it work in sketch

He's using AT commands to talk to an ESP8266 Wifi module over a serial link. There are other ways of doing this, for example using the Arduino Core software directly on the ESP8266.
What is your set up and what code are you currently running ?

my set up is esp8622 NodeMCU and DTH 22 AM2302 temperature sensor ,got arduino 1.8.1 sketch compilier and heres the whole code

// Including the ESP8266 WiFi library
#include <ESP8266WiFi.h>
#include “DHT.h”
#include <ArduinoHttpClient.h>
#include <ESP8266HTTPClient.h>
#include <espmissingincludes.h>
#include <httpclient.h>

// Uncomment one of the lines below for whatever DHT sensor type you’re using!
//#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321

// Replace with your network details
const char* ssid = “vnet-0D801E”;
const char* password = “59061008186”;

// Web Server on port 80
WiFiServer server(80);

// DHT Sensor
const int DHTPin = D1;
// Initialize DHT sensor.
DHT dht(DHTPin, DHTTYPE);

// Temporary variables
static char celsiusTemp[7];
static char fahrenheitTemp[7];
static char humidityTemp[7];

// only runs once on boot
void setup() {
// Initializing serial port for debugging purposes
Serial.begin(9600);
delay(10);

dht.begin();

// Connecting to WiFi network
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”);

// Starting the web server
server.begin();
Serial.println(“Web server running. Waiting for the ESP IP…”);
delay(10000);

// Printing the ESP IP address
Serial.println(WiFi.localIP());
}

// runs over and over again
void loop() {

// Listenning for new clients
WiFiClient client = server.available();

if (client) {
Serial.println(“New client”);
// bolean to locate when the http request ends
boolean blank_line = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();

if (c == ‘\n’ && blank_line) {
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
int h = dht.readHumidity();
delay(2000);
// Read temperature as Celsius (the default)
int t = dht.readTemperature();
delay(2000);
// Read temperature as Fahrenheit (isFahrenheit = true)
int f = dht.readTemperature(true);
delay(2000);

//aaa = /reciver.php ;
//bbb = HTTP/1.1 ;
//ccc = wurmonlinestore.xyz ;
//ddd = Content-Type: application/x-www-form-urlencoded ;
//eee = Content-Length: 20 ;
//fff = apples=12&oranges=45 ;

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(“Failed to read from DHT sensor!”);
strcpy(celsiusTemp,“Failed”);
strcpy(fahrenheitTemp, “Failed”);
strcpy(humidityTemp, “Failed”);

}
else{
// Computes temperature values in Celsius + Fahrenheit and Humidity
int hic = dht.computeHeatIndex(t, h, false);
dtostrf(hic, 6, 2, celsiusTemp);
int hif = dht.computeHeatIndex(f, h);
dtostrf(hif, 6, 2, fahrenheitTemp);
dtostrf(h, 6, 2, humidityTemp);

// You can delete the following Serial.print’s, it’s just for debugging purposes
Serial.print(“Humidity: “);
Serial.print(h);
Serial.print(” %\t Temperature: “);
Serial.print(t);
Serial.print(” *C “);
Serial.print(f);
Serial.print(” *F\t Heat index: “);
Serial.print(hic);
Serial.print(” *C “);
Serial.print(hif);
Serial.print(” *F”);
Serial.print(“Humidity: “);
Serial.print(h);
Serial.print(” %\t Temperature: “);
Serial.print(t);
Serial.print(” *C “);
Serial.print(f);
Serial.print(” *F\t Heat index: “);
Serial.print(hic);
Serial.print(” *C “);
Serial.print(hif);
Serial.println(” *F”);
}
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println(“Connection: close”);
client.println();
// your actual web page that displays temperature and humidity
client.println("");
client.println("");
client.println("

ESP8266 - Temperature and Humidity

Temperature in Celsius: “);
client.println(celsiusTemp);
client.println(”*C

Temperature in Fahrenheit: “);
client.println(fahrenheitTemp);
client.println(”*C

Adress strony: ");

client.println("*F

Humidity: “);
client.println(humidityTemp);
client.println(”%

");
client.println("");

break;
}
if (c == ‘\n’) {
// when starts reading a new line
blank_line = true;
}
else if (c != ‘\r’) {
// when finds a character on the current line
blank_line = false;
}
}
}
// closing the client connection
delay(1);
client.stop();
Serial.println(“Client disconnected.”);

}

}

If you are attempting to post your data on an existing PHP enabled web server then you need to create a web client on your ESP8266. The code you have supplied is to create a web server.
The web client does little more than putting the appropriate data on an existing web page and submitting it.

Question 1. You have issued the command:

http://mywebpage/reciver.php?apples=27&oranges=22

on a web browser and got a result in the file myfile.txt ? If not, fix that first.

Step 2. Look at the web client example here and adapt the URL and the GET statement to match your own example: Using Arduino IDE | Adafruit HUZZAH ESP8266 breakout | Adafruit Learning System

From your code, it is also clear that you are running the Arduino core software on the ESP8266 so you cannot use the AT command set.

Yes now it works !
Thank you so much ! :smiley: