Post your best Lua script examples here

User avatar
By mgrunt
#38488 Hello, I'm new in LUA... I need connect to server (for example here - JAZZ radio - http://us1.internet-radio.com:11094/ or direct MP3 link www.server.com/song.mp3) and send raw data to TX ESP8266 for further processing...

Just use this simple script?
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end )
conn:connect(11094,"us1.internet-radio.com")
conn:send("GET / HTTP/1.1\r\nHost: us1.internet-radio.com\r\n"
.."Connection: keep-alive\r\nAccept: */*\r\n\r\n")

Thank you. MG
User avatar
By mgrunt
#38569 The self answer :-) is:

conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end)
conn:connect(11094, "us1.internet-radio.com")
conn:send("GET / HTTP/1.0\r\n")
conn:send("User-Agent: Wget/1.11.4\r\n")
conn:send("Accept: */*\r\n")
conn:send("Host: us1.internet-radio.com:11094\r\n")
conn:send("Connection: keep-alive\r\n")
conn:send("\r\n")

If I use different User-Agent (for example User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.)) it doesn't work (I receive only index.html not raw audio data).

MG
User avatar
By mgrunt
#38658 Hello, yes I can play this stream with VS1053 (ESP8266-STM32F103-VS1053).

But there are projects that send audio data to I2C ESP8266 and you connect to ESP8266 - I2C pin only DAC.

But I want to go the classic way. I'm done playing MP3 from SD card to VS1053 (CD card - STM32F103 - VS1053). And instead of SD cards I connect ESP8266.