mstenta / atmospi

Atmospheric monitoring app for logging and graphing temperatures and humidities over time using a Raspberry Pi and DS18B20, DHT11, DHT22, and AM2302 sensor(s).
31 stars 9 forks source link

Missing information to run atmospi it from the browser #11

Closed aukeboskma closed 10 years ago

aukeboskma commented 10 years ago

I installed atmospi automaticly through puppet what worked great by the way. But I don't know how to see the logs and graphs in the browser. Can you please tell me how to get that working?

Thanks Auke

mstenta commented 10 years ago

Sure! Assuming your Raspberry Pi is connected to your local network router, and has an IP address, all you should have to do is go to http://[ip-address]/ in your browser, and the Atmospi graph should appear. If that isn't working, then perhaps something else is wrong. Let me know, and I'd be happy to help debug.

aukeboskma commented 10 years ago

Mmh, i did a fresh install of Raspbian tonight and the automatic install through puppet but I only get the "It works" page from apache when I go to the ip adres in the browser. What can it be?

mstenta commented 10 years ago

It sounds like the Apache virtual host was not set up correctly by the Puppet script. Either that, or Apache was not restarted. Both are taken care of by the Puppet script, but maybe something went wrong.

Try restarting Apache first (sudo apache2ctl restart)... that's easy to try and maybe will solve it.

If that doesn't work, check to see if the virtual host symlink was created. It should exist as /etc/apache2/sites-enabled/atmospi, which is a symlink to /home/pi/atmospi/atmospi.vhost (make sure this file is there too).

aukeboskma commented 10 years ago

That was my first thought as well. I restarted Apache (I only got a warning: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName). And I tried "readlink -f /etc/apache2/sites-enabled/atmospi" Raspbian respond with "/home/pi/atmospi/atmospi.vhost" so that should be right (and the .vhost file is pressent ofcource).

Which file should be served by Apache when I type in the IP-adress in the browser? I found a index file in the template folder. Is that the one?

mstenta commented 10 years ago

OH I think I know what's wrong... I forgot to include this in the documentation...

Apache starts with a Virtual host file in /etc/sites-enabled called "000-default", which takes precedence over the atmospi one because it starts with "000-". There are two possible fixes:

1) If you move the "atmospi" symlink in the Apache sites-enabled folder to be called "000-atmospi" then it should work (restart Apache too).

2) Or, if you create an entry in your /etc/hosts file that links the IP address of the Pi to a hostname of "atmospi"... then you should be able to see the graphs by going to http://atmospi (this only works on the machine that you add a /etc/hosts entry to, however).

Perhaps I should update the Puppet script to automatically name the symlink "000-atmospi"?

Let me know if that works.

mstenta commented 10 years ago

If you're interested in getting commit credit, it's an easy change...

Line 59 of atmospi/puppet/manifests/init.pp should change from:

path => '/etc/apache2/sites-enabled/atmospi',

to:

path => '/etc/apache2/sites-enabled/000-atmospi',

Do you want to fork and create a pull request?

mstenta commented 10 years ago

Thanks for the commit! Did changing the symlink name and restarting Apache solve the issue for you?

Assuming it did, I'm going to close this issue. Reopen if it doesn't...

Thanks for helping!

aukeboskma commented 10 years ago

Thanks for your fast respond. I'm a bit new to linux so figuring out which commands I need to use takes a bit of time. Apache doesn't want to start because of an error

Syntax error on line 5 of /etc/apache2/sites-enabled/atmospi:

So I'm figuring out what I did wrong and how to fix it :)

Thanks for giving me the possibility to earn commit credit

mstenta commented 10 years ago

Ok, well first thing you need to do is move /etc/apache2/sites-enabled/atmospi to /etc/apache2/sites-enabled/000-atmospi

If you ran the Puppet script again to do this, then you probably ended up with TWO virtual host symlinks (because it will not automatically remove the old one). So delete /etc/apache2/sites-enabled/atmospi

Second, did you change anything in the file that it links to (/home/pi/atmospi/atmospi.vhost) ? That shouldn't require any editing, it should just work... unless something else is going on.

aukeboskma commented 10 years ago

Awesome it is working. I removed all the symlinks and added only the symlink to /etc/apache2/sites-enabled/000-atmospi.

Now I need to find out why it doesn't show me measurements :)

Thanks for you time and help.

mstenta commented 10 years ago

Measurements are taken by running one of the sensor scripts automatically via cron, or manually via the command line.

What kind of sensor are you using? DS18B20 temperature? Or DHT11/22 temperature+humidity?

The DS18B20 sensor script is automatically set up in cron via the Puppet script. The DHT11/22 requires more manual setup, unfortunately. See the project README.md for info on how to do that if you need.

Oh, and I just remembered this issue: https://github.com/mstenta/atmospi/issues/8

Sorry, I guess the Puppet script is not 100% done. Still a few manual steps needed...

Go to /home/pi/atmospi, and run the following commands:

First, delete any existing log.db file that may have been created...

sudo rm log.db

Then, create a new log.db file (make sure you're logged in as the "pi" user, not root), and set up the tables and indexes (just copy and paste each line one at a time into the command prompt):

sqlite3 log.db CREATE TABLE Temperature(Device TEXT, Timestamp INT, C REAL, F REAL); CREATE TABLE Humidity(Device TEXT, Timestamp INT, H REAL); CREATE TABLE Flag(Device TEXT, Timestamp INT, Value TEXT); CREATE INDEX temperature_timestamp ON Temperature(Timestamp); CREATE INDEX humidity_timestamp ON Humidity(Timestamp); CREATE INDEX flag_timestamp ON Flag(Timestamp); CREATE INDEX temperature_device ON Temperature(Device); CREATE INDEX humidity_device ON Humidity(Device); CREATE INDEX flag_device ON Flag(Device); .exit

Then, run the measurement script manually, and check the graph to see if it worked:

sudo /home/pi/atmospi/Atmospi/measure-ds18b20.py

Hope that helps!

mstenta commented 10 years ago

Oops, the line breaks were not preserved in that last comment... see the README.md file for the commands I was trying to paste.

aukeboskma commented 10 years ago

While trying to create the tables I get this error: Error: database or disk is full

free -h shows me that there is more than enough.. total used free shared buffers cached Mem: 437M 162M 274M 0B 8,6M 48M -/+ buffers/cache: 105M 331M Swap: 99M 0B 99M

mstenta commented 10 years ago

Hmm, did you delete the log.db file that was there before? If not, then it could be that the file is owned by root, when it should be owned by "pi". Delete the log.db file and try again.

aukeboskma commented 10 years ago

Yes I did delete the log.db as you said. I also tried it again... without success.

mstenta commented 10 years ago

Oh wait... the "free -h" command shows you free MEMORY... not disk space.

Run df -h and look at the Avail column of the "rootfs" row. What does that tell you?

Maybe you need a bigger SD card in the Pi? How big is it? I am running my Atmospis on 4gb cards. Are you doing anything else with the Pis? Or just dedicating them to Atmospi?

aukeboskma commented 10 years ago

Damn that's stupid..

It shows me 100%, so yes its full indeed. I'm using also a 4GB card and it is also only dedicated to Atmospi. I installed rasbian with noobs.

mstenta commented 10 years ago

Did you "expand the filesystem" after installing Raspbian?

If so, maybe NOOBS uses more space... I usually just flash Rasbian to the card directly.

aukeboskma commented 10 years ago

After diner I will install Raspbian directly on a 8GB card. That will fix the problem for sure.

aukeboskma commented 10 years ago

I used an 8GB card this time and re-installed Raspbian. I was able to add the tables to the database but still no data visible in the browser.

mstenta commented 10 years ago

Ok great! So by default, the DS18B20 sensor script (which reads from the sensor and writes to log.db) is run via cron every 5 minutes.

You can also run it manually with:

sudo /home/pi/atmospi/Atmospi/measure-ds18b20.py

Try running it manually to see if that gives you the first data point in the graph. Hopefully it does. Then you can wait for the 5 minute mark and see if another point was added automatically. Then you're off and running!

aukeboskma commented 10 years ago

Mmh I tried that but doesn't give me anything on the graph. Or shall I just have some patient :) 94 212 120 98

mstenta commented 10 years ago

Hmm, it looks like something's going wrong in the Flask app when temperature and humidity data is being requested. See screenshot of warnings in Chrome: http://i.imgur.com/Od8xIL1.png

mstenta commented 10 years ago

Questions:

  1. Do you get any errors when you run measure-ds18b20.py?
  2. Can you confirm that data is going into log.db? Run the following commands, and tell me what you get:

sqlite3 /home/pi/atmospi/log.db SELECT * FROM Temperature;

  1. Is log.db owned by "pi" or by "root"?
aukeboskma commented 10 years ago

Okay.

The first time I run measure-ds18b20.py I got no response but not i'm getting "Error no such table: Temperature.

When try to read the table I get "Error: no such table : Temperature

But when I try to make that table I get "Error: table Temperature already exitsts.

I deleted the db and build it up again, same result.

aukeboskma commented 10 years ago

what about write permissions..

mstenta commented 10 years ago

No response is what you want. If you see an error then something is wrong.

Who is the owner of the file? The "pi" user? And what are the permissions on it?

aukeboskma commented 10 years ago

jup it is owned by root. Write only permissions.

mstenta commented 10 years ago

Ah ha! I mentioned that in a previous comment: https://github.com/mstenta/atmospi/issues/11#issuecomment-58366373

Working for you now? :-)

aukeboskma commented 10 years ago

Damn I was deleting log.db but I should have worked in the /home/pi/atmospi/ folder.

I see readings now. Now I only need to change the measurements to Celcius because I'm from Europe ;-)

Thank you so much for your help and fast responses. In a few week i'm going to add the humidity sensors. I hope that is easy enough for me hehe.

mstenta commented 10 years ago

Great! Good luck!

Here is a feature request I started for Celcius: https://github.com/mstenta/atmospi/issues/5

The Celsius readings are being stored in the database, so it's really just a matter of showing those instead of the Fahrenheit. But ultimately it needs to be configurable in settings.py so people can set the default.

janvdbeek commented 9 years ago

Hi all, I installed atmospi via puppet and later, when I couldn't get it to work, I installed it manually but still no luck. I get the atmospi webpage but there are no measurement data. When I manually execute measure-ds18b20.py I get the following error message:

Traceback (most recent call last): File "/home/pi/atmospi/Atmospi/measure-ds18b20.py", line 75, in id = db.fetchone () [0] TypeError: 'NoneType' object has no attribute ' getitem '

When I take a look in the database, there is no data, no sensor addresses or whatsoever. I've read this issue and tried a lot of things but i'm stuck. So I think i need some help :-)

Thanks in advance.

mstenta commented 9 years ago

Hey @janvdbeek! You may have found a new bug... that code was changed recently, and maybe it isn't properly detecting new devices.

We should create a new issue to debug it...

In the meantime, I think you can get it to work by manually adding your sensors to the Devices table. You will need to find out the unique address of the sensor you have. Do you know how to do that?

Once you have that address, insert it into the Devices table with the following SQL:

INSERT INTO Devices (DeviceID, Type, SerialID, Label) VALUES(NULL, 'ds18b20', '1234567890', 'Name');

Change "1234567890" to the actual sensor ID, and change "Name" to the name you want to give it.

mstenta commented 9 years ago

I created a new issue here: #27