Bonsoir
Voici le retour de mes expérimentations avec mon wemosD1.
J'ai fais bcp de captures pour essayer de bien comprendre le protocole, et surprise j'ai un zero de trop à la fin du premier octet (et donc un décalage de l'ensemble du message). Ainsi au lieu d'avoir un device ID qui commence par 7, le mien commence par 3,
Et lorsque je rejoue les commandes avec le zero supplémentaire, elle fonctionne.
Pour info, j'utilise les codes de @tchuene (en lecture & écriture) que j'ai modifié, j'ai rajouté la gestion du stuffing et bcp de log pour comprendre et le support de SysLog pour dumper les messages sur mon PI.
Voici la version pour lire les trames pour les courageux
Code : Tout sélectionner
// active/desactive les traces SYSLOG
//#define SYSLOG
#ifdef SYSLOG
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <Syslog.h>
// WIFI credentials
#define WIFI_SSID "********"
#define WIFI_PASS "********"
// Syslog server connection info
#define SYSLOG_SERVER "192.168.0.7"
#define SYSLOG_PORT 514
// This device info
#define DEVICE_HOSTNAME "wemosD1"
#define APP_NAME "my-app"
// A UDP instance to let us send and receive packets over UDP
WiFiUDP udpClient;
// Create a new syslog instance with LOG_KERN facility
Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
#endif
volatile long duration = 0;
volatile long prev_time = 0;
volatile boolean data_dispo = false;
byte input = 4;
String trame[3];
byte hex[20];
byte message = 0;
byte start = true;
byte intro = 0;
String prefixe = "1100";
int cpt = 1;
char text[50] ;
void setup() {
Serial.begin(500000);
Serial.println();
Serial.println();
#ifdef SYSLOG
// We start by connecting to a WiFi network
Serial.print("Connecting to ");
Serial.println(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
syslog.logf(LOG_ERR, "START");
#endif
attachInterrupt(digitalPinToInterrupt(input), declenche, CHANGE);
memset(text, 0, 50);
Serial.println("\nSTART\n");
}
void loop() {
if (data_dispo == true) {
int bit_state = digitalRead(input);
//if (bit_state == HIGH) Serial.printf("-");
//else Serial.printf("_");
if ((duration > 700) && (duration < 950)) { // pulse off court
trame[message] = trame[message] + !bit_state;
} else if ((duration > 1400) && (duration < 1950)) { // pulse off long
// verifie qu'on commence avec un pulse long à 1
if ((start == true) && (!bit_state == HIGH)) {
trame[message] = trame[message] + !bit_state + !bit_state;
start = false;
} else if (start == false) {
trame[message] = trame[message] + !bit_state + !bit_state;
}
} else {
start = true; // debut d'une nouvelle trame
if (trame[message].length() > 200) {
message++;
if (message > 2) {
for (message = 0; message < 3; message++) {
for (int x = 0; x <= 50; x=x+4) {
if (trame[message].substring(x,x+4).compareTo(prefixe) == 0) {
intro++;
} else {
break;
}
}
String sortie = "";
if (intro >= 6 ) {
sortie = "";
int nbBit = 0;
int nbOne = 0;
// décodage des bits de la trame: 00=0, 11=0, 10=1, 01=1
for (int x = (intro*4); x <= trame[message].length(); x=x+2) {
if ((trame[message].substring(x,x+2) == "00") or (trame[message].substring(x,x+2) == "11")) {
if (!((nbOne == 5) && (nbBit >= 8*7) && (nbBit <8*12))) // gestion du Stuffing pour les octets entre 7 et 11 inclu
sortie = sortie + "0";
nbOne = 0;
} else {
sortie = sortie + "1";
nbOne ++;
}
nbBit++;
}
Serial.printf("BIN = ");
for (int cpt = 0; cpt<sortie.length() ;cpt++) {
Serial.printf("%c",sortie.substring(cpt,cpt+1)[0]);
if (cpt % 4 == 3) Serial.printf(" ");
if (cpt % 8 == 7) Serial.printf(" ");
}
Serial.printf("\n");
// repartition en bytes
/*
Serial.printf("IN = ");
for (int cpt = 0; cpt<trame[message].length() ;cpt++) {
Serial.printf("%c",trame[message].substring(cpt,cpt+1)[0]);
if (cpt % 8 == 7) Serial.printf(" ");
}
Serial.printf("\nOUT = ");
for (int cpt = 0; cpt<sortie.length() ;cpt++) {
Serial.printf("%c",sortie.substring(cpt,cpt+1)[0]);
if (cpt % 8 == 7) Serial.printf(" ");
}
Serial.printf("\n");
*/
memset(hex,0,20);
strcpy(text,"");
Serial.printf("\nHEX = ");
for (int cpt=0; cpt<sortie.length(); cpt+=8) {
hex[cpt / 8] = convert(sortie.substring(cpt,cpt+8));
sprintf(text,"%s%02X",text,hex[cpt / 8]);
if ((cpt % 32) == 24) Serial.printf(" ");
if ((cpt % 32) == 24) sprintf(text,"%s ",text);
Serial.printf("%02X",hex[cpt / 8]);
}
Serial.printf("\n");
/* RAPPEL (src https://antoinegrall.wordpress.com/decodage-frisquet-ers/)
Octet 00 – 11111101 = 0xBF – Fixe, attitré à chaque chaudière
Octet 01 – 01100111 = 0xE6 – Fixe, attitré à chaque chaudière
Octet 02 – 11001111 = 0xF3 – Fixe, attitré à chaque chaudière
Octet 03 – 00000000 = 0x00 – Fixe
Octet 04 – 00000100 = 0x20 – Fixe
Octet 05 – 00000000 = 0x00 – Fixe
Octet 06 – 00000000 = 0x00 – Fixe
Octet 07 – 11000001 = 0x83 – Variable, préchauffage eau
Octet 08 – 10101010 = 0x55 – Variable, chauffage
Octet 09 – 00000000 = 0x00 – Niveau pile ?
Octet 10 – 10111111 = 0xFD – Fixe
Octet 11 – 00100010 = 0x44 – Variable checksum
Octet 12 – 11111111 = 0xFF – Fixe, fin du message
Octet 13 – 00000000 = 0x00 – Fixe
*/
bool err = 0;
// ID de ma frisquet devrait etre fixe
if (!((hex[0] == 0x3F) && (hex[1] == 0xE4) && (hex[2] == 0x0A))) {
err += 1;
Serial.printf("ID error : %02X %02X %02X\n",hex[0],hex[1],hex[2]);
#ifdef SYSLOG
syslog.logf(LOG_INFO, "ID error : %02X %02X %02X",hex[0],hex[1],hex[2]);
#endif
}
// Devrait etre fixe, mais bon ...
if (!((hex[3] == 0x00) && (hex[4] == 0x10) && ((hex[5] == 0x00) || (hex[5] == 0x80)))) {
err += 2;
Serial.printf("FIX error : %02X %02X %02X\n",hex[3],hex[4],hex[5]);
#ifdef SYSLOG
syslog.logf(LOG_INFO, "FIX error : %02X %02X %02X",hex[3],hex[4],hex[5]);
#endif
}
// Trame corromptue ?
if ((hex[8] == 0xFF) && (hex[9] == 0xFF)) {
err += 4;
Serial.printf("FF error : %02X %02X %02X\n",hex[8],hex[9],hex[10]);
#ifdef SYSLOG
syslog.logf(LOG_INFO, "FIX error : %02X %02X %02X",hex[8],hex[9],hex[10]);
#endif
}
Serial.printf("VALUE %d NUM %02X COMMAND %02X HEATING %3d ERROR %d\n",message, hex[6],hex[7],hex[8],err);
#ifdef SYSLOG
syslog.logf(LOG_INFO, "VALUE=%d; NUM=%02X; COMMAND=%02X; HEATING=%03d ;ERROR=%d; HEX=%s",message, hex[6],hex[7],hex[8],err,text);
#endif
intro = 0;
}
else { // pas de synchro
Serial.printf("SKIP [%d] = ", intro);
for (int cpt = 0; cpt<8*8;cpt++) {
Serial.printf("%c",trame[message].substring(cpt,cpt+1)[0]);
if ((cpt % 4) == 3) Serial.printf(" ");
}
#ifdef SYSLOG
syslog.logf(LOG_INFO, "SKIP [%d]", intro);
#endif
Serial.printf("\n");
}
Serial.println("----");
}
trame[0] = "";
trame[1] = "";
trame[2] = "";
Serial.println();
message = 0;
}
} else {
trame[0] = "";
trame[1] = "";
trame[2] = "";
message = 0;
}
}
data_dispo = false;
}
}
void declenche() {
duration = micros()-prev_time;
prev_time = micros();
data_dispo = true;
}
byte convert(String entree) {
byte result = 0;
for (int f = 0; f <= 7 ; f++) {
if (entree.substring(f,f+1) == "1") bitSet(result, f);
}
return result;
}