We have moved at community.getvera.com

Author Topic: Plugin with webpage data (help needed)  (Read 3055 times)

Offline mr leaver

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +2/-0
Plugin with webpage data (help needed)
« on: April 20, 2013, 02:31:22 am »
Is it possible to create a plugin with data from the webpage of my solar inverter (piko kostal 4.2)
I am interested in DC voltages and AC voltage, and produced power

The webpage looks like this

Code: [Select]
<!DOCtype HTML PUBLIC "-//W3C//Dtd HTML 4.0 Transitional//EN">
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<meta name="Generator" CONTENT="ChrisB">
<title>PV Webserver</title>
</head>
<body nof="(MB=(DefaultMasterborder, 65, 60, 150, 10), L=(HomeLayout, 700, 600))" bgcolor="#EAF7F7" text="#000000" link="#0033CC" vlink="#990099" alink="#FF0000" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>
<form method="post" action="">
<table cellspacing="0" cellpadding="0" width="770" nof="ly">
<tr><td height="5"></td></tr>
<tr><td width="190" height="55"></td>
<td width="400">
  <font face="Arial,Helvetica,Geneva,Sans-serif,sans-serif" size="+3">
  PIKO 4.2
<br><font size="+1">                 
  Leever (255)
</font>
</font>
</td>
<td><img alt="Logo" height="42" width="130" src="KSE.gif"></td>
</tr>
</table>

<font face="Arial,Helvetica,Geneva,Sans-serif,sans-serif">
<table Border="0" width="100%"><tr>
<td width="150"></td>
<td> <hr> </td>
</tr></table>
<table cellspacing="0" cellpadding="0" width="770">
<tr><td></td></tr>
<tr>
<td width="190"></td>
<td colspan="2">
  <b>AC-vermogen</b></td>
<td>&nbsp</td>
<td>
  <b>energie</b></td></tr>
<tr><td height="10"></td></tr>

<tr>
<td width="190"></td>
<td width="100">
  actueel</td>
<td width="70" align="right" bgcolor="#FFFFFF">
  227</td>
<td width="140">&nbsp W</td>
<td width="100">
  totale energie</td>
<td width="70" align="right" bgcolor="#FFFFFF">
  43</td>
<td width="50">&nbsp kWh</td>
<td>&nbsp</td></tr>
<tr height="2"><td></td></tr>
<tr>
<td width="190"></td>
<td width="100">
  &nbsp</td>
<td width="70" align="right">
  &nbsp</td>
<td width="140">&nbsp</td>
<td width="100">
  dagenergie</td>
<td width="70" align="right" bgcolor="#FFFFFF">
  0.20</td>
<td width="50">&nbsp kWh</td>
<td>&nbsp</td></tr>
<tr height="5"><td></td></tr>
<tr>
<td width="190"></td>
<td width="100">
  status</td>
<td colspan="4">
  toevoer MPP</td>
<td>&nbsp</td></tr>
<tr height="8"><td></td></tr>
<tr><td colspan="7">
<table align="top" width="100%"><tr>
<td width="182"></td>
<td><hr size="1"></font></td></tr>
<tr><td height="5"></td></tr></table>
</td></tr>
<tr>
<td width="190"></td>
<td colspan="2">
  <b>PV-generator</b></td>
<td width="140">&nbsp</td>
<td colspan="2">
  <b>uitgangsvermogen</b></td>
<td width="30">&nbsp</td>
<td>&nbsp</td></tr>
<tr><td height="10"></td></tr>
<tr>
<td width="190"></td>
<td width="100">
  <u>String 1</u></td>
<td width="70">&nbsp</td>
<td width="140">&nbsp</td>
<td width="95">
  <u>L1</u></td>
<td width="70">&nbsp</td>
<td width="30">&nbsp</td>
<td>&nbsp</td></tr>
<tr>
<td width="190"></td>
<td width="100">
  spanning</td>
<td width="70" align="right" bgcolor="#FFFFFF">
  590</td>
<td width="140">&nbsp V</td>
<td width="100">
  spanning</td>
<td width="70" align="right" bgcolor="#FFFFFF">
  235</td>
<td width="30">&nbsp V</td>
<td>&nbsp</td></tr>
<tr height="2"><td></td></tr>
<tr valign="top" align="left">
<td width="190">&nbsp</td>
<td width="100">
  stroom</td>
<td width="70" align="right" bgcolor="#FFFFFF">
  0.44</td>
<td width="140">&nbsp A</td>
<td width="100">
  vermogen</td>
<td width="70" align="right" bgcolor="#FFFFFF">
  0</td>
<td width="30">&nbsp W</td>
<td>&nbsp</td></tr>
<tr height="22"><td></td></tr>
<tr>
<td width="190"></td>
<td width="100">
  <u>String 2</u></td>
<td width="70">&nbsp</td>
<td width="140">&nbsp</td>
<td width="100">
  <u>L2</u></td>
<td width="70">&nbsp</td>
<td width="30">&nbsp</td>
<td>&nbsp</td></tr>
<tr>
<td width="190"></td>
<td width="100">
  spanning</td>
<td width="70" align="right" bgcolor="#FFFFFF">
  0</td>
<td width="140">&nbsp V</td>
<td width="100">
  spanning</td>
<td width="70" align="right" bgcolor="#FFFFFF">
  235</td>
<td width="30">&nbsp V</td>
<td>&nbsp</td></tr>
<tr height="2"><td></td></tr>
<tr valign="top" align="left">
<td width="190">&nbsp</td>
<td width="100">
  stroom</td>
<td width="70" align="right" bgcolor="#FFFFFF">
  0.00</td>
<td width="140">&nbsp A</td>
<td width="100">
  vermogen</td>
<td width="70" align="right" bgcolor="#FFFFFF">
  0</td>
<td width="30">&nbsp W</td>
<td>&nbsp</td></tr>
<tr height="22"><td></td></tr>
<tr>
<td width="190"></td>
<td width="100">
  <u> </u></td>
<td width="70">&nbsp</td>
<td width="140">&nbsp</td>
<td width="100">
  <u>L3</u></td>
<td width="70">&nbsp</td>
<td width="30">&nbsp</td>
<td>&nbsp</td></tr>
<tr>
<td width="190"></td>
<td width="100">
   </td>
<td width="70" align="right" bgcolor="#EAF7F7">
   </td>
<td width="140">&nbsp
   </td>
<td width="95">
  spanning</td>
<td width="70" align="right" bgcolor="#FFFFFF">
  237</td>
<td width="30">&nbsp V</td>
<td>&nbsp</td></tr>
<tr height="2"><td></td></tr>
<tr valign="top" align="left">
<td width="190">&nbsp</td>
<td width="95">
   </td>
<td width="70" align="right" bgcolor="#EAF7F7">
   </td>
<td width="140">&nbsp
 </td>
<td width="95">
  vermogen</td>
<td width="70" align="right" bgcolor="#FFFFFF">
  227</td>
<td width="30">&nbsp W</td>
<td>&nbsp</td></tr>

<tr><td height="15"></td></tr>
<tr><td colspan="7">
<table align="top" width="100%">
<tr><td width="182"></td>
<td><hr size="1"></font></td>
</tr><tr><td height="5"></td></tr></table>
</td></tr></table>
<table cellspacing="0" cellpadding="0" width="770">
<tr><td width="190"></td>
<td><font face="Arial,Helvetica,Geneva,Sans-serif">
<b>RS485-communicatie</b></td></tr>
<tr><td height="8"></td></tr>
<tr><td width="190"></td>
<td><font face="Arial,Helvetica,Geneva,Sans-serif">
omvormer&nbsp
<input type="Text" name="edWrNr" value="255" size="3" maxlength="3">
<input type="submit" value="weergeven/actualiseren">
</td></tr><tr><td height="10"></td></tr>
</table>
</td></tr></table></font>

<hr>
<table cellspacing="0" cellpadding="0" width="770">
<tr><td height="5"></td></tr>
<tr><td width="190"></td>
<td width="330">
<font face="Arial,Helvetica,Geneva,Sans-serif,sans-serif">
<a href="LogDaten.dat">geschiedenis</a>
&nbsp &nbsp &nbsp
<a href="Info.fhtml">informatiepagina</a></font></td>
<td align="right">
<font face="Arial,Helvetica,Geneva,Sans-serif,sans-serif">
<a href="Solar2.fhtml">instellingen</a></font></td>
<td width="50"></td>
</tr></table></font>
</form>
</body>
</html>

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: Plugin with webpage data (help needed)
« Reply #1 on: April 20, 2013, 03:43:28 am »
I don't see why a plugin shouldn't be possible. Start with the Weather Underground code; it's got web fetching and XML parsing.

Offline mr leaver

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +2/-0
Re: Plugin with webpage data (help needed)
« Reply #2 on: April 29, 2013, 08:16:11 am »
How do i start (after getting the WUIWeather xml/json etc).
Where can one find info on how to set up/build plugins

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: Plugin with webpage data (help needed)
« Reply #3 on: April 29, 2013, 08:46:04 am »
Your only option is to learn by example. It would help* if you are already a decent programmer. Read code for similar plugins (Weather Underground in your case) and adapt it.

MCV's howto is here: http://wiki.micasaverde.com/index.php/Luup_Somfy_Walkthrough

* Actually it's practically a necessity.

Offline RichardTSchaefer

  • Community Beta
  • Master Member
  • ******
  • Posts: 10091
  • Karma: +764/-143
Re: Plugin with webpage data (help needed)
« Reply #4 on: April 29, 2013, 09:19:00 am »
Quote
Read code for similar plugins (Weather Underground in your case)
You will have to get the files from the repository ... if you just install the plugin ... they are encrpted.


Also the Wiki will have a lot of info.
See:
http://wiki.micasaverde.com/index.php/Category:Development

Offline mr leaver

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +2/-0
Re: Plugin with webpage data (help needed)
« Reply #5 on: May 02, 2013, 07:52:51 am »
It seems that i might user port 81 also (not http) for the most recent information.
How do i open this port and get data from it ? tcp port 81 not http protocol.

Offline RichardTSchaefer

  • Community Beta
  • Master Member
  • ******
  • Posts: 10091
  • Karma: +764/-143
Re: Plugin with webpage data (help needed)
« Reply #6 on: May 02, 2013, 08:13:34 am »
You will need to read up on LUA libraries.
Your initial posted indicated it was HTTP request ... if not you can use a socket to read the data.
Code: [Select]
local host = "192.168.10.100"
local port = 81
local socket = require("socket")
local tcp = socket.tcp()
tcp:settimeout(5)
if (tcp:connect(host, port)) then
...
end

Offline mr leaver

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +2/-0
Re: Plugin with webpage data (help needed)
« Reply #7 on: May 30, 2013, 09:20:37 am »
In the weather app i find this part of code.
Code: [Select]
    local WEATHER_PATTERN, tmp = string.gsub([[&lt;response>.*
        &lt;current_observation>.*&lt;observation_location>.*
        &lt;full>(.-)&lt;/full>.*
        &lt;latitude>(.-)&lt;/latitude>.*&lt;longitude>(.-)&lt;/longitude>.*&lt;/observation_location>.*
        &lt;observation_epoch>(%d-)&lt;/observation_epoch>.*
        &lt;weather>(.*)&lt;/weather>.*
        &lt;temp_f>(.-)&lt;/temp_f>.*&lt;temp_c>(.-)&lt;/temp_c>.*
        &lt;relative_humidity>(%d-)%%&lt;/relative_humidity>.*
        &lt;wind_string>(.*)&lt;/wind_string>.*&lt;wind_dir>(%a-)&lt;/wind_dir>.*&lt;wind_mph>(.-)&lt;/wind_mph>.*&lt;wind_kph>(.-)&lt;/wind_kph>.*&lt;icon>(.-)&lt;/icon>.*
        &lt;/current_observation>.*
        &lt;forecast>.*&lt;simpleforecast>&lt;forecastdays>&lt;forecastday>.*&lt;period>1&lt;/period>
        &lt;high>&lt;fahrenheit>(.-)&lt;/fahrenheit>&lt;celsius>(.-)&lt;/celsius>&lt;/high>
        &lt;low>&lt;fahrenheit>(.-)&lt;/fahrenheit>&lt;celsius>(.-)&lt;/celsius>&lt;/low>.*
        &lt;/forecastday>.*&lt;forecastday>.*&lt;period>2&lt;/period>.*
]], "%s*", "")

What does (.-) do as i can't find that on the net. .- can be found but what do the parenthesis add to it ? Capture in stead of replace ?
« Last Edit: May 30, 2013, 09:25:29 am by rpleever »

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: Plugin with webpage data (help needed)
« Reply #8 on: May 30, 2013, 09:26:22 am »
What does (.-) do as i can't find that on the net.

http://www.lua.org/pil/20.3.html

Search term list: Lua pattern capture.