import
This commit is contained in:
commit
33993f60b3
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
blinkhttp.h
|
||||
BIN
IMG_20170216_194617514_HDR.jpg
Normal file
BIN
IMG_20170216_194617514_HDR.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 MiB |
BIN
IMG_20170216_194650374_HDR.jpg
Normal file
BIN
IMG_20170216_194650374_HDR.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 MiB |
BIN
NodeMCU V1.0.fzpz
Normal file
BIN
NodeMCU V1.0.fzpz
Normal file
Binary file not shown.
18
README.md
Normal file
18
README.md
Normal file
@ -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
|
||||
======
|
||||
|
||||

|
||||

|
||||

|
||||
9
blinkhttp.example.h
Normal file
9
blinkhttp.example.h
Normal file
@ -0,0 +1,9 @@
|
||||
// HTTP
|
||||
#define HTTP_PORT 80
|
||||
|
||||
// LED
|
||||
#define LED_PIN 5 // = D1
|
||||
|
||||
// WIFI
|
||||
#define wifi_ssid "XXX"
|
||||
#define wifi_password "XXX"
|
||||
BIN
blinkhttp.fzz
Normal file
BIN
blinkhttp.fzz
Normal file
Binary file not shown.
95
blinkhttp.ino
Normal file
95
blinkhttp.ino
Normal file
@ -0,0 +1,95 @@
|
||||
#include "blinkhttp.local.h"
|
||||
#include "blinkhttp.h"
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
|
||||
// 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<server.args(); i++){
|
||||
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
|
||||
}
|
||||
server.send(404, "text/plain", message);
|
||||
digitalWrite(LED_PIN, 0);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
server.handleClient();
|
||||
}
|
||||
BIN
blinkhttp_bb.png
Normal file
BIN
blinkhttp_bb.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 134 KiB |
Loading…
x
Reference in New Issue
Block a user