Apex Jr aquarium controller


(Bob) #1

The following script was created and works with hub v2. I’m not sure if it makes a difference but I have a v1 hub and when running this, it never gets past the connecting part. I can manually login and retrieve the information. Can anyone see a problem with the way this is written. The guy who wrote this only has access to v2 hub and though he has spent a lot of time trying to help we’ve had no success. (I can understand what this does but have no programming experience) Thanks

/**

  • Neptune Apex (Connect)
  • Copyright 2017 James Andariese
  • 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: “Neptune Apex (Connect)”,
namespace: “jamesandariese”,
author: “James Andariese”,
description: “Neptune Apex (Connect)”,
category: “”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”) {
appSetting “username”
appSetting “password”
}

preferences {
page(name: “page1”, “title”: “Connect”, nextPage: “page2”, uninstall: true, install: false)
page(name: “page2”, “title”: “Select”, install: true, uninstall: true)
}

def page1() {
atomicState.done = null
dynamicPage(name: “page1”, “title”: “Connect”, nextPage: “page2”, uninstall: true, install: false) {
section(“Connection”) {
input(“name”: “ip”, type: “text”, title: “IP”, description: “A static IP is recommended”)
input(“name”: “username”, type: “text”, title: “Username”, description: “(not your Apex Fusion username)”)
input(“name”: “password”, type: “password”, “title”: “Password”, description: “(not your Apex Fusion password)”)

    }
    section("Setup Requirements") {
        paragraph("You will need to have enabled LAN access on your controller for this to work.\nLAN access or Classic Dashboard is not the same as Apex Fusion and must be setup separately.")
        href(name: "classicDashboard",
        	title: "Classic Dashboard Setup",
        	required: false,
        	style: "external",
        	url: "http://support.neptunesystems.com/support/solutions/articles/3000017576-how-to-access-your-classic-dashboard-pc",
        	description: "Tap to view setup instructions for Apex Classic Dashboard (LAN access)")
	}
}

}

def page2() {
if (atomicState.done == null) {
log.debug “first run. sending off hub action”
atomicState.done = false

    def auth = "$username:$password".bytes.encodeBase64()
    
    def params = [
		"headers": [
   		 	"HOST": "$ip:80",
    	    "Authorization": "Basic $auth",
    	],
    	"method": "GET",
    	"path": "/cgi-bin/status.json",
	]
    log.debug params
	sendHubCommand(new physicalgraph.device.HubAction(params, "$ip:80", [callback: handleHubStatusResponseDuringSetup]))
    atomicState.done = false
}
if (!atomicState.done) {
	log.debug "still waiting"
	dynamicPage(name: "page2", title: "Connecting", install:false, uninstall: false, refreshInterval: 1) {
		section("Connecting") {
    		paragraph("Connecting to your Apex controller.  Please be patient")
	    }
    }
} else {
    log.debug "all done waiting"
    if (!atomicState.success) {
        dynamicPage(name: "page2", title: "Connecting", install:false, uninstall: false) {
        	section("Error") {
   	    		paragraph("There was an error connecting to your Apex controller.  Your IP or credentials may have been wrong.  Here's what the controller responded with:")
            }
            section("Raw Output") {
            	paragraph(atomicState.message)
            }