I am getting a string of data from the piccolo chip using the uart module, that I can reprint back out to serial without an issue. However, I am looking to add it to my webserver that includes the toggle switch to shutdown the system. On the uart module at the bottom, I can easily read it as needed so I have that string saved and can manipulate it, I just need to figure out how to get it updated onto the webserver. I am not concerned with how often it needs to refresh as I can control how often I receive the serial data.
--wifi.setmode(wifi.STATION)
--wifi.sta.config("HOME-CD31-2.4", "XXXXX")
--ip = wifi.sta.getip()
--print(ip)
gpio.mode(4, gpio.OUTPUT)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local buf = "";
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
if(method == nil)then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
end
local _GET = {}
if (vars ~= nil)then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
end
end
buf = buf.."<h1> Power Line Monitoring</h1><form src=\"/\">Shutdown <select name=\"pin\" onchange=\"form.submit()\">";
local _on,_off = "",""
if(_GET.pin == "ON")then
_on = " selected=true";
gpio.write(4, gpio.HIGH);
elseif(_GET.pin == "OFF")then
_off = " selected=\"true\"";
gpio.write(4, gpio.LOW);
end
buf = buf.."<option".._on..">ON</opton><option".._off..">OFF</option></select></form>";
buf = buf.."<h1> Current and Voltage Data</h1>";
client:send(buf);
client:close();
collectgarbage();
end)
end)
uart.setup(0, 9600, 8, 0, 1,0)
uart.on("data", '|',
function(data)
print("receive from uart:", data)
end,0)