Author Archives: Scott Alfter

Blog comment of the day

…though not here, but one of the commenters at Ace of Spades HQ:

How can anyone believe that the same govt that is leaving thousands to die in Afghanistan is the same govt that has your best health interest at heart?

People that think this definitely need Jesus in their lives.

http://acecomments.mu.nu/?blog=86&post=395261#c35299116

Aussie police: let’s prove NWA was right

Who signed off on pepper-spraying kids for any reason, let alone for something as stupid as a Face Diaper “violation?”

https://summit.news/2021/08/18/video-australian-police-pepper-spray-children-for-not-wearing-face-masks/

If that doesn’t get you humming this ditty, I don’t know what will.

Here’s an additional thought exercise: if Australia had something equivalent to our Second Amendment, do you think the police would be so quick to resort to this sort of brutality?

Stop #3

In the glass: StationHaus, a slightly smoky red lager to benefit local firemen.

The “next time around” board has an unclaimed donation for Red Rock Search & Rescue, to which I might need to add a bit. They got organized initially to find a hasher who’d disappeared out in that part of town…turned out he’d fallen off of Turtlehead Peak. :( On-Ron!

Stop #2

In the glass: Veteran Pale Ale. Behind the bar: Russ Gardner, a homebrewer who I hadn’t run across in years. He said he’s holding down the fort here for a bit while he gets his own beer bar spun up in another month or so.

If I hadn’t stopped at Taco Y Taco earlier, I might also have grabbed a Cuban sandwich from the food truck outside.

Hitting up the Booze District

First time in over a year, I think…starting at Bad Beat. In the glass: A Healthy Distrust, which in addition to a useful outlook on life in general, is also a blonde coffee ale with vanilla. Like Bad Beat’s previous coffee beers, this one’s not the usual dark hue you might expect. Stops at Astronomy Aleworks and CraftHaus to follow shortly.

Not bad at all for under $15

The vertical lines in the screen, while present, aren’t as obvious as they are in the photo. The time is off because it’s not on my home network right now and can’t retrieve the correct time.

I’ve been playing around a bit with ESPHome and Home Assistant lately…started with a couple of Sonoff smart outlets, one to replace a Kill-A-Watt monitoring my mining rig and another to switch a light on at sunset.

What’s up above is part of this weather station kit. The metal can on the small board in the center is a BME280 environmental sensor that picks up temperature, humidity, and barometric pressure and makes that information available over I2C. The NodeMCU on the right reads the sensor, publishes its readings over WiFi to a Home Assistant server, and displays the readings (and current time) on the I2C-connected OLED on the left. You could probably use an ESP-01S with a 4-MB flash upgrade since I2C only needs two pins to work, but the kit came with a NodeMCU, so that’s how I brought it up initially.

Wiring is simple: connect ground together on all three boards, connect the power inputs on the OLED and sensor to a 3.3V pin on the NodeMCU, connect the data pins (SDA) to pin D2, and connect the clock pins (SCK) to pin D1.

The ESPHome config file (not really a program as such) looks something like this:

esphome:
  name: bme280
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "your_wifi_ssid"
  password: "your_wifi_password"

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

i2c:

sensor:
  - platform: bme280
    address: 0x76
    temperature:
      name: "BME280 Temperature"
      id: temp
      oversampling: 16x
    pressure:
      name: "BME280 Pressure"
      id: baro
    humidity:
      name: "BME280 Humidity"
      id: humid
    update_interval: 60s

display:
  - platform: ssd1306_i2c
    model: "SH1106 128x64"
    lambda: |-
      it.strftime(127, 60, id(arial14), TextAlign::BASELINE_RIGHT, "%H:%M", id(esptime).now());      
      it.printf(0, 0, id(arial14), TextAlign::TOP_LEFT, "%.1f°", id(temp).state*1.8+32.0);
      it.printf(0, 20, id(arial14), TextAlign::TOP_LEFT, "%.1f%%", id(humid).state);
      it.printf(0, 40, id(arial14), TextAlign::TOP_LEFT, "%.2f\" Hg", id(baro).state*0.0295);
      
time:
  - platform: homeassistant
    id: esptime
    
font:
  - file: "/usr/share/fonts/corefonts/arial.ttf"
    id: arial14
    size: 14
    

The sensor returns temperature in °C and barometric pressure in hPa; the code above converts those to more sensible units for display. Also, you’ll probably need to update the font file location to whatever is correct for your system. (I have ESPHome installed on Gentoo Linux and have the corefonts package installed.)

Something like this would be useful to have indoors. For an outdoors weather sensor, leave off the screen and the related sections (display, time, and font) from the config file. Next task is to fab up an enclosure of some sort.

Connecting to Bluetooth serial devices on Gentoo LInux

This should’ve been easier, but in hindsight it isn’t too bad. The point-and-drool tools provided for managing Bluetooth (at least under KDE) fall flat on their face, but if you enable some supposedly deprecated options and rebuild BlueZ, you’ll get what you need.

I decided to try getting an HC-05 Bluetooth interface working with one of my 3D printers yesterday. bluedevil (the KDE package that manages Bluetooth) apparently knows nothing about RFCOMM devices (which emulate RS-232 connections over Bluetooth). I had gotten both Android and Windows 10 to talk to my printer over Bluetooth without much fuss: pair the device, fire up a suitable application, and connect.

The needed documentation to get RFCOMM devices working on recent Gentoo builds is a bit sparse, so this post aims to correct that.

First, BlueZ needs to be rebuilt with some more USE flags enabled:

echo net-wireless/bluez deprecated extra-tools readline | sudo tee /etc/portage/package.use/bluez && sudo emerge -1v bluez && sudo /etc/init.d/bluetooth restart

With your HC-05 at least powered up, you can retrieve its MAC address, which is needed for the following step:

hcitool scan

which returns something like this:

Scanning ...
        98:D3:32:10:F7:9C       HC-05

Next, RFCOMM needs to be configured and BlueZ restarted (wherever you see it below, substitute your device’s MAC address for the one used here):

cat <<EOF | sudo tee /etc/bluetooth/rfcomm.conf && sudo /etc/init.d/bluetooth restart
rfcomm {
  bind no;
  device 98:D3:32:10:F7:9C;
  channel 1;
}
EOF

Now we can pair the device to the computer:

sudo rfcomm connect hci0 98:D3:32:10:F7:9C 1

You should be prompted for the HC-05’s PIN; the default is 1234. (Note: while I’ve gotten this working under KDE, I never get prompted for the PIN when in a pure-CLI environment and the connection is refused.) Key it in, and you should get a notice that you’re now connected:

Connected /dev/rfcomm0 to 98:D3:32:10:F7:9C on channel 1
Press CTRL-C for hangup

Press Ctrl-C, then store the PIN for future reference:

for i in /var/lib/bluetooth/[0-9A-F]*; do echo 98:D3:32:10:F7:9C 1234 | sudo tee -a $i/pincodes; done

Create a boot script to bind /dev/rfcomm0:

cat <<EOF | sudo tee /etc/local.d/01-rfcomm-bind.start && sudo chmod +x /etc/local.d/01-rfcomm-bind.start
#!/usr/bin/env bash
rfcomm bind hci0 98:D3:32:10:F7:9C 1
EOF

Run rc-update and verify that both bluetooth and local are both being launched; in my case, both are in the default runlevel. If you reboot now, /dev/rfcomm0 should show up. Use something like minicom to connect, and if your HC-05 is plugged into a printer and the UART interface it’s using is active, you should at least see garbage coming across the line. The HC-05 defaults to 9600 bps, while your printer is probably at 115.2 kbps or faster. The only method I know of to set a different bitrate is to plug it in through an Arduino to bring up the AT-command interface, as described here. It doesn’t seem to support nonstandard speeds like 250 kbps and multiples thereof, and I even had trouble getting 230.4 kbps to work. 115.2 kbps has usually been fast enough to stream gcode without stalling; preprocessing your gcode with something like ArcWelder may help if your printer is running reasonably modern firmware.