Post your best Lua script examples here

User avatar
By alnitak
#11816 Guys,

I have successfully interfaced the nodemcu flashed esp8266 to an i2c dhu21df temp/humidity sensor. I now want to set up a tcp connection to post the sensor data to dweet.io. I'm having trouble understanding the syntax to do that. Anybody care to help?
User avatar
By Vitoa
#11842 Try this and report if works

temp=30
hum=55
conn=net.createConnection(net.TCP,0)
conn:on("receive", function(conn, pl) print("response: ",pl) end)
conn:on("connection",function(conn, payload)
conn:send("POST /dweet/for/thing_name?temperature=" .. temp .. "&hum=" .. hum .. " HTTP/1.1\r\nHost: dweet.io\r\n".."Connection: close\r\nAccept: */*\r\n\r\n")
end)
conn:connect(80,"dweet.io")

Regards,Vito
User avatar
By picstart
#11847 Does get any better than the above..dweet is ridiculously easy to use ..avoids the intrusive nature of competing services...they maybe the next twitter
User avatar
By Vitoa
#11875 dweet.io is amazing and simple to use , but no security on POST/GET requests, no QoS and no encryptation in connection.
But advantages are free and very simple to post data and request data

But for more adanced ioT projects you can go for MQTT protocol, but u need to have your own MQTT server or using a public MQTT server, I think can use iot.eclipse.org port 1883
THe advantages are low letancy in communications(based on websockets), option of QoS to garante deliver etc, optional encryptation for secure connections.