Left for archival purposes.

User avatar
By Fred28
#21294 hello

I tested this code but it does not work
I do not even happens to read it ... esp probably loop
Code: Select allSTX=0x02
ETX=0x03
function ToFile(data)
    -- open 'init.lua' in 'a+' mode
    file.open("data.txt", "a+")
    file.write(data)
    file.write('\r')
    file.close()
end
function lectureserie()
print("before setup")
 uart.setup( 0, 1200, 7, 1, 1 )
print("after setup")
 -- when 0x02 is received.
    uart.on("data", STX,
      function(data)
        print("receive from uart:", data)
        ToFile(data)
        if data==ETX then
          uart.on("data")
          ToFile(data)
        end       
    end, 0)
end


any idea?

thank you
User avatar
By Overcrash
#21404 Probably need to disconnect RX from your USB to UART adapter, i don't know why, but it's cause trouble the data reception on ESP.

My simple test func with ESP is :

Code: Select alluart.setup(0, 1200, 8, 0, 1, 0)
print("Init ok !")

uart.on("data",   255, function(d)
    print(d)
end, 0)


which give :

Code: Select allMÏÔDÅÔAÔ 000
00É0 3ýÔL5
PPÏÔ 00 £�‚
ADÃÏ 050²²60669·´ Æ�
ÏPÔAÒÉÆ HÃ.. <�
ÉSÏUSà²0 ¸�
HÃHà03·´±²300 Z�
HÃHP 0²·¸´±±²· 3�úÅàHP..  �
ÉÉNSÔ± 003 K�
ÉÉNSÔ² 00± Ê�
ÉÉNSÔ3 00± K�
ÉMAر 0±9 :�
ÉMAز 0²0 3�
ÉMAØ3 0±¸ »�
PƒÂ›Âƒ5
PAPP 0±±00 £�
HHPHàŠ0�
MÏÔDÅÔAÔ 000000 B�
User avatar
By Overcrash
#21430 i think i'm close to find the right syntax :

Code: Select alluart.setup( 0, 1200, 8, 0, 1, 0 )

print("Init ok !")

uart.on("data",   0, function(d)
    print("---------------------")
    charin = string.byte(d)
    print("Char in: "..charin)
    hexvaluein = string.format("0x%08x", string.byte(d))
    print("Hex: "..hexvaluein)
    charshift = bit.lshift(hexvaluein, 0)
    print("Char Shift: "..charshift)
    char = string.format("%c", charshift)
    print("Char out: "..char)
end, 0)


with this i' now need to find the shift value !

here the result :

Code: Select all---------------------
Char in: 255
Hex: 0x000000ff
Char Shift: 255
Char out: ÿ
---------------------
Char in: 27
Hex: 0x0000001b
Char Shift: 27
Char out: 
---------------------
Char in: 195
Hex: 0x000000c3
Char Shift: 195
Char out: Ã
---------------------
Char in: 217
Hex: 0x000000d9
Char Shift: 217
Char out: Ù
---------------------
Char in: 253
Hex: 0x000000fd
Char Shift: 253
Char out: ý
---------------------
Char in: 234
Hex: 0x000000ea
Char Shift: 234
Char out: ê
---------------------