haydnw / AirPi

A Raspberry Pi air quality station
28 stars 15 forks source link

HTTP Plugin: Several Errors #19

Open Sebb767 opened 9 years ago

Sebb767 commented 9 years ago

Hey there! I'm currently setting up my own AirPi and I'm pretty happy about this fork for having done all the things I'd need to implement myself ;) Thank you!

However, trying to use the http plugin results in serveral errors. They appear in the dev and master branches, my current setup is using the dev branch:

[AirPi] Current installed version and latest change:

commit 4c0341dea64ad26e8a3e1acd6758361dd1a4de3d
Author: Haydn Williams <pi@hwmail.co.uk>
Date:   Sun May 31 19:38:46 2015 +0000
Change: Add clarification to calibration function comments.

(snip)

My outputs.cfg (for http)

[HTTP]
filename = http
enabled = yes
calibration = on
wwwPath = www ; Must be full path if used with AirPi bootstart feature
port = 8080
history = on
historyFile = history.dat
historySize = 2880
historyInterval = 30
historyCalibrated = false
title = AirPi - <hostname>
about = This is an AirPi pollution / air quality monitoring device.
#target = internet
target = lan

Trying to simply use the http plugin throws the following error:

{'historyCalibrated': False, 'historyFile': 'history.dat', 'about': 'This is an AirPi pollution / air quality monitoring device.', 'historyInterval': '30', 'target': 'lan', 'limits': False, 'calibration': True, 'title': 'AirPi - <hostname>', 'history': True, 'historySize': '2880', 'httpVersion': False, 'wwwPath': 'www', 'port': '8080', 'metadata': False}
done first bit
done second bit
done third bit
starting hostname
starting title et al.
ERROR:   Failed to import plugin HTTP: global name 'calibration' is not defined

I solved that one myself by adding a simple import calibration at the start of the file. With that, the http plugin loads, but trying to access the site gives me the following error:

----------------------------------------
Exception happened during processing of request from ('192.168.2.112', 52948)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 649, in __init__
    self.handle()
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request
    method()
  File "/home/pi/AirPi/outputs/http.py", line 333, in do_GET
    page = replace(page, "$time$", self.server.httpoutput.lastUpdate)
AttributeError: 'HTTP' object has no attribute 'lastUpdate'
----------------------------------------

This happens no matter if the sampling has actually started or not. I fixed it by replacing self.server.httpoutput.lastUpdate with the current time, but this yields the following error:

----------------------------------------
Exception happened during processing of request from ('192.168.2.112', 52955)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 649, in __init__
    self.handle()
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request
    method()
  File "/home/pi/AirPi/outputs/http.py", line 336, in do_GET
    for i in self.server.httpoutput.data:
AttributeError: 'HTTP' object has no attribute 'data'
----------------------------------------

I'm assuming that the sample data isn't send to the http output module, but since my understanding of the projects code (and, well, python) is very shallow, I can't fix this on my own. Any ideas?

I'll maybe try an older commit until this is fixed.

Update: Reverting to commit/version 1.0 didn't fix this :/ (it did fix the import however)

haydnw commented 9 years ago

I think the HTTP output plugin needs to be moved to the new architecture seen in recent commits (where the specific plugin inherits from the Output plugin object, which inherits from the Plugin object). I will address this in a future release.

haydnw commented 9 years ago

Also worth noting that I have no idea about the final error I'm afraid (Exception happened during processing of request from ('192.168.2.112', 52955)).

Sebb767 commented 9 years ago

It really looks like the data isn't supplied to the webserver. The second error is defacto the same problem, but I fixed it by using a newly generated date (because I was thinking that only this field is missing).

Rolling back to V1.0 didn't help, which seems quite strange, since issues indicate that the plugin was/is working for others. It's a pretty fresh Raspian install, so I don't think that a tainted system is the cause. I'll do a completly fresh clone soon to exclude my cfg's as the cause.

pa2eon commented 9 years ago

Have also the same problem with the HTTP Output, on a fresh install of the AirPi software. The error will be: ERROR: Failed to import plugin HTTP: global name 'calibration' is not defined I have no idea where to setup the calibration information. Will it be a good idea to give a small doc file to setup the HTTP plugin .. so we can follow all the same setups to find the error ?

haydnw commented 9 years ago

Please see earlier comment - it's just that HTTP hasn't been updated following a change in architecture, i.e. refactoring the Output class and adding abstract methods. This will be fixed in a future release.

All other output plugins have been migrated, so if anyone wants to have a go at fixing, just compare the same output plugin between two commits (take a look at the commit comments to see when each output plugin has been migrated) and make the same set of changes to HTTP.

Sebb767 commented 9 years ago

You can actually fix your error by adding a import calibration at the top of the file - but all bets are that you will face the same errors I posted above. I'd really like to fix all this, but unfortunatly my time (and python knowledge) is limited :/

haydnw commented 9 years ago

Partial fix contained within 6a047b6 - now works as long as calibration and historyCalibrated in cfg/outputs.cfg are set to false.

If either option is enabled then the problem is the same as that described by @Sebb767 at the end of the initial bug report. I have no idea what the problem with enabling these is, and the HTTP output is a low priority for me because it's very complex and I never use it. Anyone who can offer a fix is welcome to submit a pull request.

Sebb767 commented 9 years ago

Had some time to test again today and noticed something strange - the plugin still crashed despite the fix. This was caused by the JSON/CSV output which used the calibrated option.

It can be easily fixed however by moving the config entrys below the http one to make them load after the http plugin or by disabling them.