I write following code it connect to the wifi and initialize TCP server on port 1717(choose random). How I can do now that Domoticz send data to this specific port
-- Starts the module and connect to server.
print("SWITCH")
-- variables
local deviceID = "9"
local server_ip = "192.168.1.150"
local server_port = 8080
local deep_sleep_time = 300 --seconds
PIN = 7
-- wifi connection config
wifi.setmode(wifi.STATION)
wifi.sta.config("AKMEN","af66051515")
local cfg =
{
ip="192.168.1.100" --..deviceID, --static ip based on id
netmask="255.255.255.0",
gateway="192.168.1.1"
}
-- check every 0.5seconds if we can get an ip, once we get it start the TCP client
tmr.alarm(0, 500, 1, function()
gotIP = wifi.sta.setip(cfg)
if ( wifi.sta.status() == 5 ) then
print("connected to WiFi")
tmr.stop(0)
-- restart the module after 30seconds if it's still ON:
-- it probably means it's stalled
tmr.alarm(1, 30000, 1, function()
node.restart()
end)
end
end)
server = net.createServer(net.TCP, 30)
server:listen(1717, function(socket)
socket:on("receive",function(socket, msg)
print(msg)
end)
end)
I have also second issue I try to update switch status chenge it from off to on using json and following code. When I run this code I see in Domoticz change in last seen but nothing else. What is wrong?
data="On"
local json = "GET /json.htm?type=command¶m=udevice&idx="..deviceID..
"&nvalue=0&svalue="..data..
" HTTP/1.1\r\nHost: www.local.lan\r\n"
.."Connection: keep-alive\r\nAccept: */*\r\n\r\n"