ESP-01 en Image

ESP-01 en Image

https://youtu.be/dKFcEDy2q5M


(!) Le fabriquant a créé plusieurs versions hard sans en changer la référence…

Du coup il est possible que sur certains modèles, il Ne soit PAS nécessaire de croiser la liaison série. (Oui vous avez bien lu…)

Il est également possible que le baudrate soit par défaut de 115200 au lieu de 9600.


Schémas et code | http://les-electroniciens.com/videos/arduino-ep16-installation-du-module-wifi-esp8266

Fichier attaché: server.rar

Datasheet | https://nurdspace.nl/images/e/e0/ESP8266_Specifications_English.pdf

Commandes AT | https://nurdspace.nl/ESP8266#AT_Commands

Arduino Web Server | http://allaboutee.com/2014/12/30/esp8266-and-arduino-webserver/

ESP8266 Web Server | https://www.youtube.com/watch?v=VvIoBFLj2Xo

Station météo | http://zeflo.com/2014/esp8266-weather-display/

Mettre à jour le firmware | https://www.youtube.com/watch?v=9QZkCQSHnko


#include <SoftwareSerial.h>


SoftwareSerial ESP8266(10, 11);


/* String NomduReseauWifi = "Entrez le nom de votre Box ou point d'accès Wifi"; Garder les guillemets */

/* String MotDePasse      = "Entrez le nom du mot de passe de votre Box ou point d'accès Wifi";  Garder les guillemets */

String NomduReseauWifi = "MaBox-1A2B3C";

String MotDePasse      = "FoPaRever";


/****************************************************************/

/*                             INIT                             */

/****************************************************************/

void setup()

{

  Serial.begin(9600)

  ESP8266.begin(115200);  

  initESP8266();

}

/****************************************************************/

/*                        BOUCLE INFINIE                        */

/****************************************************************/

void loop()

{

   while(ESP8266.available()) 

   {    

     Serial.println(ESP8266.readString());

   }   

}

/****************************************************************/

/*                Fonction qui initialise l'ESP8266             */

/****************************************************************/

void initESP8266()

{  

  Serial.println("**********************************************************");  

  Serial.println("**************** DEBUT DE L'INITIALISATION ***************")

  Serial.println("**********************************************************");  

  envoieAuESP8266("AT+RST")

  recoitDuESP8266(2000);

  Serial.println("**********************************************************")

  envoieAuESP8266("AT+CWMODE=3")

  recoitDuESP8266(5000);

  Serial.println("**********************************************************")

  envoieAuESP8266("AT+CWJAP=\""+ NomduReseauWifi + "\",\"" + MotDePasse +"\"")

  recoitDuESP8266(10000);

  Serial.println("**********************************************************")

  envoieAuESP8266("AT+CIFSR")

  recoitDuESP8266(1000);

  Serial.println("**********************************************************")

  envoieAuESP8266("AT+CIPMUX=1");   

  recoitDuESP8266(1000);

  Serial.println("**********************************************************")

  envoieAuESP8266("AT+CIPSERVER=1,80")

  recoitDuESP8266(1000);

  Serial.println("**********************************************************")

  Serial.println("***************** INITIALISATION TERMINEE ****************")

  Serial.println("**********************************************************")

  Serial.println("");  

}


/****************************************************************/

/*        Fonction qui envoie une commande à l'ESP8266          */

/****************************************************************/

void envoieAuESP8266(String commande)

{  

  ESP8266.println(commande)

}

/****************************************************************/

/*Fonction qui lit et affiche les messages envoyés par l'ESP8266*/

/****************************************************************/

void recoitDuESP8266(const int timeout)

{

  String reponse = "";

  long int time = millis();

  while( (time+timeout) > millis())

  {

    while(ESP8266.available())

    {

      char c = ESP8266.read()

      reponse+=c;

    }

  }

  Serial.print(reponse);   

 (reponse);   

}


https://youtu.be/i2IUDaC1n4k


-----------------------------------------------------------------
--    Programme permettant une interaction avec App Inventor   --
--                  Compatible avec un ESP8266                 --
--                         Version 1.0                         --
--                  Le 17/12/2015 par A.Pailhoux               --
--          Plus d'infos sur www.les-electroniciens.com        --
-----------------------------------------------------------------

-- Connexion au réseau Wifi
wifi.setmode(wifi.STATION)
wifi.sta.config ("MaBox-1A2B3C","FoPaRever") -- Réseau Wifi et Clé  
print(wifi.sta.getip()) -- Affiche l'IP attribuée à l'ESP8266

-- Initialisation des broches GPIO0 et GPIO2
gpio.mode(3, gpio.OUTPUT)
gpio.mode(4, gpio.OUTPUT)
gpio.write(3, gpio.LOW);
gpio.write(4, gpio.LOW);

-- Création du serveur web
srv=net.createServer(net.TCP) 
srv:listen(80,function(conn) 
    conn:on("receive", function(client,request)
    
    -- Création d'un buffer permettant "d'écouter" l'URL
        local buf = "";
        local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
        if(method == nil)then 
            _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP"); 
        end
        local _GET = {}
        if (vars ~= nil)then 
            for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do 
                _GET[k] = v 
            end 
        end
        local _on,_off = "",""
        
        -- Si l'URL contient "GPIO0ON" alors GPIO0 à 3.3V
        if(_GET.pin == "GPIO0ON")then
              _on = " selected=true";
              gpio.write(3, gpio.HIGH);
              print("GPIO0ON")
              
        -- Si l'URL contient "GPIO0FF" alors GPIO0 à 0V      
        elseif(_GET.pin == "GPIO0OFF")then
              _off = " selected=\"true\"";
              gpio.write(3, gpio.LOW);
              print("GPIO0OFF")
              
        -- Si l'URL contient "GPIO2ON" alors GPIO0 à 3.3V
        elseif(_GET.pin == "GPIO2ON")then
              _off = " selected=\"true\"";
              gpio.write(4, gpio.HIGH);
              print("GPIO2ON")
              
        -- Si l'URL contient "GPIO2ON" alors GPIO0 à 0V
        elseif(_GET.pin == "GPIO2OFF")then
              _off = " selected=\"true\"";
              gpio.write(4, gpio.LOW);
              print("GPIO2OFF")
        end        
        client:send(buf);
        client:close();
        collectgarbage();
    end)
end)




Créé avec HelpNDoc Personal Edition: Écrire des livres électroniques ePub pour l'iPad