Anyone can build a weather station --- But taking it a step further by adding an automatic analytic algorithm would add practicality to creating one in the first place. Here is an IoT project I created that does just that.
The heat in the Philippines is as bad as it gets, and I had a whole 5 days to myself away from work just bumming around and playing games, so I decided that it would be fun to try and come up with a system that analyzes the patterns, probabilities and whatnot involving the weather so I can make something of the unbearable heat in this region. Now I understand that there are multiple resources that are available elsewhere on the net, but my project differs solely because this doesn't just utilize the sensors to display data on a UI, but instead analyzes this data and comes up with bold forecasts; what time it will (probably) rain the next day, the temperature index for the next 4 days, etc. I've tested it out myself and it has been accurate about 70% of the time as of this date.
For its purpose, I won't be going into full details, but rather I'll show you how it works in the simplest manner I can. I managed to get my hands on the Intel Edison Dev Kit and used it for this project. Other MCU's or Mini Computers such as the RPi, BeagleBone Black and the Arduino are popular choices for builds like this as well.
The Intel Edison isn't really much to clamor about as is. Fortunately, the developer kit I received came with a variety of sensors. With the use of the breakout board (pictured above) sensors can be attached and interfaced with the board. As a bonus, they gave me an LED module which I used to plug into the D4 socket on the breakout. The temperature and UV sensors that came with it were attached to pins A1 and A0 respectively. The rest of the configurations are as follows:
PIN 2: DHT22/AM2302
PIN 7: LCD 16x2
PIN 8: LCD 16x2
PIN 9: LCD 16x2
PIN 10: LCD 16x2
PIN 11: LCD 16x2
PIN 12: LCD 16x2
PIN 22: LED green
PIN 24: LED red
PIN 26: Buton
PIN GND: All modules
PIN 5V: All modules except GY-651
PIN 3V: GY-651
The board is Linux based just like the Rpi. So in essence, Python was the right (and probably the only) language to use. I started off by testing the LED's with the following code:
import mraa
import time led = mraa.Gpio(4) led.dir(mraa.DIR_OUT) for i in range(10): led.write(1) time.sleep(1) led.write(0) time.sleep(1)
Analog test:
import mraa
uv = mraa.Aio(0) temp = mraa.Aio(1) while True: print uv.read() print temp.read()
If it works, then it's all good to go. Next is to create the script that runs the UV sensor.
from datetime import date, datetime import time import mraa UVThreshold = 23.42 uv = mraa.Aio(1) led = mraa.Gpio(4) led.dir(mraa.DIR_OUT) def getCurrentUVIndex(): return uv.read() / 1000.0 def setWarningLED(value): led.write(value) if __name__ == "__main__": print "UV indexer started" daySumIndex = 0.0 counterDay = date.today() while True: if counterDay.day != datetime.today().day: print "New Day resetting counter" counterDay = datetime.today() daySumIndex = 0 daySumIndex += getCurrentUVIndex() print daySumIndex setWarningLED(daySumIndex > UVThreshold) time.sleep(1)
Next, I wanted to make sure that it wasn't just a sense-and-display project. With the help of an API call, I can pull this data and send it over to a 3rd party for data sourcing and analysis. For my case, it was Weather Underground. In order to be able to leverage the predictions, this must be used. It is also handy to alert you when it rains. Using the data pulled, it processes the algorithm and the red LED will light up if it predicts it will rain in the next hour or so. Handy, isn't it? Below is the code to pull the data and send it over to the API:
import mraa import urllib2 import json from datetime import datetime, timedelta led = mraa.Gpio(4) led.dir(mraa.DIR_OUT) next_hour = datetime.now() + timedelta(hours=1) f = urllib2.urlopen('http://api.wunderground.com/api/KEY/hourly/q/Philippines/Manila.json') json_string = f.read() parsed_json = json.loads(json_string) hours = parsed_json['hourly_forecast for h in hours: if next_hour.hour == int(h['FCTTIME']['hour_padded']): wx = h['wx'] if 'Rain' in wx or 'Thunderstorms' in wx or 'Showers' in wx: led.write(1) else: led.write(0) f.close()
As an added feature, I thought it would be nice to see just how much UV radiation we're getting exposed to. Using the sensor, it automatically calculates how much exposure you receive in a day and it uploads to the cloud. How does this help, exactly? Well in the long term you can control this and notice an upward trend with your health.
POST /data/{deviceId} POST /data/admin/{deviceId} (Using admin token) { "on": 1354741967799, "accountId": "550e8400-e29b-41d4-a716-446655440000", "data": [ { "componentId": "436e7e74-6771-4898-9057-26932f5eb7e1_01", "on": 1354741966688, "loc": [ 45.5434085, -122.654422, 124.3 ], "value": "26.7" }, { "componentId": "436e7e74-6771-4898-9057-26932f5eb7e1_01", "on": 1354741966699, "loc": [ 45.5434085, -122.654422 ], "value": "26.8" }, { "componentId": "436e7e74-6771-4898-9057-26932f5eb7e1_02", "on": 1354741966688, "value": "35", "attributes": { "accuracy": "±2%RH", "reading": "digital" } }, { "componentId": "436e7e74-6771-4898-9057-26932f5eb7e1_03", "on": 1354741966677, "value": "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=" } ] } Response 201