From 44d9bff9c2ea6faa84f722b44f8882b318b98956 Mon Sep 17 00:00:00 2001 From: Goran Mahovlic Date: Thu, 5 Mar 2015 21:00:15 +0100 Subject: [PATCH 01/10] Update outputs.cfg testing Thingspeak --- outputs.cfg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/outputs.cfg b/outputs.cfg index 6326dba..0785ec0 100644 --- a/outputs.cfg +++ b/outputs.cfg @@ -7,3 +7,7 @@ filename=xively enabled=on APIKey=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY FeedID=XXXXXXXXXX + +[Thingspeak] +filename=Thingspeak +enabled=on From 36b63e2a90dbd4d677c8ad4aa06e41e021c9ca93 Mon Sep 17 00:00:00 2001 From: Goran Mahovlic Date: Thu, 5 Mar 2015 21:02:43 +0100 Subject: [PATCH 02/10] Update and rename outputs to outputs/Thingspeak.py Pushing data to Thingspeak --- outputs/Thingspeak.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 outputs/Thingspeak.py diff --git a/outputs/Thingspeak.py b/outputs/Thingspeak.py new file mode 100644 index 0000000..95772d4 --- /dev/null +++ b/outputs/Thingspeak.py @@ -0,0 +1,28 @@ +#Pushing data to Thingspeak +# python + +import output +import datetime +import httplib, urllib + +class Print(output.Output): + requiredData = [] + optionalData = [] + def __init__(self,data): + pass + def outputData(self,dataPoints): + Data[] + print "" + print "Time: " + str(datetime.datetime.now()) + for i in dataPoints: + Data[i] = str(i["value"]) + print i["name"] + ": " + str(i["value"]) + " " + i["symbol"] + return True + params = urllib.urlencode({'field1': Data[0], 'field2': Data[1],'field3': Data[2],'field4': Data[3], 'field5': Data[4],'field6': Data[5],'field7': Data[6],'field8': Data[7],'key':'34WTPBE2DXIESA5E'}) + headers = {"Content-type": "application/x-www-form-urlencoded","Accept":"text/plain"} + conn = httplib.HTTPConnection("api.thingspeak.com:80") + conn.request("POST", "/update", params, headers) + response = conn.getresponse() + print response.status, response.reason + data = response.read() + conn.close() From 1c2181a112f93567d2b00ad1243cc8434de4a1fe Mon Sep 17 00:00:00 2001 From: Goran Mahovlic Date: Thu, 5 Mar 2015 21:06:29 +0100 Subject: [PATCH 03/10] Update Thingspeak.py Try1 --- outputs/Thingspeak.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/outputs/Thingspeak.py b/outputs/Thingspeak.py index 95772d4..0d9eb5f 100644 --- a/outputs/Thingspeak.py +++ b/outputs/Thingspeak.py @@ -11,18 +11,19 @@ class Print(output.Output): def __init__(self,data): pass def outputData(self,dataPoints): - Data[] - print "" - print "Time: " + str(datetime.datetime.now()) - for i in dataPoints: - Data[i] = str(i["value"]) - print i["name"] + ": " + str(i["value"]) + " " + i["symbol"] + Data[] + print "" + #print "Time: " + str(datetime.datetime.now()) + for i in dataPoints: + Data[i] = str(i["value"]) + # print i["name"] + ": " + str(i["value"]) + " " + i["symbol"] + printData[i] return True - params = urllib.urlencode({'field1': Data[0], 'field2': Data[1],'field3': Data[2],'field4': Data[3], 'field5': Data[4],'field6': Data[5],'field7': Data[6],'field8': Data[7],'key':'34WTPBE2DXIESA5E'}) - headers = {"Content-type": "application/x-www-form-urlencoded","Accept":"text/plain"} - conn = httplib.HTTPConnection("api.thingspeak.com:80") - conn.request("POST", "/update", params, headers) - response = conn.getresponse() - print response.status, response.reason - data = response.read() - conn.close() + params = urllib.urlencode({'field1': Data[0], 'field2': Data[1],'field3': Data[2],'field4': Data[3], 'field5': Data[4],'field6': Data[5],'field7': Data[6],'field8': Data[7],'key':'34WTPBE2DXIESA5E'}) + headers = {"Content-type": "application/x-www-form-urlencoded","Accept":"text/plain"} + conn = httplib.HTTPConnection("api.thingspeak.com:80") + conn.request("POST", "/update", params, headers) + response = conn.getresponse() + print response.status, response.reason + data = response.read() + conn.close() From 19a544f7156f99a07e61fa28d12684013ff93491 Mon Sep 17 00:00:00 2001 From: Goran Mahovlic Date: Thu, 5 Mar 2015 21:07:48 +0100 Subject: [PATCH 04/10] Update Thingspeak.py --- outputs/Thingspeak.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outputs/Thingspeak.py b/outputs/Thingspeak.py index 0d9eb5f..3f2e63f 100644 --- a/outputs/Thingspeak.py +++ b/outputs/Thingspeak.py @@ -17,7 +17,7 @@ def outputData(self,dataPoints): for i in dataPoints: Data[i] = str(i["value"]) # print i["name"] + ": " + str(i["value"]) + " " + i["symbol"] - printData[i] + print Data[i] return True params = urllib.urlencode({'field1': Data[0], 'field2': Data[1],'field3': Data[2],'field4': Data[3], 'field5': Data[4],'field6': Data[5],'field7': Data[6],'field8': Data[7],'key':'34WTPBE2DXIESA5E'}) headers = {"Content-type": "application/x-www-form-urlencoded","Accept":"text/plain"} From 081096042d45023c09c7ba03f4d4cb64cad58ad9 Mon Sep 17 00:00:00 2001 From: Goran Mahovlic Date: Thu, 5 Mar 2015 21:11:57 +0100 Subject: [PATCH 05/10] Update Thingspeak.py Add APIKey --- outputs/Thingspeak.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/outputs/Thingspeak.py b/outputs/Thingspeak.py index 3f2e63f..a144225 100644 --- a/outputs/Thingspeak.py +++ b/outputs/Thingspeak.py @@ -6,10 +6,11 @@ import httplib, urllib class Print(output.Output): - requiredData = [] + requiredData = ["APIKey"] optionalData = [] def __init__(self,data): - pass + self.APIKey=data["APIKey"] +# pass def outputData(self,dataPoints): Data[] print "" @@ -19,7 +20,7 @@ def outputData(self,dataPoints): # print i["name"] + ": " + str(i["value"]) + " " + i["symbol"] print Data[i] return True - params = urllib.urlencode({'field1': Data[0], 'field2': Data[1],'field3': Data[2],'field4': Data[3], 'field5': Data[4],'field6': Data[5],'field7': Data[6],'field8': Data[7],'key':'34WTPBE2DXIESA5E'}) + params = urllib.urlencode({'field1': Data[0], 'field2': Data[1],'field3': Data[2],'field4': Data[3], 'field5': Data[4],'field6': Data[5],'field7': Data[6],'field8': Data[7],'key':self.APIKey}) headers = {"Content-type": "application/x-www-form-urlencoded","Accept":"text/plain"} conn = httplib.HTTPConnection("api.thingspeak.com:80") conn.request("POST", "/update", params, headers) From 956751e6410b202d7cbf5274ea9499cbdfb4e06a Mon Sep 17 00:00:00 2001 From: Goran Mahovlic Date: Thu, 5 Mar 2015 21:13:09 +0100 Subject: [PATCH 06/10] Update outputs.cfg Add APIKey --- outputs.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/outputs.cfg b/outputs.cfg index 0785ec0..7dc2bba 100644 --- a/outputs.cfg +++ b/outputs.cfg @@ -11,3 +11,4 @@ FeedID=XXXXXXXXXX [Thingspeak] filename=Thingspeak enabled=on +APIKey=34WTPBE2DXIESA5E From 2ae988ce69851030648f75af9558b23d34f8a248 Mon Sep 17 00:00:00 2001 From: Goran Mahovlic Date: Thu, 5 Mar 2015 21:35:54 +0100 Subject: [PATCH 07/10] Update Thingspeak.py --- outputs/Thingspeak.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/outputs/Thingspeak.py b/outputs/Thingspeak.py index a144225..9a9a486 100644 --- a/outputs/Thingspeak.py +++ b/outputs/Thingspeak.py @@ -12,19 +12,19 @@ def __init__(self,data): self.APIKey=data["APIKey"] # pass def outputData(self,dataPoints): - Data[] - print "" + Data[] + #print "" #print "Time: " + str(datetime.datetime.now()) - for i in dataPoints: - Data[i] = str(i["value"]) - # print i["name"] + ": " + str(i["value"]) + " " + i["symbol"] - print Data[i] + for i in dataPoints: + Data[i] = str(i["value"]) + # print i["name"] + ": " + str(i["value"]) + " " + i["symbol"] + print Data[i] return True - params = urllib.urlencode({'field1': Data[0], 'field2': Data[1],'field3': Data[2],'field4': Data[3], 'field5': Data[4],'field6': Data[5],'field7': Data[6],'field8': Data[7],'key':self.APIKey}) - headers = {"Content-type": "application/x-www-form-urlencoded","Accept":"text/plain"} - conn = httplib.HTTPConnection("api.thingspeak.com:80") - conn.request("POST", "/update", params, headers) - response = conn.getresponse() - print response.status, response.reason - data = response.read() - conn.close() + params = urllib.urlencode({'field1': Data[0], 'field2': Data[1],'field3': Data[2],'field4': Data[3], 'field5': Data[4],'field6': Data[5],'field7': Data[6],'field8': Data[7],'key':self.APIKey}) + headers = {"Content-type": "application/x-www-form-urlencoded","Accept":"text/plain"} + conn = httplib.HTTPConnection("api.thingspeak.com:80") + conn.request("POST", "/update", params, headers) + response = conn.getresponse() + print response.status, response.reason + data = response.read() + conn.close() From 4d3f15170220c634ce554eb70b66940894236c86 Mon Sep 17 00:00:00 2001 From: Goran Mahovlic Date: Thu, 5 Mar 2015 23:48:49 +0100 Subject: [PATCH 08/10] Update Thingspeak.py Tested working version --- outputs/Thingspeak.py | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/outputs/Thingspeak.py b/outputs/Thingspeak.py index 9a9a486..227abd7 100644 --- a/outputs/Thingspeak.py +++ b/outputs/Thingspeak.py @@ -5,26 +5,23 @@ import datetime import httplib, urllib -class Print(output.Output): - requiredData = ["APIKey"] - optionalData = [] - def __init__(self,data): - self.APIKey=data["APIKey"] -# pass - def outputData(self,dataPoints): - Data[] - #print "" - #print "Time: " + str(datetime.datetime.now()) - for i in dataPoints: - Data[i] = str(i["value"]) - # print i["name"] + ": " + str(i["value"]) + " " + i["symbol"] - print Data[i] - return True - params = urllib.urlencode({'field1': Data[0], 'field2': Data[1],'field3': Data[2],'field4': Data[3], 'field5': Data[4],'field6': Data[5],'field7': Data[6],'field8': Data[7],'key':self.APIKey}) - headers = {"Content-type": "application/x-www-form-urlencoded","Accept":"text/plain"} - conn = httplib.HTTPConnection("api.thingspeak.com:80") - conn.request("POST", "/update", params, headers) - response = conn.getresponse() - print response.status, response.reason - data = response.read() - conn.close() +class ThingSpeak(output.Output): + requiredData = ["APIKey"] + optionalData = [] + def __init__(self,data): + self.APIKey=data["APIKey"] + def outputData(self,dataPoints): + Data = ["1","2","3","4","5","6","7"] + j = 0 + for i in dataPoints: + Data[j] = str(i["value"]) + j = j + 1 + params = urllib.urlencode({'field1': Data[0], 'field2': Data[1],'field3': Data[2],'field4': Data[3], 'field5': Data[4] 'field6': Data[5],'field7': Data[6],'key':self.APIKey}) + headers = {"Content-type": "application/x-www-form-urlencoded","Accept":"text/plain"} + conn = httplib.HTTPConnection("api.thingspeak.com:80") + conn.request("POST", "/update", params, headers) + response = conn.getresponse() + print response.status, response.reason + data = response.read() + conn.close() + return True From 3e58b3f1ca83e1e298885811041b9cf649e655fd Mon Sep 17 00:00:00 2001 From: Goran Mahovlic Date: Thu, 5 Mar 2015 23:49:35 +0100 Subject: [PATCH 09/10] Update outputs.cfg --- outputs.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outputs.cfg b/outputs.cfg index 7dc2bba..13b0bae 100644 --- a/outputs.cfg +++ b/outputs.cfg @@ -11,4 +11,4 @@ FeedID=XXXXXXXXXX [Thingspeak] filename=Thingspeak enabled=on -APIKey=34WTPBE2DXIESA5E +APIKey=YYYYYYYYYYYYYYYYYY From 1e95442f1d4e9e49701bc0f4bd8c356292fece77 Mon Sep 17 00:00:00 2001 From: Goran Mahovlic Date: Wed, 10 Jun 2015 21:22:04 +0200 Subject: [PATCH 10/10] Update README.md --- README.md | 179 +----------------------------------------------------- 1 file changed, 2 insertions(+), 177 deletions(-) diff --git a/README.md b/README.md index 34a8480..45b8cb8 100644 --- a/README.md +++ b/README.md @@ -1,178 +1,3 @@ -AirPi -======== +forked from tomhartley/AirPi -A Raspberry Pi weather station and air quality monitor. - -This is the code for the project located at http://airpi.es - -Currently it is split into airpi.py, as well as multiple input and multiple output plugins. airpi.py collects data from each of the input plugins specified in sensors.cfg, and then passes the data provided by them to each output defined in outputs.cfg. The code for each sensor plugin is contained in the 'sensors' folder and the code for each output plugin in the 'outputs' folder. - -Some of the files are based off code for the Raspberry Pi written by Adafruit: https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code - -For installation instructions, see http://airpi.es/kit.php - -## Installation - -### Prerequisites - -You will need to install the following dependencies: - -`sudo apt-get install git-core python-dev python-pip python-smbus libxml2-dev libxslt1-dev python-lxml i2c-tools` - -and - -`sudo pip install rpi.gpio requests` - -AirPi requires python-eeml. To install: - -``` -cd ~/git -git clone https://github.com/petervizi/python-eeml.git -cd python-eeml -sudo python setup.py install -``` - -### i2c - -To set up i2c, first add your user to the i2c group. For example, if your username is "pi": - -`sudo adduser pi i2c` - -Now, add the modules needed. - -`sudo nano /etc/modules` - -Add the following two lines to the end of the file: - -``` -i2c-bcm2708 -i2c-dev -``` - -Exit by pressing CTRL+X, followed by y to confirm you want to save, and ⏎ (enter) to confirm the filename. - -Finally, unblacklist i2c by running the following command: - -`sudo nano /etc/modprobe.d/raspi-blacklist.conf` - -Add a `#` character at the beginning of the line `blacklist i2c-bcm2708`. Then exit in the same way as last time. - -Now, reboot your Raspberry Pi: - -`sudo reboot` - -### Board Version - -Let's check to see which board version you have. Run: - -`sudo i2cdetect -y 0` - -You should see this as the output: - -``` - 0 1 2 3 4 5 6 7 8 9 a b c d e f -00: -- -- -- -- -- -- -- -- -- -- -- -- -- -10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -70: -- -- -- -- -- -- -- 77 -``` - -If not, run: - -`sudo i2cdetect -y 1` - -and you should see the above. This tells you if your board is version 0 or 1. This is important for the next step. - -### Get The AirPi Code - -Clone this repo into your git directory (or wherever you want): - -``` -cd ~/git -git clone https://github.com/tomhartley/AirPi.git -cd AirPi -``` - -### Configuring - -Edit the settings file by running: - -`nano sensors.cfg` - -The start of the file should look like this: - -``` -[BMP085-temp] -filename=bmp085 -enabled=on -measurement=temp -i2cbus = 1 - -[BMP085-pres] -filename=bmp085 -enabled=on -measurement=pres -mslp=on -i2cbus = 1 -altitude=40 -``` - -If your board version is "0" change both instances of `i2cbus = 1` to `i2cbus = 1` - -Press CTRL+X to exit the file, when prompted, press "y" to save the file. - -If you want to push the data to Xively, edit the `outputs.cfg` file: - -`nano outputs.cfg` - -The start of the file should look like this: - -``` -[Print] -filename=print -enabled=on - -[Xively] -filename=xively -enabled=on -APIKey=xxxxxxxxxx -FeedID=xxxxxxxxxx -``` - -If you have registered with https://xively.com - you can add your API Key and Feed ID here. - -## Running - -AirPi **must** be run as root. - -`sudo python Airpie.py` - -If everything is working, you should see output similar to this: - -``` -Success: Loaded sensor plugin BMP085-temp -Success: Loaded sensor plugin BMP085-pres -Success: Loaded sensor plugin MCP3008 -Success: Loaded sensor plugin DHT22 -Success: Loaded sensor plugin LDR -Success: Loaded sensor plugin MiCS-2710 -Success: Loaded sensor plugin MiCS-5525 -Success: Loaded sensor plugin Mic -Success: Loaded output plugin Print -Success: Loaded output plugin Xively - -Time: 2014-06-04 09:10:18.942625 -Temperature: 30.2 C -Pressure: 992.55 hPa -Relative_Humidity: 35.9000015259 % -Light_Level: 3149.10025707 Ohms -Nitrogen_Dioxide: 9085.82089552 Ohms -Carbon_Monoxide: 389473.684211 Ohms -Volume: 338.709677419 mV -Uploaded successfully - -``` +added Pushing data to Thingspeak