zefanja / aqi

Measure AQI based on PM2.5 or PM10 with a Raspberry Pi and a SDS011 particle sensor
GNU General Public License v3.0
94 stars 46 forks source link

Json and other errors when running your code #2

Closed Blkprometheus closed 5 years ago

Blkprometheus commented 5 years ago

I'm using your code based on the instructions in this article, "https://openschoolsolutions.org/measure-particulate-matter-with-a-raspberry-pi/". I'm using a Raspberry PI 3 running Raspbian Stretch Lite and Python 2.7.x. with this sensor, Particulates sensor SDS011. When I run aqi.py from the command prompt, after about a minute of running I get this error, "pi@raspberrypi:~ $ ./aqi.py PM2.5: 227.6 , PM10: 261.4 PM2.5: 228.1 , PM10: 260.1 PM2.5: 230.4 , PM10: 262.4 PM2.5: 228.5 , PM10: 259.2 PM2.5: 230.1 , PM10: 259.6 PM2.5: 231.4 , PM10: 260.8 PM2.5: 232.9 , PM10: 261.9 PM2.5: 233.3 , PM10: 262.3 PM2.5: 232.4 , PM10: 261.4 PM2.5: 231.4 , PM10: 259.9 PM2.5: 228.6 , PM10: 256.8 PM2.5: 226.2 , PM10: 254.3 PM2.5: 225.5 , PM10: 253.9 PM2.5: 224.4 , PM10: 252.3 PM2.5: 225.4 , PM10: 253.2 Traceback (most recent call last): File "./aqi.py", line 110, in data = json.load(json_data) File "/usr/lib/python2.7/json/init.py", line 291, in load **kw) File "/usr/lib/python2.7/json/init.py", line 339, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded".

When I access the Raspberry Pi from a browser, at first I see the AQI (PM2.5) and AQI (PM10) boxes at the top of the page, but nothing else. After a few minutes these messages are displayed on the website, --2018-10-08 02:21:34-- https://raw.githubusercontent.com/zenfanja/aqi/master/html/index.h Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ... Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected. HTTP request sent, awaiting response... 404 Not Found 2018-10-08 02:21:34 ERROR 404: Not Found.

Any ideas on how I can resolve these issues?

Thanks,

David Lynum

jimbob666 commented 5 years ago

Hey David - Where are you in the world with PM number so high? Mine are normally under 30 and under 10 in most cases.

wallarug commented 5 years ago

Hey @Blkprometheus (David),

I am not sure what your exact issue is, however, the tutorial did contain a small error that I thought I would let you know about.

Solution One

The tutorial instructions have a small error on them where the directory for your HTML file has an extra "w". The instructions should read:

Section: Reading data on the Raspberry Pi

$ sudo chown pi:pi /var/www/html/
$ echo[] > /var/www/html/aqi.json

Section: HTML page for display of measured values and AQI

$ wget -O /var/www/html/index.html https://raw.githubusercontent.com/zefanja/aqi/master/html/index.html
$ wget -O /var/www/html/aqi.js https://raw.githubusercontent.com/zefanja/aqi/master/html/aqi.js
$ wget -O /var/www/html/style.css https://raw.githubusercontent.com/zefanja/aqi/master/html/style.css

There is a potential that you may have an issue relating to the above incorrect directory. It sounds like that instead of downloading the file correctly, you have instead copied the error into the HTML file.

Solution Two

Another possibility is that you have not set the correct permissions on the files. I would highly recommend that you issue the below command on all the files to ensure that the aqi.py program is able to access them all.

$ chmod +x aqi.py
$ chmod 755 /var/www/html/aqi.json
$ chmod 755 /var/www/html/aqi.hml

...and any other files associated with the project.

Let us know how you go.

I am also interested in what City you are in. You're numbers are absolutely crazy high! as pointed out by @jimbob666

ahabandfedallah commented 5 years ago

I had this issue as well, and I realized it was because I entered the ECHO command incorrectly.

The instructions should read (note the space between echo and the square brackets)

echo [] > /var/www/html/aqi.json

Not placing the space will render an error with the echo command. Removing the brackets will not give you the correct thing to echo.

Blkprometheus commented 5 years ago

Hi,

Sorry for the very late reply. My PM numbers are high because the testing was inside of my apartment. I think that the air conditioning filters need to be cleaned or replaced. I live in Atlanta, GA. I'll check both of your solutions to see if they work for me.

Thanks a lot,

David Lynum

On Sun, Nov 18, 2018 at 5:20 AM wallarug notifications@github.com wrote:

Hey @Blkprometheus https://github.com/Blkprometheus (David),

I am not sure what your exact issue is, however, the tutorial did contain a small error that I thought I would let you know about. Solution One

The tutorial instructions have a small error on them where the directory for your HTML file has an extra "w". The instructions should read:

Section: Reading data on the Raspberry Pi

$ sudo chown pi:pi /var/www/html/ $ echo[] > /var/www/html/aqi.json

Section: HTML page for display of measured values and AQI

$ wget -O /var/www/html/index.html https://raw.githubusercontent.com/zefanja/aqi/master/html/index.html $ wget -O /var/www/html/aqi.js https://raw.githubusercontent.com/zefanja/aqi/master/html/aqi.js $ wget -O /var/www/html/style.css https://raw.githubusercontent.com/zefanja/aqi/master/html/style.css

There is a potential that you may have an issue relating to the above incorrect directory. It sounds like that instead of downloading the file correctly, you have instead copied the error into the HTML file. Solution Two

Another possibility is that you have not set the correct permissions on the files. I would highly recommend that you issue the below command on all the files to ensure that the aqi.py program is able to access them all.

$ chmod +x aqi.py $ chmod 755 /var/www/html/aqi.json $ chmod 755 /var/www/html/aqi.hml

...and any other files associated with the project.

Let us know how you go.

I am also interested in what City you are in. You're numbers are absolutely crazy high! as pointed out by @jimbob666 https://github.com/jimbob666

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zefanja/aqi/issues/2#issuecomment-439681916, or mute the thread https://github.com/notifications/unsubscribe-auth/ApLzmSy-tvaFE8sJJHTgmXflT4p5UZmqks5uwTR3gaJpZM4XWFmN .

zefanja commented 5 years ago

@Blkprometheus Could you resolve your problem?

Blkprometheus commented 5 years ago

Yes, I used both solutions, just in case, and my problem was resolved. Thank you for your help.