It's time to finalize the OpenHAB setup on the BeagleBoneBlack, which will collect and analyze data stored on the AirVantage cloud.
The steps required to complete the installation are
Install web server
A web server is required to serve the files for the web page that shows collected data. I chose lighttpd because it's lightweight and easy to configure.
To install lighttpd, simply type
sudo apt-get install lighttpd
First, let's check that your configuration is ok:
$ lighttpd -t -f lighttpd.conf
Now let's start the server for testing:
$ lighttpd -D -f lighttpd.conf
I edited the config file in /etc/lighttpd/lighttpd.conf
server.document-root = "/var/www/airmobile/pages/" server.port = 8082 mimetype.assign = ( ".html" => "text/html", ".js" => "application/javascript", ".txt" => "text/plain", ".jpg" => "image/jpeg", ".png" => "image/png" ) index-file.names = ( "index.html" )
Then I started the webserver by typing
/etc/init.d/lighttpd start
Copy web page files
AirMobile web files (HTML and Javascript) have been copied to
"/var/www/airmobile/pages"
Copy bindings
The binding bundles developed (namely gpio and iarvantage) needs to be copied to the openhab/addons folder. To create the bundle, right click on the project and select Export. In the Export wizard, select Deployable plugins and fragments.
In the next step, enter the folder where you want the plugin to be generated and check the options as shown
During the deployment, I experienced a Java ClassNotFoundException. I was not able to completely understand the reason for that exception, and the only way to solve this issue was to create a bundle for each jar the AirVantage binding depends on (okhttp, Gson, scribe and org.json). I created bundle projects by selecting File -> New -> Project -> Bundle and following the wizard steps
Finally, I added the bundles to the Import-Package section of manifest file of the AirVantage binding.
Manifest-Version: 1.0 Bundle-Vendor: openHAB.org Bundle-Version: 1.6.0.qualifier Bundle-Activator: org.openhab.binding.airvantage.internal.AirVantageActivator Bundle-ManifestVersion: 2 Bundle-Description: This is the AirVantage binding of the open Home Automation Bus (openHAB) Import-Package: com.google.gson, com.google.gson.reflect, com.squareup.okhttp, org.scribe.builder, org.json, org.apache.commons.lang, org.codehaus.jackson, org.codehaus.jackson.map, org.openhab.core.binding, org.openhab.core.events, org.openhab.core.items, org.openhab.core.library.items, org.openhab.core.library.types, org.openhab.core.types, org.openhab.model.item.binding, org.osgi.framework, org.osgi.service.cm, org.osgi.service.component, org.osgi.service.event, org.slf4j Export-Package: org.openhab.binding.airvantage Bundle-DocURL: http://www.openhab.org Service-Component: OSGI-INF/binding.xml, OSGI-INF/genericbindingprovider.xml Bundle-ClassPath: ., lib\scribe-1.3.5.jar, lib\gson-2.2.4-sources.jar, lib\json-20140107.jar, lib\okhttp-1.2.1-sources.jar
Define the items and the sitemap
First, a set of items that show the last sensor readings are defined
Number Home_Temperature "Temperature [%.1f]" <temperature> {airvantage="system=AirMobile1,measure=temperature"} Number Home_Humidity "Humidity [%.0f]" <humidity> {airvantage="system=AirMobile1,measure=humidity"} Number Home_CO "CO [%.3f]" <co> {airvantage="system=AirMobile1,measure=co"} Number Home_NO2 "NO2 [%.3f]" <no2> {airvantage="system=AirMobile1,measure=no2"} Number Home_Dust "Dust [%.0f]" <dust> {airvantage="system=AirMobile1,measure=dust"} Number Home_AQI "AQI [%.2f]" <gauge>
Second, a set of items that show pollutant levels at a certain location (in this case the location of a public garden where I typically go for a run) are define
Number PB_Temperature "Temperature [%.1f]" <temperature> {airvantage="system=AirMobile1,measure=temperature"} Number PB_Humidity "Humidity [%.0f]" <humidity> {airvantage="system=AirMobile1,measure=humidity"} Number PB_CO "CO [%.3f]" <co> {airvantage="system=AirMobile1,measure=co"} Number PB_NO2 "NO2 [%.3f]" <no2> {airvantage="system=AirMobile1,measure=no2"} Number PB_Dust "Dust [%.0f]" <dust> {airvantage="system=AirMobile1,measure=dust"} Number PB_AQI "AQI [%.2f]" <gauge>
Finally, the item for controlling the servo for the Air Quality Index (see below) indicator is defined
Number Home_Servo "Servo [%.0f]" {gpio="pin:13 name:pwm_test_P8_13.11"}
Define the rule to compute AQI
In order to provide an easy to understand measure of the air quality, I defined a custom Air Quality Index. Unfortunately widely-used Air Quality indexes are based also on measure of the ozone concentration at ground level. Since the Air Mobile does not have a ozone sensor, I defined my own Air Quality index.
The index formula is
homeAQI = 1 -
((((homeCO - 30.0)/(1000.0-30.0))* 0.4) +
(((homeNO2 - 200.0)/(2000.0-200.0))*0.4) +
(((homeDust-0.0)/(500.0-0.0))*0.2))
The index is basically a weighted average of the percentage of the three pollutants detected by the AirMobile sensor
The value of the index range from 0 (worst air quality) to 1 (best air quality)
The index is calculate by an OpenHAB rule
rule "Home_AQI_Calculation" when Item Home_CO changed or Item Home_NO2 changed or Item Home_Dust changed then homeCO = Home_CO.state as DecimalType homeNO2 = Home_NO2.state as DecimalType homeDust = Home_Dust.state as DecimalType homeAQI = 1 - ((((homeCO - 30.0)/(1000.0-30.0))* 0.4) + (((homeNO2 - 200.0)/(2000.0-200.0))*0.4) + (((homeDust-0.0)/(500.0-0.0))*0.2)) postUpdate(Home_AQI, homeAQI) homeServo = 1500 + (homeAQI * 1000) postUpdate(Home_Servo, homeServo) end
This rule also updates the servo position by converting the index value (from 0 t 1) to a PWM duty cycle value (from 600 to 2400 microseconds). The PWM duty cycle is then posted to the Home_Servo item
Top Comments