Sunday, October 8, 2017

SSL Secure Communications in XTension

My day job remains, happily, the Home Automation software XTension. We’ve managed to avoid creating a “cloud” for ourselves and yet have to weather lots of questions about data security. Especially for the Web Interfaces that we have customized for mobile clients or desktop clients. The truth is, if you’re willing to write a few numbers on a card in your wallet you can verify the serial number of the certificate from a public computer, and if you’re connecting from your own laptop or phone then your keychain will do that for you and it’s trivially simple to know if someone is performing a man-in-the-middle type attack despite the horrible brimstone and everybody is going to die warnings from your browser. Secure Communications in XTension

Friday, September 22, 2017

cMediaFile a Xojo class for serving video or audio files to Safari on MacOS and iOS

My day job is as a developer for XTension a Mac based home automation system.

Some years ago something changed in Safari and it stopped playing the video clips that XTension saves off in response to motion or other perimeter violations. I could never get it to work on iOS either. This was remarkably frustrating to have to tell people that to view the video archives in the Web Interface they had to use a different browser. It continued to work just fine in Chrome and Firefox. I thought at first that it had to do with using a self signed certificate but it turns out that Safari absolutely requires you to support the Range header and to properly reply. The other browsers were happy with my response of the entirety of the file even though they also initially ask for a smaller range of bytes. Safari was not happy with that and flatly refused to load the files at all unless I supported their range request.

The Web Remote and Mobile Web Remote in XTension are developed with Xojo and the built in webFile class does not support range requests. Since figuring this out I’ve been able to implement a replacement class that does support them. Should any other Xojo developers need to serve up video or audio files to Safari or Mobile Safari they are free (as in beer) to use the cMediaFile class and even to improve it and make new submissions at the github repository.

Download the class and example project:

Here’s an example of XTension’s Video Archive page now working again in Safari!

Friday, August 18, 2017

Veneered Mantle

We recently “finished” some small additions to the house. A 2 month estimated project that took 7 months to complete. Then it was my turn to start working on the parts of the project that I wanted to do. That has also stretched out a bit in time, but at least now my long suffering wife knows she couldn’t get it done any faster by hiring an actual contractor ;)

We both hated the family room fireplace (and don’t even get me started on the living room fireplace, that is another blog entry and is now completely gone) it had a real flue at least, unlike the living room “fireplace” but was such a small firebox that once you put 2 logs into it the fire didn’t even start until it was up above the top of the hood. It was built into one of these great mantle/surround things. They look nice from a distance but up close they are just a bunch of particle board moldings screwed together, really clunky and not very nice or useful at all.

As part of the addition we had a hearth built and what turned out to be a very nice faux stone chimney made. I’m really happy with the way the stone turned out but I wanted a nicer mantle than what they would give me. Offers of a nice piece of reclaimed lumber or something doesn’t really fit with what I wanted so I asked then to just give me a 2x4 cleat across the stone onto which I could attach a mantle I could build myself.

The wiring from the outlets along that wall also ran through that space so I was able to bring it up through the mantle and mount another outlet on to what will be inside the mantle for plugging in lamps and clocks or anything else without having a cord falling over the side which was important to me as that always looked horrible on the existing mantle.

The box is pretty simple. Half inch plywood with an inside system of supports to make sure it stays square and strong. I drilled them out in the middle though so that any wires I ran to anything could get back and forth. The cut out on the top will be removable panels with some holes drilled for cords to come through up where you need them.

Then I went to test fit the box only to discover that the 2x4s they put up were not really alined with each other and weren’t actually straight either. Several hours of messing around with an oscillating saw and a lot of sawdust later and I had straightened up the cleat good enough for the box to fit snugly over and let it get right back against the stone. In retrospect I should have disconnected the wires and just taken off their cleats and added fresh ones of my own but somehow that didn’t occur to me at the time. The rule is doing it wrong takes a lot more time and effort than doing it right ;)

After trimming and shimming the cleats it fit very nice and tight and I only had to take a cold chisel to a couple of stone corners to make it fit fully into the stone face. I ran into another problem which you can see in the first picture above. The electrical wire was getting crimped by the support blocks and keeping them from being flush with the cleat. I could have removed the wire and pulled it through the supports, but I wanted to be able to take off the mantle in the future if the veneer failed or if something happened that I needed to change or fix it. So back to the oscillating saw and I cut some notches into the cleat to allow the wire to safely snake around the support blocks. This removes some of the structure of the thing since they won’t be pressed against the cleat, but it turned out that didn’t matter, it’s plenty strong even before I screwed it into the cleat from top and bottom. Now that the box was complete and fitted it was time to decide about the veneer.

I’ve been wanting to invest in the tools to do real veneering for a long time. Since this was a Significant Other approved project I was able to justify the purchase of a lower end vacuum pump and veneer press. Unfortunately the mantle box is a little longer than 4’ and I only bought the 4’ veneer compression bag. Instead of just buying a larger bag and waiting for it to arrive I decided to go with regular wood working glue and lots and lots of clamps and cauls.

I ordered some beautiful Redwood Burl veneer from along with the bag and vacuum pump. When it arrived I realized I had another problem. It would have to be flattened in order to properly adhere to the workpiece. For this at least I was able to use the vacuum bag and veneer press. The internet has many products you can spray on the veneer to soften it for flattening and many recipes for DIY flattening and much discussion claiming its pressure or temperature or chemical that you use that is better. It was actually hard to choose a mode of working on this that I knew would work given how many ideas are out there and how adamant the various players are. I ended up using a formula of mostly water with a small amount of glycerine in it. The glycerine to soften the wood, but not so much that it would affect the staining or finishing or glue up process. I gave the pieces a gentle spray, packed them between sheets of masonite and loaded them into the vacuum press overnight.

What came out was beautiful and flat and ready for book matching and layup. I gave it a quick wipe down with some isopropyl alcohol to remove the surface glycerine as my tests with small pieces showed that really did mess up the absorption of the oil finish if I didn’t do so. This was also a very oily veneer which would affect the adhesion of the finish without doing this. Acetone would probably have worked better.

I’ve never done anything with veneer before at all so this was an adventure. Instead of cutting the pieces to make them line up perfectly I used fine sandpaper on a wooden block. Taking 2 pieces of veneer that matched and folding them over so the two edges that would match up were together. Then clamping that between 2 pieces of wood without about half an MM or more if necessary to get the angle right, sticking out. Then gently used that sanding block to sand them down flat with the wood they were clamped between. When they were taken out they would open out and fit together perfectly. Again without all the proper tools I didn’t bother with veneer tape, just blue masking tape to hold them together as I prepared them to be glued to the box.

Lots and lots of clamps and cauls later I was really happy with the result. Don’t look too closely at the corners and edges that got dinged. This was a very fragile veneer. I hid most of those spots during finishing either with a little spot of veneer roughly matched or some appropriately colored stain.

The final veneer before finishing really looked nice and made me very happy!

First a coat of Linseed oil to really bring out the color and figure. It darkened up a little more than I would have liked, maybe danish oil next time which I think has less of a darkening effect from what I’ve seen. Perhaps I didn’t experiment with different finishes on this enough before jumping in, but it still turned out fantastic.

Thursday, April 13, 2017

The Makerbot is dead, long live the Makerbot! And a new Monoprice Select Plus 3D!

I actually use my 3D printer for printing small runs of plastic parts. They go with the Smart Meter Reader Kit and some others for kits that are not shipping yet as of this writing. They all connect to my day job which is XTension. Last week I needed to print another smart meter sensor mount for someone and found that my Makerbot was no longer recognized over USB even though it seemed to be working OK from the front panel. So the next thing I tried was to get it to print off it’s CF card and it wasn’t able to find anything on the car either even though it had just printed from that card a few months ago. Not having time to try to troubleshoot the boards myself right now I decided to upgrade to a new printer! Enter my new Monoprice Maker Select Plus 3D Printer!

Costing less than a quarter of what the Replicator cost me several years ago and supposedly producing better prints. I’ve only had it for a few days now, but I’m generally hopeful that it will be a good printer and do what I need and for under $400 you can’t beat the price for anything with that build volume and a heated bed. Putting the hardware together was very simple but the software is a huge problem. As with most things in the inexpensive range of open source stuff it’s a nightmare to figure out how to use the thing. The documentation Monoprice is shipping with recommends Cura as the slicer and control app to use. Unfortunately their docs are enough versions behind the current Cura release that there is not a single window or screen in the app that looks like what they show. Every single option is in a different place and many of them no longer exist in the app at all. Trying to slice a model for it was very frustrating on that first day. It did print the test files that come on the CF card very nicely though, as good as my makerbot after lots of tweaking and fiddling with settings and several failed prints as part of the tweaking process. So I was still positive this was going to be a useful printer if I could just figure out the software. 

There is an old version of Cura included on the CF card, but only for Windows. Why would they customize an old version of the app rather than supply the files so that you could more easily add the printer to the latest version? I have no idea. But it’s useless to me on this Mac and it’s becoming more and more useless to windows users as it gets older and older compared to the current release of Cura. 

There are a lot of older web articles explaining how to extract the profile information from the models that came with on the card, but this is also no longer available in the newer versions of Cura. Finally the best resource I found talking about it is at This is a fantastic site! The monoprice printer is a re-branded Wanhao duplicator I3 plus. On that site is a link to the slicing profile info that you need to know in order to make really nice prints on it. The same settings that were used in the demo files that ship with the printer that worked so well. The out of date instructions imply that you can somehow extract the profile info from the gcode files, but I could not find that feature anywhere in the current Cura versions so you’ll need the link from the wiki to get that setup.

Everything you need to know is on that site but you’ll do a lot of reading to get to it. 

more info here too on the machine settings

Additionally there is little point in trying to get Cura to print to the device via USB. It says it’s theoretically possible, but I was unsuccessful in making it notice the printer was connected even after a large amount of screwing around with different usb/serial drivers and settings in the Cura configuration files. I would stick to using the CF card and sneakernetting it to the printer. This also means that if you have a software crash or a power failure or just want to restart your computer or wander off with it you don’t have to leave it on the desk for however many hours the print is going to take.

The sticker on the heated bed in this printer works very well for PLA, but I’ve just received my first upgrade in the form of a glass plate and will be attaching that and resetting the Z Axiz sensor soon.

A New XTension Version

Just news from the day job. XTension is a home automation and security program for the Macintosh and today we released a maintenance release fixing a few usability issues in the new unit list controls that we added in the last version. Also adding a few minor features like Bonjour/mDNS/Zeroconf support for the JSON/web server so that your IOT devices can more easily find where it’s running and on what port to report their status changes to.

Thursday, November 17, 2016

A Distraction of Bees During A Furnace Control Board Repair

I woke up half an hour before my alarm the other morning thinking it was rather colder in the house than it should be. The furnace blower was running, but it was just blowing cold air. Thats rather frustrating. Two years ago I had to have the control board in another unit replaced and knew that this was likely going to be an expensive repair and they weren’t going to have the proper parts and would need to order them and I’d have to wait with no heat. After getting the kids to school I went up to have a look.

When I started it back up the inductor blower started up properly and something was rattling around inside the flue pipe. The gas ignitor glowed red for a moment and then the whole thing gave up. It retried 2 or 3 times before giving up, starting the blower and flashing me an error code on the control board.

I should have realized at this point that since the igniter was lighting up that all the interlocks and sensors were working properly. It is unlikely that it would heat the ignitor and just not turn on the gas if a sensor was not seeing that the inducer fan was running or something, unfortunately I was still listening to that noise in the flue pipe and was distracted by that. I thought perhaps something had made a nest in the pipe so I disconnected it to have a look. I found dead bees...

Not many and they were all dead thank goodness, cooked or blackened by the heat. Continuing to ignore the fact that the ignitor was working I decided that the flue had to be blocked by a hive even though I could hear no buzzing anywhere and no live bees came out of the furnace or the flue. I still wasted the next half an hour taking apart the inductor fan and heat exchanger to see if the sensor pipe was clogged with hundreds of cooked bees or something. This involved messing with some rather friable high temperature fiberglass gaskets that would be nasty if you got it on you or inhaled it. You probably don’t want to remove those parts because of that.

It turns out that the bees were not the problem at all and had just distracted me from what should have been the obvious conclusion that the gas valve wasn’t turning on. Now that I had eliminated the impossible bees I could move on to actual debugging. Keep in mind that your furnace has many ways to kill you, exposed line voltage, high pressure gas lines, quickly spinning sharp things that may start up when your finger is in a place to get sucked into them, a gas ignitor that heats to red hot and fire to name just a few. Then if you don’t get it back together right or if you don’t wire the interlocks back on properly it won’t protect you from itself later and may burn your house down or kill you and your family from CO poisoning some night months or years from now. Even if it doesn’t kill you it might eat itself and replacing a cracked heat exchanger because the temp cutout wasn’t working is very expensive and not something you can do yourself. I make it a point to actually look at things before I call a repair man because many times it turns out to be something I can fix and save myself the call. But thats my choice and you should probably make a different choice for safety’s sake.

Putting the meter on the gas valve showed no power to the solenoid so it wasn’t just that the gas valve was bad, the board wasn’t sending it any power. At this point if you’re screwing around inside your stuff you probably want to turn off the circuit breaker so that you don’t hit the cutoff switch while you’re holding the board and electrocute yourself.

Tracing the wires from the gas valve to the large plug at the bottom of the picture above and then to the relay right next to it. In my case there were 2 sets of red and blue wires going into this plug, so don’t rely on color to tell you which wire was which. I gave that relay a short sharp wrap with my screwdriver and reconnected it. For 2 cycles it sent power to the gas valve! Success we found the problem! I can replace a relay on a single sided PC board no problem. Unfortunately it was an 18v coil and I didn’t have any of those laying around to just drop in. I considered replacing it with a solid state relay for a moment, but the ones I have on hand don’t have an input voltage range that goes that high, and they weren’t the same form factor so I would  have had to make a mess of it by running wires to an external relay. Not an ideal solution.

Then it occurred to me that when the other furnace failed for a similar reason a couple of years ago I had actually saved the control board that they swapped out at great expense. One of the relays on this board was bad too, but there are 4 identical relays on the board so I should be able to find one of them that was still good!

You’ll see 4 empty positions on this board where I desoldered the relays. The boards are conformal coated on the back and have lots of surface mount components on the back side. You can’t desolder through the coating so I used a dremel with a small wire brush to scrape off the coating and get to the pads.

Being very careful not to damage the surface mount parts or scrape off the tiny traces that were very close to the relay pins! That was less important on the old board than it would be when working on the new board, but this was an opportunity to practice. It turns out that the brush also removed most of the solder as well turning it to very fine dust that covered the board and went into the air. This board is probably older than lead free solder so I decided to do the rest of the pads outside so that I wouldn’t breath in any lead dust or get it all over my work bench. With most of the solder scraped off the pins they desoldered very easily. It’s interesting in the picture to see the surface mount transistor and snubber diode that controls the relay and protects the CPU from induced back current are right under the relay itself there.

I was a little concerned about making sure which of the old relays was bad, but that turned out to be easy. Not just an intermittent or faulty connection one of them had a coil that was open circuit so filtering out the bad one was easy. That left me with 3 good ones. One to repair this board and 2 to save for future spares.

Now it was time to remove the existing board from the furnace. You did turn off the circuit breaker before you did this right? I would also consider it vital to label all the wires you’re taking off, there are many connections and nothing is obviously labeled on the board other than the thermostat wires. Even the thermostat wires on my furnace didn’t match up color wise, the power lead wasn’t red, it was yellow. They had run the power to the thermostat through the float switch in the pan below the furnace and returned that with a different colored wire to those connections. So don’t just rely on your perfect eidetic memory to remember where all these connections go. Make labels and take pictures.

I was concerned about the yellow and red wire there going to the blower. They were both on a pad that was called “park” rather than going to a specifically named pin that I could label them. So I took pictures of that to get it right again later. It occurred to me later that “park” probably meant that they were not connected to anything and were just “parked” there ;) Looking on the back of the board did reveal that those wires are not actually connected. It’s a place to park extra leads from the blower motors so they aren’t flopping around in there shorting against other things or getting sucked into the blower. I believe they are for running the blower at different speeds and were not needed in my install. In the case of “parked” leads the order you connect them won’t matter. Everything else is important to get right or you’ll cook the board or burn your house down.

This is the existing board. You can see there is quite a bit of discoloration of the conformal coating around some of the surface mount components where they get quite hot. None of them have failed yet, so perhaps they are still within their spec. There is a lot of airflow in that part of the furnace since this board mounts inside the blower cabinet. These still get hot enough to discolor the coating, that doesn’t look good. 

Since I had already dremeled off the coating over 4 other relays on the old board doing it one more time without damaging the surface mount connectors or board traces was easy. Since I knew the board was bad anyway if I had damaged them and couldn’t repair it I wouldn’t be any worse off than I already was except for wasting all this time.

The replacement relay has been soldered on! The conformal coating around the pads bubbled up and burned a bit during the soldering process but I was less worried about that then melting the solder on the adjacent surface mount components and having them migrate away. That didn’t happen when I was desoldering on the other board though and that takes much more time and heat than putting a new one back in. I think the coating would keep them in place even if you did overheat the board, at least to a point, but you’ll want to be careful not to do that.

Put the board back in and used my pictures and labels to reconnect all the terminals on the board and we have heat again! Nobody does board level repairs anymore but it can certainly be done depending on what the problem actually is. I have 2 more spares for when more relays fail on these now aging furnaces in the house. So far so good and however many more seasons of heat I can get out of these before they need to be replaced will save money.

Friday, July 22, 2016

OSX’s “powerd” daemon has some bugs...

There are manthreads on the internet about problems with the “powerd” daemon in OSX using up huge amounts of CPU time until everything else grinds to a halt. For me this problem started in Yosemite and has continued even through El Capitan 10.11.5. There is a .6 update for that now that I will install on my server shortly and see if that makes any difference.

On one site someone offered a bash shell script to regularly monitor the CPU usage of powerd and to kill it if it goes above 30%. I’ve wrapped that into an executable file that actually starts up in bash and doesn’t throw errors trying to run in tcsh which is the default shell on my system. I also added some code to send the CPU usage to XTension as well as keep track of the restart count. This way I can graph the CPU usage which looks like this over the last 2 days:

It takes just short of 11 hours for the spikes in activity to exceed the 30% threshold that causes the script to kill it and the system restarts it. I have no idea what the problem is, but something is definitely going on there. This graph is 24 hours of samples taken every 10 seconds so what you can’t see is that still most of the time in between those peaks it’s at 0% usage. Then it goes to do something periodically and each time it does it it takes a little bit more time. Some table not getting cleared? I don’t know what the cause is but it’s definitely real looking at that. Eventually if not killed the CPU usage becomes constant as it doesn’t finish servicing it’s queue before it has to service it again and the CPU usage becomes constant and debilitating to the machine.

If you’re also suffering from problems while having to continually kill powerd you can use this script. Cut and paste the code into any text editor, I like TextWranlger rather than using text edit built into the system, but any of them will work. Save it with the filename “powerd_monitor.command” the name is important! It must end in “.command” (and not .command.txt which text edit might try to add to the end of it) and it must be named powerd_monitor. This is because the script searches through the list of all processes for those containing the term “powerd” and it has to know how to exclude itself from the list that is returned. If you name it something else that also includes the term “powerd” then it will find multiple matches when searching and everything will error out and fail to do anything for you. So name the file “powerd_monitor.command”

You have to add the execute bit to the file. without that it won’t run when you double click it. If you’re terminal aware then thats easy. For anyone who isn’t you can do so by opening a terminal window and typing “chmod a+x “ (note the space after the x!) and then dragging the text file you’ve just created into the terminal window and pressing return.

If you aren’t an XTension user then you’ll want to remove the 2 lines that echo an applescript into osascript. Otherwise you’ll get an error printed for that with each check. Remove the 2 lines that begin “echo “tell app \”XTension\””

Lastly you must fill in your admin password into the first line of code where is says “sudopass=“ since the powerd is owned by the system and not the user you can’t kill it without executing the kill command with sudo to get the proper permissions to do so. Otherwise it will fail to actually stop the process.

The output in the terminal is multiplied by 100. So 0.1% comes out as a 10 and so forth. I don’t know why the original script author had to do that, but I suspect it’s because bash is bad at math and wasn’t able to compare against floating point numbers properly. 

The interval is currently set to check once a minute, but you can extend that or reduce it as necessary by changing the sleep value at the end. Of course, running the script too often will cause it to use far more CPU time than is necessary and make your problem worse not better. I generated the graph above with a check happening every 10 seconds.


# fill in your sudo password below or it won't be able to kill the process
# in XTension create a dimmable pseudo unit named "powerd cpu usage"
# in XTension create another dimmable pseudo unit named "powerd restart count"
# checks the cpu usage of powerd and if it's more than 30% it will kill it for you
# the output of the echo value is *100 so will say 40 for 0.4%!

sudopass='your sudo password here'
while true ; do
  cpu_usage=`ps aux | grep powerd | grep -v grep | grep -v powerd_monitor| awk 'BEGIN {ORS=""} {print $3*100}'`
  echo "powerd is using $cpu_usage"
  echo "tell app \"XTension\" to set value of \"powerd cpu usage\" to ($cpu_usage / 100)" | osascript -
  if [ $cpu_usage -ge 3000 ] ; then
    echo 'killing powerd!!!'
    echo $sudopass | sudo -S /usr/bin/killall powerd
    echo "tell app \"XTension\" to set value of \"powerd restart count\" to value of \"powerd restart count\" + 1" | osascript -
  sleep 60

There is some talk in some of those forum posts that just not running Activity Monitor or not running some other app that is listening to events from the powerd daemon solves the problem. I am testing that now on my server but it hasn’t been off long enough to tell yet. In the first hour since I quit it it seems like it might be making a difference but it’s too early to tell. I will update this afternoon when I have some more info. I have personally spoken to people who never ran activity monitor on their machines during the issue though, so that is not the only cause even if it does help mine. Perhaps something subscribed to the events from it is enough to make it start to leak CPU. Perhaps it’s calculating the energy impact which is faulty that some of those apps cause it to have to do constantly. I will play with some of those other issues after I’m done with a cycle without the activity monitor running.

UPDATE: it sure looks like just not running activity monitor is keeping it from climbing away in my case.

Since about 10:30am it’s CPU usage hasn’t climbed above about 0.5% of the CPU that it’s running on. It shows no signs of continuing to leak CPU time.

This is definitely not the only problem that causes this as my day job work neighbor Michael has the problem and has never left activity monitor running on his machine. I expect that just quitting the program won’t solve the problem, but it might keep it from continuing to escalate until you restart or kill the powerd. I will continue to watch and post any further observations as it’s a very frustrating problem!