Browse Source

import

master
Julien Cabillot 3 years ago
committed by JC
commit
33993f60b3
10 changed files with 123 additions and 0 deletions
  1. 1
      .gitignore
  2. BIN
      IMG_20170216_194617514_HDR.jpg
  3. BIN
      IMG_20170216_194650374_HDR.jpg
  4. BIN
      NodeMCU V1.0.fzpz
  5. 18
      README.md
  6. 9
      blinkhttp.example.h
  7. BIN
      blinkhttp.fzz
  8. 95
      blinkhttp.ino
  9. BIN
      blinkhttp_bb.png
  10. BIN
      logo.jpg

1
.gitignore

@ -0,0 +1 @@
blinkhttp.h

BIN
IMG_20170216_194617514_HDR.jpg

Before After
Width: 3006  |  Height: 5344  |  Size: 2.9 MiB

BIN
IMG_20170216_194650374_HDR.jpg

Before After
Width: 5344  |  Height: 3006  |  Size: 2.8 MiB

BIN
NodeMCU V1.0.fzpz

18
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)

9
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"

BIN
blinkhttp.fzz

95
blinkhttp.ino

@ -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

Before After
Width: 903  |  Height: 756  |  Size: 134 KiB

BIN
logo.jpg

Before After
Width: 800  |  Height: 593  |  Size: 116 KiB
Loading…
Cancel
Save