<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../../xslt/site.xsl"?>
<blogpost id="post-20191006">
    <content>
        <h2>Introduction</h2>
        <p>
            While on the flight to Derbycon 2019 I wanted to have a way to broadcast the conference schedule to WiFi so I didn't have to pull the program out. I didn't finish the build in time, but it may still be useful for others.
        </p>
        <p>
            <a href="https://github.com/vgrsec/wifi-messages" target="_blank">https://github.com/vgrsec/wifi-messages</a>
        </p>
        <img src="../assets/posts/20191006/wifimessagestogether.png" alt="WiFi Messages Together"/>

        <h2>Overview</h2>
        <p>This project is designed to provide messages over wifi. It has two operating modes.</p>
        <ul>
            <li><strong>Default</strong>: A single file will be loaded and broadcast. This file is located in <code>/boot/wifi-messages/input/_default.txt</code></li>
            <li><strong>Date-based</strong>: <code>ssid-rotator.py</code> grabs current date and time and broadcasts any lines that are for this hour, and the next hour. It loads the schedule from <code>/boot/wifi-messages/input/%date%.txt</code></li>
        </ul>
        <p>To perform the rotation, this project contains a systemd timer, a shell script to broadcast ssid messages, and a ssid rotation python script.</p>
        <p>The input file is located in <code>/boot</code> so that one can remove the SD Card from the raspberry pi and load new messages without having to muck with the device.</p>

        <h2>Setup</h2>

        <h3>Required Equipment</h3>
        <ul>
            <li>Raspberry Pi</li>
            <li><a href="https://www.alfa.com.tw/service_1_detail/5.htm" target="_blank">Alfa AWUS036NH</a></li>
            <li>USB Battery</li>
            <li>MicroUSB Cable</li>
            <li>Network Cable</li>
            <li>Network Adapter that supports crossover detection</li>
            <li><a href="https://www.adafruit.com/product/3386" target="_blank">Adafruit PiRTC – PCF8523 Real Time Clock (RTC)</a></li>
            <li>CR1220 coin cell battery for RTC</li>
        </ul>

        <h3>Setup Raspberry Pi</h3>
        <ul>
            <li><a href="https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-up-and-test-i2c" target="_blank">Install the RTC</a></li>
            <li><a href="https://www.raspberrypi.org/downloads/raspbian/" target="_blank">Download Raspbian Lite</a></li>
            <li><a href="https://www.raspberrypi.org/documentation/installation/installing-images/README.md" target="_blank">Image SD Card</a></li>
            <li><a href="https://www.raspberrypi.org/documentation/remote-access/ssh/" target="_blank">Enable SSH</a></li>
            <blockquote>
                The first time you setup your wifi-messages pi make sure to be connected to the internet. Otherwise the RTC may not be programmed with the correct time and the clock rotation will fail.
            </blockquote>
            <li>Connect network cable from RPi to computer</li>
            <li>SSH: <code>ssh pi@raspberrypi.local</code> <br/> Password: <code>raspberry</code></li>
            <li>
                Clone the wifi-messages repo and run the setup script:<br/>
                <code>sudo -i<br/>
                cd /usr/local/bin/<br/>
                apt-get install git -y<br/>
                git clone https://github.com/vgrsec/wifi-messages.git<br/>
                cd /usr/local/bin/wifi-messages<br/>
                ./setup.sh
                </code>
            </li>
        </ul>

        <h3>Setup WiFi Messages</h3>
        <p>
            Modify <code>/boot/wifi-messages/input/_default.txt</code> for static messages.<br/><strong>OR</strong><br/>
            Create files for the days you wish to broadcast messages in <code>/boot/wifi-messages/input/YYYYMMDD.txt</code>
        </p>
        <p>
            The easiest way to modify the input files is to remove the sd card from the raspberry pi and put it into another device. This way you can use a text editor to edit the file without having to ssh into the pi.
        </p>

        <h3>Files</h3>
        <p><strong><a href="https://github.com/vgrsec/wifi-messages/blob/master/ssid-rotator.py" target="_blank">ssid-rotator.py</a></strong></p>
        <p>
            ssid-rotator is looking for times in half hour increments. I am not a developer, and so the logic is only looking for the top of the hour and the half hour. It is also not capable of rotating over at midnight.
        </p>

        <p><strong><a href="https://github.com/vgrsec/wifi-messages/blob/master/wifi-messages.sh" target="_blank">wifi-messages.sh</a></strong></p>
        <ol>
            <li>NTP time sync</li>
            <li>Set Timezone</li>
            <li>airmon-ng is used to put the wifi card into broadcast mode.</li>
            <li>mdk3 broadcasts the ssid's from <code>/usr/local/bin/wifi-messages/output/ssid.txt</code></li>
        </ol>

        <p><strong><a href="https://github.com/vgrsec/wifi-messages/blob/master/input/_test.txt" target="_blank">input/_test.txt</a></strong></p>
        <p>
            This file shows the format that <code>ssid-rotator.py</code> expects. The first four characters for the time is what the rotator looks at.
        </p>
        <p>
            To perform a function test of your wifi-rotator copy input/_test.txt to input/%YYYYMMDD%.txt and watch it go.
        </p>

        <h2>Resources</h2>
        <ul>
            <li><a href="https://timemachines.io/blog/2015/6/3/connect-directly-to-raspberry-pi-from-mac-over-ethernet" target="_blank">https://timemachines.io/blog/2015/6/3/connect-directly-to-raspberry-pi-from-mac-over-ethernet</a></li>
            <li><a href="https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi?view=all" target="_blank">https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi?view=all</a></li>
        </ul>
    </content>
</blogpost>