Hello.
I am using a nodeMCU 12E v3.2.
It connects very well to the wifi (the wifi network is created by an internet router) and recovers the time without problem from an NTP server.
On the other hand, when I use it as a web server and try to connect it to a smartphone, there are communication problems: the requests of the smartphone do not arrive (or very slowly) and I try to understand why.
When there is a communication between the nodeMCU and the smartphone, does it go through my Internet router or is it direct (I tried to bring the nodeMCU closer to the internet router but without improvement)?
Thanks for the answers.
Of course. Here is the function that processes the request (it's called in the function loop):
void Serveur::traiterRequete()
{
WiFiClient client = available();
if (!client)
{
return;
}
Serial.print("Requête client ");
unsigned long previousMillis = millis();
while (!client.available())
{
delay(1);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 2000) {
Serial.println("Sortie boucle tant que: le client n'est plus disponible.");
client.stop();
return;
}
}
Serial.println(client.remoteIP());
String requete;
while (client.available())
{
String ligne = client.readStringUntil('\r');
Serial.print(ligne);
requete += ligne;
client.flush();
}
Serial.println("");
if (requete.indexOf("GET") != -1)
//Si c'est une requête GET, le serveur envoie la page d'accueil au client
{
envoyerPageAccueil(client);
}
else if (requete.indexOf("POST") != -1)
//Si c'est une requête POST, on récupère l'heure et les minutes saisies (de part et d'autre du : encodé en URL)
{
int positionDeuxPoints = requete.indexOf("%3A"); //encodage de : dans l'URL
int heureDec = requete.substring(positionDeuxPoints - 2, positionDeuxPoints).toInt();
int minuteDec = requete.substring(positionDeuxPoints + 3, positionDeuxPoints + 5).toInt();
modRTCServeur.miseAJourHoraireDeclenchementMoteur(heureDec, minuteDec);
client.print(stringValidationHTML);
}
else
{
Serial.println("Requête invalide !");
client.stop();
return;
}
delay(1);
client.stop();
}
The function "envoyerPageAccueil" sends an HTML page to the client (I can post it here if it's necessary).
If it's a "POST" request, I recover a few values from the request and I send an HTML page to the client.
Hello.
Finally, I managed to make the communication work by putting the "Flash Size" option in the Arduino IDE on 4M (3M SPIFFS) and uploading my HTML files to the nodeMCU again (the files are stored on the nodeMCU ).
However, it takes at least 6 seconds between the time I connect to the MCU from my smartphone and when the HTML page sent by the MCU node appears on my smartphone.
It's normal ?