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

Moderator: igrr

User avatar
By roy
#85346 Hi all i am new to esp8266 and need help i am trying to send data from a DS18B20 and send it to .php to write temp.html file and i can't figure what m i doing wrong

my scatch is

// Libraries



#include <OneWire.h>

#include <DallasTemperature.h>



#include <ESP8266WiFi.h>

#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

// Pin

#define ONE_WIRE_BUS 5 // DS18B20 pin

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature DS18B20(&oneWire);





#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;



void setup() {



Serial.begin(115200); // Start Serial

USE_SERIAL.begin(115200);

// USE_SERIAL.setDebugOutput(true);



USE_SERIAL.println();

USE_SERIAL.println();

USE_SERIAL.println();



for(uint8_t t = 4; t > 0; t--) {

USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);

USE_SERIAL.flush();

delay(1000);

}



WiFiMulti.addAP("*****", "*******");



}

void loop()

{



DS18B20.requestTemperatures();

String temp;

temp = String(DS18B20.getTempCByIndex(0));

Serial.print("Temperature: ");

Serial.println(temp);







HTTPClient http;



USE_SERIAL.print("[HTTP] begin...\n");

// configure traged server and url

http.begin("http://mywebserver/TEMP.php" ); //HTTP

int httpCode = http.POST(+"temp");

USE_SERIAL.print("[HTTP] POST...\n");

// start connection and send HTTP header





// httpCode will be negative on error

if(httpCode > 0) {

// HTTP header has been send and Server response header has been handled

USE_SERIAL.printf("[HTTP] POST... code: %d\n", httpCode);



// file found at server

if(httpCode == HTTP_CODE_OK) {

String payload = http.getString();

USE_SERIAL.println(payload);

}

} else {

USE_SERIAL.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());

}



http.end();

delay(1000);



}

my .php file

<?php

$temp = $_GET['temp'];

$temp = $_POST["temp"];

$file = 'temp.html';

?>

THX ROY