Remote People Tracker Connection Tutorial

In this tutorial, I will describe the process of setting up communication between two Raspberry Pi units using the python-socketio library. I will be following along with this Medium tutorial, which does a great job of explaining how to set up two IoT devices.

I began by flashing the raspberry pi 3B using the raspberry pi flasher. I used the 64-bit raspberry pi OS lite. I used this because the standard desktop version of the OS causes the raspberry pi to boot into a setup wizard, which is extremely difficult to complete without a mouse, keyboard, or monitor. Note that you can flash both units, the 3B and pi Zero, with the same OS, but the AIY vision bonnet requires Google's custom firmware to use, as I discovered after a few hours of struggling to get the camera working. After flashing the firmware, I created a wpa_supplicant.conf file with my wifi information. This file is used to configure the wifi settings on the Raspberry Pi units, and it needs to be copied to the microSD card that is used for each unit. Next, add an empty file titled “ssh” with no extension to the microSD card. This file is used to enable ssh on the Raspberry Pi units, which allows the units to be remotely accessed and controlled.

At this point, I ran into a problem: the default Raspberry Pi OS does not utilize the Google AIY vision bonnet by default, and will not be able to access the camera. Once I realized this, I reinstalled the Google AIY firmware and was able to detect the camera. Note that the wpa_supplicant.conf and ssh files must also be copied over after reflashing with the Google AIY firmware.

After reinstalling the firmware, I ran into another problem: PiCamera is unable to access my camera! I was worried the camera hardware itself was the problem, but I read the AIY documentation and realized a program using the camera auto-starts once the pi Zero is turned on. I disabled this program by using the following command:

sudo systemctl stop joy_detection_demo

Once I disabled that program, I was able to get the camera working and finally set up the last step in testing the IoT communication: running socketio test code. This code was provided by the tutorial I am currently following, and is pasted below for redundancy.

Client Side Code:

#clientCode.py

import socketio

import time

# create SocketIO object

sio = socketio.Client()

@sio.on('connect')

def on_connect():

print("Connected to server")

sio.start_background_task(background_task)

def background_task():

count = 0

while True:

count += 1

sio.emit('testAccept', {'counter': str(count)})

time.sleep(5)

sio.connect('<server IP address>:5000')

Server Side Code:

# serverCode.py

import eventlet

import socketio

# create a Socket.IO server

sio = socketio.Server()

# wrap with a WSGI application

app = socketio.WSGIApp(sio)


@sio.on('connect')

def on_connect(sid, environ):

print("Connected")

@sio.on('testAccept')

def test_accept_data(sid, data):

print(data)

if __name__ == '__main__':

eventlet.wsgi.server(eventlet.listen(("", 5000)), app)

This code is graciously provided by the Medium tutorial here.

Note that where it says sio.connect('<server IP address>:5000'), it is important to add the “http://” before the IP address, per the dnspython site. You can get the host IP by doing ping [hostname] -4 to return the ipv4 address since it returns ipv6 by default. Once the test code was written, I uploaded the code files to the corresponding units and tested them. However, I encountered a problem that was so scary, I almost gave up on the project entirely. My host computer was spitting out the following error:

Traceback (most recent call last): File "/home/pi/Desktop/serverCode.py", line 2, in <module> import eventlet File "/home/pi/.local/lib/python3.9/site-packages/eventlet/__init__.py", line 17, in <module> from eventlet import convenience File "/home/pi/.local/lib/python3.9/site-packages/eventlet/convenience.py", line 7, in <module> from eventlet.green import socket File "/home/pi/.local/lib/python3.9/site-packages/eventlet/green/socket.py", line 21, in <module> from eventlet.support import greendns File "/home/pi/.local/lib/python3.9/site-packages/eventlet/support/greendns.py", line 66, in <module> setattr(dns, pkg, import_patched('dns.' + pkg)) File "/home/pi/.local/lib/python3.9/site-packages/eventlet/support/greendns.py", line 61, in import_patched return patcher.import_patched(module_name, **modules) File "/home/pi/.local/lib/python3.9/site-packages/eventlet/patcher.py", line 132, in import_patched return inject( File "/home/pi/.local/lib/python3.9/site-packages/eventlet/patcher.py", line 109, in inject module = __import__(module_name, {}, {}, module_name.split('.')[:-1]) File "/home/pi/.local/lib/python3.9/site-packages/dns/zone.py", line 86, in <module> class Zone(dns.transaction.TransactionManager): File "/home/pi/.local/lib/python3.9/site-packages/dns/zone.py", line 757, in Zone ) -> dns.rdtypes.ANY.SOA.SOA:AttributeError: module 'dns.rdtypes' has no attribute 'ANY'

The error seemed like a standard issue, so I searched the error online but found no results. Sure, there were a few entries from stack overflow asking similar problems, but none applied to my situation. I was the first person ever to have this exact error. I poured over the dnspython documentation hoping I could find something to fix it, and I was slowly losing hope. Right as I was about to quit, I found this gem of info on the main page:

Python 2.x support ended with the release of 1.16.0. Dnspython 2.0.0 through 2.2.x support Python 3.6 and later. As of dnspython 2.3.0, the minimum supported Python version will be 3.7. We plan to align future support with the lifetime of the Python 3 versions.

This gave me an idea: pip install dnspython==1.16.0. The error vanished.

Unfortunately, I ran into another problem, this time on the client side: socketio was not found when I attempted to import. Thankfully this was an easy fix, I simply needed to do

pip install python-socketio==4.6.0

pip install python-engineio==3.11.2

In that order! Do these commands on both units to avoid socketio compatability issues. Note you must do a pip3 install on the pi Zero if you are using Google AIY firmware - their models only run on python3 and we will call socketio while running a model.

Now run the client and server test programs. We now have two IoT devices that can send short bits of data to each other!

This text has been enhanced with AI (ChatGPT) to make my notes more legible and digestible for the average reader.

Galen Holland 2022