Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. // Load Wi-Fi library
  2. #include <ESP8266WiFi.h>
  3. #include <Wire.h>
  4. #include <Adafruit_BME280.h>
  5. #include <Adafruit_Sensor.h>
  6.  
  7. //uncomment the following lines if you're using SPI
  8. /*#include <SPI.h>
  9. #define BME_SCK 14
  10. #define BME_MISO 12
  11. #define BME_MOSI 13
  12. #define BME_CS 15*/
  13.  
  14. #define SEALEVELPRESSURE_HPA (1022.4)
  15.  
  16. Adafruit_BME280 bme; // I2C
  17. //Adafruit_BME280 bme(BME_CS); // hardware SPI
  18. //Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
  19.  
  20. // Replace with your network credentials
  21. const char* ssid = "xxxxxxxxxxxxxx";
  22. const char* password = "xxxxxxxxxxxxxx";
  23.  
  24. // Set web server port number to 80
  25. WiFiServer server(80);
  26.  
  27.  
  28.  
  29. void setup() {
  30. Serial.begin(115200);
  31. bool status;
  32.  
  33. // default settings
  34. // (you can also pass in a Wire library object like &Wire2)
  35. //status = bme.begin();
  36. if (!bme.begin(0x76)) {
  37. Serial.println("Could not find a valid BME280 sensor, check wiring!");
  38. while (1);
  39. }
  40.  
  41. // Connect to Wi-Fi network with SSID and password
  42. Serial.print("Connecting to ");
  43. Serial.println(ssid);
  44. WiFi.begin(ssid, password);
  45. while (WiFi.status() != WL_CONNECTED) {
  46. delay(500);
  47. Serial.print(".");
  48. }
  49. // Print local IP address and start web server
  50. Serial.println("");
  51. Serial.println("WiFi connected.");
  52. Serial.println("IP address: ");
  53. Serial.println(WiFi.localIP());
  54. server.begin();
  55. }
  56.  
  57. void loop(){
  58. WiFiClient client = server.available(); // Listen for incoming clients
  59.  
  60.  
  61. // Web Page Heading
  62.  
  63. client.println("Temperatur 1");
  64. client.println("Messung");
  65. client.print("Temperatur C. ");
  66. client.print(bme.readTemperature());
  67. client.println(" *C");
  68. client.print("Temperatur F. ");
  69. client.print(1.8 * bme.readTemperature() + 32);
  70. client.println(" *F");
  71. client.print("Luftdruck ");
  72. client.print(bme.readPressure() / 100.0F);
  73. client.println(" hPa");
  74. client.print("Hoehe ca. ");
  75. client.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  76. client.println(" m");
  77. client.print("Luftfeuchte ");
  78. client.print(bme.readHumidity());
  79. client.println(" %");
  80.  
  81.  
  82.  
  83. // The HTTP response ends with another blank line
  84. client.println();
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement