Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ESP8266WiFi.h>
  2. #include <ESP8266WiFiGeneric.h>
  3. #include <Wire.h>
  4. #include <Seeed_BME280.h>
  5.  
  6. const char* ssid = "***";
  7. const char* password = "***";
  8. char bigstring[46];
  9. WiFiClient espClient;
  10. BME280 bme280;
  11. String Token  = "***";
  12. String User   = "***";
  13. int length;
  14.  
  15. void setup() {
  16.   Serial.begin(115200);
  17.   Serial.setTimeout(2000);
  18.   startwifi();
  19.   startbme();
  20. }
  21.  
  22. byte pushover(char *pushovermessage, char *priority) {
  23.    String Msg = pushovermessage;
  24.    String prio = priority;
  25.   length = 91 + prio.length() + Msg.length();
  26.     if (espClient.connect("api.pushover.net", 80)) {
  27.       Serial.println("Sending message…");
  28.       espClient.println("POST /1/messages.json HTTP/1.1");
  29.       espClient.println("Host: api.pushover.net");
  30.       espClient.println("Connection: close\r\nContent-Type: application/x-www-form-urlencoded");
  31.       espClient.print("Content-Length: ");
  32.       espClient.print(length);
  33.       espClient.println("\r\n");
  34.       espClient.print("token="+Token+"&user="+User+"&priority="+priority+"&message="+Msg);
  35.       /*
  36.       while(espClient.connected()) {
  37.         while(espClient.available()) {
  38.           char ch = espClient.read();
  39.           Serial.write(ch);
  40.         }
  41.       }
  42.       */
  43.       espClient.stop();
  44.       Serial.println("Done");
  45.       Serial.println("");
  46.       delay(100);
  47.     }
  48. }
  49.  
  50. void startwifi() {
  51.   Serial.println();
  52.   Serial.print("Connecting to ");
  53.   Serial.println(ssid);
  54.   WiFi.begin(ssid, password);
  55.   while (WiFi.status() != WL_CONNECTED) {
  56.     delay(500);
  57.     Serial.print(".");
  58.   }
  59.   Serial.println("");
  60.   Serial.println("WiFi connected");
  61.   Serial.println("IP address: ");
  62.   Serial.println(WiFi.localIP());
  63. }
  64.  
  65. void startbme() {
  66.   Wire.pins(0,2);
  67.   Wire.begin();
  68.    
  69.   if(!bme280.init()){
  70.     pushover("Kein+BME280-Sensor+gefunden!","1");
  71.     Serial.println("Could not find a valid BME280 sensor, check wiring!");
  72.     while (1);
  73.   }  
  74. }
  75.  
  76. char* setmychar(char* string1, char* string2, char* string3, char* string4, char* string5) {
  77.   bigstring[0] = 0;
  78.   strcat(bigstring, string1);
  79.   strcat(bigstring, string2);
  80.   strcat(bigstring, string3);  
  81.   strcat(bigstring, string4);  
  82.   strcat(bigstring, string5);  
  83.   return bigstring;
  84. }
  85.  
  86. void loop() {
  87.  
  88.   delay(1000);
  89.  
  90.   char cbuffer1[6];
  91.   char cbuffer2[3];
  92.  
  93.   dtostrf(bme280.getTemperature(), 5, 2, cbuffer1);
  94.   cbuffer1[5] = 0;
  95.  
  96.   dtostrf(bme280.getHumidity(), 2, 0, cbuffer2);
  97.   cbuffer2[2] = 0;
  98.  
  99.   pushover(setmychar("Temperatur%3A+", cbuffer1, "°C+++Luftfeuchtigkeit%3A+", cbuffer2, "%25"),"0");
  100.   delay(1800000);
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement