Introduction: Raspberry Pi HomeLab and Who Is Home

About: we are the valencia embedded systems team from the east campus! check out our website and projects please :) we are located in orlando florida

This is my first indestructible, But this instructable has two fazes.

faze one: is setting up a pi to work as a home-lab for IOT work for a team of student developers.

faze two: is using the system for development, by implementing a demonstration using our who is home project.

by the end of this you will have a remotely accessible headless pi that can be used by people to remotely program and work on IOT devices.

now i do warn, that by opening your pi to the public without due security you do open yourself up to the risk of having your home network attacked.

we will go over the first faze in the following steps, but this is a link to some information on our club and the who is home project.

https://github.com/ValenciaRobotics/embeddedclub

WhoIsHome

the Who Is home project does the following: runs a python script that checks for the mac addresses of devices connected to your network. it uses Nmap for this. it runs those addresses against a list of addresses and if the address listed is present it sends a char to an arduino by using serial communications. the arduino controls a LED strip and when it receives a char it has an associated color for that device and it lights the LEDs for that person based on them being present.

our divisions subsite

https://sites.google.com/view/valencia-robotics

https://sites.google.com/view/valencia-robotics/cl...

our clubs site

https://sites.google.com/view/valenciatechclub

the Python Script was provided by : Jonathan De La Cruz

https://www.linkedin.com/in/jonathandelacruz96/

the Arduino Script and walk through and setup of the home lab was done by : Dylan Poll

https://www.linkedin.com/in/dylan-poll-4a324a1a2/

I am Dylan Poll, I am the current president of the tech club of our college and I am also the embedded systems lead.

Supplies

A pi

A arduino

A breadboard

jumper wires

A webcam

individually addressable RGB LED Strip

power supply for your pi, a keyboard a mouse, computer to do the initial setup.

Step 1: Downloading and Installing Initial Setup Files

download and install putty(windows)

https://www.putty.org

download rufus and install

https://rufus.ie

download raspbian full buster and recommended software (.zip)

https://www.raspberrypi.org/downloads/raspbian/

extract the contents in the .zip this will be your [image file].

take a micro sd card, and use a dock or a microsd to usb device and plug it into your computer format your sd card

Step 2: ​part Two: Install Raspbian Using Rufus

run rufus select your sd card in the first field select the raspbian image file for the .iso/.img select start and wait for it to finish.

Step 3: ​part Three: Plugging in the Pi

after thats done pull out the sd card, put it into the sd card slot on the pi, its on the "bottom" plug in the HDMI cord to the pi first, than a keyboard and mouse, and last power cable. if you plug in power first it might not register your monitor/tv.

Step 4: ​part Four: Setting Up Your Account

log into pi !do the first run setup! do not skip it! select U.S.A English keyboard or you will not find your @ symbol later... if you don't your @ symbol is where your " is. log into your wifi on pi do not update yet. I have a reason. hit the "windows keyboard key" and go to preferences, go to pi configuration. go to the interfaces tab.

enable VNC.... and everything else don't reboot.

Step 5: ​part Five: Setting Up Your Pi As Headless(the Best Thing Ever)

look at the top right of your screen. you will see the black and blue VNC logo. open that. hit sign in, make and account. add the pi. on your desktop/laptop open browser search on google VNC viewer download install. log into your account. check your email for the log in and authorize yourself. connect to your pi (type in the pi password at the second login menu) if it works turn off your pi. unplug your pi and everything. put the pi in a corner in your room and run only the power cable to it. you can connect to the pi using VNC viewer. you now have a "headless" pi. you can also SSH to it.(see SSH info in the cool stuff section)

Step 6: ​part Six: Installing All the Core Tools for Developing on a Pi

using SSH or VNC(or if you decided to not be cool and set it up headless) do the following. open terminal (this next part may take a while....) run these commands one at a time after each one is FINISHED.

sudo apt-get update; sudo apt-get upgrade installing ffmpeg{ sudo apt-get install ffmpeg

Step 7: ​part Seven: Installing the Adafruit WebIDE

curl https://raw.githubusercontent.com/adafruit/Adafruit-WebIDE/master/scripts/install.sh | sudo sh open a browser on your main desktop. point your browser URL to "http://***.*.*.***:8080" replace the "*" with your Pi's local IP address. make a username and pass. you now have the adafruit webIDE setup.

Step 8: ​part Eight: Update Node-red and Node.js

update-nodejs-and-nodered the next code will make nodered run on startup just like the adafruit webIDE, this is important if you want to develop on these things. sudo systemctl enable nodered.service restart the Pi

Step 9: ​part Nine: Installing Arduino IDE

you can do it via command line but.... it wont be the full version.. meaning you can't use the library import/search tool, to install the full version you need to go to the arduino website and download the version for your pi model. it will be the ARM32bit for the pi3, get the stable release. open terminal.(replace the *'s with the release info) run these commands.

https://www.arduino.cc/en/Main/Software

cd Downloads/
tar -xf arduino-1.*.*-linuxarm.tar.xz sudo mv arduino-1.*.* /opt sudo /opt/arduino-1.*.*/install.sh

Step 10: ​Part Ten: Ffmpeg

1x webcam logitech

(the next items don't include what you need to run a 24/7 stream) 1x breadboard a second raspberry pi model 3 b(with sd card) individually addressable LED strip. arduino nano jumper wire enable VNC viewer on both Pi(s)

pi preferences, enable vnc make a account with VNC viewer IMPORTANT: on the pi you plan to use as a public work bench, go to vnc server settings, options, expert tab, and make idle timeout : 0 seconds, it's set to close Vnc viewer if idle after an hour, doing this will stop your window from closing mid stream install vnc viewer on streamer pi in terminal.

sudo apt-get install vnc-java y

plug in your webcam and..install your webcam.

sudo apt install fswebcam

install ffmpeg sudo apt-get install ffmpeg y

this is where your own choices come into play. in terminal, run this script to open a window on your streamer pi's desktop for your webcam.

ffplay -window_title "pi-cam" /dev/video0 -video_size 1920x1080 -vf crop=400:500:300:50 -framerate 20 ffplay will allow you to see this in a window named pi-cam, the webcam its showing you is at location dev/video0 and its original size is 1920x1080. I only want to see the crop=width:height:topleft_X:topleft_Y and a framerate of 20 is enough for me. the next code will stream to twitch.

ffmpeg -f x11grab -video_size 1280x1024 -framerate 24 -i $DISPLAY -f alsa -vf scale=1280x720 -c:v h264 -g 24 -b:v 2M -preset ultrafast -c:a aac -pix_fmt yuv420p -f flv "rtmp://live-lax.twitch.tv/app/(insertyourstreamkeyhere)"

-f x11grab is used to grab your screen. my screen resolution is set to 1280x1024 I want to display that in 1280x720 so -vf video format.

2m= 2mgb upload rate. -f flv is to format the video into .flv so twitch can use it.

now you can give your team your VNC credentials to the workbench Pi and they can see the changes to the led strip live remotely. Shout-out to this guy~! his video helped me get on track, I still had to figure out how to pop in my webcam though... and find out about ffmpeg X/

Arthur Reeder https://www.youtube.com/watch?v=kb_5_9GkwZc NOTE: I am not the most informed person, this simply works for my needs, if anyone has constructive advice i would love to hear it but please don't be mean one of the possible routes to take this further, would be to use this mechanic to stream this, and use another pi and the chrome extension lightstream to fetch that stream and than feed the webcam into that or in any other way. https://www.youtube.com/watch?v=kb_5_9GkwZc ALSO: if you want to add in audio, as seen in the mans youtube video, you can use this string, I did not want to have my house being recorded and sent to twitch, this is sitting in my room so I do not stream any audio, it also helps lessen the load on the pi.

ffmpeg -f x11grab -video_size 1280x1024 -framerate 24 -i $DISPLAY -f alsa -i default -af acompressor=threshold=0.089:ratio=9:attack=200:release=1000 -vf scale=1280x720 -c:v h264 -g 24 -b:v 2M -preset ultrafast -c:a aac -pix_fmt yuv420p -f flv "rtmp://live-lax.twitch.tv/app/(insertyourstreamkeyhere)"

Step 11:

now to the final stretch, implementing arduino and pi serial communication with python.

---the who is home project--- The project uses a python script that runs nmap in terminal, copy the contents of that, parses out the text we don't need, and compares the mac addresses on the network against the listed mac addresses and if there is a match that person is home. the mac addresses were found by doing investigative work on the router, but the nmap tool gives you information about the devices in the text file generated by the code. if the user is present, it sends a character to the arduino, and the arduino waits until the check list is done, and lights up LEDs corresponding to the profiles listed for the mac addresses of present devices. you can add other things, like having discord bots run commands upon people coming or going with this same code by using the sub-process operator to execute terminal commands within your python script. so first we install nmap sudo apt-get install nmap. next you will want to download the files on our clubs Git-Hub.

https://github.com/ValenciaRobotics/embeddedclub

for the python code, the raspbian installation comes with everything used in this code, so you do not need anything additional installed. we used import re,import subprocess,import time,import serial it is important to note that python uses indentation for separating out code blocks, so be aware of that if you decide to change the way the code is written :) the py comes with thonny ide and a few other options, i find that running the script in thonny is really straight forward, if you click on the file and attempt to execute it, it was suggest or assume thonny is what you wanted to use. before you run the program, you will need to edit out the following. line 14: the * symbols are used to mask my own router information, you will have to replace that with your own local ip. it would be the same as what you use to connect to your router. lines 28,38,48,58: these all use the * symbol to mask device mac addresses listed from my network, you have to change those to the mac addresses of the devices on your own network to detect connections. why mac addresses? because without reserving locations for your device, they are sure to stay the same unless someone is spoofing. problems with this code, it will only detect while a connection is actively using internet, so it may not detected despite a user being present. in the arduino code, you will want to change the following. first, you will want to go to the tools tab, select libraries manager, and search for "fastLED" and install the library for "fastLED". next you will need to load the "who is home" .ino code from the github page and change the following as you desire. line 86: change the colors based on what you want your users to have attached :)

//turn on what you need

if(d == 1){ leds[0] = 0xdd8bff; //purple leds[1] = 0xdd8bff;}

if(l == 1){ leds[2] = CRGB::Green; leds[3] = CRGB::Green;}

if(k == 1){ leds[4] = CRGB::Red; leds[5] = CRGB::Red; }

if(j == 1){ leds[6] = CRGB::Blue; leds[7] = CRGB::Blue;}

FastLED.show(); delay(30000); //10 second wait on the switch case a brief explanation for how to add more users is the following

void loop(){

if (Serial.available() > 0) {

Serial.println();

person = Serial.read();

delay(1000);

switch(person){

case'D': d = 1;

person = 'F';

count=count+1;

break;

case'd':

d = 0;

person = 'F';

count=count+1;

break;

the uppercase D is the received character from the python script, so it knows that the user is present because the received letter is the uppercase D, so it changes the value of the INTEGER d to 1, if it is a lowercase than it knows they are absent so the INTEGER is set to 0. the condition for leds lighting in the script from before uses a statement that IF d is 1 than it will light the led, but if it is not that led stays as "black" meaning unlit. this code uses the library "fastLED" and there is a lot of documentation on this. note that if you change the characters, add characters or remove characters you will have to change the python script to return the ones you changed them too, you will also have to change the condition in the void loop. if(count == 4){holdup();} } the count will have to reflect the number of devices you are "tracking". in my case it is 4, so it waits until 4 devices have been declared as present or absent and then it updates the LED strip. in the python code, the lines 31,34,41,44,51,54,61,64 have the following line ser.write(b'*') #sends character cast as byte over serial where * is a character it is sending to the arduino. change this if you change the code in the arduino or vice versa :)

Again, as a closing statement, I want to give credit to my team mate Jon, he did a great job at picking up the slack when we needed it.

he Python Script was provided by : Jonathan De La Cruz
https://www.linkedin.com/in/jonathandelacruz96/

the Arduino Script and walk through and setup of the home lab was done by : Dylan Poll

https://www.linkedin.com/in/dylan-poll-4a324a1a2/

Hopefully we win at least a t-shirt! I will be updating this with shell commands to auto download and install most of this, our clubs website actually has downloadable shell scripts to do the ffmpeg operations.

This project took a lot of time, I founded this division of the club from the ground up so I can proudly say this moment brings me a lot of joy. :) thank you for your time, we have a working platform to develop now in my club because of this project.

Raspberry Pi Contest 2020

Participated in the
Raspberry Pi Contest 2020