22.11.2019, 00:06 (This post was last modified: 22.11.2019, 00:07 by Erwin van der Zwart.)
Hi,
Try this:
Code:
require('socket.http')
socket.http.TIMEOUT = 5
data = socket.http.request('http://192.168.1.238/en/phase1.html')
-- Check if response value is received
if data then
-- Fetch values from HTTP response
p_activa = data:match([[<td id="p_activa">(.-)</td>]])
-- Remove units and trims leading and trailing spaces and decode to numberic
p_activa = tonumber(string.trim(string.gsub(p_activa, "W", "", 1)))
-- Write to KMX
grp.write('1/1/1', p_activa)
end
require('socket.http')
socket.http.TIMEOUT = 5
data = socket.http.request('http://192.168.1.238/en/phase1.html')
-- Check if response value is received
if data then
-- Fetch values from HTTP response
p_activa = data:match([[<td id="p_activa">(.-)</td>]])
-- Remove units and trims leading and trailing spaces and decode to numberic
p_activa = tonumber(string.trim(string.gsub(p_activa, "W", "", 1)))
-- Write to KMX
grp.write('1/1/1', p_activa)
end
BR,
Erwin
Hello @Erwin van der Zwart
Thanks for the script!!
I change the script in order to put the user and password and to change the output object (virtual byte floating point) see it:
Code:
require('socket.http')
socket.http.TIMEOUT = 5
data = socket.http.request('http://user:user@192.168.1.238/en/phase1.html')
log(data)
-- Check if response value is received
if data then
-- Fetch values from HTTP response
p_activa = data:match([[<td id="p_activa">(.-)</td>]])
log(p_activa)
-- Remove units and trims leading and trailing spaces and decode to numberic
p_activa = tonumber(string.trim(string.gsub(p_activa, "W", "", 1)))
log(p_activa)
-- Write to KMX
grp.write('32/3/1', p_activa)
end
But this doesn't work, looking to the log this is the output:
And this is the searched data read from the wibeee webpage, storeged on "data"
Data is probably loaded via JavaScript so initial HTML fields are empty. Check network tab in browser. You might get a URL for JSON data which will make parsing easier.
(22.11.2019, 08:04)admin Wrote: Data is probably loaded via JavaScript so initial HTML fields are empty. Check network tab in browser. You might get a URL for JSON data which will make parsing easier.
Hello, I completely a noob with html and java.
How can I do it?
What model do you use? When looking at the internet data i see it supports XML and modbus TCP, so integration by parsing XML or communicate over modbus should be easy and there is no need to fetch the data from the HTML (this is the last option i would use). I would go for Modbus TCP when available.
22.11.2019, 09:30 (This post was last modified: 22.11.2019, 09:52 by peyoe.)
(22.11.2019, 09:20)Erwin van der Zwart Wrote: Hi,
What model do you use? When looking at the internet data i see it supports XML and modbus TCP, so integration by parsing XML or communicate over modbus should be easy and there is no need to fetch the data from the HTML (this is the last option i would use). I would go for Modbus TCP when available.
(22.11.2019, 15:15)Daniel. Wrote: Go to modbus tab, add attached profile and then add modbus IP device. Map object and you are done.
Profile may need adjustment.
Wow, that was fast.
Thanks a lot, later at home I try it.
Finally I can do it, but not trough modbus, because when I inserted new modbus device, the software ask for the IP and one port. I don't had idea what port wibeee uses for this task.
So, searching info on the manual I founded that wibeee can answer to html request for one item.
With this info, I have used the scrip from @Erwin van der Zwart and modify to request only for the items I wanted.
This is the final script:
-- Check if response value is received
if pact then
p_activa = pact:match([[<value>(.-)</value>]])
p_activa = tonumber(string.trim(string.gsub(p_activa, "W", "", 1)))
grp.write('32/3/1', p_activa)
end
if i1 then
int_f1 = i1:match([[<value>(.-)</value>]])
int_f1 = tonumber(string.trim(string.gsub(int_f1, "W", "", 1)))
grp.write('32/3/2', int_f1)
end
if en then
energia = en:match([[<value>(.-)</value>]])
energia = tonumber(string.trim(string.gsub(energia, "W", "", 1)))
grp.write('32/3/3', energia)
end
I launch it every 5 minutes, and works pretty well
(25.11.2019, 12:30)peyoe Wrote: Finally I can do it, but not trough modbus, because when I inserted new modbus device, the software ask for the IP and one port. I don't had idea what port wibeee uses for this task...