Maneki-neko with WiFi (Part 1)

Sometimes i just want to build something stupid. And today i had a tought about something really stupid and pointless.

A Maneki-Neko with Wifi and Bluetooth.

Those adorable japanese cats, that constantly wave with their paw to welcome people and give them luck and happiness.

The Maneki neko

The idea i had is simply use a Pi Zero, connect a GPIO to the arm’s drive mechanism and hook it up to the net somehow.
To use the Pi that way i had to make sure the arm wouldn’t draw to much current, so i could hook it up directly to the GPIO.

But the cat is supposed to operate for weeks, even months on a single AA battery, so can’t be that much!

Catfood measurements

Confirmed: The cats draws 1.5mA max. That should work.

Getting the Pi Zero ready

The next steps are totally non-cat related and focus on getting the RPi to some kind of headless operation.

My goals are:

  • Headless boot
  • SSH over WiFi
  • Configure the WiFi via Bluetooth from an React Native app

I have an older Pi Zero without the on-board wifi, so i directly ordered the Pi Zero W that will go into the cat later on.
But for the next days a USB Wifi adapter and a USB BT dongle have to do.

I used the latest Raspian image and then (with keyboard and monitor hooked up) went through the basic setup:

  1. Set a hostname
  2. Setup the SSH server
  3. Manually setting up Wifi so i can work on the pi

After that i was ready to go to tackle the Bluetooth stuff

Make the Pi listen on Bluetooth

First i had to update the Bluetooth systemd file at /lib/systemd/system/bluetooth.service and add/change the ExecStart:

1
2
ExecStart=/usr/lib/bluetooth/bluetoothd -C
ExecStartPost=/usr/bin/sdptool add SP

Then i created a new service for rfcomm. Rfcomm will listen on a bt channel on the dongle and starts a terminal. So i kept it basic:

1
2
3
4
5
6
7
8
9
10
[Unit]
Description=RFCOMM service
After=bluetooth.service
Requires=bluetooth.service

[Service]
ExecStart=/usr/bin/rfcomm watch hci0 1 getty rfcomm0 115200 vt100 -a pi

[Install]
WantedBy=multi-user.target

and saved it as /etc/systemd/system/rfcomm.service. That should wait for connections on channel 1 and will open a shell on that channel. Just like a TTY terminal.

Connected from my phone to the Zeros Bluetooth TTY

The next step would be to write a small program that will get started instead of the bash so we can do the wifi configuration.

Customizing the bluetooth ‘protocol’

Now i want to replace the normal shell session with my own program.
So i put a very basic python program together that reposnds with MANEKINEKO and echos the input from the client:

1
2
3
4
5
6
#!/usr/bin/python
from sys import stdin

print "MANEKINEKO"
input = stdin.readline()
print "ECHO: ", input

I put that into /home/pi/wifi-setup.py and made it executable (chmod 755 /home/pi/wifi-setup.py). To have it run after a client connects via bluetooth i just changed the getty command in /etc/systemd/system/rfcomm.service and replaced the -a pi with -ni -l /home/pi/wifi-setup.py which directly runs the command as root. I know, i know, but eh! (at least for now :-P )

After an systemctl daemon-reload && service rfcomm restart i reconnected and my python script answered me!

HOORAY!!

Thats it for part 1. Part 2 will probably cover the development of a very small React Native app that will talk via Bluetooth with the Pi Zero to set it up.