Sunday, August 20, 2017

The Magic Of VPD

Email: hightekgrow@gmail.com
Github: github.com/smoriarty21
Website: hightekco.com
Reddit: reddit.com/r/hightek/
Support HighTek: patreon.com/hightek
Donations: paypal.me/atarimaster


[ Intro ]

    What do you think of when you hear the word humidity?  For many many years, horticulturists of all types kept close track of the relative humidity in there grow environment.  The dictionary defines relative humidity as the amount of water vapor present in air expressed as a percentage of the amount needed for saturation at the same temperature.  This means of expressing the amount of moisture in the air was great until our current day champion VPD came around.

[ What Is VPD ]

    VPD stands for vapor pressure deficit.  Vapor pressure deficit is the difference the moisture currently in the air and the total amount of moisture the air can possibly hold.  In other words, we take the difference between the current moisture level and the amount of moisture the air can potentially hold before it becomes fully saturated.  It is very important that we keep an eye on VPD.  If our air becomes over saturated it will release water molecules creating a film on our plants.  This will encourage rot in our greenhouse and that is a problem we don't want to deal with.  Below is an image of the VPD chart. The chart has green, yellow, and red sections.  The green section is the ideal range for your plant at the given temperature.  In the yellow, it is not ideal but should not cause any harm to your plants.  In the red range, you may see problems.


[ Calculating VPD ]

    Calculating VPD can seem like quite the daunting task but in all reality, it is not very difficult.  Big props to alchimiaweb for their article on calculating VPD.  I will be referencing a lot of information from them as it is the best article I found when learning about VPD.  In order to calculate our VPD we need three things.  We need our room temperature and relative humidity.  With these two things, we can calculate our SVP or saturated vapor pressure.  The saturated vapor pressure is the max amount of moisture the air can hold.  We can find our SVP using our temperature(in Celsius) and the chart below to the find SVP for our room at the current temp.


    Once we have our SVP it is very easy to calculate our VPD.  We can do this using the following formula.


VPD = ((100 - CRH) / 100) * SVP

   As you can see in the formula above all we need to do to find our VPD is first minus the current relative humidity from 100.  Next, we divide the result of that by 100 and multiply the result by the SVP we found using the chart above.  Now we know our VPD and we can start adjusting out room accordingly.

[ Controlling Your VPD ]

    If you would like to take a look at an open source system that can manage VPD and temperature in your greenhouse check out my open source grow room automation system here.  If you need any help or have any questions please comment or reach out using the information a the top of the page.  As always thanks for reading an happy growing! 

Sunday, August 13, 2017

Open Source Time Lapse Manager

[ Intro ]

This weekend I decided I wanted to get some time lapses of my peppers and basil plants I have in both my indoor and outdoor gardens.  Not only will it be fun to watch the difference between the two environments but it can also be very useful having on demand time lapses of anything we want.  I wrote this system to run on a Raspberry Pi model 3 but, you can run it on almost anything.

[ What You Need ]

  • Windows/Mac/Linux machine to run the software.  I will be using a Raspberry Pi Model 3
  • USB Webcam
  • Micro SD Card(Only needed for Raspberry Pi)
  • Git Installed
  • Pyton 2.7

[ Instructions ]

Plug in your webcam preferably using a USB hub with dedicated power.  The client and server are written in Python and node js so they should run on any of the major operating systems.  In this guide, I will be using a Pi model 3 running the latest version of Raspbian Jessie.  The very first step is to get all of the source code we need from GitHub.  This can be accomplished by cloning the repositories for both the client and server.  This can be done using the following two commands below:

    cd ~/

    git clone https://github.com/HighTekGrow/growlapse-client.git

    git clone https://github.com/HighTekGrow/growlapse-server.git

[ Server Setup ]

Now that we have both the server and client side code we need to get everything setup and running.  First, enter the server directory using the command below.

    cd ~/growlapse-server

In the root of the server repo and run the commands below to install opencv on both your system and in the python enviroment.

    sudo apt-get update
    sudo apt-get install python-dev python-opencv

Once we have completed that we can install the python dependencies using the command below.

    pip install -r requirments.txt

    pip install -U numpy

We should now be able to run our server by issuing the following command.

    python growlapse.py

Our server is now ready to go.  All we need now is the client in order to give us a nice UI to manage our time lapses.  If you would like to know that the server is running for sure you can use curl to test it.  Running the following command should issue you back a blank response with a 200 status code.

     curl 127.0.0.1:5002/timelapse

[ Client Setup ]

Before we get the client up and running we need to upgrade nodejs.  The easiest way to do this is to first run the following commands to remove any old version of node that may be on the system.

    sudo apt-get remove nodejs

    rm -f /usr/bin/node /usr/bin/npm

Now we will grab the latest version of node and unpack it to our home directory from the node download servers.

    cd

    wget https://nodejs.org/dist/v6.11.2/node-v6.11.2-linux-armv7l.tar.xz

    tar xvf node-v6.11.2-linux-armv7l.tar.xz

    cd node-v6.11.2-linux-armv7l

Once we have the latest version of node for ARMv7 we need to link our new npm and node binaries to our path making it easier to run node.  To do this we use the following commands.

    sudo ln -s bin/node /usr/bin

    sudo ln -s bin/npm /usr/bin

Now that we have the latest version of node its time to install our dependencies for the client using the command below.

    cd ~/growlapse-client

    npm install

Once this finishes we can run the client in dev mode by using the following command.

    node_modules/.bin/ember serve

This will give you the output shown below after getting everything setup and ready.  I have also attached images of the main dashboard and the create new time lapse screen.  Hope you enjoyed this entry and as always don't forget to comment and check back regularly for more content!










Sunday, August 6, 2017

HOBloom - Building Smart Outlets

Email: hightekgrow@gmail.com
Github: github.com/smoriarty21
Website: hightekco.com
Reddit: reddit.com/r/hightek/
Support HighTek: patreon.com/hightek
Donations: paypal.me/atarimaster

[ Intro ]

    In this lesson, we will be going over creating smart outlets for your HOBloom automation system. This same wiring will work for any other software but we specifically will be building it to work with HOBloom.  Once we build the outlet and wire up out relay we can use each port on the outlet to control our appliances in our grow room.  Below you will find a list of the materials needed to build the outlet.

[ Materials ]
[ Prepare The Outlet ]

    The first thing we need to do is break the little metal tab on your outlet.  This will allow you to control both outlets individually.  We only need to break the tab on the hot side of the outlet.  We can leave the tab on the neutral side of the outlet as the power is the only thing we need to control separately, they can still ground to the same negative without any issue.  Below are images of the tab before and after removal.





[ Connecting Earth Line ]

    The earth wire is the green(it may also be green and yellow striped) wire coming off your power cable.  If you just have a normal extension cable cut it and strip each wire coming off of the male end of the extension cord.  The green wire gets connected to the green screw on the outlet.  There will only be one and it will be off on its own.

[ Connecting Neutral ]

    Next, we will be connecting our neutral lines from the outlet to the power cable.  Connect the white wire from your power cord either of the two screws on the neutral side of the outlet matching the image below.




[ Connecting The Positive ]

    To connect out positive line we first need two pieces of wire about two inches long.  One end of each wire will be going inside the small holes on the back of the outlet on the positive side.  On the back of your outlet, you should see a small recess with the word "strip gage" or something along those lines.  This is a guide to show you how much you need to strip off your wire to properly seat it in the holes we will be using to set the wire in the positive outlet connectors.  Check out the image below for an idea of what you are looking for and how to use them.






    Now that we have that end connected we will be stripping a very small amount off the other end of the wire and securing it in the first socket in each relay(first from the left) as shown in the image below.



    Once this is all connected, we need to connect the outlets right next to the one we just used on each relay(the middle outlet on each relay).  We are going to connect a wire with a very small bit stripped off the end to each of these sockets.  Just like before it is important to just strip enough to allow the relay to grab the wire.  You should not have any visible wire coming out of the end without shielding on it to avoid the wires touching.  Saftey first is our goal.  Once we have these connected we need to strip a bit off the other end and connect them together as well as the black wire from our power cord using a wire nut.  The images below will show you what this should look like through the process.







[ Connecting Relay To Base ]

    Now that we have our outlet all wired up it is time to move on and connect our relays to our base unit.  On the back of the relay, you will see four pins sticking out.  From top to bottom in the image below the pins are 5V power(VCC), relay 2 control, relay 1 control and ground(GND).


  Use the diagram here for reference on where to connect these pins. Power down your BeaglBone before connecting your smart outlet.  I also highly suggest labeling the two outlets with the pin they are connected to.  This will be shown in the images below and will help immensely when you are setting up appliances in your client.   The VCC pin on the relay gets connected to any of the VDD_5V pins on the BeagleBone.  This would be either pin P9_5 or P9_6.  The next two pins are the control pins for the relay.  These can be plugged into any of the GPIO pins on the BeagleBone.  Finally, the GND pin gets connected to any of the pins labeled DGND on the BeagleBone.



[ Testing Your Outlets ]

    I have created a small python utility for testing the outlets after you have connected them.  To use this tool all you need to do is boot back up your BeagleBone after connecting all the wires for your smart outlets.  Once you are back in, navigate to your /home/debian/repo directory or wherever your home directory is.  For this next section, n you will need to know the GPIO pins you connected your smart outlet relay to in the step above.  First, clone the repo and then enter the repositories root directory using the command below.

    git clone https://github.com/HighTekGrow/hobloom-outlet-tester.git

    cd hobloom-outlet-tester

    Once you have all the code in place and you are in the root directory for the repo you can start the script using the following command.

    sudo python outlet-tester.py

    This will open the testing utility that will ask you to enter your pins you have connected your smart outlets too.  Enter a pin and type Y when prompted if you have more pins to enter, if not type in N.  Once you have completed entering the pins the script will turn them all off and then one by one power the outlets on.  The way I use this tool is plugging a small light or fan or something like that into each outlet.  I then run the script and watch the output, it will tell you what pin it is turning on.  When it outputs a pin look at what appliance it turned on and label that outlet for future use.  When you setup your appliances in your grow room you will be asked what pin the appliances are connected to.  When you are asked this it is referring to the pin the smart outlet you have the appliance connected to is using.

[ Wrap Up ]
    
    As always thank you for reading and don't forget to leave a comment below if you have any questions or suggestions.  If you would like to support open source horticulture software like this please check out the paypal and patreon links at the top of the article!

Saturday, August 5, 2017

HOBloom - How To Automate Your Grow Room For Next To Nothing

Email: hightekgrow@gmail.com
Github: github.com/smoriarty21
Website: hightekco.com
Reddit: reddit.com/r/hightek/
Support HighTek: patreon.com/hightek
Donations: paypal.me/atarimaster

Intro

Today we are going to be looking at HOBloom the newest open source product created by HighTek.  This software allows you to use a BeagleBone Black to control your lights, heaters, ACs, humidifiers, dehumidifiers and intake/exhaust fans.  It also logs data automatically and gives you a nice web interface to monitor and configure everything with.  In this article, I will go over how to build, setup and configure everything to get this system up and running in your grow room.  We will be setting up and installing the base unit, installing sensors, building smart outlets and learning how to put it all together.  I will go over getting your BeagleBone Black up and running on Linux, OSX and Windows.

What You Need




Preparing Your BeagleBone Black

This step varies a bit depending on what operating system you are running.  Below I have added links to the individual posts on setup for each system. Credit for the Linux article goes to Otto Linnemann for his great instructional!  The same goes to Derek Molloy for his awesome instructional covering Windows and Linux.

Once you have flashed your device, if you are using Linux or Windows you can find the instructions for SSHing into your BeagleBone below.
Now that you have SSH access to your BeagleBone we will start to prepare our system.  The very first thing I would recommend is changing the password for your debian and root users.  First, change the password for the current user by running the command "passwd". This will prompt you to enter the current password for the user(temppwd) and then will ask you to set a new password.  Once you have changed the password for this user I would also change the root users password.  You can do this by running the command "sudo -u root /bin/bash", entering your password that you just changed for your debian user and then running the "passwd" command again to change the password for root.  Once you are done setting the root users password type the command "exit" to go back to your debian users terminal session.

Once we have changed our password is setup we need to flash our operating system to the eMMC on the BeagleBone.  To do this you need to run the command "sudo nano /boot/uEnv.txt".  Once you have the uEnv file open you need to uncomment the line shown below.

##enable BBB: eMMC Flasher:
#cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh


Uncomment the last line from above, save and exit your text editor.  Now type the command "sudo shutdown now" to shut down your BeagleBone.  Hold down the boot button on the BeagleBone and press the power button.  This will make the lights flash for about 30 minutes and then all four lights will go out.  Once the lights are out you may remove the SD card and restart your BeagleBone Black.  For images and more detailed instructions on the boot and power button sequence check out this article.

Now that we are no longer running our operating system off of our SD card we can format it and use it to store our code and database.  This will also give us enough storage to run the client directly on the device.  Put the SD card back in your Windows/Linux/OSX machine and format it using FAT.  Shutdown your BeagleBone and insert the SD card then start it back up.  Once you are back into the BeagleBone via SSH we can format the SD card, mount it and set it to mount automatically on reboot.

Once your system comes back up with the SD card inserted, run the command "sudo fdisk -l".  This should give you an output something like the image below.


In the image above my SD card is "/dev/mmcblk0".  From here on out I will refer to it as /dev/device, whenever you see this insert your device id from the output on your machine.  It may not and likely will not be the same name as mine.

In order to format our drive we need to first run the command "sudo fdisk /dev/device".  This will open fdisk a linux command line tool for managing drives.  Once in the fdisk console you can type "m" to print out the help menu and show you the list of commands as seen in the image below.


Our first step is to remove any old partitions on the drive.  To list the partitions(if any) we type the command "p" to print the current partition table.  This will show you something like the image below.  Yours may only have one partition or it may have more it just depends on how your drive was previously partitioned.


If you have any partitions on the list when you run the "p" command you can run the "d" command to delete partitions.  We are just clearing all of them so you can just keep entering the "d" command and pressing enter to let it delete the default partition.  The default is always the last partition on the drive.  Once you see that it is deleting partition number one you can stop(after deleting partition one).  If you are confused just keep running the "d" command until you get an error about there being no partitions.

Now we are going to create one partition that takes up our entire drive.  To do this run the "n" command.  You may press enter through the questions and allow it to use the defaults.  Once we have the partition created we just need to write the partition table and exit using the "w" command.

Here we will find ourselves back at the Linux terminal and out of fdisk.  We now can run the command "sudo mkfs.ext4 /dev/devicep1" to create an ext4 filesystem on your new partition.  Note here you need to add the partition number to the command, this means you have to append "p1" to the end of your root device path you have been using previously.  This can be seen in the example command above.  Next, we need to make a folder to mount our partition and hold our code.  For this we run the command "mkdir /home/debian/repo". The only step we have left is to set the partition we just created to mount every time we boot our BeagleBone.  To do this we need to edit the fstab file using the following command: "sudo nano /etc/fstab".  Once you have the fstab file open in your text editor add the following line to the end of the file: "/dev/devicep1 /home/debian/repo auto rw 0 0".  Reboot your BeagleBone using the command "sudo reboot now".

Once your BeagleBone comes back up and you can SSH back in you should see your partition in the mounted partition table by typing the command "mount | grep /dev/device".   We are now ready to start installing all our dependencies and grabbing our source code.

To setup wifi using a USB wifi adapter follow the guide here on the HighTek wiki page.  You may also hardwire your system but, I don't suggest the wireless option.

HOBloom uses sqlite to keep track of sensors, appliances and to log data.  This database is never shared and is always kept internal to your device.  For this to work we need to install sqlite on our BeagleBone.  The Beaglebone must have an internet connection from this portion of the install forward.  Run the command "sudo apt-get update; sudo apt-get install sqlite3 git".  This will update apt and then install the sqlite3 package as well as the git package that we will need to grab our code on your system.

In order to run the client we need to upgrade the nodejs install on our BeagleBone.  To do this you need to download the latest ARMv7 binary from here.  Running the commands below will bring us into our repo directory and download the nodejs ARMv7 binary onto our SD card.

    cd ~/repo

    wget https://nodejs.org/download/release/v7.8.0/node-v7.8.0-linux-armv7l.tar.xz

    tar xvf node-v7.8.0-linux-armv7l.tar.xz

    sudo apt-get remove node

    sudo rm -rf /usr/bin/node /usr/bin/npm

    sudo ln -s /home/debian/node-v7.8.0-linux-armv7l/bin/node /usr/bin/node

    sudo ln -s /home/debian/node-v7.8.0-linux-armv7l/bin/npm /usr/bin/npm

These commands will download the correct version of node for our system, remove the old version of node and npm and link our new binary to the main path making it easier to use.

Our system is now ready to clone the HOBloom repo and start getting the server up and running.  In order to get the code we need to first enter our SD card by running the command "cd /home/debian/repo".  We can now grab our code by running the command "git clone https://github.com/smoriarty21/hobloom.git".  We should now be able to run "cd hobloom" and see our code base by using the "ls" command.  This should output the files below.


Now that we have our code our very next step is running the setup script to get our config file and database setup for us automatically.  In order to do this, we need to run the command "sudo python setup_db.py" and allow the script to run.  When it asks you about your temperature sensor give it any name you would like.  For the type enter either "dht11" or "dht22" depending on what model you have purchased.  When asked for the pin enter "P8_7", once we are done setting up the software we will shut our unit down and install the sensor in the pin we just specified.  The script should complete and now you should have your database and config files all setup to get the system running.  The last thing we need to do for the server is installing the node dependencies.  We can do this by running the command "npm install". This may take a bit to finish but should complete error free.

Before we can hook up our temperature and humidity sensor we need to shut our BeagleBone down using the command "sudo shutdown now".

In the images below I will be hooking up the dht22 but the setup for the dht11 is exactly the same.  In the images below I connected three jumper wires to my dht22 and zip tied it to my case.  This is the same case in the kit linked above and you could set it up the same if you would like.  You can see the wires hooked up in the image below.




Those three pins in the image from left to right are ground(GND), 5V power(VCC) and data(DAT). For the rest of the setup, you will need to refer to the BeagleBone pinout diagram.  This diagram should be fairly easy to read.  The pins on the left side are all "P9_" the number in the yellow or white box.  The same goes for the right side except the prefix has changed to "P8_".  The ground cable can be connected to any of the pins labeled DGND.  This means we can use either P9_1, P9_2, P9_43, P9_44, P9_45, P9_46, P8_1 or P8_2.  In the image above I have it plugged into P9_2.  The next pin is power and can be plugged into any pin labeled VDD_5V(P9_5 and P9_6).  The data pin will go into P8_7 as that is what we entered above in the setup script. Below are more images of my sensor connected to my base unit.






Now that we have our temperature and humidity sensor installed we are ready to get our unit up and running.  Power back on the BeagleBone Black and enter the directory with your code(cd /home/debian/repo/hoblom).  Run the command below to start the server.

    sudo node hobloom.js

Now that our server is running we want to get the client up and running so that we can ensure the system is working as it should be.  For this, we need to spin up a new ssh session into our BeagleBone just like we have in the past.  enter the client directory inside the main repo using the command below.

    cd /home/debian/repo/hobloom/client

Once inside this client directory run the command below to install the dependencies for the client.

    npm insall

Before we are ready to start the client there is one last thing we must do.  For this step, you will need to know the IP address of your BeagleBone.  It is the address you have been using to SSH into the device.  We will need to update our clients GlobalConfig file to point to the IP address of your specific BeagleBone.  Use the command below to open up the GlobalConfig.

    nano app/classes/GlobalConfig.ts

When you run this command you will be shown the file in the picture below.


Here we need to navigate to the line "export const IP: string = '192.168.0.21';" and change the IP from 192.168.0.21 to whatever IP you are using for your device.  Once you have changed this IP address to your BeagleBones IP address we are ready to start the client.  In order to do this, we need to run the command below.

    npm start

This command will run and first you will see the message shown below.


The important part in the image above is the sections labeled "Access URLs".  You can see mine says the external URL is 'http://192.168.0.21:3001'.  This is the address you need to type into your browser in order to see the client.  You can now point your browser at that URL and view your client.  You should see a dashboard like the image shown below.


As always thank you for reading and check back often for more.  Next, I will be going over creating smart outlets to control your appliances and setting up the fire detection sensor.

Setup Your Smart Outlets

If you would like to setup smart outlets that allow you to control your lights and appliances check out my article here.

Support More Work Like This

If you would like to help support open source horticulture software the easiest ways are through PayPal or Patreon.  Thank you for reading and as always comment below if you have any questions or feedback!

Block Ads Spotify Desktop

Email: hightekgrow@gmail.com
Website: hightekco.com
Reddit: reddit.com/r/hightek/
Support HighTek: patreon.com/hightek
Donations: paypal.me/atarimaster


[ Intro ]

Today I will be teaching you how to easily block the servers hosting Spotify ads on your machine. This will allow you to listen all day long on a free account without hearing a single ad.  This trick is very simple, legal and works great.  Spotify may catch on and find some way to stop this from working but, as of today (08/05/2017) it works swimmingly.

[ Blocking Ad Server ]

In order to remove those pesky ads, all we need to do is setup out hosts file to override the DNS for Spotify's ad servers and redirect that traffic to our local machine.  When the traffic hits out local machine the call will fail and the ad will be skipped.  Follow the steps below to add the entries needed.


  • Open your hosts file using your favorite text editor.  If you are using windows this life is located at "c:\Windows\System32\Drivers\etc\hosts".  If you are using Linux or Mac it is located at "/etc/hosts"
  • Add the following lines to the bottom of your hosts file:

# Block Spotify Ads

127.0.0.1 media-match.com
127.0.0.1 adclick.g.doublecklick.net
127.0.0.1 www.googleadservices.com
127.0.0.1 open.spotify.com
127.0.0.1 pagead2.googlesyndication.com
127.0.0.1 desktop.spotify.com
127.0.0.1 googleads.g.doubleclick.net
127.0.0.1 pubads.g.doubleclick.net
127.0.0.1 securepubads.g.doubleclick.net
127.0.0.1 audio2.spotify.com
127.0.0.1 http://audio2.spotify.com
127.0.0.1 www.audio2.spotify.com
127.0.0.1 www.omaze.com
127.0.0.1 omaze.com
127.0.0.1 bounceexchange.com
127.0.0.1 core.insightexpressai.com
127.0.0.1 content.bitsontherun.com
127.0.0.1 s0.2mdn.net
127.0.0.1 v.jwpcdn.com
127.0.0.1 d2gi7ultltnc2u.cloudfront.net
127.0.0.1 crashdump.spotify.com
127.0.0.1 adeventtracker.spotify.com
127.0.0.1 log.spotify.com
127.0.0.1 analytics.spotify.com
127.0.0.1 ads-fa.spotify.com
127.0.0.1 cs283.wpc.teliasoneracdn.net
127.0.0.1 audio-ec.spotify.com
127.0.0.1 cs126.wpc.teliasoneracdn.net
127.0.0.1 heads-ec.spotify.com
127.0.0.1 u.scdn.co
127.0.0.1 cs126.wpc.edgecastcdn.net
127.0.0.1 pagead46.l.doubleclick.net
127.0.0.1 pagead.l.doubleclick.net
127.0.0.1 video-ad-stats.googlesyndication.com
127.0.0.1 pagead-googlehosted.l.google.com
127.0.0.1 partnerad.l.doubleclick.net
127.0.0.1 prod.spotify.map.fastlylb.net
127.0.0.1 adserver.adtechus.com
127.0.0.1 na.gmtdmp.com
127.0.0.1 anycast.pixel.adsafeprotected.com
127.0.0.1 ads.pubmatic.com
127.0.0.1 idsync-ext.rlcdn.com
127.0.0.1 www.googletagservices.com
127.0.0.1 sto3.spotify.com
127.0.0.1 spclient.wg.spotify.com
127.0.0.1 d361oi6ppvq2ym.cloudfront.net
127.0.0.1 gads.pubmatic.com
127.0.0.1 ads-west-colo.adsymptotic.com
127.0.0.1 geo3.ggpht.com
127.0.0.1 showads33000.pubmatic.com

127.0.0.1 spclient.wg.spotify.com

  • Save your hosts file and restart your desktop spotify client
You should now be able to listen to all the music you want without every hearing another advertisment.


[ Why This Works ]

To understand how this works we first need to understand the role DNS plays in our operating system.  When we are communicating with other services on the web everything is referenced by IP address.  For instance, when I tell my browser to go to google.com, it has to know where to find google.com.  This is where DNS comes into play.  DNS short for Domain Name Servers is a service that translates human readable, easy to remember domain names into IP addresses that other machines can communicate with.  Whenever you add an entry to your local hosts file you are overriding the DNS entry locally for whatever domain you enter.  For instance, if I add the line "127.0.0.1 test.local" to my hosts file, whenever i type "test.local/" into my browser, it will see the entry in my hosts file and use the IP 127.0.0.1(locahost) rather than reaching out to a DNS server to try and resolve that address.  Where this comes into play for us is overriding Spotify ad servers.  When we add an entry for each server that hosts ads for Spotify and points them to our local machine, we are ensuring that whenever Spotify reaches out for an add it hits our local machine instead of the real ad server and gets an error. WhenSpotifyy detects this error it stops trying to attempt to run the ad and the ad is skipped.


[ Wrap Up ]

Hopefully after reading this you have a better understanding of how DNS works, how to override it and how to never have to listen to another spotify ad again.  As always I love feedback so leave a comment down below if you have anything you would like to add.

Friday, August 4, 2017

Relays And Raspberrys - Automate Watering Your Plants Part 2

Email: hightekgrow@gmail.com
Github: github.com/smoriarty21
Website: hightekco.com
Reddit: reddit.com/r/hightek/
Donations: paypal.me/atarimaster
Patreon: patreon.com/hightek
Instagram: @hightekgrow
Twitter: @HighTekGrow
Demo: youtube.com/watch?v=Ao-wqjrCBLg


[ Introduction ]

    If you have not read part one of this series I highly suggest you start there.  It can be found here.  I am going to quickly go back over hooking the moisture sensor up in this post as I will be using a Raspberry Pi this time around to show everyone how to do this on a Pi as well as a Beaglebone.  With that said it will be a quick run through on the sensor hookup and there will be information in the first post you should know that will not be here.  I will show you how to hook a water pump up to a relay, set up a bucket as a water reservoir, and run hoses to water your plants in order to keep them moist.  If you like work like this and would like to support more check out the patreon link above.

[ What You Need ]
  • 250V AC Relay
  • Raspberry Pi - You will need power and an SD card for the OS as well.  Poke around Google for instructions on setting up your Pi
  • Extension cord.  I recommend a long, heavy duty, three prong, 14 gauge or thicker extension cord.  The longer the cord the more room for error.
  • Moisture Sensor
  • Water Pump
  • Water hose to fit your pump and a T adapter to create the end that waters your plant.
  • Hole Punch
  • Wire Strippers
  • Wire Cutters
  • Hookup Wires
[ Connecting Moisture Sensor ]

    In the bottom image below you can see that we have six pins total on the board for our moisture sensor.  We will only be using five of the six pins.  The set of two pins gets connected to the moisture sensor seen in the top image below.  These may be connected in any order as seen in the images below.



    In the image above you can see that we are only using the first three pins on the four pin side.  These pins are our 3.3v power source, ground and our digital output pin.  The pin we are not using is the analog output.  This is used to get a specific moisture reading rather than a simple wet or dry.  The Raspberry Pi only offers digital pins making it tough to read the analog pin.  It is possible using pulse width modulation but that is a lesson for another day.  Comment below if you would like to learn about using PWM to read the analog pin and I will do another entry on it.  Below I have attached a picture of the pinout diagram for a Raspberry Pi 3.


   First with your Raspberry Pi powered down and unplugged (better safe than sorry) we will want to plug the first pin on the moisture sensors board (labeled vcc) to pin one in the diagram above(labeled 3.3V PWR).  To the left of VCC we have the GND pin.  This is the ground and needs to be connected to any of the pins on the Raspberry Pi labeled GND.  The last pin we need to connect is the pin labeled DO.  This pin gets connected to any of the pins labeled GPIO.  Keep track of the number in the label as this is how we will reference the pin in code.  For instance, if you connect DO to the pin labeled GPIO 4, in code at line four you will set the MOISTURE_SENSOR_PIN variable to 4.  Below is an image of the sensor connected to my Pi.




[ Running Power Through Relay ]

    I find the easiest way to run your power through the relay is by cutting the power cord in half and stripping away a good bit of the outer shielding in order to give you some room to work.  When you cut open the cord you will find three wires.  The white and green wires you will be connecting right back to each other.  The black wire you want to split and strip a small bit from each end(this is very important only strip a very small bit).  Below is an image of what the final result looks like.  I soldered the green and white wires back together and put heat shrink around them but you don't have to go that far if you don't want to.  Ensure they are connected very well, you don't want to have to deal with them disconnecting randomly and killing your plants.


    Now on to the black wire.  This is our power wire and we must run it through the relay.  The relay will then either connect or disconnect the contact to allow the power to flow or not based on what our software tells it to do.  This is how we will be turning our water pump on and off, by connecting the power cord for the water pump to the extension cord running through our relay.  In the picture below you can see that each relay has three ports.  We only ever need to use two.  We can set the contact normally open or normally closed based on how we connect the wires.  For this purpose, we will be using the left two for normally open.  If you would like to learn more about this write a comment below and I will do another entry on it. In the image below you can see how we connect to the common and normally open with both ends of our power wire.  It doesn't matter what side goes where as long as it looks like the image below.




 [ Connecting Relay To Pi ]

    Now that we have our extension cord running through or relay we need to connect the relay to the Pi via the four pins on the back of the relay board.  This will allow us to control the water pump from our Pi.  Above is an image of the four pins, I will only be using three as I am not using the second relay but if you repeat the steps above with a second extension cord you may also control another device in the same manner.  Reference the image above of the pinout for the Pi for help connecting these pins.  First, we will connect the left most pin labeled vcc.  This is our 5v power supply and should be connected to any of the pins labeled 5V PWR in the pinout image from the 'Connecting Moisture Sensor' section above.  To the right of this pin is the pin that will control of the left most relay.  This should be connected to one of the GPIO pins.  As before keep track of the number in the GPIO pin name as we will need it in code.  Next, we will connect to very right most pin or the ground.  This should be connected to any of the GND pins on the Pi.  Below are images of the relay and sensor connected to my Pi.




[ Water Reservoir And Drip System ]

    For my water reservoir, I used a five-gallon bucket and submerged my water pump inside the bucket (make sure you are using a submersible pump).  I then attacked a small bit of hose in a circle to a T and punched a few holes in it for the drip.  I recommend spending some time to make one that fits your pot perfect and playing with timing, pump speed and configuration/amount of punctures to suit your ideal needs.  You can also purchase a drip system like the one here and I highly recommend doing it if you have the spare cash.  Below is an image of my homemade solution but, this was a super quick build just for the sake of this tutorial and I would highly suggest spending more time on it or purchasing one.



    I also put the put I am watering on top of a fish tank just in case our software every has issues.  You can also put in all sorts of precautions like another relay in front of the one your pump is on that checks how long the water has been running and hard kills its power if it runs on for too long or any type of measure like that.  Adding checks in the software to kill the relay after the pumps have been running for more than a minute or so and then sleeping for a bit is the least I would add.  Below is an image of my final setup.


  Now we just need to plug in our Pi, connect the water pump to our extension cord and plug the extension cord into an outlet and we are good to start writing code!

[ Python For The Win ]

   I will also be writing the code for this version in Python.  Python is a great language for learning this stuff and is super easy to get setup and use.  The first thing you will need to do is make sure you have the Raspberry Pi GPIO library installed.  This can be done by running the command 'sudo apt-get install python-dev python-rpi.gpio'.  Now we are ready to start coding.  Below is the example code I have used to control my watering.




    The first two lines above are importing the libraries we will use to control the GPIO pins.  Lines four and five are where you need to do a little modification.  You need to change these values to the pins you used above when you connected your sensor and relay.  The rest is pretty self-explanatory and if you have specific questions on what is happening, leave them in the comments below.  The logic here is very simple if the soil is read as too dry, turn on the water pump for one minute and then sleep for five minutes to allow the soil to soak up the moisture then start all over again.

[ Video ]

    I apologize for the quality of the video and for the low light. I had to film this at night and I don't have much light on my porch.  I also had a lack of dry soil so I had to pull the sensor out of the soil to simulate a dry reading. I also could have messed with the potentiometer on the moisture sensors board as that sets the sensitivity but, I did not have my tools on hand and was in a rush to film with what little light I had left.  You can see the pump kick on for one minute water the plant and then it sleeps for 5 minutes to allow the moisture to spread and then starts the loop over again.  This is a very simple setup and I highly suggest you play around with the code and timing for the pump.  There is a ton to improve on in this code and I am just trying to give you an idea of ho you can accomplish these tasks.  Improving on it is half the fun.  The video can be found here.

Moisture Sensors - Automate Watering Your Plants Part 1


Email: hightekgrow@gmail.com
Github: github.com/smoriarty21
Website: hightekco.com
Reddit: reddit.com/r/hightek/
Donations: paypal.me/atarimaster
Patreon: patreon.com/hightek
Instagram: @hightekgrow
Twitter: @HighTekGrow
Demo: youtube.com/watch?v=Ao-wqjrCBLg


[ Introduction ]
    Due to popular demand, I have decided to do a write up on automating watering your plants.  Now you can feel free to go on vacation and leave your seedlings without needing someone to come water them.  The first part of the tutorial will be setting up and reading the moisture sensor.  For this demonstration I used a beaglebone black but, I only did this because I had one laying around not in use.  The same theory can be applied to the Raspberry Pi and everything will connect and work the same way.  I also chose to write the example code in Python as it will run on both systems.

[ Hookup The Sensor ]
   The sensors I am using can be found on Amazon here.  That link will bring you to a 5 pack of the exact sensors I use in this tutorial for $8.  They are also on prime so you don't have to wait weeks for them to come in from China.

    The first step is hooking the sensor up to the small board it comes with.  On the sensor that goes into the soil you will see two pins.  The small board that comes with each sensor contains all the resistors and everything else you need to use the sensor.  That board has two sets of pins, the 4 pin set is what you connect to your beaglebone or your pi and the other set is the 2 pins you connect the sensor to.  They can be connected in any order.  This can be seen in the image below.


    Next you will need to hook up the unit to your beaglebone or pi.  No matter what you are connecting the sensor to there are only three things requires.  A 3.3v power source, a ground and a digital or analog pin to read the sensor.  For this example, we will be using the digital output.  The difference here is that the digital sensor will always output a 0 or a 1.  If the sensor reads 0 it means the soil is moist.  On the other end if it reads 1 your soil is dry.  The level of moisture that triggers the sensors reading 0 can be adjusted using the small white potentiometer on the board.  The analog output will read out an exact moisture value as a floating point number.  This is much more precise but requires you to do a little testing with soils of different moistness to calibrate the device and know when to trigger turning on your water pump.  Comment below if you would like to go over analog readings and I will do another tutorial on analog readings from the same sensors.  In the image below you can see the three pins we will need.  They are the three labeled VCC, GND and DO.


  To connect to your device you need to first find the 3.3v power output pin on your device.  This gets connected to the VCC pin.  On a side note, you may also use a 5v but you would need to add a resistor in line.  You can read about this online or comment below if you would like to know more.  Next you need to connect the GND pin on the sensor to the ground pin on your device.  All thats left after that is connecting the DO pin to one of the gpio pins on your device.  Below is an example of the sensor plugged into my beaglebone black.


    In this image the very top left wire is the ground, the wire just below that is the 3.3v power source and the wire on the right side is connected to a GPIO pin.

[ The Code ]
    Here comes the fun part.  We need to write a little script to determine if we need to turn our pump on and water our plants or not.  Below is the code to check the sensor on a beaglebone black.  I will also provide sample code for a Raspberry pi as they will be almost identical.  The theory is the same its just a matter of semantics for the appropriate library for your device.


    The first line above is the import of the library I use to easily control the GPIO pins of the beaglebone black.  The next step here is the GPIO.setup call.  This call is setting up the pin in input mode.  This will allow us to take readings from the pin.  You should change the line that says "P8_7" to whatever pin you have connected to on your BBB.  Next, we will call the GPIO input method.  This is going to read the pin we provide and give us back the digital reading.  This value will either be 1 or 0 and the messages printed below will show you what the reading means.

    Below is code that will do the same thing but using a library for the Raspberry Pi.  If you have any questions or I did not explain anything clearly please comment below.  I will be sure to responsd!  The code snippet below was found here.  All credit goes there.  Here you would want to change the 11 being passed into the methods to whatever pin on the Pi you are connecting the sensor to.