I have never grown a plant from germination to fruition. I want to grow my own produce. But frankly, I know very little about gardening. As I started reading about gardening I quickly learned that my living room was sub optimal (to say the least). While I can artificially change the environment, I first wanted to start by understand what my environment actually looked lik for the plant. Other than gardening my electronics and electronic circuit knowledge is fairly limited, so I wanted to expand on that as well. Two birds, one stone.
To build this monitoring station I had a few things in mind.
- It had to work untethered to a router for internet (i.e. wireless)
- Data is collected and visualized over time
- I want to monitor the soil moisture, temperature, light, and humidity
Here were the parts I used to get this started.
I chose Arduino because it is easy for hacking, that is, getting started without having to deal with much lower-level BS. It is really easy to plug it into USB, write some code, and get the instant gratification.
The IO Expansion board technically wasn’t required; however, I only got it so I could easily connect the sensors to the board. This board turned out to be a great choice.
I also wanted WiFi connectivity. This was kind of a pain in the ass. Turns out there wasn’t any one standard or best choice for this. What I wanted was something like WISP by embdSocail
, a KickStarter project. I funded the project, but the project didn’t reach it’s goal. I reached out to the guys behind the project and told him that I was interested in getting the board even at a premium price just so I could get my device connected more easily. In the mean time I needed something. Unfortunately the board the I chose for WiFi was a huge hassle for a few reasons. First off, the communication to the board requires using serial communication. This is the same method used to communicate between the Arduino and the computer via USB. The result is that Serial output in the code can be used to send commands to the WiFi shield or to USB for debugging (but not both), this made debugging the Wifi code super fucking hard. Secondly, there are two sets of jumpers. In one state they are used to enable the computer to control the WiFi shield, in the second it allows the Uno to control the Wifi and in the third (both jumpers out) is used to program the Uno from the computer. I had my sensor shield on top of the WiFi shield. This mean that every time I wanted to release new code I had to take off the sensor shield, take out the jumpers, deploy the code, put the jumpers back on, put the sensor shield back on, restart. OUCH! I bent a few connectors in the process.
Reading the analog signals is really easy. Reading the digital ones from the temp/humidity sensor wasn’t very easy. Luckily I found a library that helped out. It’s not easy because you actually have to read binary data and synchronize it with the clock. Not fun.
With the code I finally got to the point where I could read the sensors. The WiFi was all setup and I could connect to the device. TCP stack is supported; however, HTTP wasn’t supported. Being able to control the sockets is also really difficult. So it was nearly impossible to write a HTTP server or even client. Instead, I just created a simple TCP service. I can connect to it (e.g. “telnet 192.168.2.7 4000”) and it just starts sending me the data in JSON format. Every 5 minutes a new line would appear, here is the sample from the last 4 iterations: To get the data from the board to the internet I decided to use a little agent that retrieved the data and pushed it to Cosm. The agent sits on my computer and pings the Arduino every 5 minutes to get a reading. The results are formatted in JSON. I used the Cosm gem to publish the data to the Cosm service. Check out my feed: https://cosm.com/feeds/63163
. This little baby below is the agent.
It was incredibly fun hacking on something other than fancy we apps. Hardware hacking is great as it’s a rare opportunity to interact with the real physical world.