GoveeBTTempLogger as a Debian Package

After getting my program to listen and log Bluetooth Low Energy advertisements from Govee thermometers running reliably, I needed to figure out how to make the program automatically start when my Raspberry was rebooted. I was led down two paths to get things working, systemd unit files, and debian package files created with dpkg-deb.

The final file structure I came up with is visible in https://github.com/wcbonner/GoveeBTTempLogger but still can use some explanation as to what I did.

To create the debian package, I created a file structure under my source repository that mimicked what I wanted to put on the target system.

\GOVEEBTTEMPLOGGER\GOVEEBTTEMPLOGGER
├───DEBIAN
│       control
│       postinst
│       postrm
│       prerm
│
├───etc
│   └───systemd
│       └───system
│               goveebttemplogger.service
│
├───usr
│   └───local
│       └───bin
│               goveebttemplogger
│
└───var
    └───log
        └───goveebttemplogger
                gvh507x.txt

I had decided I wanted my executable to be located in /usr/local/bin. It’s the file named goveebttemplogger. I wanted it to write log files into /var/log/goveebttemplogger/ and the easiest way to make sure that directory was created was to put a zero length file in that directory, gvh507x.txt.

The files in the DEBIAN directory are used by the dpkg-deb program when building the distributable package. More on those later.

To get the program configured to automatically run when the machine boots, and properly stop when it shuts down, I settled on the systemd unit files as the both the easiest and most reliable method. I’ve been around linux long enough to first think of /etc/rc.local manipulation, then script files for various runlevels in the /etc/init.d/ directories, and was amazed at both the power and ease of setting up to use the systemd unit files. The hardest part was figuring out what other services my program must have already started. I knew it was dependent on Bluetooth, but the specific services was a bit of a guess.

# Contents of /etc/systemd/system/goveebttemplogger.service
[Unit]
Description=GoveeBTTempLogger service
After=bluetooth.target dbus-org.bluez.service network.target
Requires=bluetooth.target
KillSignal=SIGINT

[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/goveebttemplogger -v 0 -l /var/log/goveebttemplogger/

[Install]
WantedBy=multi-user.target

After creating that file in the specified location, I was able to issue the following commands to make systemd start the program.

sudo systemctl daemon-reload
sudo systemctl enable goveebttemplogger.service
sudo systemctl start goveebttemplogger.service

The most unique bit of my unit file is that I specifically want my program to be sent the SIGINT signal to kill it, since I will recognize that and flush the log files before exiting. The ExecStart line is the command line to run my program, which I’m also specifying the log directory as one of the parameters.

I had the systemd unit file and the initial DEBIAN/control file figured out pretty easily. I’d come across this https://linuxconfig.org/easy-way-to-create-a-debian-package-and-local-package-repository article which helped understanding the control file.

Package: GoveeBTTempLogger
Version: 1.20200725-1
Section: custom
Priority: optional
Architecture: armhf
Essential: no
Installed-Size: 95
Maintainer: wcbonner@users.noreply.github.com
Description: Listen and log Govee Thermometer Bluetooth Low Energy Advertisments
Depends: libbluetooth3

What took me a while to figure out was how to get the systemctl commands to be run after the files were put in place by the package manager. There are four script commands, which I’m using three. preinst, postinst, prerm, and postrm. Each of them is a simple script and needs to be marked executable in the file system. They are each run at various stages by the package manager, Pre-Installation, Post-Installation, Pre-Removal, and Post-Removal.

#!/bin/sh
# POSTINST script for goveebttemplogger

echo "\033[36m HI I'M A POSTINST SCRIPT `date +"%s"` \033[39m"
systemctl daemon-reload
systemctl enable goveebttemplogger.service
systemctl start goveebttemplogger.service

exit 0

After installation of my program and the systemd unit file, I reload the systemd database, enable my service, and start my service.

#!/bin/sh
# PRERM script for goveebttemplogger

echo "\033[36m HI I'M A PRERM SCRIPT `date +"%s"` \033[39m"
systemctl stop goveebttemplogger.service
systemctl disable goveebttemplogger.service

exit 0

Before removal of my program, I stop the service and disable the service.

#!/bin/sh
# POSTRM script for goveebttemplogger

echo "\033[36m HI I'M A POSTRM SCRIPT `date +"%s"` \033[39m"
systemctl daemon-reload

exit 0

After removal of my program, I reload the systemd database, to make sure it’s not got my unit file in its database any longer.

When I retrieve a copy of my code with the command git clone https://github.com/wcbonner/GoveeBTTempLogger I then have a subdirectory below the GoveeBTTempLogger that is also named GoveeBTTempLogger. That deeper directory is the structure that will be created into the package.


GoveeBTTempLogger/usr/local/bin/goveebttemplogger: goveebttemplogger.cpp
        mkdir -p GoveeBTTempLogger/usr/local/bin
        g++ -lbluetooth goveebttemplogger.cpp -o GoveeBTTempLogger/usr/local/bin/goveebttemplogger

deb: GoveeBTTempLogger/usr/local/bin/goveebttemplogger GoveeBTTempLogger/DEBIAN/control GoveeBTTempLogger/etc/systemd/system/goveebttemplogger.service
        mkdir -p GoveeBTTempLogger/var/log/goveebttemplogger
        touch GoveeBTTempLogger/var/log/goveebttemplogger/gvh507x.txt
        chmod a+x GoveeBTTempLogger/DEBIAN/postinst GoveeBTTempLogger/DEBIAN/postrm GoveeBTTempLogger/DEBIAN/prerm
        dpkg-deb --build GoveeBTTempLogger

I made the very simple makefile above to both compile the code and build the debian package with the simple command of make deb. It produces the package ‘goveebttemplogger’ in ‘GoveeBTTempLogger.deb’.

I can then install the package and start it running with the command sudo apt-get install ./GoveeBTTempLogger.deb

I can stop and either remove it or purge it with the command sudo apt-get remove goveebttemplogger or sudo apt-get purge goveebttemplogger.

FlightAware and MRTG

Continuing to work on graphing data with MRTG, I finally figured out a valid script for graphing FlightAware messages from my PiAware. This is especially interesting to me because I have been playing around with different antennas and running on a couple of different Raspberry Pi platforms. On one of the platforms I’ve got two receivers, the primary one that listens on the 1090MHz frequency, and the secondary that listens on 978MHz. I’ve been especially interested in knowing how many reports come in on the secondary frequency.

Using the in and out property of MRTG graphs, I’ve got the In (green) representing 978 messages and the Out (blue) representing 1090 messages.

I added the following section to my /etc/snmp/snmpd.conf file:

pass .1.3.6.1.2.1.25.1.9 /bin/sh /usr/local/bin/snmp-dump1090
pass .1.3.6.1.2.1.25.1.10 /bin/sh /usr/local/bin/snmp-dump978
view systemonly included .1.3.6.1.2.1.25

I created two files in the /usr/local/bin directory that snmp references. /usr/local/bin/snmp-dump1090:

#!/bin/bash
if [ "$1" = "-g" ]; then
        echo .1.3.6.1.2.1.25.1.9
        echo gauge
        /bin/grep "dump1090-fa.*5m).*FlightAware" /var/log/piaware.log | /usr/bin/tail -n 1 | /usr/bin/cut -f2 -d"(" | /usr/bin/cut -f1 -d" "
fi

and /usr/local/bin/snmp-dump978:

#!/bin/bash
if [ "$1" = "-g" ]; then
        echo .1.3.6.1.2.1.25.1.10
        echo gauge
        /bin/grep "dump978-fa.*5m).*FlightAware" /var/log/piaware.log | /usr/bin/tail -n1 | cut -f2 -d"(" | /usr/bin/cut -f1 -d" "
fi

I added the following section to my /etc/mrtg.conf file:

######################################################################
#       FlightAware messages
######################################################################
Options[_]: gauge, nopercent, transparent, pngdate
Factor[_]:
MaxBytes[_]: 12500000
YLegend[_]: Messages
ShortLegend[_]: Messages
LegendO[_]: dump1090 messages
LegendI[_]: dump978 messages

# Target[WimPi4_piaware]: `/home/wim/MRTG-PiAware.sh`
Target[WimPi4_piaware]: .1.3.6.1.2.1.25.1.10&.1.3.6.1.2.1.25.1.9:public@WimPi4
Title[WimPi4_piaware]: Pi4 FlightAware messages
PNGTitle[WimPi4_piaware]: Pi4 FlightAware Messages
PageTop[WimPi4_piaware]: Pi4 FlightAware messages

Target[WimPiZeroCamera_dump1090]: .1.3.6.1.2.1.25.1.9&.1.3.6.1.2.1.25.1.9:public@WimPiZeroCamera
Options[WimPiZeroCamera_dump1090]: gauge, nopercent, transparent, pngdate, noi
Title[WimPiZeroCamera_dump1090]: PiZero FlightAware messages
PNGTitle[WimPiZeroCamera_dump1090]: PiZero FlightAware Messages
PageTop[WimPiZeroCamera_dump1090]: PiZero FlightAware messages

I was testing that snmp was responding with data using the snmpget commands, but I was getting zeros back. I could run the scripts directly while I was logged in with my regular account and they were producing results so I was scratching my head.

pi@WimPi4:~ $ snmpget -v 2c -c public wimpi4 .1.3.6.1.2.1.25.1.9
iso.3.6.1.2.1.25.1.9 = Gauge32: 130
pi@WimPi4:~ $ snmpget -v 2c -c public wimpi4 .1.3.6.1.2.1.25.1.10
iso.3.6.1.2.1.25.1.10 = Gauge32: 0

The extra complication that added about six hours to my figuring things out was that the /var/log/piaware.log log files were not all readable, only owner and group. The snmp daemon was not running as a member of any group that had access to that file. I verified the problem with the command:

sudo -u Debian-snmp cat /var/log/piaware.log

I fixed the problem with the quick hack of:

sudo chmod a+r /var/log/pi*

 

Govee H5075 and H5074, Bluetooth Low Energy, and MRTG

I have been wanting a method of keeping track of temperatures for a long time. Last week I acquired a Govee H5075 Bluetooth Thermometer Hygrometer. It communicates with an app from Govee on my iPhone using Bluetooth Low Energy (BLE).

I’ve now learned some details on BLE, and have written a program that listens for BLE advertisements from either type of thermometer and logs the temperature and humidity in a text file. The code for my project is available on GitHub. https://github.com/wcbonner/GoveeBTTempLogger

The same program can also be called to get the last value from the log and produce output compatible with MRTG. MRTG is not the best method for graphing these temperatures, because all graphs start with zero on the Y axis, and neither the temperature or humidity is likely to be near zero.

MRTG graph of Temperature and Relative Humidity

My program seems to receive advertisements from each thermometer about every ten seconds. I’ve had a friend running the code in his location with a different set of thermometers and it doesn’t get advertisements nearly as frequently. I don’t know if that’s just because environment is different, or if there’s something else going on.

Govee GVH5075 Thermometer Hygrometer

Last week I came across a deal on a small thermometer with display and Bluetooth access for under $10 so I had to give it a try. The fact that the data is available via bluetooth instead of via a web service was a major selling point for me. I am hoping to be able to to log the data via a Raspberry Pi4.

GVH5070 near my Raspberry Pi4

I installed the Govee Home app on my iPhone and it was able to find the device, communicate with it, and pull both current and accumulated data.

When I attempted to find it from my Pi4 it was much more difficult. I live in an apartment with units all around. I’m not just dealing with my own devices that may be visible, but my neighbors as well.

I managed to find the device using linux command line tools, but was not able to successfully connect. A friend suggested BLE Scanner 4.0 for my iPhone for discovering the details, and it was at least able to confirm what I should be looking for using the linux command line tools. I still had timeout issues with the iPhone app, but at least was able to confirm that I could connect to the device and retrieve GUID information.

This is my first time attempting to gather data from a Bluetooth device. I’m still in the research and test phase. I’m listing a bunch of the URLS I’ve found that have been helpful.

https://www.reddit.com/r/Govee/comments/e8ljbp/work_to_access_data_from_a_govee_h5075_indoor/
https://www.jaredwolff.com/get-started-with-bluetooth-low-energy/
https://github.com/neilsheps/GoveeTemperatureAndHumidity
https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=241686
https://www.cnet.com/how-to/how-to-setup-bluetooth-on-a-raspberry-pi-3/
https://www.real-world-systems.com/docs/hcitool.1.html

From the command line on my Pi4 I already had the tools installed to try several Bluetooth commands. I believe they were installed as part of the bluez package. The first two commands below get details on the Raspberry Pi Bluetooth hardware, then the hcitool lescan command produced a lot of devices, and I found the line referencing the GVH5075 so I could use the address in further commands.

pi@WimPi4:~ $ sudo hcitool dev
Devices:
        hci0    DC:A6:32:1C:B5:74

pi@WimPi4:~ $ sudo hciconfig -a
hci0:   Type: Primary  Bus: UART
        BD Address: DC:A6:32:1C:B5:74  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING 
        RX bytes:21284 acl:25 sco:0 events:791 errors:0
        TX bytes:4401 acl:26 sco:0 commands:172 errors:0
        Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
        Link policy: RSWITCH SNIFF 
        Link mode: SLAVE ACCEPT 
        Name: 'WimPi4'
        Class: 0x000000
        Service Classes: Unspecified
        Device Class: Miscellaneous, 
        HCI Version: 5.0 (0x9)  Revision: 0x13b
        LMP Version: 5.0 (0x9)  Subversion: 0x6119
        Manufacturer: Cypress Semiconductor Corporation (305)

pi@WimPi4:~ $ sudo hcitool lescan
LE Scan ...
7B:F9:68:96:C4:92 (unknown)
57:FA:0A:E7:61:A4 (unknown)
A4:C1:38:37:BC:AE GVH5075_BCAE
A4:C1:38:37:BC:AE (unknown)
15:FF:0C:3F:E7:35 (unknown)
57:FA:0A:E7:61:A4 (unknown)

pi@WimPi4:~ $ sudo hcitool leinfo A4:C1:38:37:BC:AE
Requesting information ...
        Handle: 64 (0x0040)
        LMP Version: 4.2 (0x8) LMP Subversion: 0x22bb
        Manufacturer: Telink Semiconductor Co. Ltd (529)
        Features: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00

Another command that I attempted before I used the hcitool command was the bluetoothctl command. It scrolls a lot of data, but now that I have an idea what I’m looking at, I may be able to see announcement data from the thermometer periodically in the stream by filtering just to see the data coming from the MAC address.

pi@WimPi4:~ $ sudo bluetoothctl
Agent registered
[bluetooth]# scan on
Discovery started
[CHG] Controller DC:A6:32:1C:B5:74 Discovering: yes
[NEW] Device 57:75:EA:B6:EC:2B 57-75-EA-B6-EC-2B
[NEW] Device E7:E7:B4:AB:4A:1F 846B219FB80338A3E9
[NEW] Device 48:56:2E:FF:59:45 48-56-2E-FF-59-45
[NEW] Device 46:53:2F:D4:6F:A1 46-53-2F-D4-6F-A1
[NEW] Device 5C:C9:C5:C9:70:5F 5C-C9-C5-C9-70-5F
[NEW] Device 48:CF:F7:19:4A:3A 48-CF-F7-19-4A-3A
[NEW] Device 4E:30:D1:5D:0F:48 4E-30-D1-5D-0F-48
[NEW] Device 7D:4A:A3:81:32:22 7D-4A-A3-81-32-22
[NEW] Device 7E:0F:63:2B:DC:3E 7E-0F-63-2B-DC-3E
[NEW] Device 7F:5D:37:A2:4E:BA 7F-5D-37-A2-4E-BA
[NEW] Device 7F:6B:44:CD:3A:E5 7F-6B-44-CD-3A-E5
[NEW] Device 00:07:80:37:BD:35 00-07-80-37-BD-35
[NEW] Device 04:52:C7:BC:1C:E3 LE-Bose Revolve SoundLink
[NEW] Device 4F:84:D2:AC:59:FF 4F-84-D2-AC-59-FF
[NEW] Device 4E:F0:6A:DD:3D:7E 4E-F0-6A-DD-3D-7E
[NEW] Device 75:25:34:3F:B9:29 75-25-34-3F-B9-29
[NEW] Device 60:EC:A4:49:B6:67 60-EC-A4-49-B6-67
[NEW] Device 98:D6:BB:20:EB:3B 98-D6-BB-20-EB-3B
[NEW] Device 78:13:28:A8:0A:FF 78-13-28-A8-0A-FF
[NEW] Device 56:6F:B2:E0:40:E3 56-6F-B2-E0-40-E3
[NEW] Device 69:D9:38:44:5C:04 69-D9-38-44-5C-04
[NEW] Device 56:63:50:90:82:D6 56-63-50-90-82-D6
[CHG] Device A4:C1:38:37:BC:AE RSSI: -43
[CHG] Device A4:C1:38:37:BC:AE ManufacturerData Key: 0xec88
[CHG] Device A4:C1:38:37:BC:AE ManufacturerData Value:
00 03 32 62 64 00 ..2bd.
[CHG] Device A4:C1:38:37:BC:AE ManufacturerData Key: 0x004c
[CHG] Device A4:C1:38:37:BC:AE ManufacturerData Value:
02 15 49 4e 54 45 4c 4c 49 5f 52 4f 43 4b 53 5f ..INTELLI_ROCKS_
48 57 50 75 f2 ff c2 HWPu…
[CHG] Device 75:25:34:3F:B9:29 RSSI: -83
[NEW] Device 47:10:2F:15:99:2E 47-10-2F-15-99-2E
[NEW] Device B8:31:B5:8B:12:D2 ETOBAN386
[NEW] Device F0:6E:0B:D1:1B:BF ELRWLK345
[CHG] Device 75:25:34:3F:B9:29 RSSI: -72
[CHG] Device 7D:4A:A3:81:32:22 RSSI: -89
[CHG] Device 7D:4A:A3:81:32:22 RSSI: -81
[CHG] Device 98:D6:BB:20:EB:3B RSSI: -94
[NEW] Device A4:83:E7:20:06:5B A4-83-E7-20-06-5B
[CHG] Device E7:E7:B4:AB:4A:1F ManufacturerData Key: 0x05a7
[CHG] Device E7:E7:B4:AB:4A:1F ManufacturerData Value:
03 13 31 68 39 63 51 6f 4b 76 54 34 00 ..1h9cQoKvT4.
[NEW] Device 00:07:80:37:CA:7D 00-07-80-37-CA-7D
[CHG] Device E7:E7:B4:AB:4A:1F ManufacturerData Key: 0x05a7
[CHG] Device E7:E7:B4:AB:4A:1F ManufacturerData Value:
03 12 78 4d 32 49 31 6d 31 6a 6f 32 67 ..xM2I1m1jo2g
[CHG] Device E7:E7:B4:AB:4A:1F ManufacturerData Key: 0x05a7
[CHG] Device E7:E7:B4:AB:4A:1F ManufacturerData Value:
03 10 01 99 44 de ad be ef 00 0a 00 ca ….D……..
[CHG] Device 4E:30:D1:5D:0F:48 ManufacturerData Key: 0x004c
[CHG] Device 4E:30:D1:5D:0F:48 ManufacturerData Value:
10 06 10 1e b0 2a e1 be …..*..
[CHG] Device 98:D6:BB:20:EB:3B RSSI: -85
[NEW] Device 00:07:80:37:BE:C9 523
[CHG] Device 5C:C9:C5:C9:70:5F ManufacturerData Key: 0x004c
[CHG] Device 5C:C9:C5:C9:70:5F ManufacturerData Value:
10 06 5a 1e 56 a0 e1 eb ..Z.V…
[CHG] Device E7:E7:B4:AB:4A:1F ManufacturerData Key: 0x05a7
[CHG] Device E7:E7:B4:AB:4A:1F ManufacturerData Value:
03 13 31 68 39 63 51 6f 4b 76 54 34 00 ..1h9cQoKvT4.
[CHG] Device 75:25:34:3F:B9:29 RSSI: -81
[NEW] Device 6B:C2:D2:28:1E:A5 6B-C2-D2-28-1E-A5
[CHG] Device 5C:C9:C5:C9:70:5F ManufacturerData Key: 0x004c
[CHG] Device 5C:C9:C5:C9:70:5F ManufacturerData Value:
0c 0e 00 41 32 56 c8 79 5a 01 9d 63 d5 79 c7 80 …A2V.yZ..c.y..
10 06 56 1e 56 a0 e1 eb ..V.V…
[CHG] Device A4:C1:38:37:BC:AE RSSI: -35
[CHG] Device A4:C1:38:37:BC:AE ManufacturerData Key: 0xec88
[CHG] Device A4:C1:38:37:BC:AE ManufacturerData Value:
00 03 32 61 64 00 ..2ad.
[CHG] Device A4:C1:38:37:BC:AE ManufacturerData Key: 0x004c
[CHG] Device A4:C1:38:37:BC:AE ManufacturerData Value:
02 15 49 4e 54 45 4c 4c 49 5f 52 4f 43 4b 53 5f ..INTELLI_ROCKS_
48 57 50 75 f2 ff c2 HWPu…
[CHG] Device 48:CF:F7:19:4A:3A RSSI: -76
[CHG] Device E7:E7:B4:AB:4A:1F ManufacturerData Key: 0x05a7
[CHG] Device E7:E7:B4:AB:4A:1F ManufacturerData Value:
03 10 01 99 44 de ad be ef 00 0a 00 ca ….D……..
[NEW] Device 78:11:F9:E8:7A:DA 78-11-F9-E8-7A-DA
[CHG] Device 47:10:2F:15:99:2E RSSI: -84
[CHG] Device 69:D9:38:44:5C:04 RSSI: -83
[CHG] Device 47:10:2F:15:99:2E ManufacturerData Key: 0x004c
[CHG] Device 47:10:2F:15:99:2E ManufacturerData Value:
10 06 1c 1e 9a e0 28 9b ……(.
[CHG] Device 5C:C9:C5:C9:70:5F ManufacturerData Key: 0x004c
[CHG] Device 5C:C9:C5:C9:70:5F ManufacturerData Value:
0c 0e 00 42 32 7b fc b2 b6 a1 46 31 82 0f 67 02 …B2{….F1..g.
10 06 56 1e 56 a0 e1 eb ..V.V…
[CHG] Device 75:25:34:3F:B9:29 RSSI: -73
[CHG] Device E7:E7:B4:AB:4A:1F ManufacturerData Key: 0x05a7
[CHG] Device E7:E7:B4:AB:4A:1F ManufacturerData Value:
03 13 31 68 39 63 51 6f 4b 76 54 34 00 ..1h9cQoKvT4.
[CHG] Device 47:10:2F:15:99:2E ManufacturerData Key: 0x004c
[CHG] Device 47:10:2F:15:99:2E ManufacturerData Value:
10 06 14 1e 9a e0 28 9b ……(.
[NEW] Device 5C:53:86:8D:A4:61 5C-53-86-8D-A4-61
[NEW] Device 42:32:EC:5F:59:C5 42-32-EC-5F-59-C5
[bluetooth]# scan off
Discovery stopped
[CHG] Device E7:E7:B4:AB:4A:1F TxPower is nil
[CHG] Device E7:E7:B4:AB:4A:1F RSSI is nil
[DEL] Device E7:E7:B4:AB:4A:1F 846B219FB80338A3E9
[CHG] Controller DC:A6:32:1C:B5:74 Discovering: no
[CHG] Device 42:32:EC:5F:59:C5 TxPower is nil
[CHG] Device 42:32:EC:5F:59:C5 RSSI is nil
[CHG] Device 5C:53:86:8D:A4:61 RSSI is nil
[CHG] Device 78:11:F9:E8:7A:DA TxPower is nil
[CHG] Device 78:11:F9:E8:7A:DA RSSI is nil
[CHG] Device 6B:C2:D2:28:1E:A5 TxPower is nil
[CHG] Device 6B:C2:D2:28:1E:A5 RSSI is nil
[CHG] Device 00:07:80:37:BE:C9 RSSI is nil
[CHG] Device 00:07:80:37:CA:7D RSSI is nil
[CHG] Device A4:83:E7:20:06:5B RSSI is nil
[CHG] Device F0:6E:0B:D1:1B:BF TxPower is nil
[CHG] Device F0:6E:0B:D1:1B:BF RSSI is nil
[CHG] Device B8:31:B5:8B:12:D2 TxPower is nil
[CHG] Device B8:31:B5:8B:12:D2 RSSI is nil
[CHG] Device 47:10:2F:15:99:2E TxPower is nil
[CHG] Device 47:10:2F:15:99:2E RSSI is nil
[CHG] Device A4:C1:38:37:BC:AE RSSI is nil
[CHG] Device 56:63:50:90:82:D6 RSSI is nil
[CHG] Device 69:D9:38:44:5C:04 TxPower is nil
[CHG] Device 69:D9:38:44:5C:04 RSSI is nil
[CHG] Device 56:6F:B2:E0:40:E3 TxPower is nil
[CHG] Device 56:6F:B2:E0:40:E3 RSSI is nil
[CHG] Device 78:13:28:A8:0A:FF TxPower is nil
[CHG] Device 78:13:28:A8:0A:FF RSSI is nil
[CHG] Device 98:D6:BB:20:EB:3B RSSI is nil
[CHG] Device 60:EC:A4:49:B6:67 TxPower is nil
[CHG] Device 60:EC:A4:49:B6:67 RSSI is nil
[CHG] Device 75:25:34:3F:B9:29 TxPower is nil
[CHG] Device 75:25:34:3F:B9:29 RSSI is nil
[CHG] Device 4E:F0:6A:DD:3D:7E TxPower is nil
[CHG] Device 4E:F0:6A:DD:3D:7E RSSI is nil
[CHG] Device 4F:84:D2:AC:59:FF TxPower is nil
[CHG] Device 4F:84:D2:AC:59:FF RSSI is nil
[CHG] Device 04:52:C7:BC:1C:E3 TxPower is nil
[CHG] Device 04:52:C7:BC:1C:E3 RSSI is nil
[CHG] Device 00:07:80:37:BD:35 RSSI is nil
[CHG] Device 7F:6B:44:CD:3A:E5 TxPower is nil
[CHG] Device 7F:6B:44:CD:3A:E5 RSSI is nil
[CHG] Device 7F:5D:37:A2:4E:BA TxPower is nil
[CHG] Device 7F:5D:37:A2:4E:BA RSSI is nil
[CHG] Device 7E:0F:63:2B:DC:3E TxPower is nil
[CHG] Device 7E:0F:63:2B:DC:3E RSSI is nil
[CHG] Device 7D:4A:A3:81:32:22 TxPower is nil
[CHG] Device 7D:4A:A3:81:32:22 RSSI is nil
[CHG] Device 4E:30:D1:5D:0F:48 TxPower is nil
[CHG] Device 4E:30:D1:5D:0F:48 RSSI is nil
[CHG] Device 48:CF:F7:19:4A:3A TxPower is nil
[CHG] Device 48:CF:F7:19:4A:3A RSSI is nil
[CHG] Device 5C:C9:C5:C9:70:5F TxPower is nil
[CHG] Device 5C:C9:C5:C9:70:5F RSSI is nil
[CHG] Device 46:53:2F:D4:6F:A1 TxPower is nil
[CHG] Device 46:53:2F:D4:6F:A1 RSSI is nil
[CHG] Device 48:56:2E:FF:59:45 TxPower is nil
[CHG] Device 48:56:2E:FF:59:45 RSSI is nil
[CHG] Device 57:75:EA:B6:EC:2B TxPower is nil
[CHG] Device 57:75:EA:B6:EC:2B RSSI is nil
[DEL] Device 57:75:EA:B6:EC:2B 57-75-EA-B6-EC-2B
[DEL] Device 48:56:2E:FF:59:45 48-56-2E-FF-59-45
[DEL] Device 46:53:2F:D4:6F:A1 46-53-2F-D4-6F-A1
[DEL] Device 5C:C9:C5:C9:70:5F 5C-C9-C5-C9-70-5F
[DEL] Device 48:CF:F7:19:4A:3A 48-CF-F7-19-4A-3A
[DEL] Device 4E:30:D1:5D:0F:48 4E-30-D1-5D-0F-48
[DEL] Device 7D:4A:A3:81:32:22 7D-4A-A3-81-32-22
[DEL] Device 7E:0F:63:2B:DC:3E 7E-0F-63-2B-DC-3E
[DEL] Device 7F:5D:37:A2:4E:BA 7F-5D-37-A2-4E-BA
[DEL] Device 7F:6B:44:CD:3A:E5 7F-6B-44-CD-3A-E5
[DEL] Device 00:07:80:37:BD:35 00-07-80-37-BD-35
[DEL] Device 04:52:C7:BC:1C:E3 LE-Bose Revolve SoundLink
[DEL] Device 4F:84:D2:AC:59:FF 4F-84-D2-AC-59-FF
[DEL] Device 4E:F0:6A:DD:3D:7E 4E-F0-6A-DD-3D-7E
[DEL] Device 75:25:34:3F:B9:29 75-25-34-3F-B9-29
[DEL] Device 60:EC:A4:49:B6:67 60-EC-A4-49-B6-67
[DEL] Device 98:D6:BB:20:EB:3B 98-D6-BB-20-EB-3B
[DEL] Device 78:13:28:A8:0A:FF 78-13-28-A8-0A-FF
[DEL] Device 56:6F:B2:E0:40:E3 56-6F-B2-E0-40-E3
[DEL] Device 69:D9:38:44:5C:04 69-D9-38-44-5C-04
[DEL] Device 56:63:50:90:82:D6 56-63-50-90-82-D6
[DEL] Device 47:10:2F:15:99:2E 47-10-2F-15-99-2E
[DEL] Device B8:31:B5:8B:12:D2 ETOBAN386
[DEL] Device F0:6E:0B:D1:1B:BF ELRWLK345
[DEL] Device A4:83:E7:20:06:5B A4-83-E7-20-06-5B
[DEL] Device 00:07:80:37:CA:7D 00-07-80-37-CA-7D
[DEL] Device 00:07:80:37:BE:C9 523
[DEL] Device 6B:C2:D2:28:1E:A5 6B-C2-D2-28-1E-A5
[DEL] Device 78:11:F9:E8:7A:DA 78-11-F9-E8-7A-DA
[DEL] Device 5C:53:86:8D:A4:61 5C-53-86-8D-A4-61
[DEL] Device 42:32:EC:5F:59:C5 42-32-EC-5F-59-C5
[bluetooth]# exit

I’m posting all of this here and hopefully will be able to make progress on retrieving the data in the next few days.

Monitoring Raspberry Pi with MRTG

I’ve used MRTG for simple monitoring for years. It’s easy to get working and dependent on very few packages. It stores it’s data in simple files. This both limits it, and makes it easy to move or duplicate.

I wanted to monitor each of my Raspberry Pi network interfaces because they are connected via WiFi and I can’t monitor a particular switch port for each device. I’ve spent nearly a year searching for the reason that MRTG didn’t enumerate the interfaces before coming up with a simple snippet fixing my problem.

Adding this line to the end of my /etc/snmp/snmpd.conf file and restarting the snmpd allowed me to run cfgmaker and see my network interfaces.

view   systemonly  included   .1.3.6.1.2.1.2

Quick and dirty addition and query:

sudo echo view   systemonly  included   .1.3.6.1.2.1.2 >>/etc/snmp/snmpd.conf
sudo systemctl restart snmpd

/usr/bin/cfgmaker --no-down --zero-speed=100000000 public@localhost
Thanks to https://www.seei.biz/cpu-temperature-of-a-raspberry-pi-via-snmp/ for giving me the simple answer that I’d been trying to figure out for over a year.

Access Windows share from Raspberry Pi

I have a shared directory from my windows server that I’d like to read and write from my Raspberry Pi. I want the share to be automatically available on my Raspberry Pi whenever both the Raspberry and the Windows server are running, but I don’t want the system to spend too much time hung up if the windows server is not available. My easy solution is below.

My Windows servername is Acid. The share I want to connect to is Web. The IP address of the server is 192.168.0.12.

sudo echo 192.168.0.12 Acid>>/etc/hosts
sudo mkdir --parents /media/acid/web
sudo echo username=WindowsUsername >/etc/wimsworld.smb.credentials
sudo echo password=WindowsPassword >>/etc/wimsworld.smb.credentials
sudo echo domain=OptionalDomainName >>/etc/wimsworld.smb.credentials
sudo chmod 0600 /etc/wimsworld.smb.credentials
sudo echo //acid/web /media/acid/web/ cifs credentials=/etc/wimsworld.smb.credentials,noauto,x-systemd.automount,x-systemd.idle-timeout=1min,_netdev 0 0>>/etc/fstab

That series of commands, with the correct details in the credentials, and the system automounter will automatically attempt to connect whenever there’s an access under /media/acid/web and then disconnect again after it’s been idle for over a minute.

I needed to add Acid to my local hosts file because the name doesn’t resolve from the DNS server the raspberry pi is using.

I put the windows Username/Password and Domain in a file with only read/write permissions to root so that it wasn’t clear text in the fstab file for anyone on the machine to read.

I did all of this on a machine that had been built from the Raspian Buster Lite image from 2019-07-10. I didn’t explicitly install the cifs-utils package. It might be needed on other distributions.

Raspberry Pi ZeroW Camera Focus with FFMPEG

I wanted a quick and dirty method to test my camera module installation on my Raspberry Pi ZeroW installation. I don’t have a monitor connected to the Raspberry, and explicitly did not install the desktop version of the operating system. This is especially important because the camera itself may not be properly focused after installation in the case, and the only way to easily focus the camera is with a video stream allowing you to make small adjustments and see them nearly real time.

I’ve used FFMPEG for years as it handles almost any kind of video or audio I can throw at it. I use VLC on my desktop machine for similar reasons.

I did a quick install of ffmpeg on my Pi with the following command, allowing it to install all the requirements, adding up to almost 126 new packages and 56MB that needed to be downloaded and installed.

sudo apt-get install ffmpeg -y

After it finished installing, I was able to run the following command with the 192.168.0.16 address being my desktop computer.

ffmpeg -f video4linux2 -input_format h264 -video_size 1280x720 -framerate 30 -i /dev/video0 -vcodec copy -an -f mpegts udp://192.168.0.16:5000?pkt_size=1316

On my desktop computer I ran VLC, under the Media menu, selected Open Network Stream, and opened:

udp://@0.0.0.0:5000

2019-09-23 (1)2019-09-23 (2)

What I’m doing is to use FFMPEG to pull video from the device and push it using UDP datagrams at my desktop on port 5000. Then VLC opens a port on the local machine at port 5000 to receive the datagrams and it decodes and displays the video. An interesting thing about this method is that I can stop transmitting from the raspberry, then restart it, and VLC will accept the packets since UDP is a connectionless protocol.

What really surprised me was that when I logged in a second time to my Raspberry Pi to view the CPU usage for streaming, it was only running around 12% of the CPU. I was interested in knowing what native formats the camera supported..

ffmpeg -f v4l2 -list_formats all -i /dev/video0
ffmpeg version 4.1.4-1+rpt1~deb10u1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8 (Raspbian 8.3.0-6+rpi1)
  configuration: --prefix=/usr --extra-version='1+rpt1~deb10u1' --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --arch=arm --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-omx-rpi --enable-mmal --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
[video4linux2,v4l2 @ 0x2367e40] Raw       :     yuv420p :     Planar YUV 4:2:0 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x2367e40] Raw       :     yuyv422 :           YUYV 4:2:2 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x2367e40] Raw       :       rgb24 :     24-bit RGB 8-8-8 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x2367e40] Compressed:       mjpeg :            JFIF JPEG : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x2367e40] Compressed:        h264 :                H.264 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x2367e40] Compressed:       mjpeg :          Motion-JPEG : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x2367e40] Raw       : Unsupported :           YVYU 4:2:2 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x2367e40] Raw       : Unsupported :           VYUY 4:2:2 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x2367e40] Raw       :     uyvy422 :           UYVY 4:2:2 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x2367e40] Raw       :        nv12 :         Y/CbCr 4:2:0 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x2367e40] Raw       :       bgr24 :     24-bit BGR 8-8-8 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x2367e40] Raw       :     yuv420p :     Planar YVU 4:2:0 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x2367e40] Raw       : Unsupported :         Y/CrCb 4:2:0 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x2367e40] Raw       :        bgr0 : 32-bit BGRA/X 8-8-8-8 : {32-3280, 2}x{32-2464, 2}
/dev/video0: Immediate exit requested

That output leads me to believe that the camera module could output either h264 or mjpeg without significant CPU overhead. What it doesn’t do is tell me efficient frame sizes. It seems to say that horizontal and vertical sizes can be anything between 32 to 3280 and 32 to 2464. I know that the specs on the camera say that it will run still frames at the high resolution, but video is significantly less.

Two Video4Linux commands that return interesting and similar results are:

pi@WimPiZeroCamera:~ $ v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
        Type: Video Capture

        [0]: 'YU12' (Planar YUV 4:2:0)
                Size: Stepwise 32x32 - 3280x2464 with step 2/2
        [1]: 'YUYV' (YUYV 4:2:2)
                Size: Stepwise 32x32 - 3280x2464 with step 2/2
        [2]: 'RGB3' (24-bit RGB 8-8-8)
                Size: Stepwise 32x32 - 3280x2464 with step 2/2
        [3]: 'JPEG' (JFIF JPEG, compressed)
                Size: Stepwise 32x32 - 3280x2464 with step 2/2
        [4]: 'H264' (H.264, compressed)
                Size: Stepwise 32x32 - 3280x2464 with step 2/2
        [5]: 'MJPG' (Motion-JPEG, compressed)
                Size: Stepwise 32x32 - 3280x2464 with step 2/2
        [6]: 'YVYU' (YVYU 4:2:2)
                Size: Stepwise 32x32 - 3280x2464 with step 2/2
        [7]: 'VYUY' (VYUY 4:2:2)
                Size: Stepwise 32x32 - 3280x2464 with step 2/2
        [8]: 'UYVY' (UYVY 4:2:2)
                Size: Stepwise 32x32 - 3280x2464 with step 2/2
        [9]: 'NV12' (Y/CbCr 4:2:0)
                Size: Stepwise 32x32 - 3280x2464 with step 2/2
        [10]: 'BGR3' (24-bit BGR 8-8-8)
                Size: Stepwise 32x32 - 3280x2464 with step 2/2
        [11]: 'YV12' (Planar YVU 4:2:0)
                Size: Stepwise 32x32 - 3280x2464 with step 2/2
        [12]: 'NV21' (Y/CrCb 4:2:0)
                Size: Stepwise 32x32 - 3280x2464 with step 2/2
        [13]: 'BGR4' (32-bit BGRA/X 8-8-8-8)
                Size: Stepwise 32x32 - 3280x2464 with step 2/2
pi@WimPiZeroCamera:~ $ v4l2-ctl -L

User Controls

                     brightness 0x00980900 (int)    : min=0 max=100 step=1 default=50 value=50 flags=slider
                       contrast 0x00980901 (int)    : min=-100 max=100 step=1 default=0 value=0 flags=slider
                     saturation 0x00980902 (int)    : min=-100 max=100 step=1 default=0 value=0 flags=slider
                    red_balance 0x0098090e (int)    : min=1 max=7999 step=1 default=1000 value=1000 flags=slider
                   blue_balance 0x0098090f (int)    : min=1 max=7999 step=1 default=1000 value=1000 flags=slider
                horizontal_flip 0x00980914 (bool)   : default=0 value=0
                  vertical_flip 0x00980915 (bool)   : default=0 value=0
           power_line_frequency 0x00980918 (menu)   : min=0 max=3 default=1 value=1
                                0: Disabled
                                1: 50 Hz
                                2: 60 Hz
                                3: Auto
                      sharpness 0x0098091b (int)    : min=-100 max=100 step=1 default=0 value=0 flags=slider
                  color_effects 0x0098091f (menu)   : min=0 max=15 default=0 value=0
                                0: None
                                1: Black & White
                                2: Sepia
                                3: Negative
                                4: Emboss
                                5: Sketch
                                6: Sky Blue
                                7: Grass Green
                                8: Skin Whiten
                                9: Vivid
                                10: Aqua
                                11: Art Freeze
                                12: Silhouette
                                13: Solarization
                                14: Antique
                                15: Set Cb/Cr
                         rotate 0x00980922 (int)    : min=0 max=360 step=90 default=0 value=0 flags=modify-layout
             color_effects_cbcr 0x0098092a (int)    : min=0 max=65535 step=1 default=32896 value=32896

Codec Controls

             video_bitrate_mode 0x009909ce (menu)   : min=0 max=1 default=0 value=0 flags=update
                                0: Variable Bitrate
                                1: Constant Bitrate
                  video_bitrate 0x009909cf (int)    : min=25000 max=25000000 step=25000 default=10000000 value=10000000
         repeat_sequence_header 0x009909e2 (bool)   : default=0 value=0
            h264_i_frame_period 0x00990a66 (int)    : min=0 max=2147483647 step=1 default=60 value=60
                     h264_level 0x00990a67 (menu)   : min=0 max=11 default=11 value=11
                                0: 1
                                1: 1b
                                2: 1.1
                                3: 1.2
                                4: 1.3
                                5: 2
                                6: 2.1
                                7: 2.2
                                8: 3
                                9: 3.1
                                10: 3.2
                                11: 4
                   h264_profile 0x00990a6b (menu)   : min=0 max=4 default=4 value=4
                                0: Baseline
                                1: Constrained Baseline
                                2: Main
                                4: High

Camera Controls

                  auto_exposure 0x009a0901 (menu)   : min=0 max=3 default=0 value=0
                                0: Auto Mode
                                1: Manual Mode
         exposure_time_absolute 0x009a0902 (int)    : min=1 max=10000 step=1 default=1000 value=1000
     exposure_dynamic_framerate 0x009a0903 (bool)   : default=0 value=0
             auto_exposure_bias 0x009a0913 (intmenu): min=0 max=24 default=12 value=12
                                0: -4000 (0xfffffffffffff060)
                                1: -3667 (0xfffffffffffff1ad)
                                2: -3333 (0xfffffffffffff2fb)
                                3: -3000 (0xfffffffffffff448)
                                4: -2667 (0xfffffffffffff595)
                                5: -2333 (0xfffffffffffff6e3)
                                6: -2000 (0xfffffffffffff830)
                                7: -1667 (0xfffffffffffff97d)
                                8: -1333 (0xfffffffffffffacb)
                                9: -1000 (0xfffffffffffffc18)
                                10: -667 (0xfffffffffffffd65)
                                11: -333 (0xfffffffffffffeb3)
                                12: 0 (0x0)
                                13: 333 (0x14d)
                                14: 667 (0x29b)
                                15: 1000 (0x3e8)
                                16: 1333 (0x535)
                                17: 1667 (0x683)
                                18: 2000 (0x7d0)
                                19: 2333 (0x91d)
                                20: 2667 (0xa6b)
                                21: 3000 (0xbb8)
                                22: 3333 (0xd05)
                                23: 3667 (0xe53)
                                24: 4000 (0xfa0)
      white_balance_auto_preset 0x009a0914 (menu)   : min=0 max=9 default=1 value=1
                                0: Manual
                                1: Auto
                                2: Incandescent
                                3: Fluorescent
                                4: Fluorescent H
                                5: Horizon
                                6: Daylight
                                7: Flash
                                8: Cloudy
                                9: Shade
            image_stabilization 0x009a0916 (bool)   : default=0 value=0
                iso_sensitivity 0x009a0917 (intmenu): min=0 max=4 default=0 value=0
                                0: 0 (0x0)
                                1: 100000 (0x186a0)
                                2: 200000 (0x30d40)
                                3: 400000 (0x61a80)
                                4: 800000 (0xc3500)
           iso_sensitivity_auto 0x009a0918 (menu)   : min=0 max=1 default=1 value=1
                                0: Manual
                                1: Auto
         exposure_metering_mode 0x009a0919 (menu)   : min=0 max=2 default=0 value=0
                                0: Average
                                1: Center Weighted
                                2: Spot
                     scene_mode 0x009a091a (menu)   : min=0 max=13 default=0 value=0
                                0: None
                                8: Night
                                11: Sports

JPEG Compression Controls

            compression_quality 0x009d0903 (int)    : min=1 max=100 step=1 default=30 value=30

 

 

5GHz WiFi on Raspberry Pi 4

In my post about quickly setting up a headless Raspberry I had a simple wpa_supplicant.conf file example. This week I got a Raspberry Pi 4, which according to the documentation supports 5GHz networks and 802.11ac.

I’d been running the command sudo iwlist wlan0 scan | grep ESSID and only seeing 2.4GHz networks.

It occurred to me that I’d seen some people in other countries putting the country detail in their wpa_supplicant.conf file, so I decided to see if it made a difference. Sure enough, after adding the line country=US to my file I was able to see 5GHz networks as well as 2.4GHz networks.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={
       ssid="MyNetworkSSID"
       psk="MyNetworkPassword"
}
After a bit of reading on the https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md page, I noticed a section that made this point with the Pi 3B+, but because I’d not used a 3B+, I didn’t realize it supported 5GHz networking as well.
On the Raspberry Pi 3 Model B+, you will also need to set the country code, so that the 5G networking can choose the correct frequency bands. You can either use the raspi-config application and select the localisation option, or edit the wpa_supplicant.conf file and add the following. (Note you need to replace ‘GB’ with the ISO code of your country. See Wikipedia for a list of country codes.)

Raspberry PiZeroW Camera Module

20190913_140539

When you’ve gotten used to Amazon Prime and free shipping, purchasing inexpensive items from other online retailers where the shipping doubles the cost of the item makes it harder to impulse buy items. An item for $5 that costs $7 in shipping often doesn’t get bought. Even a pair of items that cost $16 together that then cost $7 in shipping cause me to delay the purchase.

20190913_143154

Because I was purchasing a Raspberry Pi 4 and Raspberry Pi USB-C Power Supply from Sparkfun, I decided to throw in another Pi ZeroW and case for another $16. I then added the Raspberry Pi Camera module because the case has an optional cover enclosing the camera and I wanted to see how it all worked together. I only wish I’d realized that there was a Noir version, because I’ve always wanted to play with infrared photography.

Having recently streamlined the installation of a Pi Zero, I installed the camera and Pi ZeroW in the case, put the configured micro sd card in place, plugged it into my HDMI monitor just to watch it boot and applied power. I never saw anything on the monitor. The Pi ZeroW only has a single LED, which is generally on, but blinks for micro sd activity. Because I’d closed the case, the LED wasn’t visible, and with no monitor activity I was wondering if I’d gotten a bad board.

20190913_143130

I opened the case and powered it on again, this time I knew I was seeing LED activity. I did a quick search of my network for new devices and found the new board was responding on ssh and appeared to be working correctly other than no HDMI output.  I was even able to take a snapshot with the camera using the command:

raspistill -o image.jpg

I decided to test booting the device without the camera installed. That worked fine, and I had HDMI output during the boot process. Now I started to wonder if perhaps the power supply I was using didn’t provide enough power. Perhaps the camera and the HDMI device were mutually exclusive in the amount of power required

A lot of searching on the web resulted in nothing about the power required for the camera affecting the HDMI output. I found that I might be able to reduce the power requirements by 25mA by turning off the HDMI, but that the Pi ZeroW was already the lowest power draw available. https://www.jeffgeerling.com/blogs/jeff-geerling/raspberry-pi-zero-conserve-energy

I found the tvservice command and the -s option with the camera installed was resulting in a different result from without the camera installed.

pi@WimPiZeroCamera:~ $ sudo /usr/bin/tvservice -s
state 0x40000 [NTSC 4:3], 720x480 @ 60.00Hz, interlaced
pi@WimPiZeroW:~ $ sudo /usr/bin/tvservice -s
state 0xa [HDMI CEA (16) RGB lim 16:9], 1920x1080 @ 60.00Hz, progressive

At least recognizing that difference was progress. For some reason under Raspian Buster the camera module is causing the HDMI output to be different. I found options in https://www.raspberrypi.org/documentation/configuration/config-txt/video.md that allow me to force the HDMI output to what I want. I changed /boot/config.txt with the following and now I’ve got both camera and video working properly.

# uncomment to force a specific HDMI mode (this will force [HDMI CEA (16) RGB lim 16:9], 1920x1080 @ 60.00Hz, progressive)
hdmi_group=1
hdmi_mode=16

I hope that this helps someone else having problems with both camera and hdmi video output. I don’t know if this was specific to Buster since I never tried it under Jessie or Stretch.

Headless Raspberry Pi Setup

I’ve been using a raspberry pi as a ADSB data feeder for FlightAware and FlightRadar24 for a while and the micro sd card developed a bad sector. That meant I needed to rebuild the installation. I really didn’t want to deal with connecting a keyboard, monitor, and mouse to the Pi for the installation. I found https://core-electronics.com.au/tutorials/raspberry-pi-zerow-headless-wifi-setup.html giving me useful information on how to avoid all that. I’m documenting my steps here for my own memory.

Step 1. Download the most recent version of Raspian Buster Lite from https://www.raspberrypi.org/downloads/raspbian/

Step 2. Download balenaEtcher portable from https://www.balena.io/etcher/

Step 3. Use Etcher to overwrite an SD card with the Raspian image I downloaded earlier.

2019-09-09 (28)2019-09-09 (29)2019-09-09 (30)2019-09-09 (31)2019-09-09 (33)2019-09-09 (34)

Step 4. Eject the flash card and close Etcher, then insert the flash card again, rejecting the option to format the drive.  The flash card is now formatted with multiple partitions, only the first is easily read in windows.

Step 5. create two files on the sd card boot partition. ssh and wpa_supplicant.conf. ssh is an empty file. wpa_supplicant.conf should have the following contents, customized for your WiFi Network:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={
       ssid="MyNetworkSSID"
       psk="MyNetworkPassword"
}

Step 6. Eject your micro sd card, put it in the Raspberry Pi and power on the raspberry. You’ll need to wait a couple of minutes for the raspberry to finish several steps before you can connect to it over the network. The Raspberry Pi is expanding the native filesystem to fill the available space on the flash card, then rebooting another time with the new filesystem. You’ll need to figure out what IP address the Raspberry retrieved on your network. If you have access to your router, you may be able to see the attached devices and find the new Raspberry that way. I like the NirSoft Wireless Network Watcher to find what’s on my network https://www.nirsoft.net/utils/wireless_network_watcher.html.

Step 7. Connect to the Raspberry Pi with ssh. You’ll be using the default user and password to connect: “pi” and “raspberry”. I used the new Microsoft Windows Terminal in Windows 10 for this example. https://www.microsoft.com/en-us/p/windows-terminal-preview/9n0dx20hk701#activetab=pivot:overviewtab

2019-09-09 (35)

The Raspberry is up and running now. There are several steps I recommend to do immediately. Use sudo raspi-config to set the user password, the machine hostname, and the timezone you want the machine to use.

2019-09-09 (36)2019-09-09 (37)2019-09-09 (38)2019-09-09 (39)2019-09-09 (40)2019-09-09 (41)2019-09-09 (42)2019-09-09 (49)2019-09-09 (50)2019-09-09 (51)2019-09-09 (52)2019-09-09 (53)2019-09-09 (44)

After waiting for the raspberry to reboot and reconnecting via ssh, updating the software to the latest version is the next step.

sudo apt-get update -y
sudo apt-get upgrade -y
sudo shutdown -r now

2019-09-09 (47)

Then I install several tools that I like to have.

sudo apt-get install lighttpd mc mrtg lrzsz nmap dnsutils etherwake snmpd snmp arp-scan shairport-sync -y

My next steps are to get PiAware and FlightRadar up and running.