Webserver does not show bme280 sensor data in esp32.

This is a special forum devoted to educators using Adafruit and Arduino products for teaching.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
vickennerly
 
Posts: 1
Joined: Sat Nov 23, 2019 10:34 am

Webserver does not show bme280 sensor data in esp32.

Post by vickennerly »

Hi,
My code Webserver does not show bme280 sensor data in esp32, of my weather station.
Here is the code that I'm using:

Code: Select all


#include "ETH.h"
#include <WiFi.h>
#include <WiFiAP.h>
#include <WiFiGeneric.h>
#include <WiFiMulti.h>
#include <WiFiScan.h>
#include <WiFiSTA.h>
#include <WiFiType.h>
#include <ssl_client.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <WiFiClientSecure.h>
#include <Wire.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#include <SPI.h>
#include "WiFi.h"

// BME280

#define SEALEVELPRESSURE_HPA (1013.25)

#define BME_SCK 18
#define BME_MISO 19
#define BME_MOSI 23
#define BME_CS 2

Adafruit_BME280 bme (BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

float Temperature;
float Humidity;
float Pressure;
float Altitude;

// Webserver

const char* ssid = "Name";
const char* password = "password";
WiFiServer server(80);

//Gy521

#include<Wire.h>

const int MPU_addr=0x68; // I2C address of the MPU-6050

int AcX;
int AcY;
int AcZ;
int Tmp;
int GyX; 
int GyY;
int GyZ;

//Funções 

void bmereading() {
  Temperature = bme.readTemperature();
  Humidity = bme.readHumidity();
  Pressure = bme.readPressure() / 100.0F;
  Altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);

}
                          
void Connect_WiFi(){
WiFi.begin(ssid, password);
while(WiFi.status() != WL_CONNECTED)
{
delay(100);
}
}

void Gy(){
  Wire.beginTransmission(MPU_addr);

  AcX = Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
  Tmp = Wire.write(0x41);
  AcY = Wire.write(0x3D);
  AcZ = Wire.write(0x3F);
  GyX = Wire.write(0x43);
  GyY = Wire.write(0x45);
  GyZ = Wire.write(0x47);
  
  Wire.endTransmission(false);

  Wire.requestFrom(MPU_addr,7*2,true); // request a total of 14 registers


  Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)

  AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)

  AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)

  AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)

  GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)

  GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)

  GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
}
  


void setup()
{
   Wire.begin();

  Wire.beginTransmission(MPU_addr);

  Wire.write(0x6B); // PWR_MGMT_1 register

  Wire.write(0); // set to zero (wakes up the MPU-6050)

  Wire.endTransmission(true);
  
Serial.begin(115200);

bool status;
  status = bme.begin(0x76);
  delay(10000);

Serial.print("Setting soft access point mode");
WiFi.softAP(ssid, password);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);
server.begin();

}


void loop()
{
WiFiClient client=server.available();


// Display the HTML web page

void bmereading();

void Gy();

client.print("<html>");

client.print ("<head>");
client.print ("<title> Bar </title>");
client.print ("</head>");


client.print("<body>");
client.print ("<h1> My Kind of Bar </h1>");
      
      client.println("<p> Temperature: </p>");
      client.println(bme.readTemperature());
      client.println(" *C \n");

      client.print("<p> Temperature in *F: </p>"); 
      client.print(Tmp); //equation for temperature in degrees C from datasheet
      client.println(" *F \n");

      client.println("<p> Humidity: </p>");
      client.println(bme.readHumidity());
      client.println("% \n");

      client.println("<p> Pressure: </p>");
      client.println(bme.readPressure());
      client.println("hPa \n");

      client.println("<p> Approx Altitude: </p>");
      client.println (bme.readAltitude(SEALEVELPRESSURE_HPA));
      client.println("m \n");

      client.println("<p>Acelerometer in X: </p>"); 
      client.print(AcX );

      client.println("<p>Acelerometer in Y: </p>"); 
      client.print(AcY);

      client.println("<p>Acelerometer in Z: </p>"); 
      client.print(AcZ);

      client.println("<p>Gyroscope in X: </p>"); 
      client.print(GyX);

      client.println("<p>Gyroscope in Y: </p>"); 
      client.print(GyY);

      client.println("<p> Gyroscope in Z: </p> "); 
      client.println(GyZ);

client.print ("</body>");
client.print ("</html>");
} 
HELP ME
Last edited by Franklin97355 on Sat Nov 23, 2019 2:09 pm, edited 1 time in total.
Reason: In the future please use code tags to enclose your code.

Locked
Please be positive and constructive with your questions and comments.

Return to “For Educators”