Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim sdk As PHHueSDK
Dim APselected As PHAccessPoint
Dim BridgeSelected As PHBridge
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
sdk.Initialize("HUE","QuickStartApp")
Log(sdk.InitManager)
Log("Bridge selected="&sdk.SelectedBridge)
Log("APs found: "&sdk.AccessPointsFound)
Dim SPs As List = sdk.AccessPointsFound
If SPs.Size > 0 Then
Log("Get 1st AP")
For i = 0 To SPs.Size-1
Dim ap As PHAccessPoint = SPs.Get(i)
Log($"AP initialized = ${ap.IsInitialized}"$)
If ap.IsInitialized Then
sdk.connect(ap)
End If
Next
End If
Dim bridges As List = sdk.AllBridges
Log(bridges)
If bridges.Size > 0 Then
Log("Get 1st Bridge")
For i = 0 To bridges.Size-1
Dim bridge As PHBridge = bridges.Get(i)
Log($"Bridge initialized = ${bridge.IsInitialized}"$)
Next
End If
Dim ap As PHAccessPoint
ap.Initialize("")
ap.IpAddress = "192.168.1.116"
ap.MacAddress = "00:17:88:12:CB:6E"
ap.BridgeId = "001788FFFE12CB6E"
'Log(ap.IpAddress)
'Log(ap.MacAddress)
'Log(ap.Username)
If sdk.isAccessPointConnected(ap) Then
Log("ap connected")
Dim bridge As PHBridge = sdk.SelectedBridge
Log("Groups: "&bridge.AllGroups)
Log("Lights: "&bridge.AllLights)
Log("Rules: "&bridge.AllRules)
Log("Scenes: "&bridge.AllScenes)
Log("Sensors: "&bridge.AllSensors)
Log("AllShedules: "&bridge.getAllSchedules(True))
Log("AllTimers: "&bridge.getAllTimers(True))
Else
LogColor("ap not connected",Colors.Blue)
Log(sdk.DisconnectedAccessPoint)
'sdk.search2(True,True,True)
sdk.search(True,True)
End If
'Log(sdk.AllBridges)
'Log(sdk.SelectedBridge)
Log(sdk.AccessPointsFound)
End Sub
Sub HUE_onAccessPointsFound(APs As List)
'Log($"HUE_onAccessPointsFound(${APs})"$)
Log($"HUE_onAccessPointsFound()"$)
If APs.IsInitialized Then
Log($"AP list is initialized. size = ${APs.Size}"$)
'Log(APs)
If APs.Size = 1 Then
Log("get 1st")
If APs.Get(0) Is PHAccessPoint Then
Log("get PHAccessPoint")
Dim ap As PHAccessPoint = APs.Get(0)
Log(ap.BridgeId)
Log(ap.IpAddress)
Log(ap.MacAddress)
'Log(ap.Username)
APselected = ap
sdk.connect(ap)
else if APs.Get(0) Is PHBridge Then
Log("get PHBridge")
Dim bridge As PHBridge = APs.Get(0)
sdk.addBridge(bridge)
else if APs.Get(0) Is PHBridgeHeader Then
Log("get PHBridgeHeader")
Dim bridgehdr As PHBridgeHeader = APs.Get(0)
else if APs.Get(0) Is PHLight Then
Log("get PHLigth")
Dim light As PHLight = APs.Get(0)
End If
'sdk.startPushlinkAuthentication(ap)
'Log("Groups: "&bridge.AllGroups)
'Log("Lights: "&bridge.AllLights)
'Log("Rules: "&bridge.AllRules)
'Log("Scenes: "&bridge.AllScenes)
'Log("Sensors: "&bridge.AllSensors)
'Log("AllShedules: "&bridge.getAllSchedules(True))
'Log("AllTimers: "&bridge.getAllTimers(True))
Else
For i = 0 To APs.Size-1
Dim ap As PHAccessPoint = APs.Get(i)
Next
End If
End If
End Sub
Sub HUE_onAuthenticationRequired(apoint As PHAccessPoint)
Log($"HUE_onAuthenticationRequired(${apoint})"$)
If apoint<>Null And apoint Is PHAccessPoint Then
Dim ap As PHAccessPoint = apoint
Log(ap.BridgeId)
Log(ap.IpAddress)
sdk.startPushlinkAuthentication(ap)
End If
End Sub
Sub HUE_onBridgeConnected(bridge As PHBridge, info As String)
Log($"HUE_onBridgeConnected(${bridge},${info})"$)
BridgeSelected = bridge
sdk.addBridge(bridge)
Log("Groups: "&bridge.AllGroups)
Log("Lights: "&bridge.AllLights)
Log("Rules: "&bridge.AllRules)
Log("Scenes: "&bridge.AllScenes)
Log("Sensors: "&bridge.AllSensors)
Log("AllShedules: "&bridge.getAllSchedules(True))
Log("AllTimers: "&bridge.getAllTimers(True))
End Sub
Sub HUE_onCacheUpdated(cacheNotifications As List, bridge As PHBridge)
Log($"HUE_onCacheUpdated(${cacheNotifications},)"$)
End Sub
Sub HUE_onConnectionLost(ap As PHAccessPoint)
Log($"HUE_onConnectionLost(${ap})"$)
End Sub
Sub HUE_onConnectionResumed(bridge As PHBridge)
Log($"HUE_onConnectionResumed(${bridge})"$)
End Sub
Sub HUE_onError(code As Int, message As String)
Log($"HUE_onError(${code},${message})"$)
End Sub
Sub HUE_onParsingErrors(errors As List)
Log($"HUE_onParsingErrors(${errors})"$)
End Sub