Il y a longtemps que j’y pensais…Il est enfin la…
Grace à ma dernière acquisition et à ThingIverse
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
#include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> const int interruptPin = 0; //GPIO 0=D3 (Flash Button) const int LED = 2; //On board blue LED volatile byte compteur = 0; volatile boolean change = true; const char* ssid = "ZEOP-d751a3"; const char* password = "xxxxxx"; WiFiServer server(80); unsigned long debut; boolean ledOnOff = true; int i = 0; void setup() { Serial.begin(115200); //digitalWrite(LED, LOW); //LED on Serial.print("Connecting to "); Serial.println(ssid); WiFi.hostname("PLUVIOMETRE"); WiFi.begin(ssid, password); while ((WiFi.status() != WL_CONNECTED) && (i++ < 100)) { if (ledOnOff) digitalWrite(LED, LOW); //LED on else digitalWrite(LED, HIGH); ledOnOff = !ledOnOff; delay(500); Serial.print("." + String(i)); } Serial.println(""); Serial.println("WiFi connected"); // Start the server server.begin(); Serial.println("Server started"); // Print the IP address Serial.print("Use this URL to connect: "); Serial.print("http://"); Serial.print(WiFi.localIP()); Serial.println("/"); pinMode(LED, OUTPUT); pinMode(interruptPin, INPUT_PULLUP); //digitalWrite(LED, HIGH); attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING); debut = millis(); Serial.println(debut); digitalWrite(LED, HIGH); //LED off } void loop() { if (change) { digitalWrite(LED, LOW); //LED on Serial.println(compteur); change = false; delay(100);//evite les rebonds? attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING); } if (i++ > 100) { digitalWrite(LED, LOW); //LED on delay(10); digitalWrite(LED, HIGH); i=0; } delay(10); gereClientWifi(); if ((millis() - debut) > (1000 * 60)) { Serial.println("Faut sauvegarder " + String(compteur)); SendToPluviometre(); compteur = 0; debut = millis(); } } void SendToPluviometre() { //*************************************************************** if (compteur > 0) { String c = String(compteur); String data = "?ticks=" + c; HTTPClient http; Serial.print("[HTTP] begin...\n"); http.begin("http://www.daniel974.fr/pluviometre/xxxxxx.php" + data); //HTTP Serial.print("[HTTP] GET...\n"); Serial.print("http://www.daniel974.fr/pluviometre/xxxxxx.php"); Serial.print(data); Serial.print("\n"); // start connection and send HTTP header int httpCode = http.GET(); // httpCode will be negative on error if (httpCode > 0) { // HTTP header has been send and Server response header has been handled Serial.printf("[HTTP] GET... code: %d\n", httpCode); // file found at server if (httpCode == HTTP_CODE_OK) { String payload = http.getString(); Serial.println(payload); } } else { Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } http.end(); } } //This program get executed when interrupt is occures i.e.change of input state void handleInterrupt() { detachInterrupt(digitalPinToInterrupt(interruptPin)); compteur++; change = true; } void gereClientWifi() { // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; } // Wait until the client sends some data Serial.println("new client"); while (!client.available()) { delay(1); } // Read the first line of the request String request = client.readStringUntil('\r'); Serial.println(request); client.flush(); // Return the response client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(""); // do not forget this one client.println("<!DOCTYPE HTML>"); client.println("<html>"); client.println("<head><meta http-equiv=\"refresh\" content=\"10\"></head>"); client.println("<center><h1>Pluviometre<hr>Nombre de basculements: "); client.println(compteur); client.println("</h1><br>"); client.println("</html>"); delay(1); Serial.println("Client disonnected"); Serial.println(""); } |
qui donne cela:
(un tick c’est environ 1 mm de pluie, mais je vais changer(augmenter) l’entonnoir…)