Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <ESP8266WiFiGeneric.h>
- #include <Wire.h>
- #include <Seeed_BME280.h>
- const char* ssid = "***";
- const char* password = "***";
- char bigstring[46];
- WiFiClient espClient;
- BME280 bme280;
- String Token = "***";
- String User = "***";
- int length;
- void setup() {
- Serial.begin(115200);
- Serial.setTimeout(2000);
- startwifi();
- startbme();
- }
- byte pushover(char *pushovermessage, char *priority) {
- String Msg = pushovermessage;
- String prio = priority;
- length = 91 + prio.length() + Msg.length();
- if (espClient.connect("api.pushover.net", 80)) {
- Serial.println("Sending message…");
- espClient.println("POST /1/messages.json HTTP/1.1");
- espClient.println("Host: api.pushover.net");
- espClient.println("Connection: close\r\nContent-Type: application/x-www-form-urlencoded");
- espClient.print("Content-Length: ");
- espClient.print(length);
- espClient.println("\r\n");
- espClient.print("token="+Token+"&user="+User+"&priority="+priority+"&message="+Msg);
- /*
- while(espClient.connected()) {
- while(espClient.available()) {
- char ch = espClient.read();
- Serial.write(ch);
- }
- }
- */
- espClient.stop();
- Serial.println("Done");
- Serial.println("");
- delay(100);
- }
- }
- void startwifi() {
- Serial.println();
- Serial.print("Connecting to ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- }
- void startbme() {
- Wire.pins(0,2);
- Wire.begin();
- if(!bme280.init()){
- pushover("Kein+BME280-Sensor+gefunden!","1");
- Serial.println("Could not find a valid BME280 sensor, check wiring!");
- while (1);
- }
- }
- char* setmychar(char* string1, char* string2, char* string3, char* string4, char* string5) {
- bigstring[0] = 0;
- strcat(bigstring, string1);
- strcat(bigstring, string2);
- strcat(bigstring, string3);
- strcat(bigstring, string4);
- strcat(bigstring, string5);
- return bigstring;
- }
- void loop() {
- delay(1000);
- char cbuffer1[6];
- char cbuffer2[3];
- dtostrf(bme280.getTemperature(), 5, 2, cbuffer1);
- cbuffer1[5] = 0;
- dtostrf(bme280.getHumidity(), 2, 0, cbuffer2);
- cbuffer2[2] = 0;
- pushover(setmychar("Temperatur%3A+", cbuffer1, "°C+++Luftfeuchtigkeit%3A+", cbuffer2, "%25"),"0");
- delay(1800000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement