
Show HN: I wanted to measure CO2 in my office, so I build a C++ WebServer/App - stackmad
https://github.com/Maddimax/MadCO2
======
t0mek
Shameless plug: I wanted to measure PM10 and PM2.5 pollution level in my
neighbourhood, so I built the ESP8266-based sensor using instructions from
Luftdaten [1] and since the original interface is pretty ugly, I created my
own UI:

[http://smog.rekawek.eu/](http://smog.rekawek.eu/)
[https://github.com/trekawek/air-quality-
info](https://github.com/trekawek/air-quality-info)

(I know, it's PHP, but can be hosted virtually anywhere!)

[1] [https://luftdaten.info/feinstaubsensor-
bauen/](https://luftdaten.info/feinstaubsensor-bauen/)

~~~
blacksmith_tb
I built a pretty similar rig around an RPi Zero W, same SDS011 AQ sensor and
BME280 temp/pressure/humidity sensors as Luftdaten, just polled by a couple of
python scripts on cronjobs.

------
bhouston
I would have just had the CO2 level read via a $8 I2C device connected to an
Esp8266/Esp32 running Arduino.

I would post the result to a web service in this fashion from the Esp8266:

[https://techtutorialsx.com/2016/07/21/esp8266-post-
requests/](https://techtutorialsx.com/2016/07/21/esp8266-post-requests/)

Then just setup a nice Graphana+Prometheus as a service, graphana.com is nice
and can expose a Prometheus end point over basic http auth - easy to post to.
Then you can setup alerts, graphs, dashboards, etc.

In fact you could have a whole suite of IoT reports flowing in from various
Arduinos really easily. Or at least a couple CO2 sensors spread around the
house.

Total investment of coding would be about 30-50 lines of Arduino code for the
Esp8266 and you may even get away with the free plan on Graphana.com.

I obviously like to outsource as much as possible these days. Less learning,
but more efficient.

~~~
Hobohodo
Would you be able to share where you might get such a cheap CO2 sensor/the
name of it? I've had trouble finding them for less than £60 in the UK and
would like to set one up.

~~~
sbr464
[https://www.co2meter.com/collections/sensors](https://www.co2meter.com/collections/sensors)
has a bunch of different ones, I usually look on Mouser also. I don't have a
name of one currently. I've been using the particle.io platform with a
particle device/LTE for sending out data and programming them.

~~~
gsich
None of them are in the 8$ range. There also seem to some copies which are way
overpriced.

~~~
sbr464
Interesting to have an arbitrary $8 price point. You only live once, get the
best!

~~~
gsich
Not my restriction.

------
maxk42
Installed a CO2 monitor in my home two days ago. Already changed my life. It
warns me when I need additional ventilation and even beeps if CO2 levels raise
too high.

It sounds silly but it's scary how quickly levels rise when the windows are
closed.

~~~
coldtea
> _It sounds silly but it 's scary how quickly levels rise when the windows
> are closed._

It might be scary, but is it actually dangerous? It could just be that the
levels shown, even if raised, are inconsequential.

Basically wondering about the "Already changed my life" line.

Are we all without one risk certain CO2 death every day, or is the parent
overly worried over nothing (and opens windows without really a need for it).

~~~
bemmu
Higher ppm decreases cognitive function even at pretty low levels, so being
alerted to open your window might improve your work / study.

There's at least this study:
[https://ehp.niehs.nih.gov/doi/10.1289/ehp.1510037](https://ehp.niehs.nih.gov/doi/10.1289/ehp.1510037)

And this video has the quote "At 1000ppm there is a 15% decrease in cognitive
function".
[https://www.youtube.com/watch?v=1Nh_vxpycEA](https://www.youtube.com/watch?v=1Nh_vxpycEA)

~~~
Reason077
_" At 1000ppm there is a 15% decrease in cognitive function"_

In a century or so we could be looking at similar CO2 levels in the atmosphere
if we don’t significantly cut emissions.

Will our decencents be made stupider by higher CO2 levels? Or will they be
able to adapt?

~~~
drankula3
My wife is a respiratory therapist. When asked, she said higher-than-average
CO2 is seen in COPD patients, and is compensated through an increase in
metabolic bicarbonate production, countering the acidic properties of CO2. We
are still entering unknown territories with such large populations getting
exposed to higher CO2 levels, but she thinks we'll be fine.

~~~
thinkcontext
I'm having trouble recounciling that with the study that shows cognitive
decline, can you explain your wife's thinking?

~~~
TremendousJudge
Maybe it means that if you are _always_ exposed to high CO2 your body adjusts,
but if you are sporadically exposed it does not? Kind of like living in the
mountains vs going there occasionally

~~~
heavenlyblue
>> adjusts

Only true if adjustment isn’t giving up higher functioning of the body for a
less efficient metabolism.

~~~
Bartweiss
Fortunately, we're really good at compensating for blood acidification. It's
offset with higher bicarbonate levels and more excretion, which means the
reaction uses carbonic acid and hydrogen to offset carbonic acid - pretty low-
consequence to produce. Having more bicarbonate raises calcium and potassium
levels slightly, but even when it's way outside of any normal exposure it
doesn't seem to cause further effects.

------
wyldfire
This device's manufacturer claims an accuracy of "± 100ppm or ± 7% of
reading".

But there's a review on Amazon that describes someone getting three units and
finding as much as 600ppm variation among them.

Maybe they need some kind of calibration or tuning? Or their manufacturing
process is way out of control.

~~~
detaro
They have a calibration feature, of course most of the reviews fail to mention
if the person understood how it worked and used it. (I personally find the
mechanism a bit odd, but I guess it makes some sense if you assume some things
about the environment)

------
Waterluvian
I'm looking around for an affordable household CO2 measurement tool but
they're all wildly expensive. Is this technology complicated and cannot be
obtained for $30? They're all like $120+

Edit: I realised that this is a _perfect_ item for public libraries to loan
out. Expensive, only needed occasionally, easy to use, potential for
significant positive public impact on becoming more informed and healthier.

If you're looking for a cause that's affordable, practical, and local,
consider buying and donating one to your local library.

~~~
gsich
MH-Z14 or Z19. But this is just the sensor, you'll need an Arduino/ESP/Rpi
too.

~~~
AYBABTME
What's particular about these sensors? I've been researching technologies to
monitor plant growth and haven't yet looked into CO2 sensors, hence my asking.
Do they come in an IC package?

~~~
gsich
They use optical measurement, are reasonable in pricing. Outputs are UART, PWM
and analoge.

They have pins with 2.54mm spacing if that helps you.

~~~
AYBABTME
Would you use something else if you meant to solder something on a PCB for
medium scale production?

~~~
gsich
Don't know. There are chemical sensor with a heating element, but those
usually suck.

------
jamisteven
No story behind the build, just a link to the git repo? yay

~~~
stackmad
You can only put link + title on here. And the story is rather boring :) I
wanted to measure it, I got a device from amazon, found a python script to
read the data, the dependencies (pyhidapi) always sigfaulted, so I wrote my
own :)

~~~
WilliamEdward
Why do you need a script for this? Isn't the device good enough at telling you
the bare necessary information?

Still a cool script nonetheless, no hate.

~~~
stackmad
Sure, but I wanted to see the data over time. And I was bored :)

------
thinkcontext
Sounds like you have a ventilation problem, buildings are required by code to
get a certain amount of fresh air from outside so that CO2, VOCs, chloroform,
etc don't get too high.

Incidentally, NHTSA projects in 2100 CO2 will be at 789ppm [0] in the
atmosphere, up from 410 today and 350 pre-industrial. And there are higher
projections. One would assume that this would make ventilation more urgent, I
guess building codes will have to be updated and existing buildings
retrofitted.

[0] [https://www.washingtonpost.com/national/health-
science/trump...](https://www.washingtonpost.com/national/health-
science/trump-administration-sees-a-7-degree-rise-in-global-temperatures-
by-2100/2018/09/27/b9c6fada-bb45-11e8-bdc0-90f81cc58c5d_story.html)

------
ody4242
Whats wrong with this one? (it works with the same device)
[https://github.com/larsp/co2monitor](https://github.com/larsp/co2monitor)

~~~
stackmad
That looks good as well! I actually didn't know about that project. It
wouldn't have worked on my specific case though since I wanted it connected to
my Mac, that tool only works on Linux.

~~~
e12e
The Mac doesn't provide a device to read from? Because beyond that, it should
be pretty similar (posix-ish and golang)?

~~~
stackmad
Yeah, you have to use IOKit, which hidapi wraps.

------
Sujan
Anyone know other, possibly cheaper, devices besides
[https://www.co2meter.com/products/co2mini-co2-indoor-air-
qua...](https://www.co2meter.com/products/co2mini-co2-indoor-air-quality-
monitor) that can display current CO2?

I hoped there would be cheaper versions on Aliexpress, but no luck :(

~~~
Heliosmaster
MH-Z19 is a sensor on sale on Aliexpress for ~20 USD. It works with Arduino
and ESP32

------
jakobegger
Why are there steps in the CO2 levels?

~~~
johndough
Since this is based on a reverse-engineered binary protocol and since the step
sizes are reasonably close to 64 and 128, I'd guess it's a bug.

~~~
CamperBob2
It looks like there's no need to reverse-engineer the protocol:

[https://www.co2meter.com/products/co2mini-co2-indoor-air-
qua...](https://www.co2meter.com/products/co2mini-co2-indoor-air-quality-
monitor)

------
Leandros
Unrelated to the project, but your CO2 levels are far to high. The maximum
should be around 600ppm.

~~~
stackmad
Yes, I agree. I've already ordered a bunch of plants :) Sadly my building is
quite old and ventilation is poor.

~~~
Joakal
I heard that you would need about 40(?) plants per person. Best advice was to
be well ventilated unless the outdoor CO2 is worse than indoors.

~~~
antisthenes
You literally can't have enough plants in the house to compensate for the CO2
production of its inhabitants.

You would have to place water immersed algae farms on every open space in the
house and keep them illuminated with artificial light 24/7, because plants
will produce CO2 at night otherwise.

Like you said, good ventilation is far more effective than any plant.

------
rhcom2
I wanted to do this in my office and was told, "if we find out something is
wrong then we'd have to fix it." _facepalm_

~~~
cherrypepsi
I think it's safe to say CO2 levels in your office are already over the limit
with coworkers making arguments like that lol

The company saved $25 though!

------
blrhg
I am new to this one. I always wonder about accuracy. I think it depends on
where you place your sensor in the room matters. If it is in place where lot
of window air is hitting, it might alter the values. Or am I completely wrong?
Or are you using multiple devices to get the average of those devices?

~~~
stackmad
Yes, absolutely. I only have one device at the moment, but it sure would be
interesting to see how fast the levels equalize between rooms

------
starbugs
Friend of stackmad here. Just wanted to let you know that he got himself a
plant as a result of the CO2 measurements :)

~~~
stackmad
Actually its 9 plants ;)

------
edoo
Architecturally speaking this should be a super simple script that pulls the
sensor data into a database for any use instead of a custom written http
server that manages the sensor.

~~~
stackmad
Yes, I agree. But this was way more fun :)

------
benbristow
Isn't C++ a bit overkill for a web app?

~~~
qzy
You are right, C++ is overkill. It would be much better if it was a javascript
application with thousands of dependencies.

~~~
jordache
ahh so you're in the camp of wanting to re-create a graphing library for every
project..

~~~
WrtCdEvrydy
ahh so you're in the camp of outsourcing your development cost to the user's
hardware.

------
linuxlizard
I've been using the Microsoft cpprestsdk, too, but for client stuff. I've been
enjoying using it.

~~~
stackmad
Yeah, its quite ok.

------
tobyhinloopen
that thermostat is working pretty well, keeping the temperature stable like
that

~~~
stackmad
Yeah, I've finally managed to tweak the thermostat on the radiators and the
main thermostat for the heater to where I like it :)

------
akuji1993
I'd improve the ticks on the x-Axis a bit. Otherwise looks fine to me.

~~~
stackmad
Yeah, that was pretty quickly hacked together :)

------
khaki54
@dhh highly recommends Awair for air quality monitoring. He gave some talk on
it after be bought one for his whole staff (can't find the talk for some
reason)

I got one and it's pretty cool. A bit of a game to get a high score.

------
jackallis
what is the baseline for CO2 on certain Sq.ft?

~~~
stackmad
I guess it should match the outside air as close as possible. So around 400ppm

------
anoncake
I believe the title should be "I wanted to build a C++ WebServer/App, so I
built a C++ WebServer/App".

Not that there anything wrong with that :)

~~~
stackmad
:) But the CO2 measurement part honestly came first.

