-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
uart.on to read teleinfo (EDF) for french users #466
Comments
Hi @Overcrash86, this issues list is for Lua developers to post issues / bugs about the firmware itself. This is a more general "howto" Q. Try one of the developer forums such as Stackoverflow or esp8266.com 😄 |
I believe the teleinfo data from the French electricity meter is 1200bps 7 databits, even parity, 1 stopbit. But even parity is not supported so if you use 8 databits with no parity, then mask the msb, the data should be ok. You could then send the data through an IP socket to your server / database or whatever. I have done this before on other platforms and i will do it for the ESP8266 as soon as i have some time. |
Can we have a look about your Lua code? |
hi, my simple lua test code is : (already tried to play with stop bits, parity, etc. with no success) uart.setup(0, 1200, 8, 0, 1, 0)
print("Init ok !")
uart.on("data",255, function(d)
print(d)
end, 0) with this code, i got this result:
instead of :
|
Hi Overcrash86 I working also for an Wifi Teleinfo with ESP8266, It's not my first try with teleinfo, I think I've got some enough experience ( see there http://hallard.me/category/teleinformation-2/ ) to suspect we have a problem. I'm not using LUA but Arduino IDE ESP8266, and I've got the same problems, reception is absolutely not reliable at 1200 7E1, I even changed some resistors values but no luck not working 100% and the HW module I'm using is the same than I do for Arduino, Spark Core, Raspberry, PC and on all these devices, it works everytime. As you use LUA and me just the compiler and we have same problems. I could suspect something wrong with the serial at 1200 kpbs. When I tried test sketch send/receive Does someone has any documentation on the value
may be it's just a wrong value for constant Oh forgot to mention I also tested swapping pin with |
Teleinfo protocol is 1200 bps, 7 bits, Parity Even; 1 stop Could you try NodeMCU documentation on uart.setup does no tell anything about parity parameter (4th), just 0 is none, but looking into the firmware code the enum 0 looks more than EVEN and not NONE
|
Bonsoir Charles, Moi aussi je me sens moins seul ! Je trouves très compliqué pour moi non développeur d’arriver à faire quelque chose qui devrait être ultra simple… Donc si je comprends bien, vous n’utilisez pas du LUA (donc pas nodeMCU) mais directement en C sur l’ESP ? Si c’est le cas, je suis en mesure (avec un firmware recompilé et un pauvre fprint) d’afficher les bonnes valeurs, mais il m’est impossible par la suite de l’envoyer en LUA pour la traiter plus facilement de mon côté. Désolé pour le retard de réponse, j’ai pas mal d’occupations en ce moment du coup c’est plus compliqué pour moi :) PS : j’ai aussi ouvert un topic suite à la remarque de TerryE m’expliquant bien que je n’avais rien à faire ici avec ma question… Je suppose que Charly86 c’est vous ? http://www.esp8266.com/viewtopic.php?f=21 http://www.esp8266.com/viewtopic.php?f=21&t=3425&start=0 &t=3425&start=0 De : Charles [mailto:notifications@github.com] Teleinfo protocol is 1200 bps, 7 bits, Parity Even; 1 stop Could you try NodeMCU documentation on uart.setup does no tell anything about parity parameter (4th), just 0 is none, but looking into the firmware code the enum 0 looks more than EVEN and not NONE // Parity — |
Bonsoir, La mauvaise nouvelle du jour c'est qu'avec l'opto SHF6206 (le classique) ça ne fonctionne pas avec l'ESP, c'est un montage empirique qui fonctionne sur Arduino et Raspberry mais malheureusement pas sur l'ESP sauf à jouer avec les valeurs de résistances et encore c'est pas fiable. Résultat avec un vrai module téléino çà fonctionne nickel |
Roughly translated for those that can't read French (perhaps hallard can correct anything that is materially wrong). I am also not sure of some of the idioms, e.g : de dingue = amazing or botched? @Overcrash86 wrote:
@hallard wrote:
Oh, the trials of this multi-national world. Think how we would cope if we all had to use Chinese! |
Terry, |
@hallard, no apologies needed. I only added my poor translation so that those with English as a first or second language can track the thread 😄 |
@terry, |
When using 8 data bits instead of 7, the parity bit from the teleinfo will be the most significant bit in the character received. The Start of Frame: 0x02 becomes 0x82 with parity bit, CR (0x0D) becomes 0x8D, End of Frame: 0x03 stays the same.
-- trigger receiver on receiving end of line CR 0x0D (13) => 0x8D (141) with parity bit
|
EDF teleinfo receiver and decoder, although not fully tested it should work. Checksum is calculated and data is send to a server. Please let me know your experience with this code, i'am sure we can make improvements. -- -----------------------------------------------------------------------------
-- EDF TeleInfo Meter Reader for ESP8266 & NodeMcu
-- LICENCE: http://opensource.org/licenses/MIT
-- Theo Harbers harbers.theo@gmail.com
------------------------------------------------------------------------------
-- EDF Teleinfo format:
-- Start of Frame: 0x02 (0x82 with parity)
-- LF (0x0A) Label (4 to 8 bytes) SP (0x20) value (1 to 12 bytes) SP (0x20) CS (checksum byte) CR (0x0D)
-- End of Frame: 0x03
-- HCHC ( 9 bytes Wh )
-- HCHP ( 9 bytes Wh )
-- tarif: PTEC ( 4 bytes .. )
-- power: PAPP ( 5 bytes VA )
sk = nil -- global socket discriptor
j = ''
t = ''
gw = -- put here ip address of server to send the data
pt = -- put here port number of server to send data to
-- Configure eMeter UART, only use RX to read eMeter data (1200 bps, 7, E, 2)
-- uart.setup( id, baud, bits, par, stop, echo )
uart.setup( 0, 1200, 8, 0, 1, 0 ) -- NodeMCU can't do 7 databits Even parity and 2 stopbits
-- trigger receiver on receiving CR 0x0D (13) => 0x8D (141) with parity bit
uart.on("data", "\141", function(raw)
local rec = ''
local i,lab,val
local cs = 0x20 -- checksum start value
local cb = 0
for i = 1, #raw-3 do
cb = bit.band(raw:byte(i), 0x7f) -- get data byte and strip parity bit
if cb > 0x20 then cs = cs + cb end -- add to checksum anything bigger then space 0x20
rec = rec .. string.char(cb)
end
-- End of frame ? then output the data and clear buffer
if rec:byte(1) == 0x03 then
-- print(j)
t = j -- use temporary string t because sending is async to collecting
-- send the data to server
sk=nil
sk = net.createConnection(net.TCP,0) --not secure
sk:on("connection", function() sk:send( t .. "\r\n" ) end )
sk:on("sent", function() sk:close() end )
sk:connect(pt, gw)
j = ''
end
-- if CS matches Checksum character, extract only the label and value and add to output buffer
if string.char(bit.band(cs,0x3f) + 0x20) == string.char(bit.band(raw:byte(-2), 0x7f)) then
lab, val = rec:match("(%u+)%s([%u%d]+)")
j = j .. lab .. "=" .. val .. ';' -- or any other format you would like to send to server
-- print(lab .. "=" .. val)
end
end, 0) |
See #719. |
Is it possible to add an option to read french teleinfo serial datas ?
i'm not developper so i have not successfully get datas and pulled to LUA.
the french teleinfo is simple uart with these parameters :
i'm able to display the correct datas with these lines added to uart.c :
but i'm unable to pull this to LUA...
I just want to migrate from a big arduino to a small powerful ESP8266...
the arduino code is like this :
Regards
The text was updated successfully, but these errors were encountered: