Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Albert
#16307 Hi all,
i need some help

i try to replace my arduino with the ESP
for reporting my electrical power consumption , i need to read at 1200 bps on a serial interface

on the arduino with RX on the target interface an TX on my serial usb for debugging, i use something like:
void loop() {
if (Serial.available())
Serial.write(Serial.read() & 0x7F);
}

on ESP, it losts data during the reading
i add a call to yield() but no success

thanks
User avatar
By Overcrash
#16594 Hi,

i assume you live in france ?

I try to use ESP to replace my arduino for EDF Téléinfo retrieving, but it seems to be hard to decode 7bits... i can't find how to delete the last bit...

for the moment i can only get this result :

Code: Select allÏPÔAÒÉÆ HÃ.. <�
ÉSÏUSà ²0 ¸�
HÃHÃ 03695··56 6�
HÃHP 0²·²5·´±± 0�
PÔÅà È*]4&L64¹ü
ÉÉNSÔ² 00± Ê�
ÉÉNSÔ3 000 Ê�
ÉMAر 0±9 :�
ÉMAز 0²0 3�
ÉMAØ3 0±¸


which is like arduino code without "& 0x7F"...
User avatar
By Theo
#29378 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.

I made several edf teleinfo interfaces in the past and also for the ESP8266. Below part of the code to print teleinfo line by line.

Code: Select all-- Configure UART, EDF data (1200 bps, 7, E, 2)

uart.setup( 0,  1200, 8,    0,   1,    0    ) -- NodeMCU can't do 7 databits Even parity
-- trigger receiver on receiving end of line CR 0x0D (13) => 0x8D (141) with parity bit

uart.on("data", "\141", function(raw)

    local rec = ''
    local i

    for i = 1, #raw do
     rec = rec .. string.char(bit.band(raw:sub(i,i):byte(), 0x7f))  -- convert to byte and strip parity bit
    end

     print(rec)

  end, 0)
User avatar
By Theo
#29489 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.

Code: Select all-- -----------------------------------------------------------------------------
-- 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)