2020-06-12 15:31:23 +01:00
|
|
|
/*
|
|
|
|
xnrg_15_Teleinfo.ino - Teleinfo support for Tasmota
|
|
|
|
|
2021-01-01 12:44:04 +00:00
|
|
|
Copyright (C) 2021 Charles-Henri Hallard
|
2020-06-12 15:31:23 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef USE_ENERGY_SENSOR
|
|
|
|
#ifdef USE_TELEINFO
|
|
|
|
/*********************************************************************************************\
|
2020-10-28 16:32:07 +00:00
|
|
|
* Teleinfo : French energy provider metering telemety data
|
2020-06-12 15:31:23 +01:00
|
|
|
* Source: http://hallard.me/category/tinfo/
|
|
|
|
*
|
2020-06-17 18:54:40 +01:00
|
|
|
* Denky ESP32 Teleinfo Template
|
2020-06-19 01:28:09 +01:00
|
|
|
* {"NAME":"Denky (Teleinfo)","GPIO":[1,1,1,1,5664,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1376,1,1,0,0,0,0,1,5632,1,1,1,0,0,1],"FLAG":0,"BASE":1}
|
2021-04-20 18:16:55 +01:00
|
|
|
* Denky D4 ESP Pico V3 Teleinfo Template
|
|
|
|
* {"NAME":"DenkyD4","GPIO":[32,0,0,0,1,0,0,0,0,1,0,1,0,0,0,0,0,640,608,0,0,450,449,448,0,0,0,0,0,0,0,0,0,0,0,0],"FLAG":0,"BASE":1}
|
2020-10-28 16:32:07 +00:00
|
|
|
*
|
2020-06-17 18:54:40 +01:00
|
|
|
* Denky (aka WifInfo) ESP8266 Teleinfo Template
|
2020-08-14 18:47:13 +01:00
|
|
|
* {"NAME":"WifInfo v1.0a","GPIO":[17,255,255,255,6,5,255,255,7,210,255,255,255],"FLAG":15,"BASE":18}
|
2020-08-10 16:43:07 +01:00
|
|
|
* {"NAME":"WifInfo","GPIO":[7,255,255,210,6,5,255,255,255,255,255,255,255],"FLAG":15,"BASE":18}
|
2020-10-28 16:32:07 +00:00
|
|
|
*
|
2020-06-12 15:31:23 +01:00
|
|
|
\*********************************************************************************************/
|
2020-10-28 16:32:07 +00:00
|
|
|
#define XNRG_15 15
|
2020-06-12 15:31:23 +01:00
|
|
|
|
|
|
|
#include "LibTeleinfo.h"
|
|
|
|
#include <TasmotaSerial.h>
|
|
|
|
|
2020-10-28 16:32:07 +00:00
|
|
|
#define TINFO_READ_TIMEOUT 400
|
2020-06-14 21:04:19 +01:00
|
|
|
|
2021-04-08 19:02:19 +01:00
|
|
|
#define D_NAME_TELEINFO "Teleinfo"
|
|
|
|
|
|
|
|
// Json Command
|
2021-04-09 18:45:06 +01:00
|
|
|
//const char S_JSON_TELEINFO_COMMAND_STRING[] PROGMEM = "{\"" D_NAME_TELEINFO "\":{\"%s\":%s}}";
|
|
|
|
//const char S_JSON_TELEINFO_COMMAND_NVALUE[] PROGMEM = "{\"" D_NAME_TELEINFO "\":{\"%s\":%d}}";
|
2021-10-27 12:56:22 +01:00
|
|
|
const char TELEINFO_COMMAND_SETTINGS[] PROGMEM = "TIC: Settings Mode:%s, RX:%s, EN:%s, Raw:%s, Skip:%d, Limit:%d";
|
2021-04-08 19:02:19 +01:00
|
|
|
|
2021-04-09 18:45:06 +01:00
|
|
|
#define MAX_TINFO_COMMAND_NAME 16+1 // Change this if one of the following kTInfo_Commands is higher then 16 char
|
|
|
|
const char kTInfo_Commands[] PROGMEM = "historique|standard|noraw|full|changed|skip|limit";
|
2021-04-08 19:02:19 +01:00
|
|
|
|
|
|
|
enum TInfoCommands { // commands for Console
|
|
|
|
CMND_TELEINFO_HISTORIQUE=0, // Set Legacy mode
|
|
|
|
CMND_TELEINFO_STANDARD, // Set Standard Mode
|
|
|
|
CMND_TELEINFO_RAW_DISABLE, // Disable Raw frame sending
|
|
|
|
CMND_TELEINFO_RAW_FULL, // Enable all RAW frame send
|
|
|
|
CMND_TELEINFO_RAW_CHANGE, // Enable only changed values RAW frame send
|
|
|
|
CMND_TELEINFO_SKIP, // Set number of frame to skip when raw mode is enabled
|
2021-04-09 18:45:06 +01:00
|
|
|
CMND_TELEINFO_LIMIT // Limit RAW frame to values subject to fast change (Power, Current, ...), TBD
|
2021-04-08 19:02:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-08-11 18:58:24 +01:00
|
|
|
// All contract type for legacy, standard mode has in clear text
|
2020-06-14 21:04:19 +01:00
|
|
|
enum TInfoContrat{
|
2020-10-28 16:32:07 +00:00
|
|
|
CONTRAT_BAS = 1, // BASE => Option Base.
|
|
|
|
CONTRAT_HC, // HC.. => Option Heures Creuses.
|
|
|
|
CONTRAT_EJP, // EJP. => Option EJP.
|
2020-06-17 18:54:40 +01:00
|
|
|
CONTRAT_BBR, // BBRx => Option Tempo
|
|
|
|
CONTRAT_END
|
2020-06-14 21:04:19 +01:00
|
|
|
};
|
|
|
|
|
2020-08-11 18:58:24 +01:00
|
|
|
// contract displayed name for legacy, standard mode has in clear text
|
2020-10-28 16:32:07 +00:00
|
|
|
const char kContratName[] PROGMEM =
|
2020-06-17 18:54:40 +01:00
|
|
|
"|Base|Heures Creuses|EJP|Bleu Blanc Rouge"
|
|
|
|
;
|
|
|
|
|
2020-08-11 18:58:24 +01:00
|
|
|
// Received current contract value for legacy, standard mode has in clear text
|
2020-10-28 16:32:07 +00:00
|
|
|
const char kContratValue[] PROGMEM =
|
2020-06-17 18:54:40 +01:00
|
|
|
"|BASE|HC..|EJP.|BBR"
|
|
|
|
;
|
|
|
|
|
2020-08-11 18:58:24 +01:00
|
|
|
// all tariff type for legacy, standard mode has in clear text
|
2020-06-14 21:04:19 +01:00
|
|
|
enum TInfoTarif{
|
2020-10-28 16:32:07 +00:00
|
|
|
TARIF_TH = 1,
|
|
|
|
TARIF_HC, TARIF_HP,
|
2020-06-17 18:54:40 +01:00
|
|
|
TARIF_HN, TARIF_PM,
|
|
|
|
TARIF_CB, TARIF_CW, TARIF_CR,
|
|
|
|
TARIF_PB, TARIF_PW, TARIF_PR,
|
|
|
|
TARIF_END
|
2020-06-14 21:04:19 +01:00
|
|
|
};
|
|
|
|
|
2021-04-06 01:23:06 +01:00
|
|
|
// Legacy mode Received current tariff values
|
2020-10-28 16:32:07 +00:00
|
|
|
const char kTarifValue[] PROGMEM =
|
|
|
|
"|TH..|HC..|HP.."
|
|
|
|
"|HN..|PM.."
|
|
|
|
"|HCJB|HCJW|HCJR"
|
|
|
|
"|HPJB|HPJW|HPJR"
|
2020-06-17 18:54:40 +01:00
|
|
|
;
|
|
|
|
|
2021-04-06 01:23:06 +01:00
|
|
|
// legacy mode tariff displayed name
|
2020-10-28 16:32:07 +00:00
|
|
|
const char kTarifName[] PROGMEM =
|
|
|
|
"|Toutes|Creuses|Pleines"
|
|
|
|
"|Normales|Pointe Mobile"
|
|
|
|
"|Creuses Bleu|Creuses Blanc|Creuse Rouges"
|
|
|
|
"|Pleines Bleu|Pleines Blanc|Pleines Rouges"
|
2020-06-17 18:54:40 +01:00
|
|
|
;
|
|
|
|
|
2021-04-06 01:23:06 +01:00
|
|
|
// contract name for standard mode
|
|
|
|
#define TELEINFO_STD_CONTRACT_BASE PSTR("BASE")
|
|
|
|
#define TELEINFO_STD_CONTRACT_HCHP PSTR("H CREUSE/PLEINE")
|
|
|
|
|
|
|
|
// tariff values for standard mode
|
|
|
|
#define TELEINFO_STD_TARIFF_BASE PSTR("BASE")
|
|
|
|
#define TELEINFO_STD_TARIFF_HC PSTR("HEURE CREUSE")
|
2021-10-02 17:29:05 +01:00
|
|
|
#define TELEINFO_STD_TARIFF_HP PSTR("HEURE PLEINE")
|
2021-04-06 01:23:06 +01:00
|
|
|
|
|
|
|
|
2020-08-11 18:58:24 +01:00
|
|
|
// Label used to do some post processing and/or calculation
|
2020-06-17 18:54:40 +01:00
|
|
|
enum TInfoLabel{
|
2020-10-28 16:32:07 +00:00
|
|
|
LABEL_BASE = 1,
|
2020-08-11 18:58:24 +01:00
|
|
|
LABEL_ADCO, LABEL_ADSC,
|
|
|
|
LABEL_HCHC, LABEL_HCHP, LABEL_EAST, LABEL_EASF01, LABEL_EASF02,
|
|
|
|
LABEL_OPTARIF, LABEL_NGTF, LABEL_ISOUSC, LABEL_PREF, LABEL_PTEC, LABEL_LTARF, LABEL_NTARF,
|
2021-10-02 17:29:05 +01:00
|
|
|
LABEL_PAPP, LABEL_SINSTS, LABEL_IINST, LABEL_IINST1, LABEL_IINST2, LABEL_IINST3, LABEL_IRMS1, LABEL_IRMS2, LABEL_IRMS3,
|
2021-04-20 18:16:55 +01:00
|
|
|
LABEL_TENSION, LABEL_URMS1, LABEL_URMS2, LABEL_URMS3,
|
|
|
|
LABEL_IMAX, LABEL_IMAX1, LABEL_IMAX2, LABEL_IMAX3, LABEL_PMAX, LABEL_SMAXSN,
|
2020-06-17 18:54:40 +01:00
|
|
|
LABEL_DEMAIN,
|
|
|
|
LABEL_END
|
2020-06-14 23:52:49 +01:00
|
|
|
};
|
2020-06-12 15:31:23 +01:00
|
|
|
|
2020-10-28 16:32:07 +00:00
|
|
|
const char kLabel[] PROGMEM =
|
2020-08-11 18:58:24 +01:00
|
|
|
"|BASE|ADCO|ADSC"
|
|
|
|
"|HCHC|HCHP|EAST|EASF01|EASF02"
|
|
|
|
"|OPTARIF|NGTF|ISOUSC|PREF|PTEC|LTARF|NTARF"
|
2021-04-20 18:16:55 +01:00
|
|
|
"|PAPP|SINSTS|IINST|IINST1|IINST2|IINST3|IRMS1|IRMS2|IRMS3"
|
|
|
|
"|TENSION|URMS1|URMS2|URMS3"
|
|
|
|
"|IMAX|IMAX1|IMAX2|IMAX3|PMAX|SMAXSN"
|
2020-06-17 18:54:40 +01:00
|
|
|
"|DEMAIN"
|
|
|
|
;
|
|
|
|
|
2021-10-02 17:29:05 +01:00
|
|
|
// Blacklisted label from telemetry
|
2021-04-20 18:16:55 +01:00
|
|
|
// Each label shoud be enclosed by pipe
|
2021-10-02 17:29:05 +01:00
|
|
|
const char kLabelBlacklist[]
|
2021-05-02 20:00:01 +01:00
|
|
|
// declared as progmem for ESP8266 just crash and reset on strstr()
|
|
|
|
#ifndef ESP8266
|
2021-10-02 17:29:05 +01:00
|
|
|
PROGMEM
|
2021-05-01 17:32:29 +01:00
|
|
|
#endif
|
2021-05-02 20:00:01 +01:00
|
|
|
=
|
2021-04-20 18:16:55 +01:00
|
|
|
"|PJOURF+1"
|
|
|
|
"|MSG1"
|
|
|
|
"|"
|
|
|
|
;
|
|
|
|
|
2021-02-10 20:08:59 +00:00
|
|
|
#define TELEINFO_SERIAL_BUFFER_STANDARD 512 // Receive buffer size for Standard mode
|
|
|
|
#define TELEINFO_SERIAL_BUFFER_HISTORIQUE 512 // Receive buffer size for Legacy mode
|
|
|
|
#define TELEINFO_PROCESS_BUFFER 32 // Local processing buffer
|
|
|
|
|
2020-06-12 15:31:23 +01:00
|
|
|
TInfo tinfo; // Teleinfo object
|
|
|
|
TasmotaSerial *TInfoSerial = nullptr;
|
2020-08-11 18:58:24 +01:00
|
|
|
_Mode_e tinfo_mode = TINFO_MODE_HISTORIQUE;
|
2021-04-20 18:16:55 +01:00
|
|
|
uint8_t tic_rx_pin = NOT_A_PIN;
|
2020-08-16 19:53:28 +01:00
|
|
|
char serialNumber[13] = ""; // Serial number is 12 char long
|
2020-06-12 15:31:23 +01:00
|
|
|
bool tinfo_found = false;
|
2021-05-01 17:32:29 +01:00
|
|
|
int serial_buffer_size;
|
2020-08-10 16:43:07 +01:00
|
|
|
int contrat;
|
|
|
|
int tarif;
|
|
|
|
int isousc;
|
2021-04-08 19:02:19 +01:00
|
|
|
int raw_skip;
|
2020-06-12 15:31:23 +01:00
|
|
|
|
|
|
|
/*********************************************************************************************/
|
2020-06-14 21:04:19 +01:00
|
|
|
|
2020-06-17 18:54:40 +01:00
|
|
|
/* ======================================================================
|
2020-10-28 16:32:07 +00:00
|
|
|
Function: getValueFromLabelIndex
|
2020-06-17 18:54:40 +01:00
|
|
|
Purpose : return label value from label index
|
|
|
|
Input : label index to search for
|
|
|
|
Output : value filled
|
|
|
|
Comments: -
|
|
|
|
====================================================================== */
|
|
|
|
char * getValueFromLabelIndex(int labelIndex, char * value)
|
|
|
|
{
|
|
|
|
char labelName[16];
|
|
|
|
// Get the label name
|
|
|
|
GetTextIndexed(labelName, sizeof(labelName), labelIndex, kLabel);
|
|
|
|
// Get value of label name
|
|
|
|
return tinfo.valueGet(labelName, value) ;
|
|
|
|
}
|
|
|
|
|
2020-06-12 15:31:23 +01:00
|
|
|
/* ======================================================================
|
2020-10-28 16:32:07 +00:00
|
|
|
Function: ADPSCallback
|
2020-06-12 15:31:23 +01:00
|
|
|
Purpose : called by library when we detected a ADPS on any phased
|
2020-10-28 16:32:07 +00:00
|
|
|
Input : phase number
|
2020-06-12 15:31:23 +01:00
|
|
|
0 for ADPS (monophase)
|
|
|
|
1 for ADIR1 triphase
|
|
|
|
2 for ADIR2 triphase
|
|
|
|
3 for ADIR3 triphase
|
2021-04-20 18:16:55 +01:00
|
|
|
label (different on Normal, 3 phases, historique or standard)
|
2020-10-28 16:32:07 +00:00
|
|
|
Output : -
|
2020-08-10 16:43:07 +01:00
|
|
|
Comments: should have been initialised with a
|
2020-06-12 15:31:23 +01:00
|
|
|
tinfo.attachADPSCallback(ADPSCallback())
|
|
|
|
====================================================================== */
|
2021-04-20 18:16:55 +01:00
|
|
|
void ADPSCallback(uint8_t phase, char * label)
|
2020-06-12 15:31:23 +01:00
|
|
|
{
|
2020-08-10 16:43:07 +01:00
|
|
|
// n = phase number 1 to 3
|
|
|
|
if (phase == 0){
|
|
|
|
phase = 1;
|
|
|
|
}
|
2020-08-11 18:58:24 +01:00
|
|
|
|
2021-05-23 15:50:17 +01:00
|
|
|
Response_P(PSTR("{\"TIC\":{\"%s\":%i}}"), label, phase );
|
2020-08-16 19:53:28 +01:00
|
|
|
// Publish adding ADCO serial number into the topic
|
2021-04-20 18:16:55 +01:00
|
|
|
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_SENSOR), false);
|
2020-08-10 16:43:07 +01:00
|
|
|
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("ADPS on phase %d"), phase);
|
2020-06-12 15:31:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ======================================================================
|
2020-10-28 16:32:07 +00:00
|
|
|
Function: DataCallback
|
2020-06-12 15:31:23 +01:00
|
|
|
Purpose : callback when we detected new or modified data received
|
|
|
|
Input : linked list pointer on the concerned data
|
|
|
|
current flags value
|
2020-10-28 16:32:07 +00:00
|
|
|
Output : -
|
2020-06-12 15:31:23 +01:00
|
|
|
Comments: -
|
|
|
|
====================================================================== */
|
|
|
|
void DataCallback(struct _ValueList * me, uint8_t flags)
|
|
|
|
{
|
2020-06-14 21:04:19 +01:00
|
|
|
char c = ' ';
|
2020-06-17 18:54:40 +01:00
|
|
|
int ilabel ;
|
2020-06-14 21:04:19 +01:00
|
|
|
|
2021-05-01 17:32:29 +01:00
|
|
|
char labelName[17];
|
|
|
|
// Find the label index
|
|
|
|
for ( ilabel = 1 ; ilabel < LABEL_END ; ilabel++) {
|
|
|
|
GetTextIndexed(labelName, sizeof(labelName), ilabel, kLabel);
|
|
|
|
if (!strcmp(labelName, me->name)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We found valid label
|
|
|
|
if (ilabel<LABEL_END) {
|
|
|
|
|
|
|
|
// First values that needs to have energy object updated (in all case)
|
|
|
|
// Voltage V (not present on all Smart Meter)
|
|
|
|
if ( ilabel == LABEL_TENSION || ilabel == LABEL_URMS1 || ilabel == LABEL_URMS2 || ilabel == LABEL_URMS3)
|
|
|
|
{
|
|
|
|
Energy.voltage_available = true;
|
|
|
|
float volt = (float) atoi(me->value);
|
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Voltage %s=%s, now %d"), me->name, me->value, (int) volt);
|
|
|
|
|
2021-10-02 17:29:05 +01:00
|
|
|
if ( ilabel == LABEL_URMS2) {
|
2021-05-01 17:32:29 +01:00
|
|
|
Energy.voltage[1] = volt;
|
|
|
|
} else if ( ilabel == LABEL_URMS3) {
|
|
|
|
Energy.voltage[2] = volt;
|
|
|
|
} else {
|
|
|
|
Energy.voltage[0] = volt;
|
2020-06-17 18:54:40 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-12 15:31:23 +01:00
|
|
|
|
2021-05-01 17:32:29 +01:00
|
|
|
// Current I phase 1 to 3
|
2021-10-02 17:29:05 +01:00
|
|
|
else if (ilabel == LABEL_IINST
|
2021-05-01 17:32:29 +01:00
|
|
|
|| ilabel == LABEL_IINST1 || ilabel == LABEL_IRMS1
|
|
|
|
|| ilabel == LABEL_IINST2 || ilabel == LABEL_IRMS2
|
|
|
|
|| ilabel == LABEL_IINST3 || ilabel == LABEL_IRMS3 )
|
|
|
|
{
|
|
|
|
Energy.current_available = true;
|
|
|
|
float current = (float) atoi(me->value);
|
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Current %s=%s, now %d"), me->name, me->value, (int) current);
|
2020-08-16 19:53:28 +01:00
|
|
|
|
2021-05-01 17:32:29 +01:00
|
|
|
if (ilabel == LABEL_IINST2 || ilabel == LABEL_IRMS2) {
|
|
|
|
Energy.current[1] = current;
|
|
|
|
} else if (ilabel == LABEL_IINST3 || ilabel == LABEL_IRMS3) {
|
|
|
|
Energy.phase_count = 3;
|
|
|
|
Energy.current[2] = current;
|
|
|
|
} else {
|
|
|
|
Energy.current[0] = current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Power P
|
|
|
|
else if (ilabel == LABEL_PAPP || ilabel == LABEL_SINSTS)
|
|
|
|
{
|
|
|
|
Energy.active_power[0] = (float) atoi(me->value);;
|
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Power %s, now %d"), me->value, (int) Energy.active_power[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ok now not so real time values Does this value is new or changed?
|
|
|
|
else if (flags & (TINFO_FLAGS_ADDED | TINFO_FLAGS_UPDATED) ) {
|
|
|
|
|
|
|
|
if (flags & TINFO_FLAGS_ADDED) { c = '#'; }
|
|
|
|
if (flags & TINFO_FLAGS_UPDATED) { c = '*'; }
|
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: [%d]%c %s=%s"), ilabel, c , me->name, me->value);
|
2020-08-16 19:53:28 +01:00
|
|
|
|
|
|
|
// Current tariff (legacy)
|
|
|
|
if (ilabel == LABEL_PTEC)
|
|
|
|
{
|
|
|
|
char tarif_value[] = " "; // 4 spaces
|
|
|
|
// Find the tariff index
|
|
|
|
for (tarif = TARIF_TH ; tarif < TARIF_END ; tarif++) {
|
|
|
|
GetTextIndexed(tarif_value, sizeof(tarif_value), tarif-1, kTarifValue);
|
2020-10-28 16:32:07 +00:00
|
|
|
if (!strcmp(tarif_value, me->value)) {
|
2020-08-16 19:53:28 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-06-17 18:54:40 +01:00
|
|
|
}
|
2021-02-10 20:08:59 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Tariff changed, now '%s' (%d)"), me->value, tarif);
|
2020-10-28 16:32:07 +00:00
|
|
|
}
|
2020-08-16 19:53:28 +01:00
|
|
|
|
2021-04-06 01:23:06 +01:00
|
|
|
// Current tariff (standard)
|
2020-08-16 19:53:28 +01:00
|
|
|
else if (ilabel == LABEL_LTARF)
|
|
|
|
{
|
2021-05-02 19:39:43 +01:00
|
|
|
if (!strcmp_P(me->value, TELEINFO_STD_TARIFF_BASE)) {
|
2021-04-06 01:23:06 +01:00
|
|
|
tarif = TARIF_TH;
|
2021-05-02 19:39:43 +01:00
|
|
|
} else if (!strcmp_P(me->value, TELEINFO_STD_TARIFF_HC)) {
|
2021-04-06 01:23:06 +01:00
|
|
|
tarif = TARIF_HC;
|
2021-05-02 19:39:43 +01:00
|
|
|
} else if (!strcmp_P(me->value, TELEINFO_STD_TARIFF_HP)) {
|
2021-04-06 01:23:06 +01:00
|
|
|
tarif = TARIF_HP;
|
|
|
|
}
|
2021-02-10 20:08:59 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Tariff name changed, now '%s'"), me->value);
|
2020-10-28 16:32:07 +00:00
|
|
|
}
|
2021-04-06 01:23:06 +01:00
|
|
|
// Current tariff index (standard)
|
|
|
|
// This is the index on pointer counter (not used just for information)
|
2020-08-16 19:53:28 +01:00
|
|
|
else if (ilabel == LABEL_NTARF)
|
|
|
|
{
|
2021-04-06 01:23:06 +01:00
|
|
|
int index = atoi(me->value);
|
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Tariff index changed, now '%d'"), index);
|
2020-10-28 16:32:07 +00:00
|
|
|
}
|
2020-08-16 19:53:28 +01:00
|
|
|
|
|
|
|
// Wh indexes (legacy)
|
2020-08-21 11:32:27 +01:00
|
|
|
else if ( ilabel == LABEL_HCHC || ilabel == LABEL_HCHP || ilabel == LABEL_BASE)
|
2020-08-16 19:53:28 +01:00
|
|
|
{
|
|
|
|
char value[32];
|
|
|
|
uint32_t hc = 0;
|
|
|
|
uint32_t hp = 0;
|
|
|
|
uint32_t total = 0;
|
2020-06-17 18:54:40 +01:00
|
|
|
|
2020-08-21 11:32:27 +01:00
|
|
|
// Base, un seul index
|
|
|
|
if (ilabel == LABEL_BASE) {
|
|
|
|
total = atoi(me->value);
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Base:%u"), total);
|
2020-08-21 11:32:27 +01:00
|
|
|
// Heures creuses/pleines calculer total
|
|
|
|
} else {
|
|
|
|
// Heures creuses get heures pleines
|
|
|
|
if (ilabel == LABEL_HCHC) {
|
|
|
|
hc = atoi(me->value);
|
2020-10-28 16:32:07 +00:00
|
|
|
if ( getValueFromLabelIndex(LABEL_HCHP, value) ) {
|
2020-08-21 11:32:27 +01:00
|
|
|
hp = atoi(value);
|
|
|
|
}
|
2020-10-28 16:32:07 +00:00
|
|
|
|
2020-08-21 11:32:27 +01:00
|
|
|
// Heures pleines, get heures creuses
|
|
|
|
} else if (ilabel == LABEL_HCHP) {
|
|
|
|
hp = atoi(me->value);
|
2020-10-28 16:32:07 +00:00
|
|
|
if ( getValueFromLabelIndex(LABEL_HCHC, value) ) {
|
2020-08-21 11:32:27 +01:00
|
|
|
hc = atoi(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
total = hc + hp;
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%u HP:%u Total:%u"), hc, hp, total);
|
2020-08-21 11:32:27 +01:00
|
|
|
}
|
2020-08-14 18:47:13 +01:00
|
|
|
|
2021-10-02 17:29:05 +01:00
|
|
|
Energy.import_active[0] = total/1000.0f;
|
|
|
|
EnergyUpdateTotal();
|
2020-08-14 18:47:13 +01:00
|
|
|
}
|
2020-06-17 18:54:40 +01:00
|
|
|
|
2020-10-28 16:32:07 +00:00
|
|
|
// Wh total index (standard)
|
2020-08-16 19:53:28 +01:00
|
|
|
else if ( ilabel == LABEL_EAST)
|
|
|
|
{
|
|
|
|
uint32_t total = atoi(me->value);
|
2021-04-06 01:23:06 +01:00
|
|
|
if (contrat != CONTRAT_BAS) {
|
2021-10-02 17:29:05 +01:00
|
|
|
Energy.import_active[0] = total/1000.0f;
|
|
|
|
EnergyUpdateTotal();
|
2021-04-06 01:23:06 +01:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Total:%uWh"), total);
|
|
|
|
}
|
2020-08-14 18:47:13 +01:00
|
|
|
}
|
2020-08-11 18:58:24 +01:00
|
|
|
|
2020-08-16 19:53:28 +01:00
|
|
|
// Wh indexes (standard)
|
|
|
|
else if ( ilabel == LABEL_EASF01)
|
|
|
|
{
|
2021-04-06 01:23:06 +01:00
|
|
|
if (contrat == CONTRAT_BAS) {
|
2021-10-02 17:29:05 +01:00
|
|
|
Energy.import_active[0] = atoi(me->value)/1000.0f;
|
|
|
|
EnergyUpdateTotal();
|
2021-04-06 01:23:06 +01:00
|
|
|
}
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%u"), atoi(me->value));
|
2020-08-16 19:53:28 +01:00
|
|
|
}
|
|
|
|
else if ( ilabel == LABEL_EASF02)
|
|
|
|
{
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HP:%u"), atoi(me->value));
|
2020-08-16 19:53:28 +01:00
|
|
|
}
|
2020-08-11 18:58:24 +01:00
|
|
|
|
2020-08-16 19:53:28 +01:00
|
|
|
// Contract subscribed (legacy)
|
|
|
|
else if (ilabel == LABEL_OPTARIF)
|
|
|
|
{
|
|
|
|
char contrat_value[] = " "; // 4 spaces
|
|
|
|
// Find the contract index
|
|
|
|
for (contrat = CONTRAT_BAS ; contrat < CONTRAT_END ; contrat++) {
|
|
|
|
GetTextIndexed(contrat_value, sizeof(contrat_value), contrat, kContratValue);
|
2020-10-28 16:32:07 +00:00
|
|
|
if (!strcmp(contrat_value, me->value)) {
|
2020-08-16 19:53:28 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-06-17 18:54:40 +01:00
|
|
|
}
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Contract changed, now '%s' (%d)"), me->value, contrat);
|
2020-10-28 16:32:07 +00:00
|
|
|
}
|
2020-08-16 19:53:28 +01:00
|
|
|
// Contract subscribed (standard is in clear text in value)
|
|
|
|
else if (ilabel == LABEL_NGTF)
|
|
|
|
{
|
2021-05-02 19:39:43 +01:00
|
|
|
if (!strcmp_P(me->value, TELEINFO_STD_CONTRACT_BASE)) {
|
2021-04-06 01:23:06 +01:00
|
|
|
contrat = CONTRAT_BAS;
|
2021-05-02 19:39:43 +01:00
|
|
|
} else if (!strcmp_P(me->value, TELEINFO_STD_CONTRACT_HCHP)) {
|
2021-04-06 01:23:06 +01:00
|
|
|
contrat = CONTRAT_HC;
|
|
|
|
}
|
|
|
|
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Contract changed, now '%s'"), me->value);
|
2020-10-28 16:32:07 +00:00
|
|
|
}
|
2020-08-16 19:53:28 +01:00
|
|
|
|
|
|
|
// Contract subscribed (Power)
|
|
|
|
else if (ilabel == LABEL_ISOUSC || ilabel == LABEL_PREF)
|
|
|
|
{
|
|
|
|
isousc = atoi( me->value);
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: ISousc set to %d"), isousc);
|
2020-10-28 16:32:07 +00:00
|
|
|
}
|
2020-08-16 19:53:28 +01:00
|
|
|
|
|
|
|
// Serial Number of device
|
|
|
|
else if (ilabel == LABEL_ADCO || ilabel == LABEL_ADSC)
|
|
|
|
{
|
|
|
|
strcpy(serialNumber, me->value);
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: %s set to %s"), me->name, serialNumber);
|
2020-10-28 16:32:07 +00:00
|
|
|
}
|
2020-08-16 19:53:28 +01:00
|
|
|
}
|
2020-06-14 21:04:19 +01:00
|
|
|
}
|
2020-06-12 15:31:23 +01:00
|
|
|
}
|
2021-05-01 17:32:29 +01:00
|
|
|
|
2021-04-20 18:16:55 +01:00
|
|
|
/* ======================================================================
|
|
|
|
Function: isBlacklistedLabel
|
|
|
|
Purpose : check is a label is blacklisted for telemetry data
|
|
|
|
Input : label name
|
|
|
|
Output : true if blacklisted
|
|
|
|
Comments: -
|
|
|
|
====================================================================== */
|
|
|
|
bool isBlacklistedLabel(char * name)
|
|
|
|
{
|
2021-05-01 17:32:29 +01:00
|
|
|
bool bl = false;
|
|
|
|
// return strstr( kLabelBlacklist, name)==nullptr ? false : true;
|
|
|
|
if ( strstr(kLabelBlacklist, name) ) {
|
|
|
|
//if ( strstr("|PJOURF+1|MSG1|ADCO|", name) ) {
|
|
|
|
bl = true;
|
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: %s is blacklisted"), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bl;
|
2021-04-20 18:16:55 +01:00
|
|
|
}
|
2020-06-12 15:31:23 +01:00
|
|
|
|
2020-06-14 23:52:49 +01:00
|
|
|
/* ======================================================================
|
2020-10-28 16:32:07 +00:00
|
|
|
Function: responseDumpTInfo
|
2020-08-16 19:53:28 +01:00
|
|
|
Purpose : add teleinfo values into JSON response
|
2020-08-23 10:17:33 +01:00
|
|
|
Input : 1st separator space if begining of JSON, else comma
|
2021-04-08 19:02:19 +01:00
|
|
|
: select if append all data or just changed one
|
2021-04-09 23:49:38 +01:00
|
|
|
Output : false if asked for changed value and none has changed else true
|
2020-06-14 23:52:49 +01:00
|
|
|
Comments: -
|
|
|
|
====================================================================== */
|
2021-04-09 23:49:38 +01:00
|
|
|
bool ResponseAppendTInfo(char sep, bool all)
|
2020-06-14 23:52:49 +01:00
|
|
|
{
|
2020-08-16 19:53:28 +01:00
|
|
|
struct _ValueList * me = tinfo.getList();
|
2020-08-14 18:47:13 +01:00
|
|
|
|
2020-08-16 19:53:28 +01:00
|
|
|
char * p ;
|
2021-04-09 23:49:38 +01:00
|
|
|
bool isNumber ;
|
|
|
|
bool hasValue = false;
|
2020-08-14 18:47:13 +01:00
|
|
|
|
2020-08-16 19:53:28 +01:00
|
|
|
// Loop thru all the teleinfo frame but
|
|
|
|
// always check we don't buffer overflow of MQTT data
|
|
|
|
while (me->next) {
|
|
|
|
// go to next node
|
|
|
|
me = me->next;
|
2020-08-14 18:47:13 +01:00
|
|
|
|
2020-08-16 19:53:28 +01:00
|
|
|
if (me->name && me->value && *me->name && *me->value) {
|
2020-08-14 18:47:13 +01:00
|
|
|
|
2021-04-20 18:16:55 +01:00
|
|
|
// Does this label blacklisted ?
|
|
|
|
if (!isBlacklistedLabel(me->name)) {
|
2021-04-08 19:02:19 +01:00
|
|
|
|
2021-04-20 18:16:55 +01:00
|
|
|
// Add values only if we want all data or if data has changed
|
2021-06-11 17:14:12 +01:00
|
|
|
if (all || ( Settings->teleinfo.raw_report_changed && (me->flags & (TINFO_FLAGS_UPDATED | TINFO_FLAGS_ADDED | TINFO_FLAGS_ALERT) ) ) ) {
|
2021-04-08 19:02:19 +01:00
|
|
|
|
2021-04-20 18:16:55 +01:00
|
|
|
isNumber = true;
|
|
|
|
hasValue = true;
|
|
|
|
p = me->value;
|
|
|
|
|
|
|
|
// Specific treatment serial number don't convert to number later
|
|
|
|
if (strcmp(me->name, "ADCO")==0 || strcmp(me->name, "ADSC")==0) {
|
|
|
|
isNumber = false;
|
|
|
|
} else {
|
|
|
|
// check if value is number
|
|
|
|
while (*p && isNumber) {
|
|
|
|
if ( *p < '0' || *p > '9' ) {
|
|
|
|
isNumber = false;
|
|
|
|
}
|
|
|
|
p++;
|
2021-04-08 19:02:19 +01:00
|
|
|
}
|
2020-08-14 18:47:13 +01:00
|
|
|
}
|
|
|
|
|
2021-04-20 18:16:55 +01:00
|
|
|
// Avoid unneeded space
|
|
|
|
if (sep == ' ') {
|
|
|
|
ResponseAppend_P( PSTR("\"%s\":"), me->name );
|
|
|
|
} else {
|
|
|
|
ResponseAppend_P( PSTR("%c\"%s\":"), sep, me->name );
|
|
|
|
}
|
2020-08-14 18:47:13 +01:00
|
|
|
|
2021-04-20 18:16:55 +01:00
|
|
|
if (!isNumber) {
|
|
|
|
ResponseAppend_P( PSTR("\"%s\""), me->value );
|
|
|
|
} else {
|
|
|
|
ResponseAppend_P( PSTR("%d"), atoi(me->value));
|
|
|
|
}
|
2020-08-14 18:47:13 +01:00
|
|
|
|
2021-04-20 18:16:55 +01:00
|
|
|
// Now JSON separator is needed
|
|
|
|
sep =',';
|
|
|
|
}
|
2021-04-08 19:02:19 +01:00
|
|
|
}
|
2020-08-16 19:53:28 +01:00
|
|
|
}
|
2020-08-14 18:47:13 +01:00
|
|
|
}
|
2021-04-20 18:16:55 +01:00
|
|
|
|
2021-04-09 23:49:38 +01:00
|
|
|
return hasValue;
|
2020-08-16 19:53:28 +01:00
|
|
|
}
|
2020-08-14 18:47:13 +01:00
|
|
|
|
2020-08-16 19:53:28 +01:00
|
|
|
/* ======================================================================
|
2020-10-28 16:32:07 +00:00
|
|
|
Function: NewFrameCallback
|
2020-08-16 19:53:28 +01:00
|
|
|
Purpose : callback when we received a complete Teleinfo frama
|
|
|
|
Input : linked list pointer on the concerned data
|
2020-10-28 16:32:07 +00:00
|
|
|
Output : -
|
2020-08-16 19:53:28 +01:00
|
|
|
Comments: -
|
|
|
|
====================================================================== */
|
|
|
|
void NewFrameCallback(struct _ValueList * me)
|
|
|
|
{
|
|
|
|
// Reset Energy Watchdog
|
|
|
|
Energy.data_valid[0] = 0;
|
2020-08-14 18:47:13 +01:00
|
|
|
|
2021-04-08 19:02:19 +01:00
|
|
|
// Deprecated see setOption108
|
|
|
|
// send teleinfo raw data only if setup like that
|
2021-06-11 17:14:12 +01:00
|
|
|
if (Settings->teleinfo.raw_send) {
|
2021-04-08 19:02:19 +01:00
|
|
|
// Do we need to skip this frame
|
|
|
|
if (raw_skip == 0 ) {
|
2021-04-20 18:16:55 +01:00
|
|
|
Response_P(PSTR("{\"TIC\":{"));
|
2021-04-08 19:02:19 +01:00
|
|
|
// send teleinfo full frame or only changed data
|
2021-06-11 17:14:12 +01:00
|
|
|
bool hasData = ResponseAppendTInfo(' ', Settings->teleinfo.raw_report_changed ? false : true );
|
2021-04-20 18:16:55 +01:00
|
|
|
ResponseJsonEndEnd();
|
2021-10-02 17:29:05 +01:00
|
|
|
|
2021-04-08 19:02:19 +01:00
|
|
|
// Publish adding ADCO serial number into the topic
|
|
|
|
// Need setOption4 to be enabled
|
2021-04-09 23:49:38 +01:00
|
|
|
// No need to send empty payload
|
|
|
|
if (hasData) {
|
2021-04-20 18:16:55 +01:00
|
|
|
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_SENSOR), false);
|
2021-04-09 23:49:38 +01:00
|
|
|
}
|
2021-04-08 19:02:19 +01:00
|
|
|
|
|
|
|
// Reset frame skip counter (if 0 it's disabled)
|
2021-06-11 17:14:12 +01:00
|
|
|
raw_skip = Settings->teleinfo.raw_skip;
|
2021-04-08 19:02:19 +01:00
|
|
|
} else {
|
2021-04-09 18:45:06 +01:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: not sending yet, will do in %d frame(s)"), raw_skip);
|
|
|
|
raw_skip--;
|
2021-04-08 19:02:19 +01:00
|
|
|
}
|
2020-08-16 19:53:28 +01:00
|
|
|
}
|
2020-06-14 23:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ======================================================================
|
2020-10-28 16:32:07 +00:00
|
|
|
Function: TInfoDrvInit
|
|
|
|
Purpose : Tasmota core driver init
|
2020-06-17 18:54:40 +01:00
|
|
|
Input : -
|
2020-10-28 16:32:07 +00:00
|
|
|
Output : -
|
2020-06-14 23:52:49 +01:00
|
|
|
Comments: -
|
|
|
|
====================================================================== */
|
2020-06-12 15:31:23 +01:00
|
|
|
void TInfoDrvInit(void) {
|
2021-04-20 18:16:55 +01:00
|
|
|
// If one TInfo RX pin declared use it
|
|
|
|
if (PinUsed(GPIO_TELEINFO_RX)) {
|
|
|
|
tic_rx_pin = Pin(GPIO_TELEINFO_RX);
|
|
|
|
TasmotaGlobal.energy_driver = XNRG_15;
|
|
|
|
Energy.voltage_available = false;
|
2021-05-01 17:32:29 +01:00
|
|
|
Energy.phase_count = 1;
|
2021-04-20 18:16:55 +01:00
|
|
|
}
|
2020-06-12 15:31:23 +01:00
|
|
|
}
|
|
|
|
|
2020-06-17 18:54:40 +01:00
|
|
|
/* ======================================================================
|
2020-10-28 16:32:07 +00:00
|
|
|
Function: TInfoInit
|
|
|
|
Purpose : Tasmota core device init
|
2020-06-17 18:54:40 +01:00
|
|
|
Input : -
|
2020-10-28 16:32:07 +00:00
|
|
|
Output : -
|
2021-05-01 17:32:29 +01:00
|
|
|
Comments: -
|
2020-06-17 18:54:40 +01:00
|
|
|
====================================================================== */
|
2020-06-12 15:31:23 +01:00
|
|
|
void TInfoInit(void)
|
|
|
|
{
|
2021-09-12 18:44:01 +01:00
|
|
|
if (!PinUsed(GPIO_TELEINFO_RX)) { return; } // ignore if pin not set
|
2020-08-11 18:58:24 +01:00
|
|
|
int baudrate;
|
2021-02-10 20:08:59 +00:00
|
|
|
|
2021-04-08 19:02:19 +01:00
|
|
|
// Deprecated SetOption102 - Set Baud rate for Teleinfo serial communication (0 = 1200 or 1 = 9600)
|
|
|
|
// now set in bit field TeleinfoCfg
|
2021-06-11 17:14:12 +01:00
|
|
|
if (Settings->teleinfo.mode_standard) {
|
2020-10-28 16:32:07 +00:00
|
|
|
baudrate = 9600;
|
2020-08-11 18:58:24 +01:00
|
|
|
tinfo_mode = TINFO_MODE_STANDARD;
|
2021-02-10 20:08:59 +00:00
|
|
|
serial_buffer_size = TELEINFO_SERIAL_BUFFER_STANDARD;
|
|
|
|
} else {
|
2020-10-28 16:32:07 +00:00
|
|
|
baudrate = 1200;
|
2020-08-11 18:58:24 +01:00
|
|
|
tinfo_mode = TINFO_MODE_HISTORIQUE;
|
2021-02-10 20:08:59 +00:00
|
|
|
serial_buffer_size = TELEINFO_SERIAL_BUFFER_HISTORIQUE;
|
2020-08-11 18:58:24 +01:00
|
|
|
}
|
|
|
|
|
2021-04-20 18:16:55 +01:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("TIC: RX on GPIO%d, baudrate %d"), tic_rx_pin, baudrate);
|
2021-04-08 19:02:19 +01:00
|
|
|
|
2021-04-20 18:16:55 +01:00
|
|
|
// Enable Teleinfo pin used, control it
|
|
|
|
if (PinUsed(GPIO_TELEINFO_ENABLE)) {
|
|
|
|
int8_t en_pin = Pin(GPIO_TELEINFO_ENABLE);
|
|
|
|
pinMode(en_pin, OUTPUT);
|
|
|
|
digitalWrite(en_pin, HIGH);
|
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("TIC: Enable with GPIO%d"), en_pin);
|
|
|
|
}
|
2020-06-12 15:31:23 +01:00
|
|
|
|
2020-11-28 16:00:15 +00:00
|
|
|
#ifdef ESP8266
|
2021-04-20 18:16:55 +01:00
|
|
|
// Allow GPIO3 AND GPIO13 with hardware fallback to 2
|
|
|
|
// Set buffer to nnn char to support 250ms loop at 9600 baud
|
|
|
|
TInfoSerial = new TasmotaSerial(tic_rx_pin, -1, 2, 0, serial_buffer_size);
|
|
|
|
//pinMode(rx_pin, INPUT_PULLUP);
|
2020-11-28 16:00:15 +00:00
|
|
|
#endif // ESP8266
|
|
|
|
#ifdef ESP32
|
2021-04-20 18:16:55 +01:00
|
|
|
// Set buffer to nnn char to support 250ms loop at 9600 baud
|
|
|
|
TInfoSerial = new TasmotaSerial(tic_rx_pin, -1, 1, 0, serial_buffer_size);
|
2020-11-28 16:00:15 +00:00
|
|
|
#endif // ESP32
|
2020-06-12 15:31:23 +01:00
|
|
|
|
2021-09-12 18:44:01 +01:00
|
|
|
if (TInfoSerial->begin(baudrate, SERIAL_7E1)) {
|
2020-11-28 16:00:15 +00:00
|
|
|
#ifdef ESP8266
|
2021-04-20 18:16:55 +01:00
|
|
|
if (TInfoSerial->hardwareSerial() ) {
|
|
|
|
ClaimSerial();
|
2020-08-10 16:43:07 +01:00
|
|
|
|
2021-04-20 18:16:55 +01:00
|
|
|
// This is a hack, looks like begin does not take into account
|
|
|
|
// the TS_SERIAL_7E1 configuration so on ESP8266 this is
|
|
|
|
// working only on Serial RX pin (Hardware Serial) for now
|
2020-10-28 16:32:07 +00:00
|
|
|
|
2021-04-20 18:16:55 +01:00
|
|
|
//SetSerialConfig(TS_SERIAL_7E1);
|
|
|
|
//TInfoSerial->setTimeout(TINFO_READ_TIMEOUT);
|
2020-08-10 16:43:07 +01:00
|
|
|
|
2021-04-20 18:16:55 +01:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("TIC: using hardware serial"));
|
|
|
|
} else {
|
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("TIC: using software serial"));
|
|
|
|
}
|
2020-11-28 16:00:15 +00:00
|
|
|
#endif // ESP8266
|
2021-04-20 18:16:55 +01:00
|
|
|
// Init teleinfo
|
|
|
|
tinfo.init(tinfo_mode);
|
|
|
|
// Attach needed callbacks
|
|
|
|
tinfo.attachADPS(ADPSCallback);
|
|
|
|
tinfo.attachData(DataCallback);
|
|
|
|
tinfo.attachNewFrame(NewFrameCallback);
|
|
|
|
tinfo_found = true;
|
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
if (Settings->teleinfo.raw_send) {
|
|
|
|
raw_skip = Settings->teleinfo.raw_skip;
|
2021-04-20 18:16:55 +01:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("TIC: Raw mode enabled"));
|
|
|
|
if (raw_skip) {
|
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("TIC: Sending only one frame over %d "), raw_skip+1);
|
2021-10-02 17:29:05 +01:00
|
|
|
}
|
2020-06-12 15:31:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-08 19:02:19 +01:00
|
|
|
|
|
|
|
/* ======================================================================
|
|
|
|
Function: TInfoCmd
|
|
|
|
Purpose : Tasmota core command engine for Teleinfo commands
|
|
|
|
Input : -
|
|
|
|
Output : -
|
|
|
|
Comments: -
|
|
|
|
====================================================================== */
|
|
|
|
bool TInfoCmd(void) {
|
2021-04-09 18:45:06 +01:00
|
|
|
bool serviced = false;
|
2021-04-08 19:02:19 +01:00
|
|
|
char command[CMDSZ];
|
2021-04-09 23:49:38 +01:00
|
|
|
//uint8_t name_len = strlen(D_NAME_TELEINFO);
|
|
|
|
|
|
|
|
// At least "EnergyConfig"
|
|
|
|
if (CMND_ENERGYCONFIG == Energy.command_code) {
|
2021-04-08 19:02:19 +01:00
|
|
|
|
2021-06-05 10:47:09 +01:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: len %d, data '%s'"), XdrvMailbox.data_len, XdrvMailbox.data ? XdrvMailbox.data : "null" );
|
2021-04-09 23:49:38 +01:00
|
|
|
|
|
|
|
// Just "EnergyConfig" no more parameter
|
2021-10-02 17:29:05 +01:00
|
|
|
// Show Teleinfo configuration
|
2021-04-09 23:49:38 +01:00
|
|
|
if (XdrvMailbox.data_len == 0) {
|
2021-04-09 18:45:06 +01:00
|
|
|
char mode_name[MAX_TINFO_COMMAND_NAME];
|
|
|
|
char raw_name[MAX_TINFO_COMMAND_NAME];
|
2021-10-27 12:56:22 +01:00
|
|
|
char rx_pin[8] = "None";
|
|
|
|
char en_pin[8] = "None" ;
|
2021-06-11 17:14:12 +01:00
|
|
|
int index_mode = Settings->teleinfo.mode_standard ? CMND_TELEINFO_STANDARD : CMND_TELEINFO_HISTORIQUE;
|
|
|
|
int index_raw = Settings->teleinfo.raw_send ? CMND_TELEINFO_RAW_FULL : CMND_TELEINFO_RAW_DISABLE;
|
|
|
|
if (Settings->teleinfo.raw_send && Settings->teleinfo.raw_report_changed) {
|
2021-04-09 18:45:06 +01:00
|
|
|
index_raw = CMND_TELEINFO_RAW_CHANGE;
|
2021-10-02 17:29:05 +01:00
|
|
|
}
|
2021-04-09 18:45:06 +01:00
|
|
|
// Get the mode and raw name
|
|
|
|
GetTextIndexed(mode_name, MAX_TINFO_COMMAND_NAME, index_mode, kTInfo_Commands);
|
|
|
|
GetTextIndexed(raw_name, MAX_TINFO_COMMAND_NAME, index_raw, kTInfo_Commands);
|
|
|
|
|
2021-10-27 12:56:22 +01:00
|
|
|
if (PinUsed(GPIO_TELEINFO_RX)) {
|
|
|
|
sprintf_P(rx_pin, PSTR("GPIO%d"), tic_rx_pin);
|
|
|
|
}
|
|
|
|
if (PinUsed(GPIO_TELEINFO_ENABLE)) {
|
|
|
|
sprintf_P(en_pin, PSTR("GPIO%d"), Pin(GPIO_TELEINFO_ENABLE));
|
|
|
|
}
|
|
|
|
|
|
|
|
AddLog(LOG_LEVEL_INFO, TELEINFO_COMMAND_SETTINGS, mode_name, rx_pin, en_pin, raw_name, Settings->teleinfo.raw_skip, Settings->teleinfo.raw_limit);
|
2021-04-09 18:45:06 +01:00
|
|
|
|
|
|
|
serviced = true;
|
|
|
|
|
2021-10-02 17:29:05 +01:00
|
|
|
// At least "EnergyConfig xyz" plus one space and one (or more) char
|
2021-04-09 23:49:38 +01:00
|
|
|
// so "EnergyConfig 0" or "EnergyConfig Teleinfo Standard"
|
|
|
|
} else if (XdrvMailbox.data_len) {
|
2021-04-09 18:45:06 +01:00
|
|
|
// Now point on parameter
|
2021-04-09 23:49:38 +01:00
|
|
|
char *pParam = XdrvMailbox.data;
|
2021-04-09 18:45:06 +01:00
|
|
|
char *p = pParam;
|
|
|
|
char *pValue = nullptr;
|
|
|
|
// Check for sub parameter ie : EnergyConfig Teleinfo Skip value
|
|
|
|
while(*p) {
|
|
|
|
if (*p == ' ') {
|
|
|
|
if (*(p+1)) {
|
|
|
|
// Skip parameter by emptying th string so below getcommandcode works
|
|
|
|
*p++ = 0x00;
|
|
|
|
// Save parameter value for later
|
|
|
|
pValue = p;
|
|
|
|
}
|
|
|
|
break;
|
2021-04-08 19:02:19 +01:00
|
|
|
}
|
2021-04-09 18:45:06 +01:00
|
|
|
p++;
|
2021-04-08 19:02:19 +01:00
|
|
|
}
|
|
|
|
|
2021-04-09 18:45:06 +01:00
|
|
|
int command_code = GetCommandCode(command, sizeof(command), pParam, kTInfo_Commands);
|
|
|
|
|
2021-06-05 10:47:09 +01:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: param '%s' cmnd %d"), pParam, command_code);
|
2021-04-09 18:45:06 +01:00
|
|
|
|
|
|
|
switch (command_code) {
|
|
|
|
case CMND_TELEINFO_STANDARD:
|
|
|
|
case CMND_TELEINFO_HISTORIQUE: {
|
2021-04-08 19:02:19 +01:00
|
|
|
char mode_name[MAX_TINFO_COMMAND_NAME];
|
|
|
|
|
2021-04-09 18:45:06 +01:00
|
|
|
// Get the mode name
|
|
|
|
GetTextIndexed(mode_name, MAX_TINFO_COMMAND_NAME, command_code, kTInfo_Commands);
|
2021-04-08 19:02:19 +01:00
|
|
|
|
2021-04-09 18:45:06 +01:00
|
|
|
// Only if current settings is different than previous
|
|
|
|
if ( (tinfo_mode==TINFO_MODE_STANDARD && command_code==CMND_TELEINFO_HISTORIQUE) ||
|
|
|
|
(tinfo_mode==TINFO_MODE_HISTORIQUE && command_code==CMND_TELEINFO_STANDARD) ) {
|
|
|
|
|
2021-10-02 17:29:05 +01:00
|
|
|
// Cleanup Serial not sure it will works since
|
2021-04-09 18:45:06 +01:00
|
|
|
// there is no end() or close() on tasmotaserial class
|
|
|
|
if (TInfoSerial) {
|
|
|
|
TInfoSerial->flush();
|
|
|
|
//TInfoSerial->end();
|
|
|
|
free(TInfoSerial);
|
|
|
|
}
|
2021-04-08 19:02:19 +01:00
|
|
|
|
2021-10-02 17:29:05 +01:00
|
|
|
// Change mode
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->teleinfo.mode_standard = command_code == CMND_TELEINFO_STANDARD ? 1 : 0;
|
2021-04-08 19:02:19 +01:00
|
|
|
|
2021-06-05 10:47:09 +01:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("TIC: '%s' mode"), mode_name);
|
2021-04-09 18:45:06 +01:00
|
|
|
|
|
|
|
// Re init teleinfo (LibTeleinfo always free linked list on init)
|
|
|
|
TInfoInit();
|
|
|
|
|
|
|
|
serviced = true;
|
|
|
|
|
|
|
|
} else {
|
2021-06-05 10:47:09 +01:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("TIC: No change to '%s' mode"), mode_name);
|
2021-04-09 18:45:06 +01:00
|
|
|
}
|
2021-04-08 19:02:19 +01:00
|
|
|
}
|
2021-04-09 18:45:06 +01:00
|
|
|
break;
|
|
|
|
|
2021-10-02 17:29:05 +01:00
|
|
|
case CMND_TELEINFO_RAW_DISABLE:
|
|
|
|
case CMND_TELEINFO_RAW_FULL:
|
2021-04-09 18:45:06 +01:00
|
|
|
case CMND_TELEINFO_RAW_CHANGE: {
|
2021-10-02 17:29:05 +01:00
|
|
|
|
2021-04-09 18:45:06 +01:00
|
|
|
// Enable all RAW frame send
|
|
|
|
char raw_name[MAX_TINFO_COMMAND_NAME];
|
|
|
|
|
|
|
|
// Get the raw name
|
|
|
|
GetTextIndexed(raw_name, MAX_TINFO_COMMAND_NAME, command_code, kTInfo_Commands);
|
|
|
|
|
|
|
|
if (command_code == CMND_TELEINFO_RAW_DISABLE) {
|
|
|
|
// disable raw mode
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->teleinfo.raw_send = 0;
|
2021-04-09 18:45:06 +01:00
|
|
|
} else {
|
|
|
|
// enable raw mode
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->teleinfo.raw_send = 1;
|
|
|
|
Settings->teleinfo.raw_report_changed = command_code == CMND_TELEINFO_RAW_CHANGE ? 1 : 0;
|
2021-04-09 18:45:06 +01:00
|
|
|
}
|
|
|
|
|
2021-06-05 10:47:09 +01:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("TIC: Raw to '%s'"), raw_name);
|
2021-04-09 18:45:06 +01:00
|
|
|
serviced = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CMND_TELEINFO_SKIP: {
|
|
|
|
// Set Raw mode skip frame number
|
|
|
|
char skip_name[MAX_TINFO_COMMAND_NAME];
|
|
|
|
// Get the raw name
|
|
|
|
GetTextIndexed(skip_name, MAX_TINFO_COMMAND_NAME, command_code, kTInfo_Commands);
|
|
|
|
int l = strlen(skip_name);
|
|
|
|
|
|
|
|
// At least "EnergyConfig Teleinfo skip" plus one space and one (or more) digit
|
2021-04-09 23:49:38 +01:00
|
|
|
// so "EnergyConfig Skip 0" or "EnergyConfig Skip 123"
|
2021-04-09 18:45:06 +01:00
|
|
|
if ( pValue ) {
|
2021-04-09 23:49:38 +01:00
|
|
|
int value = atoi(pValue);
|
|
|
|
if (value >= 0 && value <= 255) {
|
|
|
|
raw_skip = value;
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->teleinfo.raw_skip = raw_skip;
|
2021-04-09 23:49:38 +01:00
|
|
|
|
|
|
|
if (raw_skip ==0) {
|
2021-06-05 10:47:09 +01:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("TIC: Raw no skip"));
|
2021-04-09 23:49:38 +01:00
|
|
|
} else {
|
2021-06-05 10:47:09 +01:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("TIC: Raw each %d frame(s)"), raw_skip+1);
|
2021-04-09 23:49:38 +01:00
|
|
|
}
|
|
|
|
serviced = true;
|
2021-04-09 18:45:06 +01:00
|
|
|
} else {
|
2021-06-05 10:47:09 +01:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("TIC: skip can be 0 to 255"));
|
2021-04-09 18:45:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
2021-06-05 10:47:09 +01:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("TIC: no skip value"));
|
2021-04-09 18:45:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-06-05 10:47:09 +01:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("TIC: bad cmd param '%s'"), pParam);
|
2021-04-09 18:45:06 +01:00
|
|
|
break;
|
|
|
|
|
2021-04-08 19:02:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-09 18:45:06 +01:00
|
|
|
return serviced ;
|
2021-04-08 19:02:19 +01:00
|
|
|
}
|
|
|
|
|
2020-06-17 18:54:40 +01:00
|
|
|
/* ======================================================================
|
2021-02-10 20:08:59 +00:00
|
|
|
Function: TInfoProcess
|
|
|
|
Purpose : Tasmota callback executed often enough to read serial
|
2020-06-17 18:54:40 +01:00
|
|
|
Input : -
|
2020-10-28 16:32:07 +00:00
|
|
|
Output : -
|
2020-06-17 18:54:40 +01:00
|
|
|
Comments: -
|
|
|
|
====================================================================== */
|
2021-02-10 20:08:59 +00:00
|
|
|
//#define MEASURE_PERF // Define to enable performance measurments
|
|
|
|
void TInfoProcess(void)
|
2020-06-12 15:31:23 +01:00
|
|
|
{
|
2021-02-10 20:08:59 +00:00
|
|
|
static char buff[TELEINFO_PROCESS_BUFFER];
|
|
|
|
#ifdef MEASURE_PERF
|
|
|
|
static unsigned long max_time = 0;
|
|
|
|
unsigned long duration = millis();
|
|
|
|
static int max_size = 0;
|
|
|
|
int tmp_size = 0;
|
|
|
|
#endif
|
|
|
|
|
2020-08-14 18:47:13 +01:00
|
|
|
if (!tinfo_found) {
|
2020-06-17 18:54:40 +01:00
|
|
|
return;
|
2020-08-14 18:47:13 +01:00
|
|
|
}
|
2020-06-17 18:54:40 +01:00
|
|
|
|
2021-02-10 20:08:59 +00:00
|
|
|
int size = TInfoSerial->read(buff,TELEINFO_PROCESS_BUFFER);
|
|
|
|
while ( size ) {
|
|
|
|
#ifdef MEASURE_PERF
|
|
|
|
tmp_size += size;
|
|
|
|
#endif
|
|
|
|
// Process as many bytes as available in serial buffer
|
|
|
|
for(int i = 0; size; i++, size--)
|
|
|
|
{
|
|
|
|
buff[i] &= 0x7F;
|
2020-06-14 21:04:19 +01:00
|
|
|
// data processing
|
2021-02-10 20:08:59 +00:00
|
|
|
tinfo.process(buff[i]);
|
2020-06-17 18:54:40 +01:00
|
|
|
}
|
2021-02-10 20:08:59 +00:00
|
|
|
size = TInfoSerial->read(buff,TELEINFO_PROCESS_BUFFER);
|
2020-06-17 18:54:40 +01:00
|
|
|
}
|
2021-02-10 20:08:59 +00:00
|
|
|
#ifdef MEASURE_PERF
|
|
|
|
duration = millis()-duration;
|
|
|
|
if (duration > max_time) { max_time = duration; AddLog(LOG_LEVEL_INFO,PSTR("TIC: max_time=%lu"), max_time); }
|
|
|
|
if (tmp_size > max_size) { max_size = tmp_size; AddLog(LOG_LEVEL_INFO,PSTR("TIC: max_size=%d"), max_size); }
|
|
|
|
#endif
|
2020-06-12 15:31:23 +01:00
|
|
|
}
|
|
|
|
|
2020-06-17 18:54:40 +01:00
|
|
|
/* ======================================================================
|
2020-10-28 16:32:07 +00:00
|
|
|
Function: TInfoShow
|
2020-06-17 18:54:40 +01:00
|
|
|
Purpose : Tasmota callback executed to send telemetry or WEB display
|
|
|
|
Input : -
|
2020-10-28 16:32:07 +00:00
|
|
|
Output : -
|
2020-06-17 18:54:40 +01:00
|
|
|
Comments: -
|
|
|
|
====================================================================== */
|
2020-06-14 23:52:49 +01:00
|
|
|
#ifdef USE_WEBSERVER
|
2020-08-16 19:53:28 +01:00
|
|
|
const char HTTP_ENERGY_ID_TELEINFO[] PROGMEM = "{s}ID{m}%s{e}" ;
|
2020-06-17 18:54:40 +01:00
|
|
|
const char HTTP_ENERGY_INDEX_TELEINFO[] PROGMEM = "{s}%s{m}%s " D_UNIT_WATTHOUR "{e}" ;
|
2020-06-14 23:52:49 +01:00
|
|
|
const char HTTP_ENERGY_PAPP_TELEINFO[] PROGMEM = "{s}" D_POWERUSAGE "{m}%d " D_UNIT_WATT "{e}" ;
|
2021-05-01 17:32:29 +01:00
|
|
|
//const char HTTP_ENERGY_IINST_TELEINFO[] PROGMEM = "{s}" D_CURRENT "%s{m}%d " D_UNIT_AMPERE "{e}" ;
|
2020-08-10 16:43:07 +01:00
|
|
|
const char HTTP_ENERGY_TARIF_TELEINFO[] PROGMEM = "{s}" D_CURRENT_TARIFF "{m}Heures %s{e}" ;
|
|
|
|
const char HTTP_ENERGY_CONTRAT_TELEINFO[] PROGMEM = "{s}" D_CONTRACT "{m}%s %d" D_UNIT_AMPERE "{e}" ;
|
|
|
|
const char HTTP_ENERGY_LOAD_TELEINFO[] PROGMEM = "{s}" D_POWER_LOAD "{m}%d" D_UNIT_PERCENT "{e}" ;
|
|
|
|
const char HTTP_ENERGY_IMAX_TELEINFO[] PROGMEM = "{s}" D_MAX_CURRENT "{m}%d" D_UNIT_AMPERE "{e}" ;
|
2021-05-01 17:32:29 +01:00
|
|
|
const char HTTP_ENERGY_IMAX3_TELEINFO[] PROGMEM = "{s}" D_MAX_CURRENT "{m}%d / %d / %d " D_UNIT_AMPERE "{e}" ;
|
2020-08-10 16:43:07 +01:00
|
|
|
const char HTTP_ENERGY_PMAX_TELEINFO[] PROGMEM = "{s}" D_MAX_POWER "{m}%d" D_UNIT_WATT "{e}" ;
|
2021-05-01 17:32:29 +01:00
|
|
|
const char HTTP_ENERGY_PMAX3_TELEINFO[] PROGMEM = "{s}" D_MAX_POWER "{m}%d / %d / %d " D_UNIT_WATT "{e}" ;
|
2021-04-20 18:16:55 +01:00
|
|
|
const char HTTP_ENERGY_LOAD_BAR[] PROGMEM = "<tr><div style='margin:4px;padding:0px;background-color:#ddd;border-radius:4px;'>"
|
|
|
|
"<div style='font-size:0.75rem;font-weight:bold;padding:0px;text-align:center;border:1px solid #bbb;border-radius:4px;color:#444;background-color:%s;width:%d%%;'>"
|
2021-05-01 17:32:29 +01:00
|
|
|
"%d%%</div>"
|
|
|
|
"</div></tr>";
|
2020-06-14 23:52:49 +01:00
|
|
|
#endif // USE_WEBSERVER
|
|
|
|
|
2020-06-12 15:31:23 +01:00
|
|
|
void TInfoShow(bool json)
|
|
|
|
{
|
2020-10-28 16:32:07 +00:00
|
|
|
// Since it's an Energy device , current, voltage and power are
|
2020-06-17 18:54:40 +01:00
|
|
|
// already present on the telemetry frame. No need to add here
|
2020-08-10 16:43:07 +01:00
|
|
|
// Just add the raw label/values of the teleinfo frame
|
2020-06-17 18:54:40 +01:00
|
|
|
if (json)
|
|
|
|
{
|
2021-04-20 18:16:55 +01:00
|
|
|
// Add new value (not part of TIC JSON Object)
|
2020-08-10 16:43:07 +01:00
|
|
|
if (isousc) {
|
|
|
|
ResponseAppend_P(PSTR(",\"Load\":%d"),(int) ((Energy.current[0]*100.0f) / isousc));
|
2020-06-14 23:52:49 +01:00
|
|
|
}
|
2020-06-18 16:12:23 +01:00
|
|
|
|
2021-05-26 22:58:42 +01:00
|
|
|
// add teleinfo TIC object
|
|
|
|
ResponseAppend_P(PSTR("},\"TIC\":{"));
|
|
|
|
ResponseAppendTInfo(' ', true);
|
2020-06-18 16:12:23 +01:00
|
|
|
|
2020-06-12 15:31:23 +01:00
|
|
|
#ifdef USE_WEBSERVER
|
2020-06-17 18:54:40 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-07 12:23:31 +01:00
|
|
|
char name[33];
|
2021-10-02 17:29:05 +01:00
|
|
|
char value[33];
|
2021-04-20 18:16:55 +01:00
|
|
|
int percent;
|
|
|
|
|
|
|
|
if (isousc) {
|
|
|
|
uint8_t hue;
|
|
|
|
uint8_t red, green, blue;
|
|
|
|
char phase_color[8];
|
|
|
|
|
2021-05-01 17:32:29 +01:00
|
|
|
for (int i=0; i<Energy.phase_count ; i++ ) {
|
2021-04-20 18:16:55 +01:00
|
|
|
percent = (int) ((Energy.current[i]*100.0f) / isousc) ;
|
|
|
|
if (percent > 100) {
|
|
|
|
percent = 100;
|
|
|
|
}
|
2021-05-01 17:32:29 +01:00
|
|
|
// Gradiant from green (low load), yellow, orange and ending red (high load)
|
2021-04-20 18:16:55 +01:00
|
|
|
// Hue from 128 (green) to 0 (red) so reversed from percent
|
|
|
|
hue = changeUIntScale(100-percent, 0, 100, 0, 128);
|
|
|
|
HsToRgb(hue, 128, &red, &green, &blue);
|
2021-10-02 17:29:05 +01:00
|
|
|
snprintf_P(phase_color, sizeof(phase_color), PSTR("#%02X%02X%02X"), red, green, blue);
|
2021-05-01 17:32:29 +01:00
|
|
|
WSContentSend_P(HTTP_ENERGY_LOAD_BAR, phase_color, percent, percent);
|
2021-04-20 18:16:55 +01:00
|
|
|
}
|
|
|
|
}
|
2020-08-16 19:53:28 +01:00
|
|
|
|
2020-08-14 18:47:13 +01:00
|
|
|
if (tinfo_mode==TINFO_MODE_HISTORIQUE ) {
|
2021-04-06 01:23:06 +01:00
|
|
|
if (getValueFromLabelIndex(LABEL_BASE, value) ) {
|
|
|
|
GetTextIndexed(name, sizeof(name), LABEL_BASE, kLabel);
|
2021-05-01 17:32:29 +01:00
|
|
|
WSContentSend_P(HTTP_ENERGY_INDEX_TELEINFO, name, value);
|
2021-04-06 01:23:06 +01:00
|
|
|
}
|
|
|
|
if (getValueFromLabelIndex(LABEL_HCHC, value) ) {
|
|
|
|
GetTextIndexed(name, sizeof(name), LABEL_HCHC, kLabel);
|
2021-05-01 17:32:29 +01:00
|
|
|
WSContentSend_P(HTTP_ENERGY_INDEX_TELEINFO, name, value);
|
2021-04-06 01:23:06 +01:00
|
|
|
}
|
|
|
|
if (getValueFromLabelIndex(LABEL_HCHP, value) ) {
|
|
|
|
GetTextIndexed(name, sizeof(name), LABEL_HCHP, kLabel);
|
2021-05-01 17:32:29 +01:00
|
|
|
WSContentSend_P(HTTP_ENERGY_INDEX_TELEINFO, name, value);
|
2021-04-06 01:23:06 +01:00
|
|
|
}
|
2021-05-01 17:32:29 +01:00
|
|
|
if (Energy.phase_count==3) {
|
|
|
|
int imax[3];
|
|
|
|
for (int i=LABEL_IMAX1; i<=LABEL_IMAX3; i++) {
|
|
|
|
if (getValueFromLabelIndex(i, value) ) {
|
|
|
|
imax[i-LABEL_IMAX1] = atoi(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WSContentSend_P(HTTP_ENERGY_IMAX3_TELEINFO, imax[0], imax[1], imax[2]);
|
|
|
|
} else {
|
|
|
|
if (getValueFromLabelIndex(LABEL_IMAX, value) ) {
|
|
|
|
WSContentSend_P(HTTP_ENERGY_IMAX_TELEINFO, atoi(value));
|
|
|
|
}
|
2021-04-06 01:23:06 +01:00
|
|
|
}
|
2021-05-01 17:32:29 +01:00
|
|
|
|
|
|
|
|
2021-04-06 01:23:06 +01:00
|
|
|
if (getValueFromLabelIndex(LABEL_PMAX, value) ) {
|
2021-05-01 17:32:29 +01:00
|
|
|
WSContentSend_P(HTTP_ENERGY_PMAX_TELEINFO, atoi(value));
|
2021-04-06 01:23:06 +01:00
|
|
|
}
|
|
|
|
|
2020-08-11 18:58:24 +01:00
|
|
|
if (tarif) {
|
|
|
|
GetTextIndexed(name, sizeof(name), tarif-1, kTarifName);
|
2021-05-01 17:32:29 +01:00
|
|
|
WSContentSend_P(HTTP_ENERGY_TARIF_TELEINFO, name);
|
2020-08-11 18:58:24 +01:00
|
|
|
}
|
|
|
|
if (contrat && isousc) {
|
2021-05-01 17:32:29 +01:00
|
|
|
int percent = (int) ((Energy.current[0]*100.0f) / isousc) ;
|
2020-08-11 18:58:24 +01:00
|
|
|
GetTextIndexed(name, sizeof(name), contrat, kContratName);
|
2021-05-01 17:32:29 +01:00
|
|
|
WSContentSend_P(HTTP_ENERGY_CONTRAT_TELEINFO, name, isousc);
|
|
|
|
//WSContentSend_P(HTTP_ENERGY_LOAD_TELEINFO, percent);
|
2020-08-11 18:58:24 +01:00
|
|
|
}
|
2021-04-06 01:23:06 +01:00
|
|
|
|
2020-08-14 18:47:13 +01:00
|
|
|
} else if (tinfo_mode==TINFO_MODE_STANDARD ) {
|
2021-04-06 01:23:06 +01:00
|
|
|
if (getValueFromLabelIndex(LABEL_EAST, value) ) {
|
|
|
|
GetTextIndexed(name, sizeof(name), LABEL_EAST, kLabel);
|
2021-05-01 17:32:29 +01:00
|
|
|
WSContentSend_P(HTTP_ENERGY_INDEX_TELEINFO, name, value);
|
2021-04-06 01:23:06 +01:00
|
|
|
}
|
|
|
|
if (getValueFromLabelIndex(LABEL_EASF01, value) ) {
|
|
|
|
GetTextIndexed(name, sizeof(name), LABEL_EASF01, kLabel);
|
2021-05-01 17:32:29 +01:00
|
|
|
WSContentSend_P(HTTP_ENERGY_INDEX_TELEINFO, name, value);
|
2021-04-06 01:23:06 +01:00
|
|
|
}
|
|
|
|
if (getValueFromLabelIndex(LABEL_EASF02, value) ) {
|
|
|
|
GetTextIndexed(name, sizeof(name), LABEL_EASF02, kLabel);
|
2021-05-01 17:32:29 +01:00
|
|
|
WSContentSend_P(HTTP_ENERGY_INDEX_TELEINFO, name, value);
|
2021-04-06 01:23:06 +01:00
|
|
|
}
|
|
|
|
if (getValueFromLabelIndex(LABEL_SMAXSN, value) ) {
|
2021-05-01 17:32:29 +01:00
|
|
|
WSContentSend_P(HTTP_ENERGY_PMAX_TELEINFO, atoi(value));
|
2021-04-06 01:23:06 +01:00
|
|
|
}
|
2021-04-07 12:23:31 +01:00
|
|
|
if (getValueFromLabelIndex(LABEL_LTARF, value) ) {
|
2021-05-01 17:32:29 +01:00
|
|
|
WSContentSend_P(HTTP_ENERGY_TARIF_TELEINFO, value);
|
2020-08-11 18:58:24 +01:00
|
|
|
}
|
2021-04-07 12:23:31 +01:00
|
|
|
if (getValueFromLabelIndex(LABEL_NGTF, value) ) {
|
2020-08-11 18:58:24 +01:00
|
|
|
if (isousc) {
|
2021-05-01 17:32:29 +01:00
|
|
|
WSContentSend_P(HTTP_ENERGY_CONTRAT_TELEINFO, value, isousc);
|
2020-08-11 18:58:24 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-17 18:54:40 +01:00
|
|
|
}
|
2020-08-16 19:53:28 +01:00
|
|
|
|
2020-08-23 10:17:33 +01:00
|
|
|
// Serial number ADCO or ADSC if found
|
|
|
|
if (*serialNumber) {
|
2021-05-01 17:32:29 +01:00
|
|
|
WSContentSend_P(HTTP_ENERGY_ID_TELEINFO, serialNumber);
|
2020-08-23 10:17:33 +01:00
|
|
|
}
|
2020-08-16 19:53:28 +01:00
|
|
|
|
2020-06-12 15:31:23 +01:00
|
|
|
#endif // USE_WEBSERVER
|
2020-06-17 18:54:40 +01:00
|
|
|
}
|
2020-06-12 15:31:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************************************\
|
|
|
|
* Interface
|
|
|
|
\*********************************************************************************************/
|
|
|
|
bool Xnrg15(uint8_t function)
|
|
|
|
{
|
2021-04-08 19:02:19 +01:00
|
|
|
bool result = false;
|
2020-06-17 18:54:40 +01:00
|
|
|
switch (function)
|
|
|
|
{
|
2021-09-12 18:44:01 +01:00
|
|
|
case FUNC_INIT:
|
|
|
|
TInfoInit();
|
|
|
|
break;
|
|
|
|
case FUNC_PRE_INIT:
|
|
|
|
TInfoDrvInit();
|
|
|
|
break;
|
2020-06-17 18:54:40 +01:00
|
|
|
case FUNC_EVERY_250_MSECOND:
|
2021-09-12 18:44:01 +01:00
|
|
|
if (tinfo_found) { TInfoProcess(); }
|
2020-06-17 18:54:40 +01:00
|
|
|
break;
|
2021-04-08 19:02:19 +01:00
|
|
|
case FUNC_COMMAND:
|
2021-09-12 18:44:01 +01:00
|
|
|
if (tinfo_found) { result = TInfoCmd(); }
|
2021-04-08 19:02:19 +01:00
|
|
|
break;
|
|
|
|
|
2020-06-17 18:54:40 +01:00
|
|
|
case FUNC_JSON_APPEND:
|
2021-09-12 18:44:01 +01:00
|
|
|
if (tinfo_found) { TInfoShow(1); }
|
2020-06-17 18:54:40 +01:00
|
|
|
break;
|
|
|
|
#ifdef USE_WEBSERVER
|
|
|
|
case FUNC_WEB_SENSOR:
|
2021-09-12 18:44:01 +01:00
|
|
|
if (tinfo_found) { TInfoShow(0); }
|
2020-06-17 18:54:40 +01:00
|
|
|
break;
|
|
|
|
#endif // USE_WEBSERVER
|
|
|
|
}
|
2021-04-08 19:02:19 +01:00
|
|
|
return result;
|
2020-06-12 15:31:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_TELEINFO
|
2021-05-01 17:32:29 +01:00
|
|
|
#endif // USE_ENERGY_SENSOR
|