Wednesday, March 19, 2014

Perils of a Part Time Project (and some solutions)

My sensors in the Remote Garden Project stopped working unexpectedly while I was away at work recently. After a few minutes of poking at my putty terminal I decided to inspect the actual setup. The breadboard and pile of wires was a much different pile of wires than the last time I saw it.  I thought I had it tucked away inside my entertainment center where it wouldn't get disturbed by anyone.....I was wrong. My wife found her way in the cabinet, and some of the wires poured out; with the best-of-intentions she pushed the pile o'wires back in without any discrimination. Needless to say that maneuver does not make for well functioning breadboard setup.

After explaining that the pile of wires was an intentional setup (and I had to re-wire everything)  it became crystal clear I needed to formalize and document my setup abit. I could also understand her point of view, it was a pretty big mess. It also certainly needs some finishing to get into the final weather station.

For reference, here is the what the "before" setup looked like on the breadboard:

After a bit of searching I came across a solution that was just what I needed: Really sweet software package that I'm just barely taking advantage of. It is nice visual breadboard capability with a ton of parts that can be dropped in an customized. As you breadboard out your design it also makes a schematic and PCB (that you can have them Fab for you.)  I've only used the visual breadboard feature so far, but it will be something I consistently use in the future.

As you can see in my fritz prototype below I was able to work on the layout to get all my sensors in a somewhat logical layout. Unfortunately the exact GPIO expansion/breakout board wasn't mocked up, so I crudely created the connections directly from the pi.

Slightly more order to the chaos, and gave me some more confidence to move to a protoboard.  My GPIO breakout came with a half sized breadboard so I went in search of protoboards that could be swapped in easily.  Adafruit had some great looking ones, but turned out they didn't fit the power rails of my GPIO expansion/breakout at all. (They looked great, but left me searching for a better fit.)

 The near exact match ended up being the SB400 from busboard, ordered from Mouser. With that part in hand my setup is now really starting to come together nicely. No longer a wild pile of wires!

So with a part time project like this it was really helpful to sit down, plan and organize abit. Fritzing was a big help, and even allowed me to revisit and test alternate sensors setups without purchasing anything which is also pretty sweet.

The other helpful tool for keeping on top of this multi-faceted project has been a decent to-do list. Seems simple enough; but I wanted it to be segregated my personal task list. To make a clean distinction I decided to use GitHubs issue tracking tools for this purpose. I've already backed up much of this project to GitHub, so why not the task list as well. With custom labels in help separate software bugs from general task, or work to do on the hardware like the solar setup. 

Tuesday, March 18, 2014

Sensors used in the weather station

Spring weather is fast approaching, so I have started to focus more on the sensors for my remote RPi Weather Station. For simplicity (and initial proof of concept purposes) I decided to utilize just digital sensors (i2c) rather than attempt analog. Analog looks possible, either this method, or perhaps ganging together a Arduino. Perhaps something I'll consider in the future.

My search for i2c sensors was somewhat two-fold: does it look to be a digital sensor (i2c compatible with some history of prior RPi integration), and is there some example code to leverage. Seemingly a low bar, but it did narrow down the options pretty well. I tend to be a fairly loyal customer, so adafruit got the brunt of my business.

The primary temperature setting I ended up getting was the weatherproof  DS18B20. The sensor being waterproof was selling point, a great tutorial, and the fact that each has individual ID, so I can have multiple of this type. (At the moment I am thinking I will use one for air temperature, internal case temp of the weather station and perhaps temperature of the battery case.)

For monitoring the soil I went with a weatherproof variant of the SHT-10 The SHT-1x seem fairly common for weather sensing. Adafruit highlights usage with Arduino, but given my limited options for soil moisture and temperature I went this route. Looks like only 1 of these sensors may be possible in a individual system, but that limitation didn't bother me much for this sensor.  I also found another resource for reading the data from an SHT-1x sensor.

So if you've hung in this far you see I really only have two external sensors in use for this weather station at the moment. Since they are i2c (and I already have a rpi900 board attached to my RPi) I needed to pick up extra long headers. If I had more foresight I could have saved my self some de-soldering/soldering when replacing the headers on the rpi900; so on the off chance your copying this exact project, hopefully you catch this early.

Perhaps, since I was in the midst of ordering diapers for my little-one, I ended up picking up a GPIO breakout/expansion kit for the RPi from Amazon instead of a more conventional electronics source. I grabbed the GeauxRobot GPIO Expansion kit which came with the GPIO breakout board, an extension cable, and a mini breadboard.  (GeauxRobot seems to have an Amazon storefront as well as a conventional site, but I've only ordered via Amazon, personally.) FWIW, in the past I have also ordered a couple different RPi cases, a GeauxRobot and Kootek. GeauxRobot case was a dollar more, but much more solid and better built.

When I had all my parts on hand going from pile-of-parts to air and soil moisture sensors was made easy with help of some of the links I posted above. I was also pleased that they inter-operated with each other, and the rpi900 board.

To get the Raspberry Pi and sensors working together I used this exact setup, the adafruit learning system (team) also included a Python program to read the temperature data. My final slight modifications include making the scripts for each different DS18B20 unique, and only writing the Fahrenheit temp to a file instead of to the terminal.

For the soil and moisture sensor I again borrowed heavily, this time from John Geek way-down in NZ. (Also see his updated link on the subject.) John provided a great overview of the wiring, as well as C code for reading the data. For the wiring I also did  a little sanity check for my specific sensor.

Now that I can get data from the sensors time to work on getting the data online...

Thursday, March 13, 2014

RF Propagation Modeling & a Field Test

One of the biggest risks of this project hinges on the fact that the remote weather station needs to be able to connect back to my base station, or it has no chance of success. Given that, I decided to undertake some RF Propagation Modeling to boost my confidence in the final system as well as determine such things as antenna placement (elevation angle/direction) and antenna type.

Due to the miracles of the internet (and procrastination), the blog is slightly behind the reality of where my project is, so I captured below the RF Modeling that took place (spoiler alert) and the field test to check the RF Modeling. As you might guess, the field test only only took place since there was at least a  glimmer of hope (Read: ~10dbm wiggle room) that the radios would connect.

After getting the DNT900 and RPi's working together nicely, it seemed a prudent time to do some more research before investing in all the other ancillary hardware to pull the remote weather station off.  Having some notion of the concept of RF Propagation Modeling, I began to search online for some tools that might help with this. (Perhaps if I had been a classically trained engineer I could have determined my link budget with pen and paper, but that is not my case, and I generally like pretty pictures and well made software.)

A search online yielded an helpful presentation(PDF) from John Hopkins ARL on Modeling and Simulation for RF Propagation. For those looking for a technical review on the subject, check it out, good read.  I happened to also use it for some ideas for possible tools to do the modeling.  Page 16 of the presentation has all sorts of suggestions. My initial criteria was simple: free (or free during trial) & decent usability (or good reference materials). Luckily I didn't have to explore for too long before finding a great solution: SPLAT!  The balance of this post includes output from SPLAT! & Google Earth.

I will also mention I tried  a software package called TAP (Softwright Terrain Analysis Package) but found it too difficult to ramp-up on (perhaps it is meant for the a very patient and forgiving  professional), I only gave it an hour of my time after install before bailing with nothing to show for it.) Perhaps not fair to TAP, but I was looking for a fairly simple answer/analysis, and the work to get that from the tool was too painful.

Some inputs to SPLAT! Included knowing the location of my antennas, EIRP/ERP, local terrain data (SPLAT! provides instructions to import); also referenced dB/Watt conversion  and Free Space Loss for sanity checks.

Going in I saw the DNT900P data sheet made claims about 40+  Line-of-Sight (LOS) coverage, an item that I needed to check for my setup. The data sheet also contains helpful nuggets about receiver sensitivities (the later being something closely looked at during this analysis). I first used Google Maps to determine the Lat/Long of my Base and Remote antennas. I also found this Elevation Profile view helpful to casually observe possible obstacles and get a feel for the elevation that would play into my ability to (not) achieve LOS.

So in summary so far:
Base: Elevation 289ft  (actually ~ +40 in attic  ) ~329
Remote: Elevation:   328 (if I can get +10 feet off the ground)
Distance 1.64 Miles

Using Google Maps Ruler tools I also was able to find the heading needed for each Antenna. (Nice to have in hand & to check against SPLAT! values, which concurred.)

Base to remote: ~192 degrees.
Remote to base: ~12 degrees

Getting going onto SPLAT! just required a few files, of which I provide generic examples of here. The actual SPLAT! site details these files in greater detail but feel free experiment with these if it can get you using the tool any quicker. I chose to Model Omni Directional antennas for simplicity.Here are some of the SPLAT! outputs.

Below we see the anticipated receive dBm of the remote, as related to the base:

Below we see the anticipated receive dBm of the base, as related to the remote:

Pictures are valuable, but SPLAT! also provides a detailed report, here is a sample from a similar model to shown above.

From the prior data I get a feel for the impact of not achieving LOS and anticipated receiver strengths for the sights, all just barely within spec of DNT900 which called for -98 at a 200 kb/s data rate. The input values could be tweaked to achieve the desired result (aka adjusting elevation and antenna gain where necessary).

SPLAT! also puts out some data in a convenient KML format which actually does a nice job visualizing the LOS obstacles. (Base to remote LOS obstacles, followed by remote to base below.)

At this point, I consulted a few co-workers who encouraged me that lack of LOS was not a show-stopper, but given the narrow margin of theoretical receive dBm (on both ends), as compared to DNT900 radio sensitivity it was a sketchy area (that could be impacted/fail on loss from poor cabling/connector choices, vegetation, precipitation, or un-describable obstructions*.) The model takes most of that into account, but it is a difficult to know how accurate is compared to the real world.  *Due to HOA rules my home-base antenna location is less than ideal. It is inside my attic, so I have the unknown variable of plywood and tar shingles in the mix. I think I ball-parked  an additional -20dBm for this in my model.

Being 'forever the optimist', I felt moderately confident to purchase my antennas and get ready for a field test. Installing my home-base station (RPi + RPi900 + DNT900) was abit cumbersome in the attic, requiring power and network to be run. Network simplified by using an old SlingNet Ethernet-over-power device. I wasn't too worried about the bandwidth limitations of such an install, as my bottle neck for data is really between my remote and base station.

With my base station in place, I prepped my remote station for a field trip to the garden. The setup was crude, but effective. I mounted the antenna, battery-pack and  RPi remote system (RPi + RPi900 + DNT900) to a good 'ol Hula Hoa (which from a gardening perspective, I also highly recommend.) The remote station-on-a-stick setup was to facilitate testing different locations and elevations within the garden.

As I ventured off to the garden, I had my wife monitoring a computer at home logged into my base station. I already configured my RPi900's to establish a PPP network, so she was monitoring a ping I had going to the remote unit I carried. I was keeping an eye on the RPi900 indicator lights to know when to ask her to pay closer attention. Here is an one of the first examples of the system establishing a PPP network connection, over the 1.64 mile RF connection:

From basepi (192.168.1.###) icmp_seq=1988 Destination Host Unreachable...........
64 bytes from remotepi (192.168.1.###): icmp_seq=2008 ttl=64 time=49.3 ms
64 bytes from remotepi (192.168.1.###): icmp_seq=2010 ttl=64 time=60.4 ms

When confident the DNT900 radio's were linked (steady green light) the dnt900 line discipline was used to check the receive rssi (signal strength) at the base, of the remote RPi I had in the field (garden).

[@basepi ~]# cat /sys/class/dnt900/ttyAMA0/0x00####/rssi
[@basepi ~]# cat /sys/class/dnt900/ttyAMA0/0x00####/rssi

A shot of the field test setup above when working (perched about 10 feet above my head) on a convenient pole on the perimeter of the garden.  From the field test I learned the very center of the garden was pretty much an RF nightmare. All sorts of metal caging around the individual plots, and the large deer fence around the parameter of the garden acting like a large Faraday cage (I believed.) My success was on the perimeter of the garden - getting in-front of, and above, those immediate impediments. (The SPLAT! modeling did in-fact predict the need for greater antenna height at the remote sight then I orginally planned.)

I am going to claim success on this field test, and endorse SPLAT! since it was extremely close in it's prediction (of between -80 to -90 dBm receive strength), and pretty easy to use.  I was able to find a few potential locations for the remote weather station at the garden, all establishing network connections at the 2nd lowest data rate (with approximately 7 dBm to spare.)

I also still have the option to drop down to an even lower data rate (38.4 kb/s and gain an additional 10 dBm of operability), since the radios are sensitive to -108 dBm, which seems believable given the performance at 200 kb/s.  I think I can also eek out a few dBm in both RPi900/antenna setups by ordering high-quality (lower loss) cable, and limiting some adapters in the mix.

 I didn't  explore the DNT900 claims of 40+ miles of LOS operation from a real world test, or even bother modeling it. I'd imagine it could be possible  in perfect/ideal conditions, or maybe in airborne/ground station setups. Either way, I'd suggest everyone should model their respective communications TX/RX setups (even on an existing functional system), I found it a helpful and informative exercise.

Sunday, March 9, 2014

The Reality of the Raspberry Pi (distant) Weather Station

The all too true true truth with most involved RPi projects..... I suppose that is abit of a 'win' that the heart of the project is so affordable. 

Pulled this off the web months ago, so not sure who to credit for it. Gave me a good laugh; either way, Sad Stormtrooper feels my 'pain.'  

All worth it in the end when it comes together into a fully functioning system. The BOM (Bill of Materials) is a little steep. Not practical for a local (co-located) weather station, but not a big surprise for project involving solar power, multiple sensors, waterproof casings, 2x RPi's, DNT900 transceivers and antennas. ....Now to turn this pile of parts into the planned system...

Thursday, March 6, 2014

Setting up the Remote & Base Raspberry Pi with the RPi900/DNT900

In fairly short order got my two RPi's running with a PPP network in the remote/base configuration  as planned for in the last post.  Closely following the tutorials on made it fairly easy work. The remote RPi  now has a network connection over RF 900 MHz ISM band  (using the RPi900/DNT900) via the base RPi. I can SSH into the remote RPi without depending on Wifi or a physical network cable (on the remote radio), just the local 'base' RPi requires a standard network connection. At the moment my test setup just has my radios covering less than 50 meters and a few levels of my townhome. Much more testing and experimenting to follow.

The RPi900 tutorials call for rpirtscts (flow control)  & dnt900 (line discipline software) , which were developed/tested on Arch Linux (I believe).  Given that, I chose Arch Linux for my Raspberry Pi's OS (to keep hassles at a minimum.) 

Not sure if it was due to initial poor configuration on my part, but I not was unable to get my dnt900's working with PPP on a basic load of (just) Arch Linux. When I jumped to NOOB (then booted Arch Linux), things seemed to go smoother for me.  NOOB likely eats up abit more memory of the SD card on the RPi, but solved some odd PPP connection  issues I could never quite narrow down. (Perhaps fodder for a future post.) 

I've controlled my Arch Linux install setup here, and my RPi900/DNT900/PPP setup steps here.  The entire Remote Garden Monitor project is also on GitHub Perhaps 10% of setup steps are specific to my setup, so buyer beware (this is not something you can just clone and build, but I hope it is of some help). I cannot stress enough that the tutorials on were invaluable, and nearly followed verbatim.