commit 33993f60b393cfd7b0177d512556487a264b1a57 Author: Julien Cabillot Date: Thu Mar 2 17:15:46 2017 +0100 import diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1ee1afc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +blinkhttp.h diff --git a/IMG_20170216_194617514_HDR.jpg b/IMG_20170216_194617514_HDR.jpg new file mode 100644 index 0000000..913f3db Binary files /dev/null and b/IMG_20170216_194617514_HDR.jpg differ diff --git a/IMG_20170216_194650374_HDR.jpg b/IMG_20170216_194650374_HDR.jpg new file mode 100644 index 0000000..c85e7c6 Binary files /dev/null and b/IMG_20170216_194650374_HDR.jpg differ diff --git a/NodeMCU V1.0.fzpz b/NodeMCU V1.0.fzpz new file mode 100644 index 0000000..188cc8a Binary files /dev/null and b/NodeMCU V1.0.fzpz differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..3ae60a9 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +Introduction +============ + +Simple blink qui toggle la led à chaque appel HTTP à / + +Matériel +======== + * 1x ESP8266 Lolin (Nodemcu v3) + * 1x Breadboard + * 1x Resistance 220Ω (jusqu'à 1kΩ) + * 1x LED + +Médias +====== + +![Fritzing BreadBoard](blinkhttp_bb.png) +![IRL](IMG_20170216_194617514_HDR.jpg) +![IRL](IMG_20170216_194650374_HDR.jpg) diff --git a/blinkhttp.example.h b/blinkhttp.example.h new file mode 100644 index 0000000..8af6329 --- /dev/null +++ b/blinkhttp.example.h @@ -0,0 +1,9 @@ +// HTTP +#define HTTP_PORT 80 + +// LED +#define LED_PIN 5 // = D1 + +// WIFI +#define wifi_ssid "XXX" +#define wifi_password "XXX" diff --git a/blinkhttp.fzz b/blinkhttp.fzz new file mode 100644 index 0000000..7e86850 Binary files /dev/null and b/blinkhttp.fzz differ diff --git a/blinkhttp.ino b/blinkhttp.ino new file mode 100644 index 0000000..9bf9fab --- /dev/null +++ b/blinkhttp.ino @@ -0,0 +1,95 @@ +#include "blinkhttp.local.h" +#include "blinkhttp.h" + +#include +#include +#include +#include + +// WIFI +WiFiClient espClient; + +// HTTP +ESP8266WebServer server(HTTP_PORT); + +void setup() +{ + Serial.begin(115200); + Serial.println("\nresetting"); + + // LED + pinMode(LED_PIN, OUTPUT); + digitalWrite(LED_PIN, 0); + + // WIFI + setupWifi(); + + // HTTP + setupHTTP(); +} + +// WIFI +void setupWifi() { + Serial.print("Connexion a "); + Serial.print(wifi_ssid); + WiFi.begin(wifi_ssid, wifi_password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + Serial.println(); + Serial.print("IP : "); + Serial.println(WiFi.localIP()); + + if (MDNS.begin("esp8266")) { + Serial.println("MDNS responder started"); + } +} + +// HTTP +void setupHTTP() +{ + server.on("/", handleRoot); + + server.on("/inline", [](){ + server.send(200, "text/plain", "this works as well"); + }); + + server.onNotFound(handleNotFound); + + server.begin(); + Serial.println("HTTP server started"); +} + +void handleRoot() +{ + digitalWrite(LED_PIN, 1); + server.send(200, "text/plain", "hello from esp8266!"); + delay(500); + digitalWrite(LED_PIN, 0); +} + +void handleNotFound() +{ + digitalWrite(LED_PIN, 1); + String message = "File Not Found\n\n"; + message += "URI: "; + message += server.uri(); + message += "\nMethod: "; + message += (server.method() == HTTP_GET)?"GET":"POST"; + message += "\nArguments: "; + message += server.args(); + message += "\n"; + for (uint8_t i=0; i