Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <ESP8266WiFi.h>
- #define CYCLE 1800000 //Hier die Zeit in Millisekunden angeben (1800000 sind 30 minuten)
- #include <Bme280BoschWrapper.h>
- Bme280BoschWrapper bme280(true);
- const char* ssid = "Hier_dein_Wlanname"; //Wlan Name eingeben
- const char* password = "Hier_dein_Wlanpasswort"; //Wlan Passwort eingeben
- const char* host = "192.168.0.xxx"; //IP Adresse des Raspi eingeben
- unsigned long value = 0;
- unsigned int lastcall = CYCLE;
- int conn_time;
- void setup() {
- Serial.begin(115200);
- delay(10);
- while(!bme280.beginI2C(0x76)) //I2C adresse des BME280 standartmäsig 0x76
- {
- Serial.println("Cannot find sensor.");
- delay(1000);
- }
- // We start by connecting to a WiFi network
- Serial.println();
- Serial.println();
- Serial.print("Connecting to ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- conn_time++;
- if (conn_time > 20) {
- break;
- }
- }
- if (WiFi.status() == WL_CONNECTED) {
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- }
- else {
- Serial.println("");
- Serial.println("no WiFi connection");
- ESP.deepSleep(100000);
- Serial.println("gone to sleep");
- }
- }
- void loop() {
- bool ok = bme280.measure();
- while (millis() - lastcall < CYCLE) {
- delay(1);
- }
- lastcall = millis();
- ++value;
- Serial.print("connecting to ");
- Serial.println(host);
- // Use WiFiClient class to create TCP connections
- WiFiClient client;
- const int httpPort = 80;
- if (!client.connect(host, httpPort)) {
- Serial.println("connection failed");
- return;
- }
- // We now create a URI for the request
- String url = "/messung.php";
- url += "?temp=";
- url += (bme280.getTemperature()/100.0);
- url += "_*C";
- url += "&hum=";
- url += (bme280.getHumidity()/1024.0);
- url += "_%Luftfeuchtigkeit";
- url += "&druck=";
- url += (bme280.getPressure()/100.0);
- url += "_hPa";
- Serial.print("Requesting URL: ");
- Serial.println(url);
- // This will send the request to the server
- client.print(String("GET ") + url + " HTTP/1.1\r\n" +
- "Host: " + host + "\r\n" +
- "Connection: close\r\n\r\n");
- delay(1000);
- // Read all the lines of the reply from server and print them to Serial
- while (client.available()) {
- String line = client.readStringUntil('\r');
- Serial.print(line);
- }
- Serial.println();
- Serial.println("closing connection");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement