Saturday, January 6, 2018

Copper Veneer Is Beautiful

I am in the middle of a project building floor to ceiling bookshelves across one wall of our living room. It’s a rather larger project than I normally take on and has provided many unique and stimulating challenges both in design and fabrication... We decided on a gentle arch at the top of each book case and in order for them not to look ordinary and drab I’m experimenting with some antiqued copper veneers that I got from Veneer The same place I got the wonderful dark burl I used to make our Veneered Mantle. I chickened out and didn’t buy any of the really weird and wonderful copper patinas available, but opted for a sheet of just the antiqued stuff to experiment with.  this stuff is beautiful.

This is just a test run to hang one up so that She Who Must Be Obeyed can get a feel for it and make sure that it’s what she wants before I commit to making a dozen of these things. There are only 6 bookshelves, but there will be an arch at the top section, and an arch below the library ladder rail 8 feet up. With each part of this project I keep thinking that won’t be a lot of extra work, and then I remember that oh, there are six bookshelves so I have to do it six times. And then with these I have to make twice that number. But it will be worth it, these look fantastic.

Now if only I could make the stain on the routed edge look a bit more even. I will have to sand that a lot more aggressively to smooth out the wood before applying the stain on the real ones.

Dont worry about the slightly funky edges. I made it an inch or so wider than it needs to be and will trim those off to perfection on the table saw before putting it into place.

Friday, January 5, 2018

High Sierra hangs your main thread when the screen is asleep!

Thanks to Ben Bird of bensoftware and SecuritySpy fame I was able to work around the problem in High Sierra. If any Mac users are interested in really good DVR software I can whole heartedly recommend his Security Spy app. It works great with XTension and we even have an interface that will let you get motion data out of the program and assigned to units in XTension for taking other actions based on that.

The problem is evident in Mac OS version 10.13.2 and may actually have been introduced in the .2 update as I don’t recall having this problem immediately upon my updating to High Sierra but only more recently. I could be completely wrong about that though.

It turns out it has nothing to do with App Nap at all, I was barking up the wrong tree about that completely. It’s a rather nasty bug in some of Apple's screen drawing code. If you have an app that has an interface and it causes interface elements to update once the screen goes to sleep High Sierra will eventually just hang. Something causes a thread contention with the screen drawing. This might not be a big problem for most user apps as if the screen is asleep then you’re not using them. They will wake up along with the screen as soon as you touch the computer again. For an app that needs to keep doing things while you’re not there like XTension does this is tragic.

My first attempt at a fix was not successful. You can subscribe to events to tell you when the screen is put to sleep or woken up. In the event where the screen is going to sleep I hid all my open windows and in the event waking up the screen I showed them again. This was not enough to stop the thread contention issue. Possibly even drawing the menu is enough to cause the problem. I am not able to disable all the drawing in the app as far as I know. Though there are calls for windows to defer updates. There may be a Cocoa way to disable all screen drawing and I’ll have a look at that later. The pressure is off right now because I was able to get it working with a background helper app to check for the the main thread hanging in the app.

Ben had suggested a thread that pinged or otherwise checked on the regular spinning of the apps main thread. I tried this, but since I’m working in Xojo I’m limited to cooperative threads. If you block the main thread in a Xojo app you also block any other threads. Which is important to know if you’re working with threads and using semaphores to manage access to resources between the threads and the main thread. So I wasn’t very confident that the pinging thread would be effective since I expected that thread to get hung as well. That was indeed the case, the second thread stopped as well and so was never able to wake the screen.

The solution, hopefully temporary until Apple fixes this, was to create a separate terminal app to do the waking of the screen. Since command line apps have no GUI they aren’t affected by the problem. The background app just listens for a single character to arrive via STDIN. If it doesn’t get one from the main app at least every 5 seconds it makes a call to the Power Manager to assert a User Activity. Using the MBS plugins for Xojo this is easy, but I suspect it could fairly easily be done with a declare or external method call to the right library.  To wake the screen I just did this:

Dim userActivityID as integer

Dim err As Integer = IOPMAssertionMBS.DeclareUserActivity( "waking screen for thread contention", IOPMAssertionMBS.kIOPMUserActiveLocal, userActivityID)
You’re supposed to keep that userActivityID around and re-use it for any previous calls, so don’t just reset it to 0 each time you make this call. Though I’m not sure if thats really necessary.

The terminal app is copied into XTension’s resources folder during compilation and I’ve created an interactive shell class in XTension that is very simple. It just launches the app and starts a timer that sends a “P” to the shells stdin every second. Since timers fire on the main thread they are all silenced by the thread contention issue and so it stops sending that ping. 5 seconds later the screen wakes up and all starts working again. If I set the timing to much less than 5 seconds then I seem to get a lot of wakeups for slightly longer program operations like regular database saves and such. The 5 seconds seems a good compromise between having it hang all the time and just keeping the screen awake all the time.

Which is the other solution. You could just call that user activity constantly or tell your users to not let the screen go to sleep at all. Both things also “solve” the problem. Interestingly enough making the request to stop app nap and adding the flag for stopping idle sleeping of the screen did not solve the problem. So App Nap is not keeping the screen awake in those cases, or perhaps the screen saver is starting or something I don’t know, but just doing that did not solve the problem.

Sunday, December 24, 2017

App Nap in High Sierra

Update: 1/5/2018 It turns out this problem had nothing to do with app nap at all. It’s a thread contention issue in the screen drawing code in High Sierra and there is a very nasty workaround you can do to get it working. I’ve written about it Here

There is an undocumented change to how App Nap is handled in the latest build of the High Sierra operating system. In past OS versions the operating system actually believed you when you said you were executing a user initiated process and let your app continue to operate as normal even when the user wasn’t using your app. That seems no longer to be the case with High Sierra.

App Nap is a great idea overall. If your app isn’t being used it can be put to sleep and we can not waste the battery or the power to keep it doing all it’s interface animation and what now while the user isn’t using it. Unfortunately apps like my day job at XTension need to remain responsive to incoming data or connections even when the user has been absent for months. In the past this was no problem! MacOS was efficient and my app managed it’s memory carefully and didn’t leak and so for 6 months or more you could run in the background and keep doing all you needed to do.

That is no longer the case with High Sierra. If the user isn’t there and the screen goes to sleep then ALL the user apps will go to sleep. Even if they have done what apple suggested and register a “user initiated action” that should continue to work even while the user wanders off. High Sierra seems to decide that if the user has let the screen go to sleep then no user tasks need to be of high priority. This is remarkably frustrating as there are definitely apps that want to run while there is no user sitting at the machine.

The officially documented way to disable app nap does NOT work with High Sierra.

The only work around that I’ve been able to figure out is to disable putting the screen sleep. You can do this manually in the energy saver preferences just set the screen to never go to sleep. If you’re doing the official apple way of doing things then you can set the disable Idle Screen Sleep flag when you create your action.

Or you can just tell your users to set their energy saver preferences to never shut off the screen... This is a completely undocumented change that makes a huge difference to us developers of apps that run without the user sitting in front of the machine. I am very frustrated.

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.