I had an issue with an alarm pad that links to Hubitat via an Arduino to WiFi to Hubitat.
I was testing the alarm and when I performed power off testing I received multiple messages very quickly that the arduino didn't know to filter. So they were sent on to the Hubitat.
Finally I shut off the Arduino and was left with the below.
I haven't been able to determine how the error was repeated with nothing coming in to be parsed.
Any thoughts?
BTW line 48 is the Runin line.
Oh and the runin modification was mine not Dan's
Thanks
John
from code:
/**
* HubDuino_Ethernet_On_Off.groovy
*
* Copyright 2018 Dan G Ogorchock
*
* 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.
*
* Change History:
*
* Date Who What
* ---- --- ----
* 2018-08-17 Dan Ogorchock Original Creation
* 2019-01-26 jrf (Mod03) disabled some debug.log lines, added watchdogAlarm "runIn"
* and function.
* 2019-08-04 jrf No change to this code but the NodeMCU was updated to WiFiSerialv7.ino change was the addition of a client NAME
*/
metadata {
definition (name: "HubDuino Ethernet On Off Vista", namespace: "ogiewon", author: "Dan Ogorchock") {
capability "Configuration"
capability "Refresh"
capability "Switch"
capability "Signal Strength"
attribute "Status", "string"
}
simulator {
}
// Preferences
preferences {
input "ip", "text", title: "Arduino IP Address", description: "IP Address in form 192.168.1.226", required: true, displayDuringSetup: true
input "port", "text", title: "Arduino Port", description: "port in form of 8090", required: true, displayDuringSetup: true
input "mac", "text", title: "Arduino MAC Addr", description: "MAC Address in form of 02A1B2C3D4E5", required: true, displayDuringSetup: true
}
}
// parse events into attributes
def parse(String description) {
runIn(310, watchdogAlarm,[overwrite: true]) // [] because overwrite is a map // <<<<<<<added
//log.debug " ReceivedMsgDescription '${description}'"
def msg = parseLanMessage(description)
//log.debug " ParsedMsg '${msg}'"
def headerString = msg.header
def bodyString = msg.body
if (bodyString) {
//log.debug " ParsingBodyString ${bodyString}"
if (bodyString.startsWith("rssi"))
{
bodyString = bodyString.replaceAll(" ", ":")
}
def parts = bodyString.split(":")
def name = parts.length>0?parts[0].trim():null
def value = parts.length>1?parts[1].trim():null
//log.debug "parts = ${parts}"
//log.debug "name = ${name}"
//log.debug "value = ${value}"
def results = []
results << createEvent(name: name, value: value, isStateChange: true)
//log.debug " results of Parsing '${results}'"
return results
}
}
private getHostAddress() {
def ip = settings.ip
def port = settings.port
log.debug "Using ip: ${ip} and port: ${port} for device: ${device.id}"
return ip + ":" + port
}
def sendData(message) {
sendEthernet(message)
}
def sendEthernet(message) {
if (message.contains(" ")) {
def parts = message.split(" ")
def name = parts.length>0?parts[0].trim():null
def value = parts.length>0?parts[1].trim():null
message = name + "%20" + value
}
log.debug "Executing 'sendEthernet' ${message}"
if (settings.ip != null && settings.port != null) {
new hubitat.device.HubAction(
method: "POST",
path: "/${message}?",
headers: [ HOST: "${getHostAddress()}" ]
)
}
else {
log.debug "Parent HubDuino Ethernet Device: Please verify IP address and Port are configured."
}
}
// handle commands
def on() {
log.debug "Executing 'on()'"
sendEthernet("switch:on")
}
def off() {
log.debug "Executing 'off()'"
sendEthernet("switch:off")
}
def configure() {
log.debug "Executing 'configure()'"
updateDeviceNetworkID()
}
def refresh() {
log.debug "Executing 'refresh()'"
sendEthernet("refresh")
state.MissingReportCount = 0
}
def installed() {
log.debug "Executing 'installed()'"
if ( device.deviceNetworkId =~ /^[A-Z0-9]{12}$/)
{
}
else
{
log.error "Parent HubDuino Ethernet Device has not been fully configured."
}
}
def initialize() {
log.debug "Executing 'initialize()'"
}
def updated() {
if (!state.updatedLastRanAt || now() >= state.updatedLastRanAt + 5000) {
state.updatedLastRanAt = now()
log.debug "Executing 'updated()'"
updateDeviceNetworkID()
log.debug "Hub IP Address = ${device.hub.getDataValue("localIP")}"
log.debug "Hub Port = ${device.hub.getDataValue("localSrvPortTCP")}"
}
else {
log.trace "updated(): Ran within last 5 seconds so aborting."
}
}
def updateDeviceNetworkID() {
log.debug "Executing 'updateDeviceNetworkID'"
def formattedMac = mac.toUpperCase()
formattedMac = formattedMac.replaceAll(":", "")
if(device.deviceNetworkId!=formattedMac) {
log.debug "setting deviceNetworkID = ${formattedMac}"
device.setDeviceNetworkId("${formattedMac}")
}
}
def watchdogAlarm() { // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<added
log.debug "Missed Keypad Reports"
state.MissingReportCount++
}