Bonjour à tous
j'essaie en vain d'afficher une page HTML sur mon nouveau Arduino Wifi rev2.
La page HTML apparait bien lorsque je l'appelle de Chrome.
Mais si je l'intègre dans le sketch, elle n'apparait plus lors de la connexion.
Cela fonctionne bien avec ESP8266WebServer.
Si quelqu'un pouvait m'indiquer mon erreur.....Merci
Michel

voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <Arduino.h>
#include <WiFiNINA.h>
#include <WiFiServer.h>
#include <ssidpass.h>
 
const char* SSID = SECRET_SSID;
const char* PASS = SECRET_PASS;
 
const char index_html[] PROGMEM = R"=====(
<!DOCTYPE html>
<html lang="fr">
    <head>
        <title>Gestion volets roulants</title>
        <meta charset="utf-8">
        <link rel="shortcut icon" type="image/x-icon" href="data:image/png;base64,
        iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAADX0lEQVRIx52Wy47jVBCGv/KtO4kT58KLILFAoJYSpFmxQMxiEEK
        waA08FNCzQyyQYJgtiMwCIdDMo0zHiZ3OzPhWLHwcOzd3oBZWVHbqr/r/qjpHnk6V0gTN8IY8+AG3DwpCbQpCGvPbFyQrAC848e
        WuWfsOJV2Tv0Z1163kr0nXoBXeeeY0Q4tNtuGPay6GTL/D9atAQrbh+de8XVIkiI1m/wOgZAnSCLGg2P2wIIlII6zLNkLuAdAMB
        LER5yCKIE4j97MpspohvAAvAIGiUgKUiv1i95uGPHoazzHMZHgDZjcA82uSmPljvAGzJ5UnIr3D6zP7HhF+/wrNDYxIG2kNigTX
        r6pSkhWoUSJZkUSIDRauD4JIzVIcI0LPR47BHGlTzdC8ocSW/RzNMKyBgu1wt+HRFY+uuIsNXW0il4glxemdUQIa7A8OUtoVoBV
        A0By3z+yGZMXzb0gi5o8BkhhvwPRbvACnY1BFyDN6Pr/8DXDZAbCsFoCtq4vmDSVKOixcH6dbZ7OXtQiqrGNUd8Q4AtBUwroEKN
        5U7LMTt9TgsyuAn/4E5csHLBcGrBXAwgtQpXgD4Ja9f8C+gCrLEK3ECG9ZhozG7RUoTpePbni7Yn4NMHvCRYB1sbs4xTxcF1XTu
        2IxmvDjnGBEliJyogIR7A5uNUquj905uR6ak6wFIvh9ul0jxgmKtkrklcj/xUq88tkKUM4ER8bxfDsBUDLTNdvJ7VbO80qRakfd
        R9F2O50Rzvy2ANYxttMqcoPOuqAdd14RDWlat6kWLEM+n7ZTdLhQtJmqAt6gGmCqrhcRGE0MM9sY8nSq99wnjpWVlgPYQZX1BsD
        vwXmrQolXZvvUVrZ3ALBeoeo6FkCEQN8pEEEDRPqD/XDNW4XiCJuIhx8S3mI11lgBozHPXgB8+gHhwmwJARHNYTyRn/9iEGihe+
        fOQQVaEL4ivGU8qYHDWygMXviKcMF4YmhUldUCC7Tg2PF5ACAWIown/PqS4QhgGfLJe7XI+28XfPwueX78wDzZRQL9AT0fIM93W
        qsUcfu2KBi9YzI7F+AsUxO95/PsHwC/X1d5H4CgBXGEbQPE0bF7T2Mb9IctiRyKrNg2yyUP36+dccRwvN/hzb8cy/1UBYqI6aXm
        adsyetI2lv8CCWmIK1xToTcAAAAASUVORK5CYII="/>
    </head>
    <body>
        <h1>Commande des volets roulants</h1>   
        <fieldset id="unit" class="volet_unitaire">
            <legend>Selection unitaire</legend>
            <input type="radio" id="v1" name="selection" value="1">
            <label for="v1">Cuisine</label>
            <input type="radio" id="v2" name="selection" value="2">
            <label for="v2">Salle</label>
            <input type="radio" id="v3" name="selection" value="3">
            <label for="v3">Salon tele</label>
            <input type="radio" id="v4" name="selection" value="4">
            <label for="v4">Salon canape</label>
            <input type="radio" id="v5" name="selection" value="5">
            <label for="v5">Chambre</label>
            <input type="radio" id="v6" name="selection" value="6">
            <label for="v6">Entree</label>
            <input type="radio" id="v7" name="selection" value="7">
            <label for="v7">Garage</label>
        </fieldset><br><br>
        <fieldset id="grp" class="volets_groupe">
            <legend>Sélection groupe</legend>
            <input type="radio" id="jardin" name="selection" value="E">
            <label for="jardin">Cote jardin</label>
            <input type="radio" id="rue"    name="selection" value="D">
            <label for="rue">Cote rue</label>
            <input type="radio" id="int"    name="selection" value="A">
            <label for="int">Tous Interieur maison</label>
            <input type="radio" id="ext"    name="selection" value="B">
            <label for="ext">Tous Exterieur</label>
        </fieldset><br><br>
        <fieldset class="commandes">
            <legend>Commandes</legend>
            <input type="radio" id="ouv" name="manoeuvre" value="O">
            <label for="ouv">Ouverture</label>
            <input type="radio" id="fer" name="manoeuvre" value="F">
            <label for="fer">Fermeture</label>
            <input type="radio" id="dmo" name="manoeuvre" value="8">
            <label for="dmo">Demi-ouverture</label>
            <input type="radio" id="dmf" name="manoeuvre" value="9">
            <label for="dmf">Demi-fermeture</label>
            <input type="radio" id="arr" name="manoeuvre" value="C">
            <label for="arr">Arret manoeuvres en cours</label>
        </fieldset><br><br>
        <p id="afficheChoix"> - - </p><br><br>
        <button id="va">Click pour envoyer la commande</button> 
        <p id="result"> Resultat </p>   
        <style>
            .volet_unitaire{
                border: 2px solid orange;
                color: blue;               
            }
            .volets_groupe{
                border: 2px solid red;
                color: black;
            }
            .commandes{
                border: 2px solid green;
                color: darkslategray;
            }
            button{
                background-color: white;
            }
        </style>
        <script type="text/javascript">
            let vBouton = document.getElementById("va");       //trouve le bouton
            vBouton.addEventListener("click",transmit);
            vBouton.addEventListener("mouseover",function(){this.style.backgroundColor="red"});
            vBouton.addEventListener("mouseout",function(){this.style.backgroundColor="white"});
 
                //****le bouton de transmission est enfoncé****
                function transmit(){               
                    let laSelection = document.querySelector("[name='selection']:checked").value;
                    let vManip = document.querySelector("[name='manoeuvre']:checked").value;          //trouve la manoeuvre Ã* exécuter
                    if(vManip==null) alert("Il faut une commande!");
                    else{                    
                        document.getElementById("afficheChoix").innerHTML= vManip + laSelection;     //écrit sur la page
                        const xhr=new XMLHttpRequest();                                             //Objet xhr Http request
                        xhr.open("GET","/action?commande=" + vManip + "&volet=" + laSelection);     //commande GET formatté
                        xhr.send();
                        xhr.onload = function(){                                                    //sur réception d'une réponse
                          document.getElementById("result").innerHTML = this.responseText;
                          if (xhr.status != 200){         
                            alert("Erreur " + xhr.status + " : " + xhr.statusText); //...On affiche le statut et le message correspondant
                          }
                          else{ 
                            document.getElementById("result").innerHTML=xhr.response;
                          }
                        };
                        xhr.onerror = function(){           //Si la requête n'a pas pu aboutir...
                            alert("La requete a echoue");
                        }; 
                    }                   
                }
            </script>
        </body>
    </html>
)=====";
 
//*****gestion du serveur. Prototype des fonctions*****
void testRequeteClient();
void commandeRelais();
 
WiFiServer serveur(80);
 
void setup() {
  Serial.begin(9600);
  WiFi.begin(SSID, PASS); 
  while(WiFi.status() != WL_CONNECTED){
    Serial.print("-");
  }
  Serial.print(F("Connected"));
  serveur.begin();
}
 
void loop(){
  testRequeteClient();
}
 
void testRequeteClient(){
  WiFiClient client = serveur.available();
  if(!client) return;  
  while(client.connected()){
    client.setTimeout(500);
    String req = client.readStringUntil('!');   //attend un POST pendant 500ms
    Serial.println(req);
    client.flush();
    if(req.indexOf("GET / HTTP/1.1")>=0){       //si pas de POST, envoi de la page HTML
      client.println(F("HTTP/1.1 200 OK"));
      client.println(F("Content-Type: text/html\r\n"));
      client.println(index_html);
      delay(100);
      Serial.println(F("Envoi de la page HTML"));
      client.stop(); 
    }
    else if(req.indexOf("GET /favicon")){
      Serial.println(F("Favicon demande"));
      client.println(F("HTTP/1.1 200 OK"));
    }
    else if(req.indexOf("POST">=0)){
      //suite commandeRelais
    }
  }
}