SHARE
TWEET

Untitled

a guest Jan 19th, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. #include "Seeed_BME280.h"
  4. #include <Wire.h>
  5.  
  6. int buttonState = 0;
  7. int windRichting = 0;
  8. const int NOORD = 1;
  9. const int NOORDOOST = 2;
  10. const int OOST = 3;
  11. const int ZUIDOOST = 4;
  12. const int ZUID = 5;
  13. const int ZUIDWEST = 6;
  14. const int WEST = 7;
  15. const int NOORDWEST = 8;
  16.  
  17. const int hallSensorPin = 2;
  18. const unsigned long sampleTime = 1000;
  19. const int maxRPM = 1260;
  20. int rpmMaximum = 0;
  21. BME280 bme280;
  22.  
  23. byte mac[] = {
  24.   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
  25. };
  26. IPAddress ip(192, 168, 0, 177);
  27. IPAddress myDns(192, 168, 0, 1);
  28.  
  29. EthernetClient client;
  30.  
  31. void setup() {
  32.   if (Ethernet.begin(mac) == 0) {
  33.       Serial.println("Failed to configure Ethernet using DHCP");
  34.       // Check for Ethernet hardware present
  35.       if (Ethernet.hardwareStatus() == EthernetNoHardware) {
  36.         Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
  37.         while (true) {
  38.           delay(1); // do nothing, no point running without Ethernet hardware
  39.         }
  40.       }
  41.       if (Ethernet.linkStatus() == LinkOFF) {
  42.         Serial.println("Ethernet cable is not connected.");
  43.       }
  44.       // try to congifure using IP address instead of DHCP:
  45.       Ethernet.begin(mac, ip, myDns);
  46.     } else {
  47.       Serial.print("  DHCP assigned IP ");
  48.       Serial.println(Ethernet.localIP());
  49.     }
  50.   Serial.begin(9600);
  51.  
  52.   {
  53.     Serial.begin(9600);
  54.       if (!bme280.init()) {
  55.       Serial.println(F("Device error!"));
  56.       }
  57.   }
  58.  
  59.   pinMode(hallSensorPin, INPUT);
  60.   Serial.begin(9600);
  61.  
  62.   pinMode(NOORD, INPUT);
  63.   pinMode(NOORDOOST, INPUT);
  64.   pinMode(OOST, INPUT);
  65.   pinMode(ZUIDOOST, INPUT);
  66.   pinMode(ZUID, INPUT);
  67.   pinMode(ZUIDWEST, INPUT);
  68.   pinMode(WEST, INPUT);
  69.   pinMode(NOORDWEST, INPUT);
  70.  
  71.   delay(1000);
  72. }
  73.  
  74. int getWindspeed() {
  75.   delay(100);
  76.   int rpm = getRPM();
  77.   if (rpm > rpmMaximum) rpmMaximum = rpm;
  78.  
  79.   int kmh = 10*rpm*0.001885;
  80.   return kmh;
  81. }
  82.  
  83. int getRPM()
  84. {
  85.   int count = 0;
  86.   boolean countFlag = LOW;
  87.   unsigned long currentTime = 0;
  88.   unsigned long startTime = millis();
  89.   while (currentTime <= sampleTime)
  90.   {
  91.     if (digitalRead(hallSensorPin) == HIGH)
  92.     {
  93.       countFlag = HIGH;
  94.     }
  95.     if (digitalRead(hallSensorPin) == LOW && countFlag == HIGH)
  96.     {
  97.       count++;
  98.       countFlag=LOW;
  99.     }
  100.     currentTime = millis() - startTime;
  101.   }
  102.   int countRpm = int(60000/float(sampleTime))*count;
  103.   return countRpm;
  104. }
  105.  
  106. int getWindDirection() {
  107.   if (digitalRead(NOORD) == HIGH) {
  108.     int windRichting = 1;
  109.   } else if (digitalRead(NOORDOOST) == HIGH) {
  110.     int windRichting = 2;
  111.   } else if (digitalRead(OOST) == HIGH) {
  112.     int windRichting = 3;
  113.   } else if (digitalRead(ZUIDOOST) == HIGH) {
  114.     int windRichting = 4;
  115.   } else if (digitalRead(ZUID) == HIGH) {
  116.     int windRichting = 5;
  117.   } else if (digitalRead(ZUIDWEST) == HIGH) {
  118.     int windRichting = 6;
  119.   } else if (digitalRead(WEST) == HIGH) {
  120.     int windRichting = 7;
  121.   } else if (digitalRead(NOORDWEST) == HIGH) {
  122.     int windRichting = 8;
  123.   }
  124.   return windRichting;
  125. }
  126.  
  127. void loop() {
  128.   if (client.connect(server, 80)) {
  129.       client.print(F("GET /write_data.php?"));
  130.       client.print(F("temp="));
  131.       client.print(bme280.getTemperature());
  132.       float pressure;
  133.       client.print(F("&pres="));
  134.       client.print(pressure = bme280.getPressure());
  135.       client.print(bme280.calcAltitude(pressure));
  136.       client.print(F("&humi="));
  137.       client.print(bme280.getHumidity());
  138.       client.print(F("&wnsp="));
  139.       client.print(getWindspeed());
  140.       client.print(F("&wndi="));
  141.       client.print(getWindDirection());
  142.       client.println(F(" HTTP/1.1"));
  143.       client.println(F("Host: 213.134.252.166")); //Mijn ip niet ddos'en aub
  144.       client.println(F("Connection: close"));
  145.       client.println(); // Niet weghalen
  146.       client.println(); // Niet weghalen
  147.       client.stop();
  148.     } else {
  149.       Serial.println(F("Geen verbinding\n"));
  150.     }
  151.  
  152.     delay(10000);
  153. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top