recap
This is a continuation of an ongoing series of work logs following my journey to dockerize my people counter raspberry pi app. I feel like I’m almost done with it, but every day is a new discovery of things I didn’t know I needed to do, followed by figuring out how to do those things. Follow along if you like, and feel free to go back through the annals of time:
17 sep
Continuing my quest to configure email on the pi. Since I plugged in the original SD card, it doesn’t have any of the mail stuff I installed on the other SD card. I’m following the instructions from the raspberry pi forum post No mail command with heirloom-mailx on Raspbian-Stretch then re-following the sending email via gmail in linux post and hoping for the best.
This approach worked as long as I use the command mail
instead of mailx
. Now to figure out how to configure the unattended-upgrades
email…
There are many layers to this email business. I thought mailx
was a program, but turns out it’s just a command line tool to pass mail to your Mail Transfer Agent (sendmail, postfix, etc.). I ended up following the advice in the “No mail command…” post linked above and symlinked the commands mail
and mailx
to heirloom-mailx
. I ran a test using both mail
and mailx
and they both sent email, so I’m going to say I’m good. Now I need to swap out the SD cards and update the other card and run the unattended-upgrades
dry run to make sure it’s sending the update email.
Ugghh, I installed too much crap on Thursday. Gotta uninstall sendmail
:
sudo apt-get removed sendmail
-
sudo apt-get purge sendmail*
- that asterisk is important, yo
Here’s what ended up working:
- install heirloom-mailx:
sudo apt-get install heirloom-mailx
- create mail config:
vim ~/.mailrc
- add these lines:
account gmail { set smtp-use-starttls set smtp=smtp://smtp.gmail.com:587 set smtp-auth=login set smtp-auth-user=abcd@gmail.com set smtp-auth-password=mypassword set from="ABCD " }
- replace the last three lines with gmail stuff, including the gmail email between quotes on the last line
- set up symlinks for mail and mailx commands:
sudo ln -s /usr/bin/heirloom-mailx /usr/bin/mail
sudo ln -s /usr/bin/heirloom-mailx /usr/bin/mailx
- test with this command:
echo "Test Email" | mailx -v -A gmail -s "test" yyyyyyyy@gmail.com
- check the sent folder of your new gmail account to see if it send the mail
- you can also send a second test to yourself at a different email address
18 sep
Time to fix that weird container timezone issue. Added this to the Dockerfile:
ENV TZ=America/Indiana/Indianapolis
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
Re-ran the docker build and this seemed to fix it. Boom!
github
I’ve decided to keep both the google version and libinsight version of the people counter in the github file. I’ll update the README to indicate they’ll need to edit the package.json
start command depending on which version they use. Then I’ll push the image to docker hub. Huzzah!
20 sep
Fire at Lawrence so we were closed yesterday. I was actually a little sad I didn’t have my SD card at home to work on this. On my day off. Yikes.
libinsight
Something I hadn’t thought about until now is how the count will be translated to the LibInsight API. The way our current gate counter works, it counts every person that walks through the gate regardless of whether that person is coming or going. The spreadsheet those count numbers ends up in then does the math to cut the number in half. That’s also how I set up the google sheet for the counter before moving the count to the LibInsight API.
My original plan was to have the request sent with something along the lines of gate_start = (count/2)
to account for the in/out numbers. It doesn’t seem that the libinsight API accepts decimal numbers. So how do I deal with this? Send full numbers and just know that those are raw counts? Do I write a program that holds on to half numbers and sends a full number when it can? (Maybe that doesn’t make sense in writing…)
After talking with the libapps taskforce, I’m going to try to set up a new dataset and making the “divide count by 2” the default setting. If that’s not an option, everyone seems okay with dividing by two and rounding up. Sounsd like a plan.
The automatic bidirectional count was exactly what I was looking for! It takes the count and divides it by two. Boom! I’m running tests overnight, and hopefully it’ll be doing it’s thing and I can finish dockerizing tomorrow.
21 sep
Friday means day full of testing! I brought Scott’s pi zero w to see if my docker image will run on it. So excited!
It booted! There’s only one usb slot, so I’m going to try to navigate raspbian with the keyboard.
The original docker image from the first pull to this SD card is still on here. For whatever reason, my docker run
is exiting with a weird code (139) that I can’t identify via google. When I try to override CMD
with --entrypoint /bin/bash
flag, it still exits the container without dropping me into a REPL.
Found a stack overflow (docker exiting status code 139) that suggests testing the app outside the container, but I really don’t want to do that. The whole point of using a container is that shit should just work in there. I don’t want to have to download node and install npm and all the libraries, blah blah blah…
So I’ll keep trying, but it might be that this just won’t work on a zero. If it turns out that there’s just not enough RAM, maybe I’ll need to try a stretch-lite image? Or switch to alpine?? The SD card that came with the zero is regular ol’ NOOBS, so this little guy is pretty powerful… why wouldn’t my container run?
Decided to try running a docker node container for testing:
docker pull node
-
docker run -it node
- ALSO EXITED WITH CODE 139
- this makes me feel much better about my container
- some more googling revealed that maybe it was an architecture incompatibility problem, so I ran
uname -a
on both to see my os version and kernel info.- Pi 3: 4.14 (stretch) armv7
- Zero: 4.14 (stretch) armv6
- blerrrrggghhh
- see the answer in this stack overflow post: pi zero armv6 or armv7?
So. Zeros are out. OR. I could try to build another image but using an ARM6-compatible base image. I guess it depends on how much time I have vs. how much money we want to save. If we’re talking about potentially ~80 devices, it might be worth while to get it to work on different architectures.
Because I’m a glutton for punishment, I’m pulling the armv6 version of node:
docker pull arm32v6/node:alpine
-
docker run -it arm32v6/node:alpine
dropped me into a REPL - HOWEVER, I forgot what a hellscape alpine linux is (no apt-get, no /bin/bash)
- run detached container:
docker -it -d arm32v6/node:alpine
docker exec -it [container ID] /bin/sh
- checked node and npm versions to make sure they’re installed
- again, forgot about how truly awful alpine linux is– so bare bones there is no git, then I have to google around to install it
- that’s
apk add git
for future reference
- that’s
git clone https://github.com/carylwyatt/gate-counter.git
cd gate-counter
npm install --save request moment node-schedule raspi-io johnny-five
- WHY DID I THINK THIS WOULD WORK; I ABANDONED ALPINE FOR A REASON!
- and that reason is that
pigpio
can’t be installed viaapk
and I couldn’t get the make file to build correctly - this right here is why I keep a log. I SHOULD READ IT, right?!
- cuz I just wasted like… 2 hours. Dumb.
- and that reason is that
Obviously I’m a big-time idiot, because I’m continuing on this pi zero quest instead of moving on. Switching to the hypriot/rpi-node
image.
docker pull hypriot/rpi-node
docker run -it -d hypriot/rpi-node
docker exec -it [cont ID] /bin/bash
git clone https://github.com/carylwyatt/gate-counter.git
-
apt-get install pigpio
- couldn’t find it… does this mean it’s not a debian/ubuntu distro?
cd gate-counter
npm install --save request moment node-schedule raspi-io johnny-five
- but of course the npm install fails for
raspi-io
because it can’t installpigpio
blerrrgghhhh
Time for my last resort! Going to clone my gate counter repo to the SD card and try to build a docker image that will run on the zero.
- just kidding! I forgot the reason I didn’t do that on this SD card is because I didn’t want to install node and all the rest of the stuff. I will be wiping the SD card back to the state it was when I started this morning. Not a complete waste of day because I learned some stuff, but it’s still greatly annoying.