Skip to content

Instantly share code, notes, and snippets.

@lucianenache
Last active March 20, 2019 21:34
Show Gist options
  • Save lucianenache/0c026fa81198fea323c664a93463db31 to your computer and use it in GitHub Desktop.
Save lucianenache/0c026fa81198fea323c664a93463db31 to your computer and use it in GitHub Desktop.
temperature reader from lm35 (look into dht11/12)
#include "WiFi.h"
#include "ESPAsyncWebServer.h"
int analogPin = A0;
const char* ssid = "SOME_SSID";
const char* passwd = "SOME_PASSWD";
AsyncWebServer server(80);
float readTemp() {
vout = analogRead(analogPin);
return (vout * 500) / 1023;
}
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, passwd);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Initializing wifi ...);
}
Serial.println("Connected at %s:, WiFi.localIP());
server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *req) {
float temp = readTemp();
req->send(200, "text/plain", String(temperature));
});
server.begin();
}
void loop() {
// TODO post temp reading every 5 minutes to the node (hub)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment