2016创客成都训练营Edison工作坊项目:个人穿衣提示器

个人穿衣提示器

功能:

1、连接互联网获取天气预报数据

2、根据个人习惯,计算穿衣类型

3、LED灯提示穿衣指数

4、DHT11

5、LCD液晶屏幕显示天气预报数据

6、通过网页控制LED灯

材料:

1、1x Edison Arduino板

2、1x DHT11

3、1x RGB LED

4、1x OLED Display

5:  2x Micro usb cable

代码:

#!/usr/bin/env python

# Author: bloomlj <li.jun@swjtu.edu.cn>
#use the api by http://www.thinkpage.cn

import sys, urllib, urllib2, json,mraa

url = 'https://api.thinkpage.cn/v3/weather/daily.json?key=YOUR-THINKPAGE-KEY&location=chengdu&language=en&unit=c&start=0&days=3'

req = urllib2.Request(url)

resp = urllib2.urlopen(req)
content = resp.read()
#if(content):
#    print(content)

objdata = json.loads(content)
#tomorrow weather information
#print objdata['results'][0]['daily'][1]['code_day']
tmp_high =  int(objdata['results'][0]['daily'][1]['high'])
tmp_low =  int(objdata['results'][0]['daily'][1]['low'])
wind = int(objdata['results'][0]['daily'][1]['wind_scale'])

#sample caluate the dree index
dress = 0; #dress type: 0 tshirt, 1 shirt 2 jacket,3 feather coat
if (tmp_high >= 25):dress = 0
elif (tmp_high < 25 and tmp_high >= 15 ):dress = 1
elif (tmp_high < 15 and tmp_high >= 5 ):dress = 2
else :dress = 3
print tmp_high
print dress;

print (mraa.getVersion())

for i in range(10,13):
x =mraa.Gpio(i)
x.dir(mraa.DIR_OUT)
x.write(0)

x = mraa.Gpio(10+dress)
x.dir(mraa.DIR_OUT)
x.write(1)

资料:

关于Edison:http://www.intel.com/content/www/us/en/do-it-yourself/edison.html

Getting started guide:https://software.intel.com/zh-cn/iot/library/edison-getting-started

驱动、工具、IDE下载:官方链接:https://software.intel.com/en-us/iot/hardware/edison/downloads

mraa:https://github.com/intel-iot-devkit/mraa

c,java,node.js,python各种语言的例程UPM:https://github.com/intel-iot-devkit/upm

Python例程全集:https://github.com/intel-iot-devkit/upm/tree/master/examples/python

 

Leave a Reply

Your email address will not be published. Required fields are marked *