How To Grow Mushrooms. Sort Of.

So, you may be new, and asking… how do I grow mushrooms? Honestly, the full answer is beyond the scope of a single blog post. That said, hopefully I can go over some basic concepts in an easy to understand way. Core concepts glossed over here will be explored in future articles.

To grow mushrooms, you will need three basic things:

  • A culture of what you want to grow. This could be a culture on agar, a liquid culture syringe, or possibly even stem butts from purchased mushrooms grown out on cardboard.
  • Spawn. Either purchased spawn, which will already be colonized and ready to use (in which case you can skip the culture), or spawn you produced yourself, which is basically hydrated grain that’s been sterilized in a pressure canner (there’s a lot of steps you can skip or do halfway, but sterilizing grain is absolutely not one of them.) Consider this “baby food” for the culture. It won’t fruit well from spawn, but it’s highly nutritious and your mycelium will tear through it quite quickly.
  • Substrate. This is what the mushroom actually fruits in. If it were a plant, this would be the soil, but we’re gonna stop the plant metaphors right there because most of them are super inaccurate. For many gourmet mushrooms, this will be sawdust, either as sawdust itself or in the form of hardwood fuel pellets. Straw can also be used with oyster mushrooms. This is what the mushroom would be growing on on nature, and this is what the mushroom will fruit from after you inoculate it with spawn. Most substrate is either pasteurized (with heat or chemical methods) or sterilized.

You’ll also need somewhere to fruit your mushrooms once your substrate is colonized, but we’ll worry about that later since depending where you live, you might just be able to put them outside and forget about it.

Your culture, if you’re making your own spawn and not purchasing it pre-made (which is a good option if you’re starting out and don’t have much of a lab setup), will probably be in the form of either a culture on agar, or a liquid culture, which look like this.

lc-backlit.jpg

IMG_9917.jpeg

The purpose of the culture is to inoculate sterilized grain. Attempting to inoculate the fruiting substrate directly with the culture is unlikely to work, and if it did, would take so long to colonize without the extra nutrients from the grain that it would be likely to contaminate.

Starting out, you may have a choice of which to buy – liquid culture or an agar plate. If you have experience with aseptic technique and a semi-sterile setup (either a still-air box, or a flow hood), I would recommend agar. If not, I would recommend liquid culture, since it doesn’t require you to open the jars in a non-sterile environment for inoculation, and you can get quite a bit of good grain spawn from a 10cc syringe of live mycelium.

Mycelium is white, generally. This is the sort of “vegetative” form of the mushroom that will later turn into an actual mushroom. Some mycelium is thick, some is wispy, but for 90% of gourmet species, it’s white. You can basically gauge how much of a container is colonized by how much has turned white.

NOTE: We’re glossing over sterile technique entirely. This is an overview, not a step by step guide.

If you have a pretty sterile place to work, you can just cut some wedges (thumbnail size) from your agar plate and very carefully drop them into your grain and gently shake it up a bit. After a few days, the mycelium will grow from the agar wedges onto the nearby grains, which looks like this.

IMG_9923.jpeg

This is in a filter patch bag, but it doesn’t really look any different in jars. If you used a liquid culture instead of agar, it’ll honestly look pretty similar, just perhaps in a different pattern where the culture dripped down the side of the bag or jar. When maybe half of it is white, give it a decent shake to distribute the already-growing mycelium to the entire container, and it should speed up from there. Be patient. Eventually your entire spawn bag or jar will be white and fully colonized.

Eventually you’ll end up with something like this. A small amount of yellowish metabolite is nothing to worry about. Colors like green and black, you might have a pretty big problem on your hands and the spawn should probably be discarded somewhere outside. Birds will happily eat it and it would be good for your garden or compost.

IMG_9924.JPG

If you went the route of purchasing pre-made spawn, you’re already at this step, congratulations!

At this point you have two options. You can use your grain spawn to make more grain spawn by just adding it to hydrated and sterilized grain at about 10% by weight, if you have a still-air box or flow hood, or you can put it directly to the fruiting substrate. I usually do both – I use a bag of grain to make 4 more bags of grain, and also to make 10 or 15 fruiting bags. It’s good practice to only transfer to other grain maybe 3 or 4 times – eventually the mycelium becomes too accustomed to a single food source, and will not perform well.

To use the grain spawn, break it up by either mashing the sealed bag around, or by hitting the jar against something solid but soft (such as a bike tire.) Please don’t whack jars onto your hand, after repeated sterilization cycles the glass can get brittle, and this can end very poorly. If you left your spawn sitting a little too long, this can be challenging if it’s in a jar. Ideally you want the grain such that it could be easily poured.

At this point you’ll need prepared substrate bags or other containers – with fuel pellets, you can often get away with simple pasteurization (hydrate bags of pellets in a camp cooler with boiling water, let sit overnight, once cool, inoculate), or if you’re growing species that take a lot of time (shiitake, etc), sterilized in a pressure canner at 15 PSI for two hours. That’s the subject of another post entirely, and you can also find good information online.

I tend to inoculate substrate bags at about 5% by weight with grain spawn – so if I have a 5 pound bag of sawdust (which is pretty standard), I use about a quarter pound (1 cup or so) of spawn. You can use more or less, using more will make it colonize faster, using less will save spawn. You’ll find a happy medium. Once you’ve inoculated the substrate bags in whatever sterile-ish area you have, seal them (either with a heat sealer or a very tight zip tie) and give them a very good shake to evenly distribute the spawn in the fruiting substrate. Put them somewhere to colonize – conditions aren’t important, anything approximately room temperature is fine, light or dark doesn’t really matter.

As mentioned before, you’ll be able to tell how far along it is by how much of it has turned white. This is a sawdust-based fruiting bag approximately one week after inoculation with grain spawn.

IMG_9925.jpeg

Again, colors like green or black generally indicate you have a problem and that you might have to abandon that bag.

At some point the bag will be fully white, and ready to start producing mushrooms. That will probably look something like this. Shiitake looks quite different, but that’s a discussion for another post.

IMG_9926.JPG

At this point, you’ll need to make slits in the bag to expose the mushrooms to air and encourage fruiting. I’ve drawn red lines where I would usually slit my bags – you can do more or less, longer or shorter, you’ll find what works best for you. Smaller slits tend to produce multiple smaller clusters, whereas one large cut tends to produce one massive cluster. Use a sharp knife such as a boxcutter or carpet knife.

At that point, put your bag in its fruiting environment. This can either be a purpose-built chamber with a humidifier, outdoors if it’s cool but not cold and with high humidity, or even just on your kitchen counter, if you can remember to lightly mist it several times a day to maintain humidity.

After some time, sometimes days, sometimes a week, mushrooms will start to push through the slits. Let them grow out until the edges of the cap start to turn upwards, and then harvest and store them in your fridge. This is pretty much the ideal time to harvest them, if they’re oysters.

phoenix-flush.JPG

After harvesting, enjoy! Just leave the fruiting bag in whatever conditions you have it in, it should produce multiple harvests every week and a half or so, up to 3 or 4. Each harvest will generally be smaller than the last. When it’s stopped producing, or if it appears to be growing mold, you can break it up and put it in your compost to help break down woody matter, or put it in your garden with some wood chips and try to produce more mushrooms! You’ll know the block is done when it’s pulled away from the sides of the bag, appears dried up, and is quite a bit lighter in weight than when you started.

Many other growing methods exist as well – outdoor wood chip beds, plastic buckets, old coffee containers with holes drilled in them – options for any budget and commitment level. In this post we focused on using filter patch bags, made by a company called Unicorn, that allow the mycelium to breathe while still keeping contaminants out.

And that’s… not really it! We’ve skipped a LOT of important things, including hydration and sterilization of grains and substrate, but we’ll cover that in future posts – this is just meant to be a rough outline. Hopefully you’ve found it helpful, and stay tuned for more!

The Shed, Part 3

Sorry for the long delay – I was busy growing mushrooms! When we last left off, I’d just finished the shed conversion. Now I am pleased to report I’m growing mushrooms in it. The first bag was put in there to fruit on January 28th.

P1010979 copy.jpg

It looks much as it did last time, just with… more shelving and more mushrooms! I’m using black resin shelving for the time being, it could be easier to clean but it’s very cheap and lightweight (and can hold a whole lot of fruiting blocks.)

IMG_7008.jpg

It’s mostly oysters in there, but several other species are co-existing, including chestnut / cinnamon cap (Pholiota adiposa.)

IMG_7616.jpg

The overall design hasn’t much changed – although now it’s summer, so the marine space heater has been replaced with a 14,000 BTU/hr portable air conditioner. It’s managed to keep it nice and cool all summer. The fogger was upgraded to 12 ultrasonic fog heads, with a larger fan to move all that moisture around.

IMG_7283 2.jpg

One thing I ended up changing was adding loose filter material (I purchased it as a cut-to-size air conditioner prefilter, it’s just poly filter material) over all of the fan intakes – the humidifier fan runs nonstop, so basically also acts as a crude air filter. Same over the exhaust fan, to preserve its longevity.

Keeping a close eye on the mushrooms and picking when ready is critical to not wasting time cleaning filters daily. With oysters, it only takes a couple over-mature clusters to create an apocalypse of spores in the grow area. I always wear a half-mask respirator when working in there (with just a particulate filter.) I have a stash of disposable N95 dust masks for the rare times when I have a guest coming to view the operation.

Looking back on the old posts, it took a while to get here, but I can’t describe how nice it is to have a fruiting space that will pretty much look after itself for days at a time, other than harvesting. Best of luck in your own endeavors!

The Shed, Part 2

Well this is gonna be long, boring, and full of text and links. Maybe a couple pictures? We’ll see what we can do I guess. Starting from the absolute basics I guess.

Construction

Roxul R14 ComfortBatt insulation: It’s made of rock wool so it’s nicer to deal with than pink fiberglass. You should wear a dust mask when handling it but it’s easily cut with a bread knife and while it’s still a little itchy, it’s not the claw-your-skin-off sensation that you can get from the other stuff. Obviously cellulose isn’t a possibility since mushrooms can eat it. Closed-cell foam would be an option but it seemed like it would have been a nightmare with the uneven studs. Obviously buy the appropriate thickness for whatever studs you have.

6 mil vapor barrier, sheathing tape, staples, screws: It’s building supplies. What can I say.

Pond liner: This stuff is very decently thick and has enough traction that I’m not worried about putting anything else like bar mats down on the floor. It DOES stink a bit for its first while in a warm environment, but just keep the air moving.

Sashco Lexel sealant/adhesive: I love this stuff. Dries clear, paintable, can be applied to wet surfaces, very flexible when cured, etc. It’s also full of godawful solvents so actually do use it in a decently ventilated area. I think I went through 4 tubes of this stuff. You could use pretty much any silicone or construction adhesive suitable for your materials though.

Ventilation/Humidity/Heat

Pest-resistant dryer vent: Has a cheesy little screen over it to keep rodents out. Probably doesn’t work very well, cover it with something more sturdy if you ACTUALLY have pest problems. Make sure the flapper opens fully when the fan is on and closes fully when it’s off. If it doesn’t close fully (due to positive pressure from air intake etc), you can put a small weight on it like a washer or coin. Being fully closed will help keep insects out when the fan isn’t blowing.

4″ extractor fan: You should ideally get an exhaust fan that’s actually intended to work at absurd relative humidity. Y’know, for safety and so you’re not buying another one every 3 months. This one has two speed settings, you can change it by opening up the compartment the power cable goes into. I guess you could put this on the inside or the outside, depending how much you cared about outside noise.

A couple 5V blower fans: One for the fogger, one to gently assist with air intake. They’re surprisingly durable, and it’s hard to get too freaked out over 5 volts. If your humidifier is outside the fruiting area, these will probably last a long time, since that one shouldn’t actually be pulling humid air. If you’re using a giant barrel for a fogger you might need something a little bigger like this handy dandy but not TOO powerful version of the extractor fan.

A suitable tote/barrel: Or however you make your fogger. Ideally a very large bucket. Find what works for you (and what’s big enough to fit your fogger unit.)

A 6-head pond fogger: Also the included float and power supply. These things can in theory blow through a gallon of water in an hour and a half. Realistically not so much, but it is still a LOT of fog. It’s about the perfect size both for this space and with the heater running as often as it does. If in doubt about which to get, go bigger, you’re probably going to be putting it on a controller anyways.

A cheap little fan heater: Worked well enough to keep me warm while I was working in there but I’ll be getting something better.

Inkbird IHC200 humidity controller: Same one most people use. Make sure the sensor doesn’t get wet, it’s good to build a little hat over it to prevent condensation. The sensors still aren’t gonna last forever. It’ll take a bit of experimenting to get the various parameters set so it’s how you want it, but after that it just does its thing as long as you make sure the fogger has water. The cool thing is that it also has a dehumidifier output – you probably won’t be using a dehumidifier obviously, but you could use it to turn on a second intake fan or something.

Inkbird ITC1000 temperature controller: Not pre-wired, just so you know. Apparently you save thirty bucks if you can wire it up yourself. Obviously only do this if you’re comfortable working with line voltage. Also has an ‘alarm’ relay feature that I haven’t used.

UPDATE: I’ve switched to the Inkbird ITC-308 temperature controller, which does both heating and cooling. This unit is pre-wired.

Lighting

A whole bunch of these LED strips: They’re 16 feet long, and I wanted 8′ lengths so it’s perfect. It’s cuttable every few inches. There’s a whole bunch of LED strips you can get, but this one is specifically 6500k, waterproof, super bright, and with (not 600, 300) total LEDs per strip. Note that this does not include a power supply. The power supplies some of them come with can only power one strip. I’ve tried two, it was not a good idea. All come with one end wired with a plug, once you cut it you’ll need to wire a plug onto the other end. UPDATE: The 600-LED string appears to no longer be available, the links is for a 300-LED unit of brighter LEDs.

These snap-on things that pierce the waterproofing: You’ll need these or something like them to wire up plugs on cut-up LED strips. LED strip goes in one side, your wire goes in the other. Make sure you get ones specific to the kind of strip you have.

Barrel plugs and sockets: You’ll need a bunch, there’s a decent amount of wiring involved and most of it’s DIY. Sorry. Luckily it’s not very hard and everything is very clearly marked. One side has screw terminals for your wire.

A whole bunch of wire: I got a huge thing of stranded 20ga red/black wire. Made my own splitters for the LED power, etc, saved a bunch of money. Wherever you get wire I guess. I used some 16ga speaker wire I had for the “main” runs from the power supply to the mass of splitters.

12V/30A power supply: I got three, how many you need depends on your LED strip, see the strip for wattage details. Each of these gives you three 12V outputs with a combined total capacity of 360 watts per unit. Note that these are not pre-wired, you’ll need to be comfortable working with line voltage and crimping spade connectors. It’s worth it though, they’re really nice and the fan only comes on when needed.

Cable staples, wire guideways, etc: Whatever you need to make it work in your space. With how cheap the LED strips are I ended up just stapling them to the studs with actual staples. Even the one time I missed and put a staple directly through an LED, only that one stopped working, the rest of the strip was fine.

…part 3 is gonna be the actual growing of mushrooms in there, so it may be a little while 😉

UPDATE! Part 3! 

The Shed, Part 1

It’s gonna be a long one.

So when I moved into this place, one of the nice things was that there was a semi-finished shed that I thought would be good to use for growing mushrooms. It’s about 100 sq ft, give or take. Not insulated, but the walls weren’t covered so that would be easy enough. Locking door, hose bib nearby, pretty much ideal. Even a covered area for materials storage.

IMG_4474.jpg

 

Problem is, previous owner went and did something silly like use it as a workshop. There was also no power to the shed, so trenches were dug and power was run. I have one 15A circuit out there to use for EVERYTHING, so I gotta save on watts here and there.

IMG_4477.jpg

Well, that’s gonna have to come out. Originally the plan was to construct a huge greenhouse inside the shed, almost the exact dimensions as the interior, and do it that way, but that started proving to be impractical pretty quickly, so I decided to just make the shed as moisture resistant as possible with what I had / could afford.

After months of procrastinating and wasting my time on useless stuff, I actually got started on the insulating and vapor barrier. I used Roxul stone wool insulation, because it’s easy to work with, has a decent R value, and mushrooms can’t eat it.

IMG_5935.jpg

That’s when I found out the stud centers were… well, not random, but a decently wide range between 14 and 25 inches. Anyways, insulation went up, walls and roof. I think I went through 4 or 5 packages of insulation. Bare wood floor up on patio blocks, so there’s not much I can do about that, but it’s not too cold. There was also sort of a hayloft thing. WAS. God I love reciprocating saws.

IMG_5937.jpg

Of course I started in the easy, accessible corner with the insulating since that damn workbench was still there. I did need to get to that eventually but looked VERY sturdy. Luckily, I made a new friend at the hardware store.

IMG_6022.jpg

The workbench actually came out relatively easily despite a million nails. And one lag bolt in an incredibly non-obvious spot. Thanks for that, whoever built it. The cupboards and other nonsense went too, which was easy since most of them had all of two screws holding them up. Varying levels of workmanship in this shed.

IMG_6031.jpg

This is around the time the temperature controller arrived, so I put that out there and a small fan heater set to low power (750 watts) to see what it could do. Modest results, but that’s probably because the insulation was only half done. When the insulation was finished, it was able to maintain pretty much any temperature I wanted on not all that much power. At best it was doing 30C/50F degrees above ambient (maintaining the shed at 25C/77F with an outdoor temperature of -5C/23F.) Obviously once there’s ventilation that’s gonna go down a bit, but I can live with that.

All insulated up, but still no airflow or floor. Which are sort of important things to have, I’m told. Decided to use pond liner for the floor, but then I got a bunch of fans and stuff so I started working on ventilation. Just so we’re not sucking moist air from outside through every gap in the walls from negative pressure, I put a pipe through the wall to eventually put an intake fan on the end of.

IMG_6269.jpg

Also threw a 90 degree fitting on it to keep rain out in the meantime. For exhaust we have a 4″ extractor fan (designed for humid conditions) running through a 4 1/8″ hole in the wall to a standard pest-resistant dryer vent. If you have this motor or similar, check to make sure it’s wired how you want it. You can wire it for low power or high, mine arrived wired for low power.

IMG_6281.jpg

Good thing I put the fan in first, it turns out. Next to go in was the pond liner. A 10×10 pre-cut piece cost like three times what it cost to get it off the giant roll, so I got a 20′ x 6′ piece and cut it in half. This allowed for a decent overlap and also for it to come about four inches up the walls on all sides, which is important so there’s fewer seams and places for water and dirt to accumulate or damage the underlying wood.

IMG_6289.jpg

Yeah, that stuff stinks. Bad. It took like a week to offgas even with the fan running nonstop. But anyways, I am after all not using it for its intended purpose, so I guess I can’t complain. The pond liner is sealed to the floor and to the vapor barrier on the walls with Lexel. You could probably use any kind of silicone but I like this stuff because it’s flexible enough that I won’t trip over a seam and rip it up. The only seam on the floor is where the two pieces overlap, which was sealed VERY well with Lexel (then covered with sheathing tape to reduce the trip hazard.)

Lighting time! I was planning to use a decent amount of LED strips, so I got a couple beefy 30 amp 12V power supplies.

IMG_6284.jpg

This is about 1/4 of the total lighting that’s going in. Around the walls, then under the shelves once they exist.

IMG_6311.jpg

As of this writing there’s 4800 individual LEDs in there with that many again on the way. Three 30A power supplies. The wiring’s a bit of a nightmare, soon I’ll put in cable raceways to get all this off the floor.

IMG_6439.jpg

The effect is quite dramatic at night, I gotta say. Whatever, the neighbors can think what they will.

IMG_6429.jpg

I also got the humidity started at this point. It’s just a six-head fogger in a tote with 1/3 of the lid cut off, with a fan blowing on it. The fogger float is ‘corralled’ under the covered part so it doesn’t spit water everywhere. It’ll do until I get the rest of the actual fogger design worked out.

IMG_6416.jpg

Okay, that’s it, I’ve bored you enough. For now. Next post I’ll go over materials and supplies and a few notes about why I chose them. That’ll be a non-stop thrill ride, won’t it?

Update: Check out part 2!

 

Remote Sensing, Part 2

Last time we had a look at the sensor hardware, now it’s software time. I’m sorry, there’s less pretty pictures. It’s boring nerd stuff, that’s just the way it goes sometimes.

I’ll leave the Raspberry Pi setup as an exercise to the reader. There are many fine tutorials. Get a microSD card, flash Raspbian to it (I used the desktop version for easier setup then had it boot to CLI afterwards.) Obtain a USB wifi adapter (check compatibility) if you don’t have onboard wifi. Connect it to your network (or use a cable.) Please please please change the default password on the Pi. Enable SSH at the very least unless you want to sit wherever your Pi is while you’re monitoring it, which would sort of defeat the purpose.

So at this point we have the Mega2560 (again, another more reasonable board would work, a Pro Micro would be ideal probably) listening to the sensors, cleaning up the data a bit, and sending it to the Pi over the USB serial connection. You’ll need drivers for this if your board uses a CH340G, almost everything else works out of the box. Here’s what’s running on the Arduino board.

/*
Ideally, spitting things over serial while using very little power.
 */

// include the library code:
#include "DHT.h"

// dht sensor's output
#define DHTPIN 30

// dht sensor's "power"
#define DHTPOWER 40

// either this or a DHT11
#define DHTTYPE DHT22

// flame sensor power is connected to 3.3V rail
// only analog output is connected, digital trigger is not
#define FLAMEPIN A0

// initialize the library with the numbers of the interface pins
DHT dht(DHTPIN, DHTTYPE);

void setup() {

 // totally powering the dht22 from a gpio
 pinMode(DHTPOWER, OUTPUT);
 digitalWrite(DHTPOWER, HIGH);

// flame sensor input
 pinMode(FLAMEPIN, INPUT);

// sure why not
 Serial.begin(9600);
}

void loop() {
 float h = dht.readHumidity();
 float t = dht.readTemperature();

// 600-700+ seems to be a normal reading
 // under 400 and i'd be extremely worried
 // if it's under 100 the sensor's on fire probably
 int f = analogRead(FLAMEPIN);

// read errors are extremely common on the first readings
 if (isnan(t) || isnan(h)) {

 } else {
 // output it to wherever
 Serial.print("T");
 Serial.print(t);
 Serial.print("H");
 Serial.print(h);
 Serial.print("F");
 Serial.println(f);
 }
 delay(500);
}

It appears the tabs don’t work. Thanks, WordPress. You get the idea. Basic sanity checking on the sensor readings, not much else, let the Pi deal with it. You’ll want to adapt it to your sensors obviously. I’m only using one analog sensor at the moment so I’m not too concerned with what AREF is set to or anything like that.

As a side note, I’m not powering the DHT22 from a digital pin just because I’m an idiot (although it’s possible), with the LCD shield in place there actually aren’t any exposed 5V pins on the Mega, but there’s a whole bunch of GPIOs. The sensor doesn’t use even close to enough power to stress the output pin.

The Arduino code is brief. This would run on almost literally any board you could buy. Currently communication is only in one direction although the code on the Pi anticipates that changing.

Before we move on to the Pi, a word of caution. The Pi uses 3.3V logic. Arduino boards vary. The Mega uses 5V logic. This is why I’m using the USB serial chipset and not one of the Mega’s several hardware serial ports. Also I’m saving one of those for a future datalogger. If your voltage levels are compatible and Linux drivers are being a pain for your CH340G you could totally use a hardware UART to communicate to the Pi.

Find where your Arduino shows up on the Pi (mine was on /dev/ttyACM0), you’ll need to know that. You shouldn’t really have to install anything that isn’t included in the basic Raspbian image.

This is the script that reads the serial data. Yeah, perl. Whatever, I like it.

#!/usr/bin/perl

# reads serial output from the arduino (DHT22 sensor, flame sensor)

# the thing is, jumping into the serial stream mid-write gives a lot of funky data.

# attempts are made to filter it out

# expected data format is 'Tnn.nnHnn.nnFnnn'

use IPC::Open2;

# we don't technically need open2 but it's easier and lets us talk both ways in the future

open2 $out, $in, "/usr/bin/minicom -b 9600 -o -D /dev/ttyACM0" or die "Could not open serial portn";

# basically just read data until we get something properly formatted

while(<$out>) {

 my $line = $_;

 # is the data even remotely valid?

 next unless $line =~ /^T/;

 chomp($line);

 $line =~ /T([1234567890.]+)H([1234567890.]+)F([1234567890]+)/;

 my $t = $1;

 my $h = $2;

 my $f = $3;

 # the below is largely for ignoring weird serial data

 next unless $t =~ /^\d{1,2}\.\d{1,2}$/;

 next if length($t) == 0;

 print("T$t");

 print("H$h");

 print("F$f\n");

 # break out of the loop (and end the script) when valid data is received

 last;

};

Oh hey, tabs again. Ah well, it’s short. You’ll work it out.

The most obvious thing is that it has the same output as the Pi, in terms of format. This time it’s just ‘guaranteed’ to be good and valid data in the appropriate format. This is what other scripts use to get sensor data, with the exception of the userland one, which I’ll get to.

This is the output.

Screen Shot 2017-12-19 at 2.02.44 PM.png

Of course, that’s real handy if all you want to do is see what it’s like out in the shed. Which is exactly what I wanted it for, initially, because I was getting real sick of walking out there every 10 minutes while getting the heat dialled in.

The next script logs the output. It does so every minute. It logs to three files, all of which have been set to mode a+r, which will become important later. It also copies the logs to the web server root directory, where they sit not doing anything, because I haven’t gotten to that part yet. I’m using lighttpd because I don’t really want to mess with Apache for something this trivial. Since it only does this every minute, I’m not super concerned about it losing power during the fraction of a second it’s writing, etc.

#!/usr/bin/perl

$delay = 60; # 1 minute

$| = 1;

while(1) {

 $data = `/usr/bin/readsensors`;

 # print $data;

 chomp $data;

 $data =~ /T([1234567890.]+)H([1234567890.]+)F([1234567890]+)/;

 $t = $1;

 $h = $2;

 $f = $3;

 open(TEMPLOG, ">>", "/logs/temperature.log");

 open(HUMLOG, ">>", "/logs/humidity.log");

 open(FLAMELOG, ">>", "/logs/flame.log");

 print(TEMPLOG time . " " . "$t\n");

 print(HUMLOG time . " " . "$h\n");

 print(FLAMELOG time . " " . "$f\n");

 close(TEMPLOG);

 close(HUMLOG);

 close(FLAMELOG);

 system("cp /logs/*.log /var/www/html/");

 sleep($delay);

}

Currently I’m starting this script by hand, but it should really be started immediately at boot time, ideally as a service. Also something I haven’t gotten to yet.

Everything’s timestamped, so if you wanted to feed this to RRDtool or something (possibly an upcoming blog post!) it’s in a semi-appropriate format, or at least you can write a simple script to make it so. Here’s what the log files look like, in this case the flame sensor.

root@shedpi:~# tail /logs/flame.log

1513753311 713

1513753371 714

1513753431 714

1513753492 712

1513753552 713

1513753612 713

1513753672 713

1513753732 712

1513753792 713

1513753853 713

Huzzah! Data! Everyone loves data! So now we can check the status of our sensors, read data from them, and log it to disk (to the tune of roughly 25MB/year with these sensors.) Presuming we’re running as root at the time. Which is… sort of really not great. We want any user to be able to see this data, but we don’t actually want to let any user access the serial port, or it could mess up the script trying to use it.

The last script is “sens”, because I wanted a short name. It doesn’t actually read the sensors, which it wouldn’t be able to as a normal user, but it DOES give you the last line of each log file. So your data could be up to a minute old, but it’s the most recently collected data by the logger. It’s an imperfect solution.

#!/bin/sh

tail -n1 /logs/temperature.log

tail -n1 /logs/humidity.log

tail -n1 /logs/flame.log

…I didn’t say it was complicated. So now we can read sensor data, sort of, without having to be a superuser at the time. Its output looks like this. It could be a bit cleaner, but I can tell which number is which sensor pretty easily.

Screen Shot 2017-12-19 at 2.02.10 PM.png

And that’s pretty much it, up until now. More construction-related projects are occupying my free time at the moment, and it does what I need it to at this very second, which is just read and log temperature and humidity.

For the more DIY-oriented among you, this is all you need, once you can get sensor data from a regular user account, you can do all sorts of things with it. Graph it, analyze it, e-mail it to yourself every 12 hours if you’re a nervous parent.

Likely additions this week include using a big-kid database instead of a flat file, archiving old data (do you really need to know how humid it was 119 days ago?), and setting some basic range alarms on the Pi to trigger… well, I’m not sure yet. Of course at this point I should probably advise everyone not to work with line voltage unless they’re experienced and comfortable with it, and not to leave any line-voltage-using DIY creation unattended unless you’re very confident in it.

For the less DIY-oriented, I’ll be doing some more actual useful things with the data in the coming days once I have a wee bit more time. I may even offer some pre-built units for sale! Stay tuned!

Hot tip: Does your Pi keep dropping the wifi connection after a while? Possible solution here! (Worked for me!)