Compare commits

...

9 Commits

Author SHA1 Message Date
Charles 8bdba6f2a5 Fix buffer size 2020-06-14 21:39:37 +02:00
Charles 4e2a5b603d Bump to 1.1.2 2020-06-14 21:39:03 +02:00
Charles c23c353a96 cleanup 2020-06-13 02:11:09 +02:00
Charles 3272960531 Fixed link ESP8266 2020-06-13 02:07:05 +02:00
Charles 54c54575f0 Ajout exemple ESP8266 2020-06-13 02:06:06 +02:00
Charles c3fdacc8db fixed (hopefully) corruption of data 2020-06-13 01:38:00 +02:00
Charles fe33bf622a bump to v1.1.1 2020-06-13 01:37:00 +02:00
Charles f54c40bdb3 Re ordered struct to be more aligned 2020-06-13 01:35:53 +02:00
Charles f85ec633a0 Fixed samples links 2020-06-11 13:23:01 +02:00
6 changed files with 218 additions and 15 deletions

View File

@ -32,6 +32,7 @@ Sketch d'exemples
- [Raspberry_JSON][12] Retourne les informations de téléinformation au format JSON sur stdout.
- [Wifinfo][5] ESP8266, ESP32 Wifi Teleinformation, Web + Rest + bonus, version en cours de développement, à venir mais un article [dédié][13] est déjà présent sur mon blog
- [ESP32][14] ESP32 Basic test pour WifInfo32 nouveau nom Denky :-)
- [ESP8266_DataChanged][15] ESP8266 Surveille et affiche les données changées entre 2 trames, clignote la LED RGB en fonction
Pourquoi
========
@ -55,11 +56,12 @@ Vous pouvez aller voir les nouveautés et autres projets sur [blog][7]
[9]: https://community.hallard.me
[10]: https://hallard.me/libteleinfo
[3]: https://github.com/hallard/LibTeleinfo/blob/master/Examples/Arduino_Softserial/Arduino_Softserial_Etiquette.ino
[4]: https://github.com/hallard/LibTeleinfo/blob/master/Examples/Arduino_Softserial_JSON/Arduino_Softserial_JSON.ino
[3]: https://github.com/hallard/LibTeleinfo/blob/master/examples/Arduino_Softserial/Arduino_Softserial_Etiquette.ino
[4]: https://github.com/hallard/LibTeleinfo/blob/master/examples/Arduino_Softserial_JSON/Arduino_Softserial_JSON.ino
[5]: https://github.com/hallard/LibTeleinfo/tree/master/examples/Wifinfo/Wifinfo.ino
[11]: https://github.com/hallard/LibTeleinfo/blob/master/Examples/Arduino_Softserial/Arduino_Softserial_Blink.ino
[12]: https://github.com/hallard/LibTeleinfo/blob/master/Examples/Raspberry_JSON/Raspberry_JSON.ino
[11]: https://github.com/hallard/LibTeleinfo/blob/master/examples/Arduino_Softserial/Arduino_Softserial_Blink.ino
[12]: https://github.com/hallard/LibTeleinfo/blob/master/examples/Raspberry_JSON/Raspberry_JSON.ino
[13]: https://hallard.me/wifiinfo/
[14]: https://github.com/hallard/LibTeleinfo/blob/master/Examples/ESP32/ESP32.ino
[14]: https://github.com/hallard/LibTeleinfo/blob/master/examples/ESP32/ESP32.ino
[15]: https://github.com/hallard/LibTeleinfo/blob/master/examples/ESP8266_DataChanged/ESP8266_DataChanged.ino

View File

@ -0,0 +1,200 @@
// **********************************************************************************
// ESP8266 Teleinfo, display changed data received and blink RGB Led
// **********************************************************************************
// Creative Commons Attrib Share-Alike License
// You are free to use/extend this library but please abide with the CC-BY-SA license:
// Attribution-NonCommercial-ShareAlike 4.0 International License
// http://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For any explanation about teleinfo ou use , see my blog
// http://hallard.me/category/tinfo
//
// This program works with the Wifinfo board
// see schematic here https://github.com/hallard/teleinfo/tree/master/Wifinfo
//
// Written by Charles-Henri Hallard (http://hallard.me)
//
// History : V1.00 2020-06-11 - First release
//
// All text above must be included in any redistribution.
//
// **********************************************************************************
#include <LibTeleinfo.h>
#define RGB_LED_PIN 0 // GPIO0
// Output Debug on Serial1 since Hardware Serial is used to receive Teleinfo
#define SerialMon Serial1
#ifdef RGB_LED_PIN
#include <NeoPixelBus.h>
#define colorSaturation 128
// three element pixels, in different order and speeds
NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod> strip(1, RGB_LED_PIN);
RgbColor red(colorSaturation, 0, 0);
RgbColor green(0, colorSaturation, 0);
RgbColor blue(0, 0, colorSaturation);
RgbColor white(colorSaturation);
RgbColor black(0);
#endif
TInfo tinfo; // Teleinfo object
// Pour clignotement LED asynchrone
unsigned long blinkLed = 0;
uint16_t blinkDelay= 0;
/* ======================================================================
Function: ADPSCallback
Purpose : called by library when we detected a ADPS on any phased
Input : phase number
0 for ADPS (monophase)
1 for ADIR1 triphase
2 for ADIR2 triphase
3 for ADIR3 triphase
Output : -
Comments: should have been initialised in the main sketch with a
tinfo.attachADPSCallback(ADPSCallback())
====================================================================== */
void ADPSCallback(uint8_t phase)
{
// n = numero de la phase 1 à 3
if (phase == 0)
phase = 1;
SerialMon.print(F("ADPS:"));
SerialMon.println('0' + phase);
#ifdef RGB_LED_PIN
strip.SetPixelColor(0, red);
// Keep it RED between all frame until it disapears
blinkDelay = 2500; // 2.5s should be enough
strip.Show();
blinkLed = millis();
#endif
}
/* ======================================================================
Function: DataCallback
Purpose : callback when we detected new or modified data received
Input : linked list pointer on the concerned data
current flags value
Output : -
Comments: -
====================================================================== */
void DataCallback(ValueList * me, uint8_t flags)
{
RgbColor col(0, 0, colorSaturation);
// Nouvelle etiquette ?
if (flags & TINFO_FLAGS_ADDED) {
SerialMon.print(F("NEW -> "));
#ifdef RGB_LED_PIN
strip.SetPixelColor(0, green);
strip.Show();
blinkDelay = 10; // 10ms
#endif
}
// Valeur de l'étiquette qui a changée ?
if (flags & TINFO_FLAGS_UPDATED) {
SerialMon.print(F("MAJ -> "));
#ifdef RGB_LED_PIN
strip.SetPixelColor(0, blue);
strip.Show();
blinkDelay = 50; // 50ms
#endif
}
// Display values
SerialMon.print(me->name);
SerialMon.print("=");
SerialMon.println(me->value);
blinkLed = millis();
}
/* ======================================================================
Function: setup
Purpose : Setup I/O and other one time startup stuff
Input : -
Output : -
Comments: -
====================================================================== */
void setup()
{
// Serial1, pour le debug la Serial est pour la téléinfo
// Donc débrancher la téléinfo pour les update via USB
SerialMon.begin(115200);
SerialMon.println(F("\r\n\r\n=============="));
SerialMon.println(F("Teleinfo"));
// this resets all the neopixels to an off state
#ifdef RGB_LED_PIN
SerialMon.printf_P(PSTR("Enable WS2812 RGB LED on GPIO=%d\r\n"), RGB_LED_PIN);
strip.Begin();
strip.SetPixelColor(0, green);
strip.Show();
blinkLed = millis();
blinkDelay = 500; // 500ms
#endif
// Configure Teleinfo Soft serial
// La téléinfo est connectee sur D3
// ceci permet d'eviter les conflits avec la
// vraie serial lors des uploads
Serial.begin(1200, SERIAL_7E1);
//If you have no pullup on Serial entry try to uncomment the following line
//pinMode(TIC_RX_PIN, INPUT_PULLUP);
// Init teleinfo
tinfo.init();
// Attacher les callback dont nous avons besoin
// pour cette demo, ADPS et TRAME modifiée
tinfo.attachADPS(ADPSCallback);
tinfo.attachData(DataCallback);
}
/* ======================================================================
Function: loop
Purpose : infinite loop main code
Input : -
Output : -
Comments: -
====================================================================== */
void loop()
{
static char c;
static unsigned long previousMillis = 0;
unsigned long currentMillis = millis();
// On a reçu un caractère ?
if ( Serial.available() ) {
// Le lire
c = Serial.read();
// Gérer
tinfo.process(c);
// L'affcher dans la console
//if (c!=TINFO_STX && c!=TINFO_ETX) {
//SerialMon.print(c);
//}
}
// Verifier si le clignotement LED doit s'arreter
if (blinkLed && ((millis()-blinkLed) >= blinkDelay)) {
#ifdef RGB_LED_PIN
strip.SetPixelColor(0, black);
strip.Show();
#endif
blinkLed = 0;
}
}

View File

@ -1,6 +1,6 @@
{
"name": "LibTeleinfo",
"version": "1.1.0",
"version": "1.1.2",
"keywords": "teleinfo, french, meter, power, erdf, linky, tic",
"description": "Decoder for Teleinfo (aka TIC) from French smart power meters",
"repository":

View File

@ -1,5 +1,5 @@
name=LibTeleinfo
version=1.1.0
version=1.1.2
author=Charles-Henri Hallard <hallard.me>
maintainer=Charles-Henri Hallard <community.hallard.me>
sentence=Decoder for Teleinfo (aka TIC) from French smart power meters

View File

@ -210,9 +210,10 @@ ValueList * TInfo::valueAdd(char * name, char * value, uint8_t checksum, uint8_t
me = me->next;
// Check if we already have this LABEL (same name AND same size)
if (lgname==strlen(me->name) && strncmp(me->name, name, lgname)==0) {
if (lgname==strlen(me->name) && strcmp(me->name, name )==0) {
// Already got also this value return US
if (lgvalue==strlen(me->value) && strncmp(me->value, value, lgvalue) == 0) {
if (lgvalue==strlen(me->value) && strcmp(me->value, value) == 0) {
*flags |= TINFO_FLAGS_EXIST;
me->flags = *flags;
return ( me );
@ -223,7 +224,7 @@ ValueList * TInfo::valueAdd(char * name, char * value, uint8_t checksum, uint8_t
// Do we have enought space to hold new value ?
if (strlen(me->value) >= lgvalue ) {
// Copy it
strlcpy(me->value, value , lgvalue );
strlcpy(me->value, value , lgvalue + 1);
me->checksum = checksum ;
// That's all
@ -421,12 +422,12 @@ char * TInfo::valueGet(char * name, char * value)
me = me->next;
// Check if we match this LABEL
if (lgname==strlen(me->name) && strncmp(me->name, name, lgname)==0) {
if (lgname==strlen(me->name) && strcmp(me->name, name)==0) {
// this one has a value ?
if (me->value) {
// copy to dest buffer
uint8_t lgvalue = strlen(me->value);
strlcpy(value, me->value , lgvalue );
strlcpy(value, me->value , lgvalue + 1 );
return ( value );
}
}
@ -661,7 +662,7 @@ ValueList * TInfo::checkLine(char * pline)
return NULL;
// Get our own working copy
strlcpy( buff, _recv_buff, len+1);
strlcpy( buff, pline, len+1);
p = &buff[0];
ptok = p; // for sure we start with token name

View File

@ -80,10 +80,10 @@ typedef struct _ValueList ValueList;
struct _ValueList
{
ValueList *next; // next element
uint8_t checksum;// checksum
uint8_t flags; // specific flags
char * name; // LABEL of value name
char * value; // value
uint8_t checksum;// checksum
uint8_t flags; // specific flags
};
#pragma pack(pop)