BMP280 to HUZZAH ESP8266 connection - data not refreshing

Hi,

I have contracted a wireless sensor set-up using the ESP8266 as an access point. I am able to read data and get them on a web page at the defined IP address but the values do not seem to update as I change the environment (heat or height) for the sensor. They remain stuck at the initial value. I am including the code below. I would appreciate any help.

ANKAR

/* Example ESP8266 project for WiFi Access Point to read and dispaly sensor data.
 * This code is modified from 42 BOTS to read temperature, pressure and altimeter data.
 */

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

#define PA_to_InHg 2100

Adafruit_BMP280 bmp; // I2C

#define RED_LED_ESP8266 0

IPAddress  apIP(192,168,4,100); //Define static IP Address: local & gateway
                                //Default IP in AP mode is 192.168.4.1

//Define WiFi Access Point settings
const char *ssid = "myESP8266";
const char *password = "pwESP8266";

//Use web server port 80
ESP8266WebServer  server(80);

bool red_led_state = false;
float temp;
float pres_act;
float altitude;

void handleRoot() {
  //

  char html[1000];

  temp = bmp.readTemperature();
  pres_act = bmp.readPressure()/PA_to_InHg;
  altitude = bmp.readPressure()/PA_to_InHg/30.12*25;

  // Build an HTML page to display on the web-server root address
  snprintf ( html, 1000,
  "<html>\
    <head>\
    <meta http-equiv='refresh' content='8'/>\
      <title>ESP8266 WiFi Network</title>\
      <style>\
        body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; font-size: 1.5em; Color: #000000; }\
        h1 { Color: #AA0000; }\
      </style>\
    </head>\
    <body>\
      <h1>ESP8266 Wi-Fi Access Point and Sensor Application!</h1>\
        <p>Temperature  [C]: %3.1f%</p>\
        <p>Pressure [In-Hg]: %3.2f%</p>\
        <p>Altitude     [m]: %3.2f%</p>\
        <p>This page refreshes every 10 seconds. Click <a href=\"javascript:window.location.reload();\">here</a> to refresh the page now.</p>\
    </body>\
  </html>", temp, pres_act, altitude);
  
  server.send ( 200, "text/html", html );

  //
  digitalWrite(RED_LED_ESP8266, LOW);
  delay(1000);
  digitalWrite(RED_LED_ESP8266, HIGH);
  delay(1000);
}

void handleNotFound() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)

  //Build and send error message
  String message = "File not found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += ( server.method() == HTTP_GET ) ? "GET" : "POST";
  message += "\nArguments: ";
  message += "\n";

  for ( uint8_t i = 0; i < server.args(); i++ ) {
    message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n";
  }

  server.send ( 404, "text/plain", message );  //Send failed message to browser
  //
  
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
}

void setup() {
  // put your setup code here, to run once:

  //RED LED used as OUTPUT.
  pinMode(RED_LED_ESP8266, OUTPUT);

  //Drive Bliknk RED LED Once on Start Up.
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);

  //Connect to serial port and display message for sensor & wifi.
  Serial.begin(115200);
  Serial.println();

  //Locate Sensor
  if (bmp.begin()) {  
    Serial.println(F("Found a valid BMP280 sensor!"));
  }
  else {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);
  }

  //Set up custom IP Address
  Serial.println("Configuring Access Point ...");
  WiFi.mode(WIFI_AP_STA);
  WiFi.softAPConfig(apIP, apIP, IPAddress(255,255,255,0)); //Subnet 0xFF.0xFF.0xFF.0x00
  WiFi.softAP(ssid); //Make access point open to all, use WiFi.softAP(ssid, password) for password login
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP Address: ");
  Serial.println(myIP);
  server.on( "/", handleRoot );
  server.onNotFound( handleNotFound );
  server.begin();
  Serial.println("HTTP server started!");

}

void loop() {
  // put your main code here, to run repeatedly:

  //Handle server request
  server.handleClient();

  //Blink RED LED
  //digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  //delay(100);                       // wait for a second
  //digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  //delay(100);
}

I don’t know if this is will fix your sketch, but it is a problem.

<p>Temperature  [C]: %3.1f%</p>\
        <p>Pressure [In-Hg]: %3.2f%</p>\
        <p>Altitude     [m]: %3.2f%</p>\

Support for the floats in snprintf is disabled in the Arduino IDE. You can use dtostrf to convert the floats to strings (and format the strings) then use the %s format specifier in place of %f.