Hello, i would like to make an application to use slider and measure temperature on Nodemcu. Im using DS18B20 termometer. I send you a code, maybe there is a false. Please make an app in MIT to show me how it should look like or fix the code. Slider is working well but temperature measurment not.
#define ENB 12
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
OneWire oneWire(D4); //Podłączenie do D4
DallasTemperature sensors(&oneWire); //Przekazania informacji do biblioteki
String command; //String to store app command state.
String command_2;
int data = 0; // 400 - 1023.
double tempC = 0;
const char* ssid = "wifi_temp_slider";
ESP8266WebServer server(80);
void setup() {
sensors.begin(); //Inicjalizacja czujnikow
pinMode(ENB, OUTPUT);
Serial.begin(115200);
// Connecting WiFi
WiFi.mode(WIFI_AP);
WiFi.softAP(ssid);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
// Starting WEB-server
server.on ( "/", HTTP_handleRoot );
server.onNotFound ( HTTP_handleRoot );
server.begin();
}
void goAhead()
{
analogWrite(ENB, data);
}
void loop() {
server.handleClient();
command = server.arg("State");
//command_2 = server.arg("State2");
if (command == "0"){ data = 20; goAhead();}
else if (command == "1") { data = 0; goAhead();}
else if (command == "2") { data = 100; goAhead();}
else if (command == "3") { data = 150; goAhead();}
else if (command == "4") { data = 250; goAhead();}
else if (command == "5") { data = 370; goAhead();}
else if (command == "6") { data = 400; goAhead();}
else if (command == "7") { data = 480; goAhead();}
else if (command == "8") { data = 550; goAhead();}
else if (command == "9") { data = 700; goAhead();}
temperatura();
}
void HTTP_handleRoot(void) {
if( server.hasArg("State") ){
Serial.println(server.arg("State"));
}
server.send ( 200, "text/html", "" );
delay(1);
}
void temperatura
{
sensors.requestTemperatures(); //Pobranie temperatury czujnika
//Serial.print("Aktualna temperatura: ");
tempC = sensors.getTempCByIndex(0);
Serial.println(tempC);
}