Monday, May 31, 2021

Filtering out distant Bluetooth signals

 TL/DR: nearby Bluetooth devices have a RawSignalStrengthInDbm in the 50s and 60s.

I love playing with Bluetooth devices and writing little apps to control them (including the very special Gopher of Things). One of the hassles with developing, though, is that we're in a sea of Bluetooth devices. Any "watcher" code you write will be inundated with events from everyone else's device (notably their Apple devices which helpfully send lots of Bluetooth advertisements)

So how to filter them out? Step 1 is to look at the RawSignalStrengthInDbm in your Bluetooth watcher's BluetoothLEAdvertisementReceivedEventArgs argument. I did a little experiment: all of the devices I was interested in coding for had a signal strength in the 50's and 60's. Everything in the 80's and higher was noise from the rest of the house.

Note, though, that the strength is in decibels. A strong signal is -50 and a weak signal is 89. To quickly return when the signal strength is too low, do this:

    const int filterLevel = -75;
    if (args.RawSignalStrengthInDBm < filterLevel)
    {
         return;
    }


In my test, this filters out most of the undesired signals.


Wednesday, February 24, 2021

Everything wrong with the FINGER protocol

 Everything wrong with the FINGER protocol 

For those of you who have never heard of it, Finger is one of the old "litle"¹ TCP services. As a user of a big multi-user machine, you can edit the ".plan" file in your directory; people can then run a command like finger person@example.com and it will retrieve your .plan file along with other information like where and when you last logged in. It was a super useful way to coordinate with teammates back in the days before cell phones had been created. 

 The protocol itself is pretty simple: the finger command sends a single line of data with the user name, and the server replies with a bunch of text and then closes the connection. So what could go wrong? In this minor screed, I list both things that should have been known at the time, and also things that we know about protocols today that weren’t known then. 

TL/DR: the spec is wrong, confusing, incorrectly implemented and potentially dangerous. But other than that, it works pretty well :-) 

The protocol spec is incorrect (/W). 

 Firstly, the finger spec, RFC  1288, is wrong. The "BNF" query notation, section 2.3, with query type #1, attempts to allow an optional /W before the user. The /W is the verbose switch (W stands for "whois") and servers can reply with more information when it's provided. (This is accessed by the finger -l person@example.com switch; -l stands for long). But that's not what the BNF actually says. What the BNF says is that the /W switch is required whenever a username is provided. What should be an optional switch into a mandatory one. 

Good news! Every actual finger client implements what the spec tried to say and not what it failed to say. Which is good, because a number of existing (as of February 2021) Finger servers implement the earlier RFC 742, which doesn’t allow the /W switch. 

The protocol BNF is clumsy. 

The protocol “BNF” in general is more formalistic than useful. There’s an old saying that every level of indirection makes code harder to follow; the corresponding saying for BNF is that simple and common definitions like CRLF should be spelled out each time they are used, not hidden behind a layer of naming indirection. The BNF also loves using short name; {C} is the name of the rule that eventually expands to CRLF, and {U} the rule for user names. 

Additionally, the BNF is split into two rules: one for direct user lookup, and one for an indirect network lookup (these are Q1 and Q2 in the BNF). But this makes the Q1 clumsy, as it has to handle both user lookups with no user, and user lookups with a user. A better split would be three query types: a NULL query (with or without a /W), a user query (also with or without a /W) and a network query. 

On-behalf-of is not good networking 

We can totes forgive the original spec from adding in the slightly weird “Q2” format. This format is used when we're asking server “A” to ask server “B” for information. It’s like the user can’t get the information they want directly; they have to go through a gatekeeper server. The other servers are called Remote User Information Program (RUIP). Back in the 1970s when the RFC was created, the internet was often provided to a single computer at a site; the site then used other protocols and network to connect to other computers at the site (hence the internet used to be described as a “network of networks” which were expected to use non-Internet protocols). 

But in modern times, the Q2 “on behalf of” experience isn’t needed. Indeed, none of the servers I found would handle it. 

Massive security issues 

 Finger servers often return the time and location of user logins. For example, FINGER might say that a particular user is currently logged in at a particular terminal in a particular room. This is handy when dealing with friendly teammates, but is totes wrong when dealing with stalkers and worse. Lots of people really don’t want other people to know where they are. 

Giant compat issues with modern servers 

You might be confused by this one – what could I possibly mean about modern Finger servers? Have there even been any modern Finger servers at all? Why would anyone build a new Finger server given that the Finger protocol is often blocked by firewalls and provides very few features needed by people. 

It turns out that just looking on GitHub shows a bunch of different Finger servers. These servers are mostly derived from the original RFC 742 Finger protocol. It’s almost the same as the RFC 1288 Finger, but doesn’t allow for the /W switch. Other servers attempt to handle the /W switch, but don’t do it correctly (finger.farm, for example, failed until recently).  


One more thing about the /W switch spec: case-insensitive

[Later edit]: the RFC set of specs has long declared that just strings in the BNF descriptions should always be assumed to be case-insensitive: "monday" is the same as "Monday" and "MONDAY" and "MoNDAy". The FINGER spec takes the opposite approach: the /W switch, AFAICT, is actually case-sensitive and should always be upper-case.

As a fun aside: the RFC editors are, in the instance, wrong. While I understand why they decided that BNF should be case-insensitive (it's part of our text-based heritage), it's also the case that the workaround they use (specify case-sensitive strings as hex characters) is demonstrably error-prone. I've personally filed about a half-dozen different bugs against Internet protocols for getting the HEX representation of strings wrong.

The best solution is to require each BNF description to say if they are case-sensitive or not.

Use these learning for your own protocols! 

Finger is part of the old tradition of text-based services that are almost designed for direct command-line manipulation. As such, it’s now mostly out of favor (when was the last time you read your email by directly talking to a POP server?). That said, there are still lessons from FINGER for today. 

  • Simple, direct protocol descriptions are easier to debug than complex ones. 
  • Be aware of bad actors. Don't let your APIs enable stalkers and thieves. 
  • Make sure that the easy path for handling your protocol also allows servers an upgrade path. 


 


Note¹: Finger is one of the litte TCP services noted in RFC 848 along with echo, discard, systat, netstat, quotd chargen, finger and a couple of time-related services. 


 


Sunday, October 11, 2020

 

Why do (American) plugs have holes?

American-style electrical plugs are special in that the prongs “always” have little holes in them:

The question that’s never been answered is why. There have been attempts at answers (and some have some good research). This post is going to evolve over time: my goal is to find as many images of plugs as possible, organized by date.

The timeline seems to be: 1906: Hubbell made an early form of electric plug+socket 1913..1915: there are a bunch of different plugs 1916:NELA starts to try to standardize 1921:each company still makes their original plug and the new standard plug. 1922: standardization is complete.

More updates -- 1913 Lighting Journal has multiple plug types, and the June 1916 Lighting Journal has two interesting articles: one about the attempt to create a single plug standard.  

Another update: Hubbell has a modern looking plug in the January 1916 Electrical Age.

Update: the funny-looking Hubbell Attachment Plug is listed in the 1906 Hubbell catalog! (page 36)



1906 Hubbell Catalog

The 1906 Hubbell Catalog, page 34, includes the somewhat oddly shaped Hubbell Attachment Plug. The plug is a user-applied thing: they rewire their device to use the plug, and then screw the socket into a standard Edison-type (or T.H type) screw base.

It's claimed to have been patented August 16, 1892 and also on November 8, 1904.

They call the top thing the "cap" or "plug cap" and the unit as a whole a "plug" 


Note that the image does no include any holes in the blades.

1913 Electrical Record, February

The Hubbell company may have started the trend, but eventually other companies jumped on the bandwagon. The C-H plug from Cutler-Hammer is one such plug.



This Cutler-Hammer ad shows that a variety of interchangeable sockets for their "double lug" plug. Note that the plug has either dimples or holes.

The April issue of the Electrical Record has this competing ad from the Hubbell company:



There are also companies that try to make plugs that fit into the existing E26 and E27 screw-base sockets (that it, that can just be put into a standard light socket without having to screw and unscrew the cord). This ad is from the Trumbull company.



Or look at this from the Electrical Review and Western Electrician, vol 64--No 3, (Jan--June, 1914) page 153. The Trumble plug is kind of wavy in-and-out and there's a better view of the Cutler-Hammer double-lug plug.




More Hubble! National Electrical Contractor, November 1914!


It's kind of faint, but the diagram here shows that the parallel-blade (more modern style) plug seems to have either a hole or dimple



More Hubbell, this time with a nice blow-up image The parallel-blade plug doesn't seen to have any dimples or holes, although the in-line older style ones do. This image is page 31 of the Electrical Contractor.

 

Electrical Record, May 1916

The end result of all of the work? The "standard" plug (from the Electrical Record, May 1916, page 34). Frustratingly, the plugs are seen head-on. Also frustratingly, apparently the company published a 4-page folder with details on exactly how the plug works.


Ha! There's a better view here:


And look here!


Interim Report (1920-ish?)

This is from the NELA bulletin, volume 8, 1921, page 87.



1915 Gernsback Electrical Experimenter

There’s nothing quite like the 1910’s era electrical magazine. Among the puff pieces are popular accounts of up-to-date science, alongside ads for cheap pistols, motorcycles, and electrical surplus equipment.

World War I had already started by 1915, but America hadn’t yet joined. It surprised me how many German articles are included, including this little piece (page 47 of the June edition) on a novelty cigar lighter:

Unfortunately, the shape of plugs is entirely unremarked. The only plug shown in the entire years set is this bad image of what appears to be a battery charging that’s “plugged” into a ceiling lamp (back cover of the July and other months).

This is a really common setup: almost all picture of things plugged in are plugged into a screw-type light fixture. Here’s a phonograph that can be “plugged in” via a screw-plug: (September 1915, page 186)

Often cartoons show the latest devices the most clearly. This one, from the July 1915 issue, page 117, manages to show an enormous amount of detail without a single plug anywhere (everything is wired directly to a panel which includes some frightening and non-OSHA-compliant switches).

(The July 1915 issue of Electrical Experimenter included reviews of scientific movies, including ‘The Exploits of Elaine’ which I had only read in book form).

In the terrifying department: a lamp doesn’t need a plug if it’s violently radioactive! (September 1915, page 181)

A very unsatisfying picture of plugged-in equipment at a dentists office in the November 1915 Electrical Experimenter, page 332. The nurse on the left is controlling an electrical respirator; that respirator is plugged into a wall socket. Not shown, of course, is what the plug looks like.

In the same issue: Lionel trains advertises this transformer for their toy trains. Note that it has the old-fashioned screw ‘plug’

1916 Electrical Age (January)

The Hubbell company comes through! Here's a short article from the January 1916 Electrical Age magazine, page 62:



Earlier Hubbell plugs were in-line, not parallel, and had a sort of wavy shape. This plug, in contrast, looks like it would work in one of today's sockets!

The text: Very often both alternating and direct current is used in the same building, requiring some distinctive means of differentiating between the two for certain types of apparatus. This is very ingeniously done by means of the polarized attachment plug show in the illustration which is being brought out by an enterprising manufacturer.

...one knife blade contact has been made smaller than the other in both width and length (different from modern polarized plugs which are different in width only, and often only at the tip) and the slot in the base reduced proportionately. As the opposite blade is the standard size it cannot be inserted in the small slot...

1916 Electrical Age, February


After the surprising modern Hubbell socket in the January issue, here's a notice in the February issue. Note that the blades are the classic Hubbell wavy in-line blades. Unlike past images, there are holes in the blades!













1916 Gernsback Electrical Experimenter

This is almost a plug, but it’s not. It’s a picture of a high-intensity lamp from the February 1916 edition, page 553. What looks like a plug is actually the lamp directly wired to an incredibly dangerous knife switch. As a young’un, I had always assumed that knife switches were used when dealing with lots of current; I was surprised when I started to read the specs and discovered that knife switches are simultaneously dangerous, expensive, and have low current ratings.

I think this is also not a plug (March 1916, page 620)

1916 Electrical Age

The November 1916 Electrical Age, page 59 has this picture! Its a heater control. It's described as having a "indicating switch, a concealed receptacle and in parallel with it an Edison receptacle for a pilot lamp ... By means of a standard cap which fits into the receptacle, current can be supplied for the electric iron, washing machine, and other current consuming devices. The standard caps for use with this outfit have two parallel blades for making connection with phosphor bronze spring contacts located well below the surface of the receptacle."
 











Looking very closely at the scan, it looks like the maker is Bryant and it's seemingly a type BA 260

1920 Patent 1341468

1341468

This 1920 patent shows the little holes in the plug.


1922 NELA bulletin page volume 9 Jan page 23 of 626

Hot darn! The 1922 NELA bulletin has this report from the Wiring Commitee. It seems that by 1922 the plugs were fully standardized:

The standardization of attachment plugs and recepticals having been completed the Committee has been working on advertising this fact.

The Committee is working on standardizing medium size plugs and recepticals for large heater ranges, small motors, etc.

Also on the standardization of the appliance plug, where the cord connects to the flat-iron or other device.

Entry: Catalog Record: Bulletin | HathiTrust Digital Library



The Non-Standard Plugs

Lots of companies sold plugs that aren't the standard plugs. Here's a short list of companies and their plugs.


Arrow standard plugs and sockets

From the National Electrical Contractor, volume 16, February 1917, page 2. 

The Arrow company seems to make three kinds of plugs, all with standard prongs:




They have a line of sockets as well (13 pictured in the ad); all seem to have openings for both standard and Hubbell-type inline plugs.

From the Electrical Record, October 1917, page 48, we get this nice cutaway view




Bryant

From Electrical Contractor-Dealer Vol 17, no 9, June 1917.

Bryant had a line of compatible plugs. They have both the horrible half-dome type plug and some more ergonomic plugs.






Campbell Attachment Plugs 

Campbell Attachment plugs and receptacles (Steel City Electric) from Electrical Contractor-Dealer, June, 1918 page 137

Steel City Electric 1207-129 Columbus Ave, Pittsburgh, PA


A better view of the square plug from volume 25, Electrical Record, February 1919 page 104. The text says, "At left is shown attachment plug for use in factories, mills and shopw where rugged construction is required. At right attachment plug is show inserted into recptacle.



Chelten Electric

A pox on all badly-lit and unclear illustrations. This is a socket from the Chelton Electric company, Philadelphia; it's a small ad showing a push-button light switch and this socket. But what kind of socket is it? A standard one, or non-standard?

From the National Electric Contractor, volume 16, November 1916, page 20.



Cutler-Hammer Standard No. 7700

From the Electrical Record, volume 19, May, 1916.

Several electrical manufacturers have agreed on the making of standard plugs and receptacles, the caps and bodies of the various makes of which can be interchanged. This is proving beneficial and convenient both to those in the electrical industry and to the plug. The C-H No. 7700 is the "Standard" type separable plug made the Cutler-Hammer Mfg. Co, of Milwaukee, Wis. This is an all-composition plug, small in size, but having a rating of 660 watts, 250 volts. The accompanying illustration is approximately fully size. The knurled cap does not wear shiny when use, nor show the results of scratches. On the contrary, the makers claim that the appearance of the knurled cap improves with use. The contact blades are firmly riveted to the cap and held in perfect alignment. No screws whatever are used except for those provided for securing the cord terminals. The live parts are concealed.




G-E Standard Separable attaching plugs and sockets


The February 1917 National Electrical Contractor (volume 16, number 4) has several new-to-the-magazine ads. On page 44 is a big G-E (General Electric Company) ad with a set of 3 (or 4) plugs ana 6 sockets. Each socket seems to allow for standard or Hubbell type plugs (but separate, not in a T form). Each plug has a single hole; the other prong does not have a hole.











Hart and Hegeman

A 100% non-compatible plug, sold with the idea that most of the prongs are non-metallic and are less likely to short-circuit. They even have a picture of using a plug through a carpet (they claim that for most rugs the weave an be pushed aside enough to fit a plug).

From  From Electrical Contractor-Dealer, Vol 17 number 12, October June, 1918 page 55

Details are from the National Electrical Contractor, volume 7 number 1,  November 1907, page 2




The "plug through the rug" picture


 

They also have an ad in the March 1917 issues, page 119, with a better view of the plug.

"The simple, dignified lines and rich finish of a "Diamond H" Receptacle appeal to the most fastidious task. Nothing cheap-looking here -- nothing conspicuous -- but a sturdy simplicity that suggests sound reliability and real service. And "Diamond H" appearances are never deceitful. There are cheaper receptacles made. We could cheapen "Diamond H" Receptacles if we wished. But-we are possessed of an ideal, viz., to make every "Diamond H" product a standard of quality, not of price.



Then in the November 1907 issue I saw this full explanation and diagram.3



Hubbell Interchangeable Cap and Plug

From the Electrical Record, May, 1916 (volume 19), page 34. This is quite the time for new attachment plugs since it's right after the standardization. Hubbell decided that they would continue to make their only kind of plugs -- so these are "interchangeable" only with their own brand.

This image is from an ad o page 154 of the May, 1916 Electrical Record. The Hubbell company is certainly using the word "standard" all over their ad. The 5406 is the Hubbell Standard Plug and the 6915 is the polarized plug (T-shaped)



Jiffy Attachment plug

Here's a picture of a plug with absolutely nothing showing of what the actual plug looks like! Made by (or at least sold by) the Best Electric Company, Pittsburgh, PA.

Their claim is "You can wire TWO "Jiffy's" in the time of ONE ordinary plug. "Jiffy" means efficiency--time-saving, money-saving Efficiency. And it is practically indestructible.

From National Electrical Contractor, vol 16, December 1916, page 133.




And they have a line of them walking along :-)


Lockfast Attachment plug

Made by the yost Electric Mfg Co, Toledo, Ohio. Note that they hardly have a thread on the plug, so it can be screwed in more quickly.

From the May 1916 Electrical Record, page 155.




MESCO (Manhattan Electrical Supply) plug

From National Electrical Contractors, 1918, volume 17, number 7, page 138

MESCO is the Manhattan Electrical Supply Company (17 Park Place, NY)


They have a similar ad in the October 1914 (volume 13, number 12), page 123, but with a small paragraph of text describing the plug.


A Small Separable plug made of black molded material under great pressure. The smoothly finished surface has the appearance of hard rubber. It is extremely tough, will stand hard usage, and is one of the smallest, neatest and most substantial plugs made.

The terminal contacts in the base of the plug are arranged so that it is impossible to short circuit the plug. The cap terminal contacts are of heavy brass, and when inserted into the plug form a strong rubbing contact. Ample space is provided in the cap to knot the cord securely.


From the  November? 1913 (volume 13, number 1) National Electrical Contractor, page 98, they also sold this odd-looking plug







Tregoning Plugs

From the 1913 National Electrical Contractor, page 94, is a small add for a non-standard plug






Trumbull Electric Mfg Company

The Trumbell Electric Mfg. Company, Plainville, Conn.

In the April 1917 (vol 16) National Electrical Contractor, page 173, is a notice that the Trumbull company had a new line of standard sockets (but maybe not plugs?)


The Trumbull Electric Manufacturing Company have recently brought upon the market their Side Outlet Current Tap and "Standard" Flush Receptacle, both of which are pictured herewith. 

The base and caps are interchangeable with similar products manufactured by Bryant, General Electric, Paiste, Cutler-Hammer, etc. and are included in the so-called "Standard" devices.




From the 1916 Electrical Record, April 1913, page 22
"The annexed cut show a new Standard attachment plug that has just been brought ou by the Trumbell Electric Mfg Co, Plainville, Conn. It is made throughout of fireproof material, and is of the straight plug, prong type. As show in the cut, the cap is well proportioned, and the top of the body is rounded to prevent breakage. The cap will interchange with all plugs on the market made in accordance with the standard recommended by the National Electric Light Association. It takes only two complete turns to seat the plug in the socket.

From an ad in the May 1916 Electrical Record, page 208, we learn that the standard attachment plug is catalog 792 for the complete plug and 793 for the "body" only, and that a seven pound pull will separate the cap from the base.  

From the 1914 Electrical Record, November 1913





Unilet from the Appleton company

I'm not quite sure what's going on with this socket -- there's a T type socket, but is that a set of crescent-shaped slots, too? And what plug is being shown?

The company is the Appleton Electric Company, 218-230 North Jeffereson St, Chicago

The first is is from the National Electric Contractor, volume 16, November 1916, page 20 

The next set are from the January 1917 issue, volume 16 number 3, page 19











It looks like the 2d item is Hubbell and that crescent thing, the third is just the Hubbell style, and the last is the standard size. Perhaps this is the month they added the more standard styles into their ad?