Skip to content

Commit

Permalink
HTTPD: Live measurement
Browse files Browse the repository at this point in the history
When accessing the device via web a new set of measurements will be retrieved from the sensor
  • Loading branch information
adlerweb committed Sep 2, 2018
1 parent 2dfe4d4 commit 7a37784
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ ESP8266WebServer server(80);
#define MQTT_PRJ_HARDWARE "esp8266tls-bme280"
#define MQTT_PRJ_VERSION "0.0.1"

unsigned long lastTime;
float temperature;
float pressure;
float humidity;

#ifdef USE_MQTT
class PubSubClientWrapper : public PubSubClient{
private:
Expand Down Expand Up @@ -234,10 +229,9 @@ void sendStatsInterval(void) {
client.publish(((String)mqtt_root + CONFIG_MQTT_TOPIC_STATUS_SIGNAL), rssiToPercentage(WiFi.RSSI()));
#endif

temperature = bme.readTemperature();
humidity = bme.readHumidity();
pressure = bme.readPressure() / 100.0F;
lastTime = millis();
float temperature = bme.readTemperature();
float humidity = bme.readHumidity();
float pressure = bme.readPressure() / 100.0F;

Serial.print(F("T: "));
Serial.print((String)temperature);
Expand Down Expand Up @@ -380,15 +374,17 @@ void setup_wifi() {
#endif

void handleRoot() {
float temperature = bme.readTemperature();
float humidity = bme.readHumidity();
float pressure = bme.readPressure() / 100.0F;

String out = "Temperatur: ";
out += temperature;
out += "*C\nHumidity: ";
out += humidity;
out += "%\nPressure: ";
out += pressure;
out += "hPa\nAge: ";
out += ((millis() - lastTime) / 1000);
out += " Seconds";
out += "hPa";
server.send(200, "text/plain", out);
}

Expand Down

0 comments on commit 7a37784

Please sign in to comment.