Last active
January 4, 2019 19:38
-
-
Save tosiara/f86debee9582812601daf8b3f44d29d8 to your computer and use it in GitHub Desktop.
NodeMCU DS18B20 Hotspot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <DallasTemperature.h> | |
#include <OneWire.h> | |
#include <WiFiClient.h> | |
#include <ESP8266WebServer.h> | |
#define PIN 5 // nodemcu D1 | |
OneWire oneWire(PIN); | |
DallasTemperature sensors(&oneWire); | |
double celsius; | |
const char* ssid = "mynetwork"; | |
const char* password = "myappassword"; | |
int refresh = 3; | |
String html = "<meta http-equiv=\"refresh\" content=\"" + String(refresh) + "\" />"; | |
ESP8266WebServer server(80); | |
void handleRoot() | |
{ | |
server.send(200, "text/html", html + "<h1>" + String(celsius) + "</h1>"); | |
} | |
void setup() | |
{ | |
Serial.begin(115200); | |
delay(10); | |
Serial.print("Access point..."); | |
WiFi.softAP(ssid, password); | |
IPAddress myIP = WiFi.softAPIP(); | |
Serial.print("IP address: "); | |
Serial.println(myIP); | |
server.on("/", handleRoot); | |
server.begin(); | |
Serial.println("HTTP server started"); | |
sensors.begin(); | |
} | |
void loop() | |
{ | |
sensors.requestTemperatures(); | |
celsius = sensors.getTempCByIndex(0); | |
Serial.print(" Temperature = "); | |
Serial.print(celsius); | |
Serial.println(" Celsius, "); | |
server.handleClient(); | |
delay(refresh * 1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment