Post your best Lua script examples here

User avatar
By David Rio
#33977 Hi,

I am working on a project that requires sending data to a webserver from a esp8266 running
nodemcu (branch: dev140).

At some point on my code I call this function:

Code: Select allsendData = function()
  sk = net.createConnection(net.TCP, 0)

  sk:on("receive", function(data)
    print("receive: " .. data)
  end)

  sk:on("connection", function(lsocket)
    payload = tempStatus()
    print("sending... " .. payload)
    lsocket:send("POST /proxy HTTP/1.1\r\n")
  end)

  -- sk:on("sent", function() sk.close() end)

  sk:connect(5000, "192.168.1.212")
end


I can see the payload (json) in the console, right before calling the method
send on the socket. The problem is that the server does not receive any
request.

I can also see the wifi setup has been done correctly and I have an IP
address assigned.

Any feedback on what may be wrong here would be appreciate it.

Thanks,
-drd
User avatar
By forlotto
#34009 net socket example:

Code: Select all sk=net.createConnection(net.TCP, 0)
    sk:on("receive", function(sck, c) print(c) end )
    sk:connect(80,"192.168.0.66")
    sk:on("connection", function(sck,c)
        -- Wait for connection before sending.
        sk:send("GET / HTTP/1.1\r\nHost: 192.168.0.66\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
        end)


Dunno if port 5000 is supported you would have to research this more I suppose for kicks you could try with port 80...

otherwise visit here for more info
https://github.com/nodemcu/nodemcu-firm ... ketconnect

I am sure there is something you are not doing correctly IDK for sure not so sure about proxy etc

Another way to see your weather data would be to iframe it from your IP and have the window auto referesh every 10minutes with java and setup a webpage... Of course your node would have to be free of your firewall on the correct ports or put into DMZ...