Newbie question: I have a local IP web server set to record the status of a reed switch. How can I parse the page (ex: http://192.168.0.100/Read ) to look for the text “Opened” or “Closed”? I’ve tried httpGet, but found out this doesn’t work for local addresses.
My HTML page source is :
<HEAD> <meta http-equiv="refresh" content="2"></head>Opened
You can check my DTH as an example:
/**
* Air Mentor Pro 2
*
* Copyright 2017 Philippe PORTES
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
definition (name: "Air Mentor Pro 2", namespace: "philippeportesppo", author: "Philippe PORTES", oauth: true) {
capability "refresh"
capability "polling"
capability "sensor"
This file has been truncated. show original
The basic is: in the parse, call a parser on the description you get and use a html like way to address your parameter.
Example:
def parse(description) {
def msg = parseLanMessage(description)
if (msg.status == 200)
{
def xmlParser = new XmlParser()
def html = xmlParser.parseText(msg.body)
// log.debug html
log.debug "CO2: ${html.body.table.tr[1].td[0].text()}"
Would read the value of a HTML table in the body section having line 1, column 0