Hateful gate controller

By   March 19, 2023

I’m essentially lazy. After installing a gate on the end of the driveway, we quickly tired of getting out of the car to open and then close the gate behind us. I bought a gate actuator which came with a couple of linear actuators and a controller. Since we don’t have wired power out there, I also needed a battery and solar panel plus charge controller.

The charge controller it came with was shit and the panel was too small, so I bought a new panel and charge controller. That solved that problem. No longer getting ‘Low Voltage’ warnings from the gate controller.

The next problem was access for friends. See the article https://www.beer.org/blog/index.php/2022/07/03/playing-with-fiducials/

Another annoyance was that if we were expecting a friend or courier or other, we had to walk down the driveway with a remote, and after getting close enough to the gate, press a combination of buttons in order for the gate to open and stay open.  Then before bedtime, we had to remember to walk down the driveway to close the gate which is particularly disquieting in the dark where a hundred reflective eyeballs are looking at you from the surrounding forest.  There was also no way to know whether the gate was actually open or closed without also going for a walk.

To help address this last annoyance, I added a VHF radio module connected to a BLE dongle and a relay module with a set of ADCs to read the limit switches.  A bit of Micropython and I could send queries to the dongle to get the state of the limit switches, and press buttons remotely.  Add in some MQTT handling and I have a link to HomeAssistant.

 

Unfortunately, now I have 2 boxes mounted out by the gate, one with the clunky COTS gate controller+battery, and another with the barnacles that I added to the system:

There must be a better way.  The heart of the system is the COTS controller board which is really just a couple of H bridges, some current sensing, limit switch inputs and push button inputs.  Time to start experimenting.

Playing with Fiducials.

By   July 3, 2022

As part of some tinkering I was doing with my robotics team, I was learning about AprilTags.  Coincidentally, I had also recently installed a gate opener at the front gate and was struggling with how to organize guest access.

I grabbed my OpenMV camera, a spare buck/boost converter, and an old Axis surveillance camera housing.  Put it all together and mounted it to a post in front of the gate:

 
Google Photos Refresh Token invalid. Please authenticate from Photonic → Authentication.
Error encountered during authentication:
{
  "error": "invalid_grant",
  "error_description": "Bad Request"
}
See here for documentation.

I played with the QR Code recognition and various families of AprilTag. While the QR Code recognition worked fine and allowed me some nice flexibility in terms of content, it was more fallible under varying light conditions. AprilTags are more robust and recognized pretty quickly from a few feet away.

The code is simple:

import sensor, image, time, math, omv, utime
import pyb
import machine


thresholds = ( 150,255 )
sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
sensor.skip_frames(time = 2000)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.

tag_families = image.TAG36H11|image.TAG36H11

last_tag = 0
tag_repeat_cnt = 0
tag_repeat_threshold = 5
rtc = pyb.RTC()

def set_rtc(epoch):
    dt=time.localtime(int(epoch))
    rtc.datetime(tuple(dt))


P1_PIN="P4"
P2_PIN="P5"
p1 = 0
p2 = 0

STATE_NORMAL=0
STATE_STAY_OPEN=1
STATE_STAY_CLOSED=2

state = 0
rtc_valid = 0

red_led = pyb.LED(1)
green_led = pyb.LED(2)
blue_led = pyb.LED(3)
ir_leds = pyb.LED(4)

# micropython Epoch is 2000-01-01.  My timezone is UTC+8.
epoch_fixup=946728000


def set_p1(dur=0):
    p1.low()
    red_led.on()
    time.sleep_ms(dur)
    p1.high()
    red_led.off()


def set_p2(dur=0):
    p2.low()
    green_led.on()
    red_led.on()
    if (dur == 0):
        return
    time.sleep_ms(dur)
    p2.high()
    green_led.off()
    red_led.off()

def init_gpios():
    p1=pyb.Pin(P1_PIN, pyb.Pin.OUT_PP, pyb.Pin.PULL_DOWN)
    p2=pyb.Pin(P2_PIN, pyb.Pin.OUT_PP, pyb.Pin.PULL_DOWN)
    p1.high()
    p2.high()

    return p1,p2

p1,p2 = init_gpios()
blue_led.on()

i=0
while True:
    if i > 10:
        sensor.sleep(True)
        time.sleep_ms(500)
        sensor.sleep(False)
        i = 0
    i = i+1

    img = sensor.snapshot()         # Take a picture and return the image.
                                    # to the IDE. The FPS should increase once disconnected.
    tag_list = []

    try:
        tag_list.extend(img.find_apriltags(families=tag_families))
    except (MemoryError, OSError):
        pass

    for tag in tag_list:
        if tag.id() == last_tag:
            tag_repeat_cnt = tag_repeat_cnt + 1
        else:
            tag_repeat_cnt = 0
            last_tag = tag.id()

        if tag_repeat_cnt > tag_repeat_threshold:
            if tag.id() > 1 and tag.id() < 100 and state==STATE_NORMAL:
                print("Access granted (FRIEND): {}".format(tag.id()))
                set_p1(1000)

Obviously this isn’t super secure but most people who are breaking into houses aren’t sophisticated enough to know about Fiducials. Most people will assume the camera is for someone in the house to remotely activate a switch. I am actually using somewhat different code.

Because the only power I have out there is the deep cycle battery running the gate controller, I put the OpenMV to sleep for 1/2 second at a time. Seems to do ok and has gotten through an entire winter with temps that fell to -40C.

3D printer upgrade, Klipper, thermistors, and power supplies.

By   September 29, 2020

Boring preamble

It took forever for my 3D printer to reach temperate and then the bed heater just stopped working. Not sure what happened.  So friend Derwyn gave me a spare Prusa magnetic heated bed.  This was a terrific gift!

Bad: it’s 24v and the rest of my printer is 12v.

Good: I had a 24v 60A DC power supply!

Good: I had a Creality CR10s v2 controller that has both 12v and 24vdc inputs.

Bad: my extruder heater was 12v, fans were 12v, etc.  I don’t have a spring steel sheet.

Good: those items are cheap on Amazon.

Anyway, to make along preamble shorter, I changed everything all at once except some acrylic and some bolts.   I also decided Klipper was worth a try because Marlin is a disgusting mess of nearly incomprehensible twisty #ifdef’s and my printer was a mashup of several different printers.  Let me tell you, Klipper is a breath of fresh air and worthy of a different blog post.

Meat of this article

I was having trouble getting the PID on the extruder to settle on a temperature.   Especially the high temperatures (230+):

PID can't settle this down

 

It took forever for prints to start because Klipper could not get the printer to the proper temperature.

I accidentally stumbled upon this Hackaday post which is a link to this fellow who helpfully outlines the process to change a capacitor to better filter power on the CR10s v2.0 board that I have.  Could that be the problem?

So first I decided to check the current state of things.

Power with Extruder running.

Power with Extruder and Bed heater running

 

Here’s the best part.  Normally, Octoprint turns on the bed heater first, and when that comes up to temperature, it turns on the extruder heater.  However, I turned on the extruder first and set it to 260C.  Then I turned on the bed heater.  The two photos above show that.  Here’s what happened on Octoprint:

Note how Klipper was able to use PID to get the temperature under control until I turned on the bed heater

 

Look how the poor power filtering was affecting the ADC measurements for the Extruder heater?  The NTC 100k (B3950) thermistors only read 380ohms (approx) at 240C.  That means a difference of only a few ohms at high temperatures has a big affect on temperature.  So voltage swings will dramatically affect ADC measurements, causing havoc with PID!

I didn’t feel like waiting for Digikey and paying the shipping so I used a 220uf electrolytic capacitor instead.  Ugly as fuck but much better.

 

New lab!

By   August 28, 2020

The whole Covid-pocalypse thing has expedited our move to DebtRidge.  It was a temporary move and we’re mulling whether to make it more permanent, or at least, invert the weighting on where our possessions are located.

This created a new problem; not enough room for me to do my ‘lab’ type stuff.  The 28’x36′ shop is great for big dirty work (welding, grinding, sawing, transmission rebuilds, etc) but not so good for hot air rework, 3D printing, etc.

Here’s what I had to do for 3D printing in the meantime:

Oddly enough, one of the companies I work for had a portable building previously used by CATSA as a Portable Screening Unit (xray, walkthrough metal detectors, preflight security) and it was just sitting there doing nothing.  This portable building was able to collapse to a size barely legal for road transport, was able to lift itself up high enough for a truck to back a trailer under it, and has a 20kW generator!

After a couple of years of sporadic but persistent querying on my part, finally I was given approval to buy this building from my customer.  Now I had a new problem:  Where to put it.

A bit of excavation and compacting later and here we have it:

The next problem was transport.  It took 2 months of research until I arrived at something cost effective and reasonably possible. To spare the details, the end result is I paid to have it trucked to the road in front of the driveway, and then had 2 friends come over to back it down the driveway on a trailer I rented in Sundre.

Loaded and on the way to DebtRidge

In front of the driveway.

Ready to lower onto the rental trailer

Not much room to spare

On the pad just after removing trailer. Standing on 3 legs.

Powered up and expanded

20kW diesel generator!

Initial layout.

I have lots more stuff to put in and set up but at least it’s functional now.

More Google Nest Mini Hacks

By   December 26, 2019

A few minutes more of playing around this morning. I think I found where the Mic On/Off mechanism is located.  I think I found an I2C and a couple of devices on it (0x78, 10 bit?)(0x62 DAC?).  I’ve started annotating where things are that I find.

 

Google Nest Mini teardown

By   December 25, 2019

Google seems to be giving away these Nest Mini things so my son gave me one of his.  While waiting for the family to wake up on Christmas morning, I decided to tear into it and see what’s inside.  I’ve only been at it for a couple of hours so I don’t have much to report yet.

Once you get its pajamas off, you see a board with a cpu (Synaptics AS-370), some DDR,  and what looks like a TC58NVG2S0HBAI6 4Gb NAND.   On the back of the board is a Wifi/Bluetooth thing probably.  I haven’t taken the RF can off yet.

 

I usually start by soldering fly wires onto whatever test pads I can find and run the logic analyzer while I boot the thing in hopes I can find a serial port and maybe some I2C or SPI.

I found the serial port:

decompressing kernel image size 3866136…
kernel img addr 0x2080000, kern img len 12017672.
HACK! skip setup_android_kernel_param
mkbootimg bootargs: init=/init console= mtdblock.ro_fspart=”rootfs” ro nooverlayfs
Generated bootargs: init=/init console= mtdblock.ro_fspart=”rootfs” ro nooverlayfs
update opp V2 table to dtb
chip rev is A1
vl = 825000
vh = 900000
Got 2 value for vcpu vl and vh
chip rev is A1
Select PMIC chip sy8824b for Kernel !
Update silergy,sy8824!
Update cpu0-supply!
Delete silergy,sy20276 for Kernel !
Delete silergy,sy20278 for Kernel !
Delete silergy,sy20278 for Kernel !
Set dtb param for linux: ramdisk start 0xC3B0800, size 0x21EB30
chip rev is A1
chip rev is A1

Boot normal GTV image
Start kernel at 0x02080000, dtb at 0x0be00000

Looks like it’s running a modified Google TV image just like the old Chromecast.

The Serial console is at 1.8v and I don’t have a USB<->TTL serial converter at 1.8v right now so it looks like that’ll be the end of that for now.  I’m guessing it won’t let me interrupt the boot anyway and nothing appears after the kernel boots (see “console=” is blank).

Time to open presents.

 

After firmware update, the serial port is slightly more interesting:

 

bg6cd z1 erom: release id 0x5741fac, commit time Fri May 17 14:26:53 2019 -0700
bg6cd z1 hal : release id 0x8651a82, commit time Thu Jun 13 09:30:56 2019 -0700
disable pcie
ild-in module: release id 0xd32a267, commit time Fri May 17 14:29:05 2019 -0700
Load sysinit
Start ACPU
set vcore
DHL v0p90
hw_init done
custom table done
asking BCM to load miniloader.
try to verify flash miniloader
init syspll 400MHz
image2_init fitnsismh: erd,e lejaumspe iingd 0txo 85nbe5xt58 6i,ma cgoem.
m
it time Tue Jun 25 10:2’14’tz5_:l5o0a der2 0s1t9art .- 0b7oot0_0s
t
rap=0x00010003 (source=SPI Secure), boot_state=0x0
syspll 400MHz, 600MHz
set nna_sys at speed 600
set nna_core at speed 600
set avio_sys at speed 400
set nna_core at speed 600
set avio_sys at speed 400
set atb at speed 200
set perif_sys at speed 200
set apb_core at speed 100
set nfc_ecc at speed 200
set nfc_core at speed 200
pinmux 0 0 0 0
clk a1 a1
clk a1 121
ULT (byte[0:7]) = aba80aa2ac782956
NAND block size 0x40000, page size 0x1000, ecc_strength 0x30
— TZ_loader — bootloader
NAND block size 0x40000, page size 0x1000, ecc_strength 0x30
Read from block 1
nand read 1250000, 7f800, 800
lastK: 0x202c237, 0x202c237, 0xa1346d2
NAND block size 0x40000, page size 0x1000, ecc_strength 0x30
ret = 0
tz_loader: image4 verified.
tz_en image load verify success
ret = ffe00301
Load LastK: return value: 0xffffffff
ret = 0
tz_loader: image4 verified.
bl_en image read and verify success
feature:video/dolby_vision=true; feature:video/tcl_hdr=true;
tz_loader: start image4.
NOTICE: BL31: v1.3(debug):7bf8e6b
NOTICE: BL31: Built : 09:46:49, Jan 18 2019
INFO: ARM GICv2 driver initialized
INFO: BL31: Initializing runtime services
INFO: BL3-1: Initializing berlinspd
INFO: BL31: Initializing BL32
tz kernel starting… total 4 cpus, v3.2.0.9, May 29 2019 10:48:04@HEAD:cff79c5
INFO: BL31: Preparing for EL3 exit to normal world
INFO: Entry point address = 0x4580000
INFO: SPSR = 0x3c9
Board: valens-b4

—— Entered Power_measurement_script() ——-
powerdown emmc
powerdown spi
powerdown pcie

—— End Power_measurement_script() ——
Pinmux reg 0: 0xf7ea0840 = 0x08003049
Pinmux reg 1: 0xf7ea0844 = 0x00009200
Pinmux reg 0: 0xf7ea0840 = 0x08003049
Pinmux reg 1: 0xf7ea0844 = 0x00009200
Pinmux reg 2: 0xf7ea0848 = 0x00000000
Pinmux reg 3: 0xf7ea084c = 0x00000000
Pinmux reg 4: 0xf7ea0850 = 0x00001200
Pinmux reg 5: 0xf7ea0854 = 0x00000000
Pinmux reg 6: 0xf7ea0858 = 0x09209249
PMIC detected with SY8824B
cpupll: 1400
PMIC: SY8824B selected!
chip rev is A1
leakage info 626.
set Vcpu from 850000uv to 825000uv
Clock configuration:
fts: v11 loaded from 0x00028000
chip is warm boot.
****************************************************************
Read and setup kernel Image
****************************************************************
DBGDBG k_buff_img[0]=0x0
DBGDBG k_buff_img[1]=0x0
DBGDBG k_buff_img[2]=0x0
DBGDBG k_buff_img[3]=0x20
decompressing kernel image size 3888875…
kernel img addr 0x2080000, kern img len 12085256.
HACK! skip setup_android_kernel_param
mkbootimg bootargs: init=/init console= mtdblock.ro_fspart=”rootfs” ro nooverlayfs
Generated bootargs: init=/init console= mtdblock.ro_fspart=”rootfs” ro nooverlayfs
update opp V2 table to dtb
chip rev is A1
vl = 825000
vh = 900000
Got 2 value for vcpu vl and vh
chip rev is A1
Select PMIC chip sy8824b for Kernel !
Update silergy,sy8824!
Update cpu0-supply!
Delete silergy,sy20276 for Kernel !
Delete silergy,sy20278 for Kernel !
Set dtb param for linux: ramdisk start 0xC3B6000, size 0x21EF1C
chip rev is A1
chip rev is A1

Boot normal GTV image
Start kernel at 0x02080000, dtb at 0x0be00000

Homeassistant Internet monitor and reset

By   November 9, 2019

The Xplornet modem out at DR has decided to become unreliable and needs a sporadic restart. I’ve been pleased with how well the TP-Link Kasa HS105 Wifi switches perform so I just needed to figure out how to get HomeAssistant to reliably monitor the internet connection and reset it without inducing an infinite power-cycle loop. This is what I ended up with. Seems to work ok.

 

In configuration.yaml:

device_tracker:
platform: ping
hosts:
google: 8.8.8.8
beer: 67.205.176.146

In automations.yaml:

- id: Ensure Internet is on
alias: Ensure Internet is on
initial_state: on
trigger:
platform: state
entity_id: switch.internet
to: 'off'
for:
minutes: 1
action:
service: homeassistant.turn_on
entity_id: switch.internet

id: Ensure Internet is on at HA startup
alias: Ensure Internet is on at HA startup
initial_state: on
trigger:
platform: homeassistant
event: start
action:
service: homeassistant.turn_on
entity_id: switch.internet

id: Restart internet connection
alias: Restart internet connection
initial_state: on
trigger:
- platform: state
entity_id: device_tracker.google
to: 'not_home'
- platform: state
entity_id: device_tracker.beer
to: 'not_home'
condition:
condition: and
conditions:
- condition: state
entity_id: device_tracker.google
state: 'not_home'
- condition: state
entity_id: device_tracker.beer
state: 'not_home'
action:
service: homeassistant.turn_off
entity_id: switch.internet

Super slow write speeds to Synology DS414

By   December 2, 2018

I was successfully running my DS414 with a combination of 4TB+4TB+4TB+1.8TB disks in two volumes.  I wanted to increase capacity so I bought a 6TB seagate external disk because the price was right.  I figured I’d pull the disk out of the chassis and slide it into my NAS.  Mistake number one.

The disk inside the chassis was a Seagate ST6000DM003.

After waiting 3 weeks for the volume to resize I started using the Volume.  My plan was to move some ProxMox containers and VM’s onto the Volume as part of a PVE update.  But any reads/writes to/from the volume would cause the entire volume to lock up for 30 seconds at a time.  This was causing Plex streaming to block as well. Something was wrong.

I used the Synology tools to try to figure it out but there was no help there.  So I did what I do best and dove into the shell.  I ssh’d and started digging around.   After some digging, here is what I discovered.

Here’s the configuration:

/dev/sda – Seagate ST4000DX001

/dev/sdb – Seagate ST4000DX001

/dev/sdc – Seagate ST6000DM003

/dev/sdd – Western Digital WD40EZRX

/proc/diskstats showed that the weighted average IO completion time for the ST6000DM003 was 160x slower than the other disks:

sh-4.3# cat diskstats | grep ” sd[abcd] ” | awk ‘{print $3,$14}’
sda 5628640
sdb 5558600
sdc 946825590
sdd 5950130

I have a bad disk.

The more bad news is that Seagate’s website doesn’t appear to be able to pull up the warranty status because the disk serial number is not found on Seagate’s side.  I probably have to get the serial number of the chassis.  This probably implies that Seagate is not going to honor the disk warranty because I pulled it out of the chassis.   I’ve sent a support request so we’ll see what I get back on that.

 

Anyone have a use for Yak fur?

By   September 15, 2018

This morning, I find myself with a small corral of naked Yaks. I’m guessing most people know about Yak Shaving Here’s how it went this morning.

Actually, it started yesterday.  I wanted to change the thermostat setting at the Cabin so it’d be nice and toasty when we got there.  Can’t for some reason.  Dig into the HomeAssistant console and discover the reason is that the component for my Venstar ColorTouch thermostat isn’t disabling the schedule so changing the temperature fails and generates an error from the thermostat.  I should fix it.

I figure out how to fix the bug but in order to submit a patch, I need to upgrade my HomeAssistant installation.

So do all the requisite ‘git fetch; git merge upstream/….’ stuff, and then upgrade everything in the virtual environment.

Unfortunately, I can’t upgrade the virtual environment because my Python is too old.

Can’t ‘apt install’ a new Python because I’m on an old Ubuntu 16.04.  Don’t want to go down that path right now.

Download a new Python, build, install.

Create a new virtual environment and reinstall all of the packages.

Installing packages fails (Twisted) because libbz2-dev wasn’t installed.

Install libbz2-dev.

Rebuild Python and reinstall.

Create a new virtual environment with the new python and reinstall all of the packages.

Installing packages fails due to a build problem with libopenzwave.

Looks like I need to upgrade my toolchain (g++ specifically).

I don’t like the look of that particular Yak. Lets try upgrading to Ubuntu 18.04.

My current version of ProxMox doesn’t support Ubuntu 18.04.

I need to upgrade ProxMox first.  Oh, that’s the greasiest Yak yet. It’s a major version upgrade.

I should really just build a new ProxMox from scratch, while running the old one.

I don’t have enough hardware to build a new ProxMox server, even temporarily.

I think I’m on the last Yak. So in order to submit a patch against HomeAssistant, I need to go to the Hardware Store.

Recover your zoneminder data after inadvertent loss of ib_logfile[01]

By   September 3, 2018

In the unlikely event that you’ve lost your Mysql ib_logfile[01] files, you will google and try to figure out whether you can get the data back.  All the googling will tell you that all of your data is in those log files but that’s not true as of any recent version of mysql.  I was looking around in /var/lib/mysql/zm/ and noticed the .ibd files were sizable which suggested the data was actually in there instead.  After some googling, I found you can import data back into a freshly created Zoneminder DB.

I decided to uninstall/reinstall zoneminder  from scratch and then recreate the DB:

https://stackoverflow.com/questions/18761594/how-do-i-do-a-clean-re-install-of-zoneminder

After doing that, I did the following:

(there are shell commands interspersed with the mysql commands so you can see the order of operations):

 

lock tables Devices write;
alter table Devices discard tablespace;
# cp -p saved/Devices.idb /var/lib/mysql/zm/
alter table Devices import tablespace;

lock tables Events write;
alter table Events discard tablespace;
# cp -p saved/Events.idb /var/lib/mysql/zm/
alter table Events import tablespace;

lock tables Filters write;
alter table Filters discard tablespace;
# cp -p saved/Filters.idb /var/lib/mysql/zm/
alter table Filters import tablespace;

lock tables Frames write;
alter table Frames discard tablespace;
# cp -p saved/Frames.idb /var/lib/mysql/zm/
alter table Frames import tablespace;

lock tables Groups write;
alter table Groups discard tablespace;
# cp -p saved/Groups.idb /var/lib/mysql/zm/
alter table Groups import tablespace;

lock tables Logs write;
alter table Logs discard tablespace;
# cp -p saved/Logs.idb /var/lib/mysql/zm/
alter table Logs import tablespace;

lock tables MonitorPresets write;
alter table MonitorPresets discard tablespace;
# cp -p saved/MonitorPresets.idb /var/lib/mysql/zm/
alter table MonitorPresets import tablespace;

lock tables Monitors write;
alter table Monitors discard tablespace;
# cp -p saved/Monitors.idb /var/lib/mysql/zm/
alter table Monitors import tablespace;

lock tables Servers write;
alter table Servers discard tablespace;
# cp -p saved/Servers.idb /var/lib/mysql/zm/
alter table Servers import tablespace;

lock tables States write;
alter table States discard tablespace;
# cp -p saved/States.idb /var/lib/mysql/zm/
alter table States import tablespace;

lock tables TriggersX10 write;
alter table TriggersX10 discard tablespace;
# cp -p saved/TriggersX10.idb /var/lib/mysql/zm/
alter table TriggersX10 import tablespace;

lock tables Users write;
alter table Users discard tablespace;
# cp -p saved/Users.idb /var/lib/mysql/zm/
alter table Users import tablespace;

lock tables ZonePresets write;
alter table ZonePresets discard tablespace;
# cp -p saved/ZonePresets.idb /var/lib/mysql/zm/
alter table ZonePresets import tablespace;

lock tables Zones write;
alter table Zones discard tablespace;
# cp -p saved/Zones.idb /var/lib/mysql/zm/
alter table Zones import tablespace;

After that, ‘systemctl restart zoneminder’ and hope for the best.