I'm trying to extract the status of 4 plug sockets via the html source code of the device, which is returned by a http.request.
The values i needed are recorded against the <script> var sockstates = e.g [1,0,1,0] ` but it can be anything 1/0 for each below.
I've created the following script as an example to try try and work it through, but I'm not able to extract the 4 values that are reported between the square brackets [1,1,1,1]
Any help on how i can focus in on that section and extract the values, would be appreciated.
local responseBody = [[ Example source code returned via http.request - <title>EnerGenie LAN Power Manager</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" /><link rel="stylesheet" type="text/css" href="s.css" />
<script>var sockstates = [1,1,1,1];var mac= "C58A6B4AACE2";var ipid = 0;var serv = 0;var trycon = 0;var active = 0;var actbtn = 1;var warn = 0;var timer= null;var period = 3000;
</script>]]
local socket1, socket2, socket3, socket4 = responseBody:match("(.-)<script>var sockstates = [(%d),(%d),(%d),(%d)];var mac=")
print(socket1, socket2, socket3, socket4)