Page 1 sur 1

nodemcu conflit entre led ir et wifi

Publié : 04 nov. 2016, 05:45
par DJANGO
bonjour ,je viens vers vous aujourd'hui car cherchant a finaliser un projet de boitier de commande de climatisation a distance a base d'un nodemcu v0.9 et d'une diode ir je rencontre un problème de connexion wifi

le problème est le suivant après avoir televerser le programme dans la carte celle ci ne réagit pas ,pour établir une connexion wifi avec ma livebox je dois débrancher la diode (branché sur le port d3 et gnd)et redémarré électriquement la carte afin que celle ci se connecte puis rebranché la diode et la tous fonctionne correctement mais a la première coupure de courant je doit recommencer la manœuvre afin que tous rentre dans l'ordre

je met ici le code que j'ai assemblé en prenant plusieurs code de projet différent aussi certaine chose sont peut être inutile

je remercie d'avance les personnes qui m'aideront a comprendre mon erreur


#include <IRremoteESP8266.h>
#include <IRremoteInt.h>
#include <ESP8266WiFi.h>
#include <Dhcp.h>
#include <Dns.h>
#include <string.h>
#include <SPI.h>

const char* ssid = "Livebox-....";
const char* password = "...............................";

// Create an instance of the server
// specify the port to listen on as an argument
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
byte gateway[] = { 90,.., ..., ... }; // internet access via router
WiFiServer server(80);
WiFiServer serveurHTTP(7000);



int khz = 38; //NB Change this default value as neccessary to the correct modulation frequency






// CHAUD - ON
unsigned OFF[201] = {4432, 4332, 604, 1576, 608, 488,
604, 1572, 608, 1572, 608, 488, 604, 488,
604, 1576, 604, 492, 580, 508, 608, 1572,
608, 488, 604, 488, 604, 1576, 604, 1576,
604, 488, 608, 1576, 580, 512, 604, 488,
604, 1576, 604, 1576, 604, 1576, 604, 1576,
604, 1576, 604, 1576, 580, 1600, 604, 1576,
604, 488, 604, 488, 608, 488, 604, 488, 604,
488, 604, 492, 580, 508, 608, 1572, 608, 488,
604, 488, 604, 1576, 604, 1576, 604, 488,
604, 492, 580, 1596, 608, 484, 608, 1572, 608,
1572, 608, 488, 604, 488, 604, 1576, 604,
1572, 584, 5172, 4412, 4328, 580, 1600, 604,
488, 608, 1572, 608, 1572, 608, 488, 604, 488,
604, 1572, 608, 488, 580, 512, 604, 1576, 604,
488, 604, 488, 604, 1576, 604, 1576, 604, 488,
604, 1576, 580, 512, 604, 488, 608, 1572, 604,
1576, 604, 1576, 604, 1576, 604, 1576, 604, 1576,
580, 1600, 604, 1576, 604, 488, 604, 488, 604, 488,
608, 488, 604, 488, 604, 488, 580, 512, 604, 1576,
604, 488, 604, 488, 608, 1572, 604, 1576, 604, 488,
608, 488, 580, 1596, 608, 488, 604, 1572, 608, 1576,
604, 488, 604, 488, 604, 1576, 604, 1576, 580, 64788, 140,

};

// FROID -ON
unsigned COOL[199] = { 4436, 4324, 580, 1600, 580, 512, 608, 1576, 604, 1576, 604, 488,
608, 488, 604, 1576, 580, 516, 604, 488, 604, 1576, 580, 512, 608, 488, 604, 1576, 604,
1576, 608, 488, 604, 1576, 584, 508, 608, 1572, 608, 1576, 580, 1600, 608, 1576, 604, 488,
608, 1572, 608, 1576, 584, 1596, 608, 488, 604, 488, 608, 488, 580, 512, 608, 1572, 608,
484, 608, 488, 584, 1596, 608, 1572, 608, 1576, 580, 516, 604, 488, 604, 488, 608, 488,
604, 488, 584, 508, 584, 508, 584, 512, 604, 1576, 604, 1576, 608, 1576, 604, 1576, 608,
1576, 580, 5180, 4384, 4360, 584, 1596, 608, 488, 604, 1576, 608, 1572, 584, 512, 604,
488, 608, 1572, 584, 516, 604, 484, 608, 1576, 604, 488, 608, 488, 604, 1576, 580, 1600,
608, 488, 604, 1580, 580, 512, 604, 1576, 608, 1576, 580, 1600, 580, 1600, 608, 488, 608,
1572, 608, 1576, 584, 1596, 584, 512, 604, 488, 608, 488, 604, 488, 608, 1572, 584, 512,
604, 488, 608, 1572, 608, 1576, 604, 1576, 580, 516, 604, 488, 604, 488, 608, 488, 604, 492,
604, 488, 604, 488, 608, 484, 608, 1576, 580, 1600, 608, 1576, 604, 1576, 580, 1604, 580,


};

IRsend irsend(0);
String readString; //string
boolean COOLON = false; // flag status Cooling
boolean DRYON = false; // flag status Drying




void setup(void){
irsend.begin();
Serial.begin(115200);
WiFi.begin(ssid, password);
serveurHTTP.begin();
Serial.println("");


// Connect to WiFi network
Serial.println();
Serial.print("Connecting to ludo ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.println(WiFi.localIP());

}

void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
readString.concat(c); //memorizzo ogni carattere della stringa
//if HTTP request has ended
if (c == '\n' && currentLineIsBlank) {
Serial.print(readString);

if (readString.indexOf("L=0") > 0) {
if (COOLON || DRYON) { // if is ON, switch it OFF
//Serial.println("AC -> OFF");
irsend.sendRaw(OFF, sizeof(OFF) / sizeof(int), khz);
COOLON = false;
DRYON = false;
}
}
else if (readString.indexOf("L=1") > 0) { // lettura del valore se il AC si deve accendere
if (!DRYON) { //se non è acceso
//Serial.println("CHAUD ON");
irsend.sendRaw(OFF, sizeof(OFF) / sizeof(int), khz);
DRYON = true;
COOLON = false;
}
}
else if (readString.indexOf("L=2") > 0) {
if (!COOLON) { //se è acceso
//Serial.println("FROID ON");
irsend.sendRaw(COOL, sizeof(COOL) / sizeof(int), khz);
COOLON = true;
DRYON = false;
}
}



// COSTRUZIONE PAGINA HTML
client.println("HTTP/192.168.1.14");
client.println("Content-Type: text/html");
client.println();
// inizializzo pagina (da togliere se uso ajax)
client.print("<html><head><title>CONTROLE CLIMATISATION</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ></head><body>");
//iniza il body
client.println("<div style='width:960px; height:1136px;'>");
client.println("<h1>COMMANDE</h1>");
//scrivo il AC status
client.print("<font size='5'>Status: ");
if (COOLON) {
client.println("<span style='color:green; font-weight:bold;'>FROID</span></font>");
}
else {
client.println("<span style='color:grey; font-weight:bold;'>CHAUD</span></font>");
}
client.print("<h2><a href='/?L=0'> ON </a> | <a href='/?L=2'> OFF </a></h2>");

//semnătura ;)
client.println("<hr />");
client.print("<h4>CLIMATISATION HIVER V1.0</h4>");
client.println("<hr />");

// chiudo il div
client.println("</div>");
// chiudo pagina da togliere se uso ajax
client.println("</body></html>");

// pulisco la stringa per la successiva lettura
readString = "";
//fermo il client
client.stop();

} //if c == /n
} // if client available
} // while client connesso
} // FINE if client
} // fine loop



// The client will actually be disconnected
// when the function returns and 'client' object is detroyed

Re: nodemcu conflit entre led ir et wifi

Publié : 04 nov. 2016, 08:14
par deennoo
Prennons mon cas :

Barre de son samsung, mais telecommande non reconnu comme une samsung, c'est le meme signal pour on et off.

Tele trop ancienne pour du HDMI CEC.

Une prise meuble TV avec la tv, la freebox et la barre de son.

A chaque fois que j'allume le meuble tv, tout s'allume sauf la barre de son.

Avec le sketch que j'ai donner la barre de son ne s'allumait qu'une fois sur deux, bizzare.

Il fonctionne si je lance la requette http 2 fois d'affiler.

Donc dans domoticz :
Un virtuel on/off + delai d'extinction de 1 seconde.
Dans action on et off la meme requete http.

Un blocky qui dit :

Si meuble tv On alors barre de son ON (et avec le delai d'extinction de 1 sec Off de suite apres).

Et voila plus besoin d'appuyer sur un bouton pour allumer la barre de son, cela ce fait tout seul

Re: nodemcu conflit entre led ir et wifi

Publié : 04 nov. 2016, 12:49
par Neutrino
D3 correspond au GPIO 0.
Quand le GPIO 0 est relié à la masse au boot, il démarre en mode FLASH.
C'est pour cette raison que ton nodemcu ne démarre pas.
Change de GPIO, D1 ou D2 par exemple et cela ira mieux.
J'aime ton code et son côté international :)

PS : on a une section sur le forum dédiée au nodemcu

Re: nodemcu conflit entre led ir et wifi

Publié : 04 nov. 2016, 15:13
par DJANGO
merci pour vos réponse rapide grâce a vous j'ai pu résoudre mon problème en quelque minute

je posterais le code modifié au cas ou quelqu'un soit intéressé par le projet mais en attendant il ma suffit de brancher la diode sur d2 qui correspond a gpio4 et de remplacé la ligne IRsend irsend(0);
par IRsend irsend(4);

maintenant je vais m'attelé a y rajouter un dht11 afin d'obtenir la température et l'humidité

comme je l'ai dit il s'agit de morceaux de code provenant de plusieur projet simple telle que allumé une diode ou se connecter a un reseau wifi que j'ai assemblé en partant a la base du meme projet mais en arduino que j'ai trouvé a cette adresse:

http://www.instructables.com/id/Air-Con ... y-Arduino/

d'où le coté international

encore un grand merci je recours au forum pour la première fois et ne suis pas déçu j'espère pouvoir moi aussi un jour apporté mon aide

Re: nodemcu conflit entre led ir et wifi

Publié : 09 nov. 2016, 20:26
par DJANGO
bonsoir

Comme je vous l'ai dit sur le précédent message je vous met le code fonctionnel(comprenant le dht11) pour commander une climatisation a distance depuis une page internet il suffit de modifier l identifiant de votre box ainsi que son code et les codes on/off de votre climatisation

le materiel nécéssaire pour ce projet :-un nodemcu v0.9
-une diode ir
-un capteur dht11
-un boitier plastique


les branchement :-diode ir gnd/d2
-DHT11 3V3/D1/GND


DSC_0028.JPG




#include <dht11.h>
#include <IRremoteESP8266.h>
#include <IRremoteInt.h>
#include <ESP8266WiFi.h>
#include <Dhcp.h>
#include <Dns.h>
#include <string.h>
#include <SPI.h>


const char* ssid = "LiveBox.....";
const char* password = ".......................";


byte subnet[] = { 255, 255, 255, 0 };
byte gateway[] = { 90, 57, 150, 158 };
WiFiServer server(80);
WiFiServer serveurHTTP(7000);



int khz = 38;






// CHAUD - ON
unsigned OFF[201] = {4432, 4332, 604, 1576, 608, 488,604, 1572, 608, 1572, 608, 488, 604, 488,604, 1576, 604, 492, 580, 508, 608, 1572,608, 488, 604, 488, 604, 1576, 604, 1576,604, 488, 608, 1576, 580, 512, 604, 488, 604, 1576, 604, 1576, 604, 1576, 604, 1576,604, 1576, 604, 1576, 580, 1600, 604, 1576,604, 488, 604, 488, 608, 488, 604, 488, 604,488, 604, 492, 580, 508, 608, 1572, 608, 488,604, 488, 604, 1576, 604, 1576, 604, 488, 604, 492, 580, 1596, 608, 484, 608, 1572, 608,1572, 608, 488, 604, 488, 604, 1576, 604,1572, 584, 5172, 4412, 4328, 580, 1600, 604,488, 608, 1572, 608, 1572, 608, 488, 604, 488,604, 1572, 608, 488, 580, 512, 604, 1576, 604,488, 604, 488, 604, 1576, 604, 1576, 604, 488,604, 1576, 580, 512, 604, 488, 608, 1572, 604, 1576, 604, 1576, 604, 1576, 604, 1576, 604, 1576,580, 1600, 604, 1576, 604, 488, 604, 488, 604, 488,608, 488, 604, 488, 604, 488, 580, 512, 604, 1576, 604, 488, 604, 488, 608, 1572, 604, 1576, 604, 488, 608, 488, 580, 1596, 608, 488, 604, 1572, 608, 1576,604, 488, 604, 488, 604, 1576, 604, 1576, 580, 64788, 140,
};

// FROID -ON
unsigned COOL[199] = { 4436, 4324, 580, 1600, 580, 512, 608, 1576, 604, 1576, 604, 488,608, 488, 604, 1576, 580, 516, 604, 488, 604, 1576, 580, 512, 608, 488, 604, 1576, 604,1576, 608, 488, 604, 1576, 584, 508, 608, 1572, 608, 1576, 580, 1600, 608, 1576, 604, 488,608, 1572, 608, 1576, 584, 1596, 608, 488, 604, 488, 608, 488, 580, 512, 608, 1572, 608,484, 608, 488, 584, 1596, 608, 1572, 608, 1576, 580, 516, 604, 488, 604, 488, 608, 488,604, 488, 584, 508, 584, 508, 584, 512, 604, 1576, 604, 1576, 608, 1576, 604, 1576, 608,1576, 580, 5180, 4384, 4360, 584, 1596, 608, 488, 604, 1576, 608, 1572, 584, 512, 604,488, 608, 1572, 584, 516, 604, 484, 608, 1576, 604, 488, 608, 488, 604, 1576, 580, 1600,608, 488, 604, 1580, 580, 512, 604, 1576, 608, 1576, 580, 1600, 580, 1600, 608, 488, 608, 1572, 608, 1576, 584, 1596, 584, 512, 604, 488, 608, 488, 604, 488, 608, 1572, 584, 512, 604, 488, 608, 1572, 608, 1576, 604, 1576, 580, 516, 604, 488, 604, 488, 608, 488, 604, 492,604, 488, 604, 488, 608, 484, 608, 1576, 580, 1600, 608, 1576, 604, 1576, 580, 1604, 580,
};

dht11 DHT11;
#define DHT11PIN 5
#define DHTTYPE DHT11
IRsend irsend(4);
String readString; //string
boolean COOLON = false; // flag status Cooling
boolean DRYON = false; // flag status Drying




void setup(void){

irsend.begin();
Serial.begin(115200);
WiFi.begin(ssid, password);
serveurHTTP.begin();
Serial.println("");


// Connect to WiFi network
Serial.println();
Serial.print("Connecting to ludo ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.println(WiFi.localIP());

}

void loop() {



// Check if a client has connected
WiFiClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
readString.concat(c); //memorizzo ogni carattere della stringa
//if HTTP request has ended
if (c == '\n' && currentLineIsBlank) {
Serial.print(readString);

if (readString.indexOf("L=0") > 0) {
if (COOLON || DRYON) { // if is ON, switch it OFF
//Serial.println("AC -> OFF");
irsend.sendRaw(OFF, sizeof(OFF) / sizeof(int), khz);
COOLON = false;
DRYON = false;
}
}
else if (readString.indexOf("L=1") > 0) { // lettura del valore se il AC si deve accendere
if (!DRYON) { //se non è acceso
//Serial.println("CHAUD ON");
irsend.sendRaw(OFF, sizeof(OFF) / sizeof(int), khz);
DRYON = true;
COOLON = false;
}
}
else if (readString.indexOf("L=2") > 0) {
if (!COOLON) { //se è acceso
//Serial.println("FROID ON");
irsend.sendRaw(COOL, sizeof(COOL) / sizeof(int), khz);
COOLON = true;
DRYON = false;
}
}


{
Serial.print(" --- Nouvelle lecture --- ");

int chk = DHT11.read(DHT11PIN); // Lecture du capteur

Serial.print("Etat du capteur: ");

switch (chk) // Est-ce que le capteur fonctionne?
{
case DHTLIB_OK:
Serial.println("OK");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Checksum erreur");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println("Time out erreur");
break;
default:
Serial.println("Erreur inconnue");
break;
}

Serial.print("Humidite (%): "); // Humidité
Serial.println((float)DHT11.humidity, 2);

Serial.print("Temperature (°C): "); // Température
Serial.println((float)DHT11.temperature, 2);

delay(1000); // Pause avant prochaine lecture

}


// COSTRUZIONE PAGINA HTML
client.println("HTTP/192.168.1.16");
client.println("Content-Type: text/html");
client.println();

// inizializzo pagina (da togliere se uso ajax)
client.print("<html><head><title>CONTROLE CLIMATISATION</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ></head><body>");
//iniza il body
client.println("<div style='width:960px; height:1136px;'>"); //risoluzione per nokia 5800 640x360, iPhone4 960x640 pixel, iPhone5 1136x640
client.println("<h1>INFORMATION</h1><hr />");
//Scrive sul browser il valore del termistore
client.println("<p>TEMPERATURE = ");
client.print((float)DHT11.temperature, 2);
client.println(" *C <br /></p>");

//Scrive sul browser il valore della fotoresistenza
client.println("<p>HUMIDITY = ");
client.print((float)DHT11.humidity, 2);
client.println(" % <br /></p>");

// link per aggiornare pagina e valori
client.print("<h2>Rafraichir: <a href=''>actualiser</a></h2><hr />");
client.println("<h1>COMMANDE</h1>");
//scrivo il AC status
client.print("<font size='5'>etat: ");
if (COOLON) {
client.println("<span style='color:green; font-weight:bold;'>OFF</span></font>");
}
else {
client.println("<span style='color:grey; font-weight:bold;'>ON</span></font>");
}
client.print("<h2><a href='/?L=0'> ON </a> | <a href='/?L=2'> OFF </a></h2>");

//semnătura ;)
client.println("<hr />");
client.print("<h4>CLIMATISATION HIVER V1.1</h4>");
client.println("<hr />");


client.println("</div>");
// chiudo pagina da togliere se uso ajax
client.println("</body></html>");


readString = "";
//fermo il client
client.stop();

} //if c == /n
} // if client available
} // while client connesso
} // FINE if client
} // fine loop



// The client will actually be disconnected
// when the function returns and 'client' object is detroyed






A BIENTOT