News for hackers. Stuff that matters.
Re:Show HN: I wanted to measure CO2 in my office, so I build... by benbristow on Friday January 25, 2019 @07:37AM (#18997401)
Isn't C++ a bit overkill for a web app?
Re:Show HN: I wanted to measure CO2 in my office, so I build... by qzy on Friday January 25, 2019 @07:46AM (#18997446)
You are right, C++ is overkill. It would be much better if it was a javascript application with thousands of dependencies.
Re:Show HN: I wanted to measure CO2 in my office, so I build... by drngdds on Friday January 25, 2019 @08:33AM (#18997713)
There are memory-safe languages that aren't Javascript, you know
Re:Show HN: I wanted to measure CO2 in my office, so I build... by jordache on Friday January 25, 2019 @08:11AM (#18997586)
ahh so you're in the camp of wanting to re-create a graphing library for every project..
Re:Show HN: I wanted to measure CO2 in my office, so I build... by WrtCdEvrydy on Friday January 25, 2019 @08:27AM (#18997675)
ahh so you're in the camp of outsourcing your development cost to the user's hardware.
Re:Show HN: I wanted to measure CO2 in my office, so I build... by stackmad on Friday January 25, 2019 @08:01AM (#18997521)
Depends, this was a question I tried to answer for myself with this project. I did not easily find a good library for Python that would work on my Mac for reading the HID messages, so writing the device part in C++ was easier for me ( and an interesting excercise in c++17'ifying C code ). I thought about just having the c++ app be called from python, but wanted to try and see how hard it would be in c++ and found it extremely easy with the cpprestsdk.
Re:Show HN: I wanted to measure CO2 in my office, so I build... by andor on Friday January 25, 2019 @08:11AM (#18997589)
Did you search for... "co2 meter python"? The pypi package called "CO2meter" (https://github.com/vfilimonov/co2meter) not only works well as a library on Mac OS, but also comes with a web-based dashboard:

  $ pip install CO2meter flask pandas
  ...
  $ co2meter_server
Edit: link
Re:Show HN: I wanted to measure CO2 in my office, so I build... by stackmad on Friday January 25, 2019 @08:19AM (#18997636)
Though with your steps it at least starts, but the webserver fails, and CTRL+C doesn't work ^^

   * Serving Flask app "co2meter.server" (lazy loading)
   * Environment: production
     WARNING: Do not use the development server in a production environment.
     Use a production WSGI server instead.
   * Debug mode: off
  INFO:werkzeug: * Running on http://127.0.0.1:1201/ (Press CTRL+C to quit)
  ERROR:flask.app:Exception on / [GET]
  Traceback (most recent call last):
    File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 2292, in wsgi_app
      response = self.full_dispatch_request()
    File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
      rv = self.handle_user_exception(e)
    File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1718, in handle_user_exception
      reraise(exc_type, exc_value, tb)
    File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
      rv = self.dispatch_request()
    File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1799, in dispatch_request
      return self.view_functions[rule.endpoint](**req.view_args)
    File "/usr/local/lib/python2.7/site-packages/co2meter/server.py", line 64, in home
      data = read_logs()
    File "/usr/local/lib/python2.7/site-packages/co2meter/server.py", line 236, in read_logs
      with open(os.path.join('logs', name + '.csv'), 'r') as f:
  IOError: [Errno 2] No such file or directory: 'logs/co2.csv'
  INFO:werkzeug:127.0.0.1 - - [25/Jan/2019 14:18:23] "GET / HTTP/1.1" 500 -
  INFO:werkzeug:127.0.0.1 - - [25/Jan/2019 14:18:23] "GET /favicon.ico HTTP/1.1" 404 -
  ^C^C^C^C
  ^C^C
Re:Show HN: I wanted to measure CO2 in my office, so I build... by andor on Sunday January 27, 2019 @05:38AM (#19011214)
co2meter_server writes measurements to "logs/co2.csv" in the current working directory every 30 seconds or so. As long as there is no measurement, you'll get this error from the web app trying to access the file. Just wait a minute and refresh the page.
Re:Show HN: I wanted to measure CO2 in my office, so I build... by stackmad on Friday January 25, 2019 @08:17AM (#18997622)
That looks great as well! But for some reason the library they use (pyhidapi) would always crash on my Mac.
Re:Show HN: I wanted to measure CO2 in my office, so I build... by sgt on Friday January 25, 2019 @07:39AM (#18997416)
Not necessarily. You see web servers running on microcontrollers all the time and they are mostly written in C.