Friday, January 19, 2018

Unifi Cloud Key not updating firmware?

Was trying to update from 5.22 to 5.29 and it kept returning without updating or saying what happened anywhere I could find. After Googling for a bit I found a few posts suggesting to move of trim the DB along the lines of this
The problem with disk space is usually because the DB is growing too large for the original install location. Since the Cloud Key unit ships with an 8GB SD card which mounts as /data (as you pointed out) I was able to solve this problem by moving the db folder to the SD card and then setting up a symbolic link to the new location. This provides much more storage space for the DB to grow and should free up space to handle future firmware updates. Here are the steps to do this:

## STOP SERVICES
sudo /etc/init.d/unifi stop
sudo /etc/init.d/cloudkey-webui stop


## MOVE DB AND SETUP SYMBOLIC LINK
sudo mv /srv/unifi/data/db /data
sudo ln -s /data/db/ /srv/unifi/data/db

## START SERVICES
sudo /etc/init.d/unifi start
sudo /etc/init.d/cloudkey-webui start

I then also ran the script located here to clean out older data from the DB:
https://help.ubnt.com/hc/en-us/articles/204911424-UniFi-Remove-prune-older-data-and-adjust-mongo-database-size


I am thinking about setting this script as a cron job to run periodically on its own, but I haven't done that yet. So far everything seems stable but your mileage may vary. Be sure to check the log files for any errors.

This got me thinking so I checked the available space:
ssh ubnt@keyIP (password is your admin user password or default ubnt)
df -h
But the only even close to full filesystem was .rofs
Filesystem                     Size  Used Avail Use% Mounted on
aufs-root                      1.1G  319M  735M  31% /
udev                            10M     0   10M   0% /dev
tmpfs                          201M  372K  201M   1% /run
/dev/disk/by-label/userdata    1.1G  319M  735M  31% /mnt/.rwfs
/dev/disk/by-partlabel/rootfs  291M  291M     0 100% /mnt/.rofs
tmpfs                          503M     0  503M   0% /dev/shm
tmpfs                          5.0M     0  5.0M   0% /run/lock
tmpfs                          503M     0  503M   0% /sys/fs/cgroup
tmpfs                          503M   96K  502M   1% /tmp
/dev/mmcblk0p7                 1.5G  1.2G  321M  78% /srv
/dev/mmcblk1p1                 7.2G  1.6G  5.7G  22% /data

So I tried just compacting the DB instead.



Note much of a change but it did the trick

Filesystem                     Size  Used Avail Use% Mounted on
aufs-root                      1.1G  319M  735M  31% /
udev                            10M     0   10M   0% /dev
tmpfs                          201M  372K  201M   1% /run
/dev/disk/by-label/userdata    1.1G  319M  735M  31% /mnt/.rwfs
/dev/disk/by-partlabel/rootfs  291M  291M     0 100% /mnt/.rofs
tmpfs                          503M     0  503M   0% /dev/shm
tmpfs                          5.0M     0  5.0M   0% /run/lock
tmpfs                          503M     0  503M   0% /sys/fs/cgroup
tmpfs                          503M   96K  502M   1% /tmp
/dev/mmcblk0p7                 1.5G 1000M  449M  70% /srv
/dev/mmcblk1p1                 7.2G  1.6G  5.7G  22% /data

Saturday, December 16, 2017

Hack to fix bug in the BLAN Homeseer plugin

For some reason a couple versions back the BLAN plugin stopped updating the value with the status of a monitored device changed. At least as far as switching the value back to on when the device comes back online. The following script looks at all the devices with location2 set to BLAN and sets the value based on the status string. I have an event set up to run it every 10 minutes.

' Hack to make Blan devices have a status value
' call from a set or value changed event
Public Sub statusBlan(ByVal refID As Object)
    Dim status As String = hs.DeviceString(refID)
    Dim oldVal = hs.DeviceValue(refID)

    If (InStr(status, "Offline") > 0) Then
        hs.SetDeviceValueByRef(refID, 0, False)
    ElseIf (InStr(status, "Online") > 0) Then
        hs.SetDeviceValueByRef(refID, 100, False)
    Else
        hs.SetDeviceValueByRef(refID, 50, False)
    End If

    Dim newVal = hs.DeviceValue(refID)

    If Not oldVal = newVal Then
        hs.WriteLog("statusBlan", "Fixed value of BLAN device " & refID & " with status of " & status & " from " & oldVal & " to " & newVal)
    End If
End Sub

Public Sub fixBlan(Parms As Object)
    Dim label As String = "fixBlan"
    Try
        Dim lowBatVal As Double = 100  'start at 100% max for low battery value
        Dim dv, dvLowBat As Scheduler.Classes.DeviceClass
        Dim EN As Scheduler.Classes.clsDeviceEnumeration = hs.GetDeviceEnumerator  'Get all devices

        If EN Is Nothing Then
            hs.WriteLog(label, "Error getting Enumerator")
            Exit Sub
        End If

        Do  'check each device that was enumerated
            dv = EN.GetNext
            If dv Is Nothing Then  'No device, so quit
                hs.WriteLog(label, "No devices found")
                Exit Sub
            End If
            'hs.WriteLog(label, "location:" & dv.Location(Nothing) & ":location2:" & dv.Location2(Nothing) & ":InStr:" & InStr(UCase(dv.Location2(Nothing)), "BLAN"))
            If InStr(UCase(dv.Location2(Nothing)), "BLAN") > 0 Then  'Only work with devices in location BLAN
                'hs.WriteLog(label, "ref:" & dv.ref(Nothing) & ":Address:" & dv.Address(Nothing) & ":value:" & dv.devValue(Nothing) & ":location:" & dv.Location(Nothing) & ":location2:" & dv.Location2(Nothing) & ":device name:" & dv.Name(Nothing) & ":type:" & dv.Device_Type_String(Nothing))
                statusBlan(dv.ref(Nothing))
            End If
        Loop Until EN.Finished

    Catch ex As Exception
        hs.WriteLog("Error", "Exception in script " & label & ":  " & ex.Message)
    End Try
End Sub