J'ai installé début janvier 2 NodeMcu ESP8266 AMICA en surveillance de tension batterie. Je suis en cours d'installation de nouveaux modules mais j'ai un blocage que je n'identifie pas : domoticz ne prend pas en compte les données envoyées.
En injectant le même programme, donc même SSID, adresse, mdp, idx, aucun log n’apparaît. Le NodeMcu se connecte bien en wifi, il est détecté sur le réseau.
Le seul changement effectué depuis début janvier est la mise à jour de l'IDE Arduino de 1.6.9 vers 1.8.5 mais, avec cette version, alors impossible de compiler le programme. Après recherche sur les forums, il semble qu'il y a un bug dans IDE depuis la 1.8. J'ai désinstaller IDE et réinstaller la version 1.6.9 mais comme les librairies avaient aussi été désinstallées, elles ont été remise en place. L'un d'entre elle doit certainement posée problème mais laquelle?
Je vous joins le code qui marche sur 2 NodeMcu, attention une partie n'a pas d'utilité, j'ai repris un code de surveillance de qualité d'air et je n'ai pas encore nettoyé les éléments inutilisés.
La config de IDE
ESP-12E Module; 80Mhz; 4M (3M SPIFFS); v2 Prebuilt (MSS=536);Serial;HTTP_SERVER;115200;COM14
Merci de me donner une piste
Code : Tout sélectionner
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <SoftwareSerial.h>
const char* ssid = "xxxxxxx";
const char* password = "xxxxxxxxx";
const char* idx = "2"; //IDX of dummy tension 1 = 12v ; 2 = 24v
const char* host = "192.168.1.47"; // //IP Address of domoticz server
SoftwareSerial mySerial(12, 13); // RX, TX
int port = A0; // port A0 utilisé pour lire la tension appliquée
int valeur = 0;
float vin = 0;
float vint = 0;
void(* resetFunc) (void) = 0; //declare reset function @ address 0
void setup() {
Serial.begin(115200);
mySerial.begin(9600); //C02 sensor read serial
delay(1000);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
int wifi_ctr = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.println("IP address: " + WiFi.localIP());
}
void loop() {
// Lit l’entrée analogique A0
////ancien code
////valeur = analogRead(port);
valeur = analogRead(port);
// convertit l’entrée en volt
float fvaleur = (valeur * 30 / 1024.0);
vint = fvaleur ;
vin = vint *1.08; // ajustement tension
Serial.print("connecting to ");
Serial.println(host);
WiFiClient client;
const int httpPort = 8085;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
Serial.println("Reset everything");
ESP.reset();
return;
}
int ppm = vin; //int ppm = readCO2();
delay(1000);
bool dataError = false;
Serial.println(" Tension = " + String(vin));
Serial.println(vin);
if (ppm < 1 || ppm > 60000)
{
Serial.println("PPM not valid");
return; //start over again
}
delay(1000);
client.print(String("GET ") + "/json.htm?type=command¶m=udevice&idx=" + idx + "&nvalue=0&svalue=" + vin + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");// modif ligne 80 + idx + "&nvalue=" + vin + ......
delay(1000); // wait for server to respond
// read response
String section="header";
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
if (section=="header") { // headers..
Serial.print(".");
if (line=="\n") { // skips the empty space at the beginning
section="json";
}
}
else if (section=="json") { // print the good stuff
section="ignore";
String result = line.substring(1);
// Parse JSON
int size = result.length() + 1;
char json[size];
result.toCharArray(json, size);
StaticJsonBuffer<200> jsonBuffer;
JsonObject& json_parsed = jsonBuffer.parseObject(json);
if (!json_parsed.success())
{
Serial.println("parseObject() failed");
return;
}
if (strcmp(json_parsed["status"], "OK") == 0) {
Serial.println("Returned OK");
}
else if (strcmp(json_parsed["status"], "ERR") == 0){
Serial.println("Returned ERR or");
}
else{
Serial.println("Not working at all");
}
}
}
Serial.println("closing connection");
client.stop();
delay(5000);// delais entre 2 mesures
}
int readCO2()
{
byte cmd[9] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
// command to ask for data
char response[9]; // for answer
mySerial.write(cmd, 9); //request PPM CO2
mySerial.readBytes(response, 9);
if (response[0] != 0xFF)
{
Serial.println("Wrong starting byte from co2 sensor!");
return -1;
}
if (response[1] != 0x86)
{
Serial.println("Wrong command from co2 sensor!");
return -1;
}
int responseHigh = (int) response[2];
int responseLow = (int) response[3];
int ppm = (256 * responseHigh) + responseLow;
return ppm;
}