Last active
September 27, 2016 09:22
-
-
Save awong1900/efca66884b54f9c02204 to your computer and use it in GitHub Desktop.
Easy make your outdoor temp. device. (http://www.seeedstudio.com/recipe/1092-make-your-simple-outdoor-temp-device.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# copyright 2015 seeed, [email protected] | |
import requests | |
import random | |
import time | |
indoor_access_token = "your indoor wiolink token" | |
outdoor_access_token = "your outdoor wiolink token" | |
INDOOR_DISPLAY_API = "https://cn.iot.seeed.cc/v1/node/GroveLedWs2812_Digital1/segment/" | |
OUTDOOR_DISPLAY_API = "https://cn.iot.seeed.cc/v1/node/GroveLedWs2812_Digital2/segment/" | |
INDOOR_TEMP_API = "https://cn.iot.seeed.cc/v1/node/GroveTempHumPro_Digital0/temperature?" | |
OUTDOOR_TEMP_API = "https://cn.iot.seeed.cc/v1/node/GroveTempHumPro_Digital1/temperature?" | |
start_temp = 8 | |
temp_setp = 1 | |
led_count = 20 | |
st = ["100006", "100000", "101000", "001010", "060010"] | |
colors = st[0:1]*3 + st[1:2]*5 + st[2:3]*5 +st[3:4]*5 | |
# def get_rainbow(number): | |
# if number > 40: #wiolink only support 40 led | |
# number = 40 | |
# # color_items = ["FF0000", "FFA500", "FFFF00", "00FF00", "00FFFF", "0000FF", "9B30FF"] | |
# color_items = ["2F0000", "00002F", "2F2F00", "002F2F", "002F00",] | |
# # color_items = ["2F0000","2F0000","2F0000","2F0000","2F0000","2F0000","2F0000"] | |
# # color_items = ["002F00","002F00","002F00","002F00","002F00","002F00","002F00"] | |
# random.shuffle(color_items) | |
# if number <= len(color_items): | |
# color_items = color_items[0:number] | |
# color_items += ["000000"]*(40-number) | |
# else: | |
# color_items *= int(number/len(color_items)) | |
# color_items.extend(color_items[:number%len(color_items)]) | |
# color_items += ["000000"]*(40-number) | |
# rgb_hex_string = "".join(color_items) | |
# return rgb_hex_string | |
def get_rainbow(number): | |
color_items = colors[0:number] | |
color_items += ["000000"]*(40-number) | |
rgb_hex_string = "".join(color_items) | |
return rgb_hex_string | |
def get_temp(url): | |
r = requests.get(url) | |
if r.status_code is not 200: | |
return None | |
json = r.json() | |
if json is None: | |
return None | |
if json["status"] is not 200: | |
return None | |
temp = json["msg"]["celsius_degree"] | |
return temp | |
def temp(): | |
indoor = INDOOR_TEMP_API+"access_token="+indoor_access_token | |
outdoor = OUTDOOR_TEMP_API+"access_token="+outdoor_access_token | |
indoor_temp = get_temp(indoor) | |
outdoor_temp = get_temp(outdoor) | |
return {"indoor_temp":indoor_temp, "outdoor_temp":outdoor_temp} | |
def led_dis(url, number): | |
pass | |
def display(temps): | |
print temps | |
indoor_temp = temps["indoor_temp"] | |
if indoor_temp is not None: | |
url = INDOOR_DISPLAY_API + "0/" + get_rainbow(int(indoor_temp-start_temp)) + "?access_token=" + indoor_access_token | |
requests.post(url).json() | |
outdoor_temp = temps["outdoor_temp"] | |
if outdoor_temp is not None: | |
url = OUTDOOR_DISPLAY_API + "0/" + get_rainbow(int(outdoor_temp-start_temp)) + "?access_token=" + indoor_access_token | |
requests.post(url).json() | |
def main(): | |
while True: | |
baby_temp = {} | |
baby_temp = temp() | |
display(baby_temp) | |
time.sleep(300) #5s | |
# update_display(40000) | |
# prompt_everbody(5) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment