• Software Setup

    blinkingthing12/15/2020 at 19:14 0 comments

    The software setup is split into two parts.

    1. Software running on the Raspberry Pi
    2. Scripts running on a server in my home.

    Raspberry Pi

    Kismet

    For the Raspberry Pi, I'm using Kismet to detect wireless networks. Kismet does all the heavy lifting and combines the GPS data along with the Wireless Networks it detects and spits out a nice log file. The Kismet package includes scripts to convert the .kismet logs into other file formats that can be loaded into other tools or uploaded to Wigle.net for instance.

    There are plenty of guides out there for installing Kismet, I just followed the instructions, and got Kismet running as a service so it always run on startup.

    Safe Shutdown

    The relay circuitry is only half of what is required to safely shutdown the Pi, you also need some software running on the Pi to detect the GPIO pin changes and run a script to shutdown the Pi. Again, there is a lot of info and instruction out there on how to do this, I used a slightly modifed version of this script to detect the GPIO pin getting pulled low. I added some code that resets the network interface on the Pi so that it will attempt to connect to the network defined in my file and then run a bash script that will upload the Kismet logs to my server. 

    #restart networking                
    os.system('sudo /etc/init.d/networking restart')                 
    time.sleep(2)                 
    os.system('sudo wpa_supplicant -c /etc/wpa_supplicant.conf -i wlan0')                 
    #10 seconds for authentication                 
    time.sleep(10)                 
    #upload logs                 
    subprocess.call("/home/pi/bin/kismetupload.sh", shell=True)                 
    #shutdown                 
    os.system('sudo shutdown now')

     Kismet Upload

    The Kismet Upload bash script essentially checks that the network you are connected to is the one you want it to be, then it uses rsync to upload the logfiles to your server, removing the source files after they have been uploaded. This process is dependent on you setting up SSH access with SSH Keys between your Pi and your Server.

    Server Side

    The server also has Kismet installed on it so it can do the heavy-lifting of converting the kismet logs into different types for different uses. There are a few different built in scripts that Kismet comes with for conversion, but I'm mainly using the kismetdb_to_wigglecsv and kismetdb_to_kml script so I can upload logs to wigle.net. I have a cronjob that runs once a day to run my kismet log conversion script. In my case, this script also moves the converted logs to a separate computer although this is may be unnecessary if you try to replicate this setup yourself.

    #cronjob to convert and upload logs everyday at 1 AM
    0 1 * * * /home/user/bin/kismet_log_convert_and_backup.sh

     

    The end result is a daily tar.gz file that can be directly uploaded to Wigle.net without me having to do anything. Exactly what I wanted.

  • Hardware Setup

    blinkingthing12/15/2020 at 18:13 0 comments

    I knew I wanted to put a Raspberry Pi in my car, and I knew I would need a way to shut it down gracefully without having to think about it. Luckily, I'm not the first person to want this.

    I found some posts on car-computer forums on Reddit detailing a circuit using 12v relaays, 5v relays and a buck converter in combination with a vehicles 12v constant, ground, and 12v ignition power lines to trigger a safe shutdown of the Pi.

    This was the example circuit I based my hardware on. This continually supplies 5v to the Pi until the ignition switch is turned off, then the circuit remains powered by the constant 12v from the vehicle and a GPIO pin is pulled low and runs a shutdown script on the Pi.

    All the parts were readily available on Amazon.

    HitLetgo 5V Relays

    HitLetgo 12v Relays

    12/24v to 5V 10A Converter

    After receiving the parts, I set everything up on the workbench with a switched 12v source to emulate the ignition switch in the vehicle. This required some specific software that I will detail in another post.

    After confirming that shutting down the Pi safely worked, I mounted the hardware inside a plastic case used for holding photographs using standoffs. I cut a hole on the edge to pass through the power cables from the vehicle as well as the USB cables for the wireless antenna and GPS receiver.

    The GPS receiver I'm using is the GlobalSat BU-353-S4 USB GPS Receiver.

    The wireless adapter I'm using is an Alfa AC1200. This required a little futzing with to get to work with the Pi, this thread pointed me in the right direction for getting the drivers I needed to make the AC1200 work with the Pi.

    For now, the wireless antenna and GPS receiver aren't properly mounted, but I'm thinking about getting some suctions cups and sticking them on a window.

    The plastic box containing the Pi and the relays lives in the foam piece that holds the tools for changing my spare tire underneath the panel in the cargo area at the back of my vehicle. I was lucky to have a 12v power port in the cargo area of my car that is controlled by the ignition, so I bought an adapter that plugs into the power port and gives me a power and ground lead to wire into my relay circuit. I also had a constant 12v supply at the rear of the vehicle for a trailer hitch, this was trivial to tap into for the 12v supply.

    Everything installed in it's final resting place.
    This is the 'mess' you can see with the cargo panel baseboard re-installed.

    For now, the wireless adapter and GPS receiver are just resting atop the cover for the cargo area.