Tuesday, March 12, 2019

OpenSCAD Module for Rounded Boxes

I got kind of tired of rewriting the same OpenSCAD code to build rounded boxes for things and messing up the minkowski sum math in the process, so I built a simple module to do it for me. 

Usage is simple:
include <rounded_case.scad>
rounded_case(25, 25, 10, 2);

The paramaters are:
rounded_case(X, Y, Z, T, LID, LID_OFFSET)

X, Y, Z : Inside dimensions of box
T : Thickness of walls
LID : optional, bool : true to also make a lid
LID_OFFSET : optional :  how much smaller to make the "lip" of the lid that fits inside the top of the box

The outside dimensions of the box will be the inside dimensions + 2 x T.   E.g. if the X dimension is 20mm, and T is 2mm, then the width of the box will be 24mm (20 + 2 + 2).   The example above will make a box that is 29mm x 29mm x 14mm (with the lid on) on the outside, and 25 x 25 x 10 on the inside.

Get it here: rounded_case.scad

Monday, October 8, 2018

"Full Boat" - flew to Lompoc, CA to watch the Falcon 9 launch

I flew down to Lompoc, CA on Sunday with Miles, and our friends the Baalmans (Gary, Laura, & their two kids) to watch the SpaceX Falcon 9 launch at Vandenberg AFB. This was the first Falcon 9 "return to land" on the west coast, and it went spectacularly. We found a great viewing spot along HWY 1 overlooking the launchpad.

Wednesday, September 12, 2018

Monday, July 30, 2018

I bought a new aircraft!

I decided, at long last, it was time to upgrade to something capable of more speed, altitude, and carrying my family.   N6779B is a 1978 Cessna T210M.  It's turbocharged and capable of climbing into the flight levels, so it's much more suitable for getting in and out of the Sierras.  ;)

Adventures to come!

Sunday, January 21, 2018

Sonoff S31 Disassemble and Flash Instructions

I recently bought some Sonoff S31 "smart outlet" switches, as I like the form factor better than the Sonoff Basic and the larger Sonoff S20.  I was able to disassemble and flash them with the fantastic Sonoff-Tasmota firmware from Theo Arends.

Disassembly instructions:

1. The darker colored square panel with the button on it snaps off.  Pry it carefully off from one side to remove it:

2. There's two "slide-out" corner pieces on the male plug side. Slide these towards the button side:

3. Remove the three screws that are now exposed:

4. The case containing the female outlet side should separate easily now.  No prying necessary:

5. The circuit board is actually two boards soldered together in an "L" shape.  The small edge with the button on it contains the serial header for the ESP8266.  From the top down, the connections are VCC, RX, TX, N/C, N/C, GND   (Notice the two unused pads labeled TX & RX.  They don't appear to be connected.)

6. Here's a shot of the ESP8266EX chip on the back of the smaller board, beneath the relay.

7. I soldered a pin-header to the pads to program it.  At the time I didn't know which two TX/RX pins to use so I soldered all four.  You can ignore the lower two.

8. The button is connected to GPIO0, just like the Sonoff Basic.  Press and hold the button while plugging in the USB Serial adapter to put the ESP8266 in flash mode (Follow the flash instructions on the Sonoff-Tasmota project from here.)

The S31 purportedly does power/current monitoring, too.  I haven't tried getting that working yet.  (I'll update this blog post if I get that working too.)  As of this writing the Sonoff-Tasmota 5.11.1 firmware runs on it and controls it as a "Sonoff Basic" just fine.  Relay toggling and button control work as expected.

UPDATE 1: Looking at the board I see the ChipSea 7766 energy monitoring chip. Seems that it sends energy use via uart:

It's connected to the ESP8266 UART0 port through R2.  More to come!

UPDATE 2: Theo Arends added support for the S31 in version Sonoff-Tasmota ver 5.11.1i


Thursday, August 4, 2016

TOWL - Telemetry over Opportunistic WiFi Links

Premise & Background:

Can you build a "LoJack" style asset tracking capability using open WiFi hotspots?

The proliferation of cheap, lightweight WiFi embedded ("IoT") devices made me wonder.  The WiFi association stack, DHCP client stack, et al. has to be incredibly lightweight and simple to fit in the firmware on, say, an ESP8266.  If you programmed one to scan, find an AP, associate, get an address, and send a single packet - would it be able to do it fast enough to report its location from a moving vehicle?

[Aside: This is actually something I've wondered about for years, but the IoT chips offered a unique and low-cost way to try it.]

"But wait," you say, "there really aren't that many open APs these days.  Most of them are captive or paywall portals, or at least make you agree to some goofy ToS."

Right, but as has been pointed out multiple times by multiple people all the way back to Dan Kaminsky's DNS tunneling talk in 2004 - hotspots diligently resolve DNS queries.  All you have to do is base32 encode the data you want to send in the hostname of a valid DNS record request, and set up a DNS server for a subdomain (under a domain you own) to catch the queries.

If it works, you get near real-time telemetry over opportunistic WiFi links using DNS recursion!  Think: "low cost LoJack with no data subscriptions".
Digistump Oak ESP8266

I used the Digistump Oak variant of the ESP8266 prototype boards.  I like the fact that it can be flashed OTA, which proves to be useful once the device is deployed in something like an automobile.

In my testing, the complete chain from calling connectAP() to getting the DNS query response typically takes between 3 and 6 seconds, which is certainly fast enough from a slow moving vehicle.

Device Output

The device stores the telemetry in a 16-byte struct consisting of:

struct telem {
  uint32_t tstamp;  // GPS time in ctime format
  int32_t lat;      // Latitude * 1000000
  int32_t lon;      // Longitude * 1000000
  uint8_t spd;      // Speed in MPH
  uint8_t sats;     // Number of GPS satellites received
  uint8_t id;       // Arbitrary number for ACK
  uint8_t mode;     // Object state information
};  // 16 bytes total

The fields are largely self-explanatory.  You'll notice that I used an 8-bit number for speed, so the max speed it will report is 255 MPH.  Also, the 32-bit ctime field means it's vulnerable to the Year 2038 Problem.

The field worth explanation is "mode", which is set as follows:

Value |   Meaning
 255  |  Startup position.
 254  |  Live. Transmitted and ACKed in realtime
 1-n  |  Stored position

The first few position observations are always flagged as mode 255, regardless of whether they're able to be transmitted live or not.  (This way you know where the device started.)

The stored position value is simply the number of 10-second intervals since last transmission modulo the MAX_INTERVAL setting.  This is how the unit "downsamples" the stored waypoint resolution if the buffer fills up.

So... how well does it work?

Here's a plot on OpenStreetMaps of me driving to work one morning.  The blue markers are live (mode 254) and the red markers are stored.

Of note are the blue markers along the freeway.  I've regularly observed this device successfully logging the telemetry data at speeds upward of 60 MPH! 

Technical Details


  • Digistump Oak
  • NMEA serial GPS module (e.g. uBlox or MTK)


The software for the Digistump Oak, as well as a PoC DNS server (in python) to log the output, is available here:  

Check the README notes under both subdirectories for build dependencies / config notes.


You'll need to host a custom nameserver on the Internet to receive the DNS queries.  You'll also need to control a domain so that you can designate your DNS query receiver as a subdomain. 

E.g. if you own the domain "MyDomain.com", you could designate a server to receive the TOWL queries by creating a NS record for "TOWL.MyDomain.com", pointing at the server you intend to run the catcher on. If said server is at IP address, then that record looks something akin to:


Run the PoC code on the designated server. Be sure to configure both the TOWL devices and the server code for the "TOWL.MyDomain.com" domain name. (See README under each directory for instructions.)

Have fun!

gps tracker dns