Gitlab will be downgraded to CE in a couple of weeks due to the fact that Gitlab does not offer free Starter licenses to non-profits anymore. In the meantime, don't use any of the EE features. We apologize for the inconvenience.

Commit bc20d689 authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca

File server wemosD1 added

parent 4dc3ced9
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
const char* ssid = "Thomas";
const char* password = "*****************";
ESP8266WebServer server(12345);
const int led = LED_BUILTIN;
void handleRoot() {
server.send(200, "text/plain", "hello from esp8266!");
}
void handleNotFound(){
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);
}
void setup(void){
pinMode(led, OUTPUT);
pinMode(0, OUTPUT);
digitalWrite(led, LOW);
digitalWrite(0, LOW);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("iotApriPortone")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/on", [](){
server.send(200, "text/plain", "attesa di 2000ms");
digitalWrite(led, HIGH);
digitalWrite(0, HIGH);
delay(2000);
digitalWrite(led, LOW);
digitalWrite(0, LOW);
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
unsigned long previousMillis = 0;
const long interval = 1000;
int ledState = LOW;
void loop(void){
server.handleClient();
if (WiFi.status() != WL_CONNECTED) {
Serial.println("NO CONNECTION");
ESP.restart();
}
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (ledState == LOW)
ledState = HIGH; // Note that this switches the LED *off*
else
ledState = LOW; // Note that this switches the LED *on*
digitalWrite(LED_BUILTIN, ledState);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment