Пример #1
0
def update_outdoor():
    try:
        outdoor.get_weather_from_api()
        outdoor.set_wind_direction_number()
    except:
        print 'get outdoor from weather api error'
    outdoor.set_update_time(get_current_time())
    save_db_outdoor(outdoor)
    print 'outdoor updated', get_current_time()
Пример #2
0
def update_outdoor():
    """ 获取温室外环境数据,从服务器端获得 """
    try:
        outdoor.get_weather_from_api()
        outdoor.set_wind_direction_number()
    except:
        print 'get outdoor from weather api error'
    outdoor.set_update_time(get_current_time())
    save_db_outdoor(outdoor)
    print 'outdoor updated', get_current_time()
Пример #3
0
    def lighting(self, Outdorr, Parameter,
                 Control):  # 补光策略,在currenttime 加了一个get_time()函数

        while True:
            if Control.get_lighting_1() == "off" and Control.get_lighting_2(
            ) == "off":
                if get_current_month(
                ) > Parameter.month_to_open_lighting and get_current_month(
                ) < Parameter.month_to_close_lighting:
                    if get_current_time(
                    ) > Parameter.period1_start_lighting and get_current_time(
                    ) < Parameter.period1_stop_lighting:
                        if Outdoor.radiation < Parameter.radiation1_to_open_lighting:
                            Control.set_lighting_1("on")
                            open_time = get_time()
                    elif get_current_time(
                    ) > Parameter.period2_start_lighting and get_current_time(
                    ) < Parameter.period2_stop_lighting:
                        if Outdoor.radiation < Parameter.radiation2_to_open_lighting:
                            Control.set_lighting_1("on")
                            open_time2 = get_time()

            elif Control.get_lighting_1() == "on" and Control.get_lighting_2(
            ) == "off":
                t1 = int(get_time() - open_time)
                t2 = int(get_time() - open_time2)
                if t1 > 1750 and t1 < 1850:
                    Control.set_lighting_2("on")
                if t2 > 1750 and t2 < 1850:
                    Control.set_lighting_2("on")

            elif Control.get_lighting_1() == "on" and Control.get_lighting_2(
            ) == "on":
                if get_current_time(
                ) > Parameter.period1_start_lighting and get_current_time(
                ) < Parameter.period1_stop_lighting:
                    if Outdoor.radiation > Parameter.radiation1_to_open_lighting:
                        Control.set_lighting_1("off")
                        stop_time = get_time()
                elif get_current_time(
                ) > Parameter.period2_start_lighting and get_current_time(
                ) < Parameter.period2_stop_lighting:
                    if Outdoor.radiation > Parameter.radiation2_to_open_lighting:
                        Control.set_lighting_1("off")
                        stop_time2 = get_time()
                else:
                    Control.set_lighting_1("off")
                    stop_time3 = get_time()

            elif Control.get_lighting_1() == "off" and Control.get_lighting_2(
            ) == "on":
                t3 = get_time() - stop_time3
                t4 = get_time() - stop_time2
                t5 = get_time() - stop_time
                if t3 > 1750 and t3 < 1850:
                    Control.set_lighting_2("off")
                if t4 > 1750 and t4 < 1850:
                    Control.set_lighting_2("off")
                if t5 > 1750 and t5 < 1850:
                    Control.set_lighting_2("off")
Пример #4
0
def update_indoor():
    global start_time,indoor_node_data
    indoor_node_data=sensor.get_sensor_data()
    if isConnect == True:
        start_time = get_current_time()
    obj=json.loads(indoor_node_data)
    for key in obj.keys():
        node0.set_name(key)
        value=obj.get(key)
        node0.set_update_time(value['update_time'])
        node0.set_co2(value['co2'])
        node0.set_temperature(value['temperature'])
        node0.set_humidity(value['humidity'])
        save_db_indoor(node0)
    print 'indoor updated', get_current_time()
Пример #5
0
def save_db_control_state(Control):
    with app.app_context():
        db = get_db()
        db.cursor().execute(
            'insert into control_state(update_time,roof_vent_south,roof_vent_north,side_vent,shade_screen_north,shade_screen_south,thermal_screen,\
        cooling_pump,cooling_fan,fan,fogging,heating,co2,lighting_1,lighting_2,irrigation) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',
            [
                get_current_time(),
                Control.get_roof_vent_south(),
                Control.get_roof_vent_north(),
                Control.get_side_vent(),
                Control.get_shade_screen_north(),
                Control.get_shade_screen_south(),
                Control.get_thermal_screen(),
                Control.get_cooling_pump(),
                Control.get_cooling_fan(),
                Control.get_fan(),
                Control.get_fogging(),
                Control.get_heating(),
                Control.get_co2(),
                Control.get_lighting_1(),
                Control.get_lighting_2(),
                Control.get_irrigation()
            ])
        db.commit()
        db.cursor().close()
        db.close()
    print 'control save success'
Пример #6
0
 def __init__(self, name):
     self.__name = name
     self.__temperature = 5
     self.__humidity = 60
     self.__radiation = 500
     self.__co2 = 400
     self.__update_time = get_current_time()
Пример #7
0
 def __init__(self, name):
     self.__name = name
     self.__temperature = 5
     self.__humidity = 60
     self.__radiation = 500
     self.__co2 = 400
     self.__update_time = get_current_time()
Пример #8
0
 def handle_post(self, data):
     obj = json.loads(data)
     keys = obj.keys()
     json_response = "{"
     for key in keys:
         if key in Control.tri_states_actuators:
             value = obj.get(key)
             if value in Control.tri_states:
                 setattr(self, "_Control__" + key, value)
                 print key, getattr(self, "_Control__" + key)
                 try:
                     tri_state_relay_output(key, value)
                 except:
                     print "the relay don't have the actuator, please review"
                 json_response += '''"%s" : "%s",''' % (key, value)
             else:
                 print value, "tri illegal state"
         elif key in Control.bi_states_actuators:
             value = obj.get(key)
             if value in Control.bi_states:
                 setattr(self, "_Control__" + key, value)
                 print key, getattr(self, "_Control__" + key)
                 try:
                     bi_state_relay_output(key, value)
                 except:
                     print "the relay don't have the actuator, please review"
                 json_response += '''"%s" : "%s", ''' % (key, value)
             else:
                 print value, "illegal state"
         else:
             print key, "bi illegal actuator"
     json_response += '''"status" : "%s", ''' % "success"
     json_response += '''"update_time" : "%s"''' % get_current_time()
     json_response += "}"
     return json_response
Пример #9
0
def update_indoor():
    """ 从无线传感器获取温室内各个节点测量的环境数据 """
    global start_time, indoor_node_data
    indoor_node_data = sensor.get_sensor_data()
    if isConnect:
        start_time = get_current_time()
    obj = json.loads(indoor_node_data)
    for key in obj.keys():
        node0.set_name(key)
        value = obj.get(key)
        node0.set_update_time(value['update_time'])
        node0.set_co2(value['co2'])
        node0.set_temperature(value['temperature'])
        node0.set_humidity(value['humidity'])
        save_db_indoor(node0)
    print 'indoor updated', get_current_time()
Пример #10
0
 def handle_post(self, data):
     obj = json.loads(data)
     keys = obj.keys()
     json_response = "{"
     for key in keys:
         if key in Control.CONSTANT.tri_states_actuators:
             value = obj.get(key)
             if value in Control.CONSTANT.tri_states:
                 setattr(self, "_Control__" + key, value)
                 print key, getattr(self, "_Control__" + key)
                 json_response += '''"%s" : "%s",''' % (key, value)
             else:
                 print value, "illegal state"
         elif key in Control.CONSTANT.bi_states_actuators:
             value = obj.get(key)
             if value in Control.CONSTANT.bi_states:
                 setattr(self, "_Control__" + key, value)
                 print key, getattr(self, "_Control__" + key)
                 json_response += '''"%s" : "%s", ''' % (key, value)
             else:
                 print value, "illegal state"
         else:
             print key, "illegal actuator"
     json_response += '''"status" : "%s", ''' % "success"
     json_response += '''"update_time" : "%s"''' % get_current_time()
     json_response += "}"
     return json_response
Пример #11
0
 def handle_post(self, data):
     obj = json.loads(data)
     keys = obj.keys()
     json_response = "{"
     for key in keys:
         if key in Control.tri_states_actuators:
             value = obj.get(key)
             if value in Control.tri_states:
                 setattr(self, "_Control__" + key, value)
                 print key, getattr(self, "_Control__" + key)
                 try:
                     tri_state_relay_output(key, value)
                 except:
                     print "the relay don't have the actuator, please review"
                 json_response += '''"%s" : "%s",''' % (key, value)
             else:
                 print value, "tri illegal state"
         elif key in Control.bi_states_actuators:
             value = obj.get(key)
             if value in Control.bi_states:
                 setattr(self, "_Control__" + key, value)
                 print key, getattr(self, "_Control__" + key)
                 try:
                     bi_state_relay_output(key, value)
                 except:
                     print "the relay don't have the actuator, please review"
                 json_response += '''"%s" : "%s", ''' % (key, value)
             else:
                 print value, "illegal state"
         else:
             print key, "bi illegal actuator"
     json_response += '''"status" : "%s", ''' % "success"
     json_response += '''"update_time" : "%s"''' % get_current_time()
     json_response += "}"
     return json_response
Пример #12
0
def save_db_indoor(Indoor):
    with app.app_context():
        db=get_db()
        db.execute('insert into indoor(node_number,update_time,temperature,humidity,radiation,co2) values(?,?,?,?,?,?)',
                    [Indoor.name,get_current_time(),Indoor.get_temperature(),Indoor.get_humidity(),Indoor.get_radiation(),Indoor.get_co2()])
        db.commit()
    print 'indoor save success'    
Пример #13
0
def save_db_outdoor(Outdoor):
    with app.app_context():
        db=get_db()
        db.execute('insert into outdoor(update_time,temperature,humidity,radiation,co2,wind_direction,wind_speed,rain_snow,atmosphere)\
                   values(?,?,?,?,?,?,?,?,?)', [get_current_time(),Outdoor.temperature,Outdoor.humidity,Outdoor.radiation,Outdoor.co2,Outdoor.wind_direction,\
                                                Outdoor.wind_speed,Outdoor.rain,Outdoor.atmosphere])
        db.commit()
    print 'outdoor save success'
Пример #14
0
def save_db_control(Control):
    with app.app_context():
        db=get_db()
        db.execute('insert into control_state(update_time,roof_vent_south,roof_vent_north,side_vent,shade_screen_out,shade_screen_in,thermal_screen,\
        cooling_pad,fogging,heating,co2,lighting_1,lighting_2,irrigation) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
        [get_current_time(),Control.get_roof_vent_south(),Control.get_roof_vent_north(),Control.get_side_vent(),Control.get_shade_screen_out(),Control.get_shade_screen_in(),\
         Control.get_thermal_screen(),Control.get_cooling_pad(),Control.get_fogging(),Control.get_heating(),Control.get_co2(),Control.get_lighting_1(),Control.get_lighting_2(),Control.get_irrigation()])
        db.commit()
    print 'control save success'
Пример #15
0
 def __init__(self):
     self.__update_time = get_current_time()
     self.__temperature = 10.0
     self.__humidity = 5
     self.__radiation = 600
     self.__co2 = 600
     self.__wind_direction = "12"
     self.__wind_speed = 3
     self.__rain = 1
     self.__atmosphere = 0
Пример #16
0
 def __init__(self):
     self.__update_time = get_current_time()
     self.__temperature = 10.0
     self.__humidity = 5
     self.__radiation = 600
     self.__co2 = 600
     self.__wind_direction = "12"
     self.__wind_speed = 3
     self.__rain = 1
     self.__atmosphere = 0
Пример #17
0
def server_connect():
    global isConnect, start_time
    try:
        data = urllib.urlopen(url).read()
        if data == 'success':
            isConnect = True
        print 'server connect'
    except:
        start_time = get_current_time()
        isConnect = False
        print 'server disconnect'
Пример #18
0
def update_indoor():
    global indoor_all_state
    number = node_num
    get_db_indoor(indoor)
    indoor_all_state = '''{''' + indoor.build_json_array()
    for i in range(number - 1):
        temp = Indoor(str(i + 2))
        indoor_all_state += ','
        get_db_indoor(temp)
        indoor_all_state += temp.build_json_array()
    indoor_all_state += '''}'''
    print 'indoor update', get_current_time()
Пример #19
0
def server_connect():
    """ 测试与服务器连接状况 """
    global isConnect, start_time
    try:
        data = urllib.urlopen(url).read()
        if data == 'success':
            isConnect = True
        print 'server connect success'
    except:
        start_time = get_current_time()
        isConnect = False
        print 'server disconnect'
Пример #20
0
def control():
    if request.method == 'POST':
        try:
            data = request.data
            c.set_update_time(get_current_time())
            r=c.handle_post(data)
            save_db_control(r)
            return r
        except ValueError:
            return "get currently control state success"
    else:
        return c.build_json()
Пример #21
0
def handle_query_condition(request_data):
    obj = json.loads(request_data)
    keys = obj.keys()
    start_time = make_time(obj.get('start'), 0)
    end_time = make_time(obj.get('stop'), 1)
    if (end_time > get_current_time()):
        end_time = get_current_time()
    response_data = '''{"series":['''
    for key in keys:
        value = obj.get(key)
        if (value == 'true'):
            data = key.split('_')
            if (data[0][1] == 'n'):
                sheet_name = 'indoor_node_' + data[0][4]
            else:
                sheet_name = 'outdoor'
            sheet_title = "update_time," + data[1]
            query = "SELECT " + sheet_title + " FROM " + sheet_name + " WHERE update_time BETWEEN " + "'" + start_time + "'" + " AND " + "'" + end_time + "'"
            rows = query_db_2(query)
            data = '''['''
            for row in rows:
                temp = '''[%s,%s]''' % (stamp_for_series_start_time(str(
                    row[0])), float(row[1]))
                data += temp
                data += ','
            data_list = list(data)
            data_list.pop()
            data = "".join(data_list)
            data = "]"
            response_data += '''{
                "name":"%s",
                "data":%s,
                "pointStart":%s,
                "pointInterval": "5 * 60 * 1000"
                },
                ''' % (key, data, stamp_for_series_start_time(start_time))
    response_data += '''{}
                    ]}'''
    return response_data
Пример #22
0
def save_db_control_command(CommandControl):
    with app.app_context():
        db = get_db()
        db.cursor().execute(
            'insert into ' + control_command_database +
            '(update_time,control_actuator,control_cmd) values(%s,%s,%s)', [
                get_current_time(),
                CommandControl.get_actuator(),
                CommandControl.get_command()
            ])
        db.commit()
        db.cursor().close()
        db.close()
    print 'control command save success'
Пример #23
0
def control():
    """ 处理服务器及其他设备对被控对象(继电器)的手动控制请求 """
    global r
    if request.method == 'POST':
        try:
            data = request.data
            c.set_update_time(get_current_time())
            r = c.handle_post(data)
            save_db_control(c)
            return r
        except:
            return "post error"
    else:
        return c.build_json()
Пример #24
0
 def build_json(self):
     return '''
     {
        "indoor":{
            "%s":{
                 "temperature": "%s",
                 "humidity": "%s",
                 "radiation": "%s",
                 "co2": "%s",
                 "update_time": "%s"
             }
         }
     }''' \
            % (self.name, self.get_temperature(), self.get_humidity(), self.get_radiation(),
               self.get_co2(), get_current_time())
Пример #25
0
    def lighting(self,Outdorr,Parameter,Control):#补光策略,在currenttime 加了一个get_time()函数

        while True:
            if Control.get_lighting_1()=="off" and Control.get_lighting_2()=="off":
                if get_current_month()>Parameter.month_to_open_lighting and get_current_month()<Parameter.month_to_close_lighting:
                    if get_current_time()>Parameter.period1_start_lighting and get_current_time()<Parameter.period1_stop_lighting:
                        if Outdoor.radiation<Parameter.radiation1_to_open_lighting:

                            Control.set_lighting_1("on")
                            open_time=get_time()
                    elif get_current_time()>Parameter.period2_start_lighting and get_current_time()<Parameter.period2_stop_lighting:
                        if Outdoor.radiation<Parameter.radiation2_to_open_lighting:
                            Control.set_lighting_1("on")
                            open_time2=get_time()

            elif Control.get_lighting_1()=="on" and Control.get_lighting_2()=="off":
                t1=int(get_time()-open_time)
                t2=int(get_time()-open_time2)
                if t1>1750 and t1<1850:
                    Control.set_lighting_2("on")
                if t2>1750 and t2<1850:
                    Control.set_lighting_2("on")

            elif Control.get_lighting_1()=="on" and Control.get_lighting_2()=="on":
                if get_current_time()>Parameter.period1_start_lighting and get_current_time()<Parameter.period1_stop_lighting:
                    if Outdoor.radiation>Parameter.radiation1_to_open_lighting:
                        Control.set_lighting_1("off")
                        stop_time=get_time()
                elif get_current_time()>Parameter.period2_start_lighting and get_current_time()<Parameter.period2_stop_lighting:
                    if Outdoor.radiation>Parameter.radiation2_to_open_lighting:
                        Control.set_lighting_1("off")
                        stop_time2=get_time()
                else:
                    Control.set_lighting_1("off")
                    stop_time3=get_time()

            elif Control.get_lighting_1()=="off" and Control.get_lighting_2()=="on":
                t3=get_time()-stop_time3
                t4=get_time()-stop_time2
                t5=get_time()-stop_time
                if t3>1750 and t3<1850:
                    Control.set_lighting_2("off")
                if t4>1750 and t4<1850:
                    Control.set_lighting_2("off")
                if t5>1750 and t5<1850:
                    Control.set_lighting_2("off")
Пример #26
0
 def build_json(self):
     return '''
     {
        "indoor":{
            "%s":{
                 "temperature": "%s",
                 "humidity": "%s",
                 "radiation": "%s",
                 "co2": "%s",
                 "update_time": "%s"
             }
         }
     }''' \
            % (self.name, self.get_temperature(), self.get_humidity(), self.get_radiation(),
               self.get_co2(), get_current_time())
Пример #27
0
def init_parameter():
    global now_time, temperature_set_temp0, temperature_set_temp1, temperature_set_temp2, side_wait_time, lighting_open_time, lighting_open_time2, lighting_stop_time, lighting_stop_time2, lighting_stop_time3
    global bad_weather
    now_time = get_current_time()
    temperature_set_temp0 = 0
    temperature_set_temp1 = 0
    temperature_set_temp2 = 0
    side_wait_time = 0.0

    lighting_open_time = "0"
    lighting_open_time2 = "0"
    lighting_stop_time = "0"
    lighting_stop_time2 = "0"
    lighting_stop_time3 = "0"

    bad_weather = "true"
Пример #28
0
def init_parameter():
    global now_time, temperature_set_temp0, temperature_set_temp1, temperature_set_temp2, side_wait_time, lighting_open_time, lighting_open_time2, lighting_stop_time, lighting_stop_time2, lighting_stop_time3
    global bad_weather
    now_time = get_current_time()
    temperature_set_temp0 = 0
    temperature_set_temp1 = 0
    temperature_set_temp2 = 0
    side_wait_time = 0.0

    lighting_open_time = "0"
    lighting_open_time2 = "0"
    lighting_stop_time = "0"
    lighting_stop_time2 = "0"
    lighting_stop_time3 = "0"

    bad_weather = "true"
Пример #29
0
def save_db_indoor(Indoor):
    with app.app_context():
        db = get_db()
        indoor_node = "indoor_node_" + Indoor.get_name()
        db.cursor().execute(
            'insert into ' + indoor_node +
            '(node,update_time,temperature,humidity,radiation,co2) values(%s,%s,%s,%s,%s,%s)',
            [
                Indoor.get_name(),
                get_current_time(),
                Indoor.get_temperature(),
                Indoor.get_humidity(),
                Indoor.get_radiation(),
                Indoor.get_co2()
            ])
        db.commit()
        db.cursor().close()
        db.close()
    print 'indoor save success'
Пример #30
0
def handle_outdoor_data(request_data):
    with app.app_context():
        db = get_db()
        obj = json.loads(request_data)
        obj = obj['outdoor']
        for key in obj.keys():
            value = obj.get(key)
            db.cursor().execute(
                'insert into outdoor(update_time,temperature,humidity,radiation,co2,wind_direction,wind_speed,rain_snow,atmosphere)\
                values(%s,%s,%s,%s,%s,%s,%s,%s,%s)', [
                    value['update_time'], value['temperature'],
                    value['humidity'], value['radiation'], value['co2'],
                    value['wind_direction'], value['wind_speed'],
                    value['rain'], value['atmosphere']
                ])
            db.commit()
        db.cursor().close()
        db.close()
    print 'outdoor data save success  ' + get_current_time()
Пример #31
0
 def get_weather_from_api(self):
     url = "https://api.heweather.com/x3/weather?city=jiading&key=8924d0a789dd4e348982cfe7f721267c"
     data = urllib.urlopen(url).read()
     wea_json = json.loads(data)
     wea_json = wea_json["HeWeather data service 3.0"][0]
     update_time = get_current_time()
     temperature = str(wea_json["now"]["tmp"])
     humidity = str(wea_json["now"]["hum"])
     radiation = "not included"
     co2 = "not included"
     wind_direction = wea_json["now"]["wind"]["dir"]
     wind_speed = str(wea_json["now"]["wind"]["spd"])
     rain = wea_json["now"]["pcpn"]
     if (float(rain)) > 1.0:
         rain = "true"  # raining
     else:
         rain = "false"  # no rain
     atmosphere = str(wea_json["now"]["pres"])
     self.set_outdoor(
         update_time, temperature, humidity, radiation, co2, wind_direction, wind_speed, rain, atmosphere
     )
Пример #32
0
def handle_indoor_data(request_data):
    with app.app_context():
        db = get_db()
        obj = json.loads(request_data)
        keys = obj.keys()
        for key in keys:
            value = obj[key]
            indoor_node = "indoor_node_" + key
            for key2 in value.keys():
                value2 = value[key2]
                db.cursor().execute(
                    'insert into ' + indoor_node +
                    '(node,update_time,temperature,humidity,radiation,co2) values(%s,%s,%s,%s,%s,%s)',
                    [
                        key, value2['update_time'], value2['temperature'],
                        value2['humidity'], value2['radiation'], value2['co2']
                    ])
                db.commit()
        db.cursor().close()
        db.close()
    print 'indoor data save success' + get_current_time()
Пример #33
0
 def get_weather_from_api(self):
     try:
         data = urllib.urlopen(url).read()
     except:
         print 'Internet error'
     wea_json = json.loads(data)
     wea_json = wea_json['HeWeather data service 3.0'][0]
     update_time = get_current_time()
     temperature = str(wea_json['now']['tmp'])
     humidity = str(wea_json['now']['hum'])
     radiation = '300'
     co2 = '600'
     wind_direction = wea_json['now']['wind']['dir']
     wind_speed = '%.1f' % (float(wea_json['now']['wind']['spd']) / 3.6)
     rain = wea_json['now']['pcpn']
     # if (float(rain)) > 1.0:
     # rain = 'true'  # raining
     #else:
     #    rain = 'false'  # no rain
     atmosphere = str(wea_json['now']['pres'])
     self.set_outdoor(update_time, temperature, humidity, radiation, co2, wind_direction, wind_speed, rain,
                      atmosphere)
Пример #34
0
def save_db_parameter(Parameter):
    with app.app_context():
        db=get_db()
        db.execute('insert into parameter(update_time,time1,temperature1,time2,temperature2,time3,temperature3,time4,temperature4, co2_upper_limit,co2_lower_limit, cooling_start_temperature,cooling_stop_temperature,\
                    expect_humidity,humidity_influence_range_of_air_temperature,low_humidity_influence_on_air_temperature,high_humidity_influence_on_air_temperature,expect_light,light_influence_on_air_temperature_slope,high_light_influence_on_temperature,low_light_influence_on_temperature,frost_temperature,\
                    indoor_temperature_lower_limit,roof_vent_wind_speed_upper_limit,roof_vent_rain_upper_limit, heating_start_lowest_temperature,heating_stop_highest_temperature, month_to_open_thermal_screen,month_to_close_thermal_screen,time_to_open_thermal_screen,time_to_close_thermal_screen, temperature_to_open_side,\
                    wait_time_to_open_side,rain_upper_limit_to_close, upper_limit_light_to_open_shade_screen_out,upper_limit_light_to_open_shade_screen_in,soil_humidity_to_start_irrigation,soil_humidity_to_stop_irrigation,temperature_to_open_fogging,temperature_to_open_cooling_pad,\
                    month_to_open_lighting,month_to_close_lighting,period1_start_lighting,period1_stop_lighting,period2_start_lighting,period2_stop_lighting,radiation1_to_open_lighting,radiation2_to_open_lighting,roof_vent_open_time,side_vent_open_time,shade_screen_out_open_time,\
                    shade_screen_in_open_time,thermal_screen_open_time ) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',\
                    [get_current_time(),Parameter.get_time_1(),Parameter.get_temperature_1(),Parameter.get_time_2(),Parameter.get_temperature_2(),Parameter.get_time_3(),Parameter.get_temperature_3(),Parameter.get_time_4(),Parameter.get_temperature_4(),Parameter.get_co_2_upper_limit(),Parameter.get_co_2_lower_limit(),
                     Parameter.get_cooling_start_temperature(),Parameter.get_cooling_stop_temperature(),
                     Parameter.get_expect_humidity(),Parameter.get_humidity_influence_range_of_air_temperature(),Parameter.get_low_humidity_influence_on_air_temperature(),Parameter.get_high_humidity_influence_on_air_temperature(),Parameter.get_expect_light(),Parameter.get_light_influence_on_air_temperature_slope(),
                     Parameter.get_high_light_influence_on_temperature(),Parameter.get_low_light_influence_on_temperature(),Parameter.get_frost_temperature(),Parameter.get_indoor_temperature_lower_limit(),Parameter.get_roof_vent_wind_speed_upper_limit(),Parameter.get_roof_vent_rain_upper_limit(),
                     Parameter.get_heating_start_lowest_temperature(),Parameter.get_heating_stop_highest_temperature(),Parameter.get_month_to_open_thermal_screen(),Parameter.get_month_to_close_thermal_screen(),Parameter.get_time_to_open_thermal_screen(),Parameter.get_time_to_close_thermal_screen(),
                     Parameter.get_temperature_to_open_side(),
                     Parameter.get_wait_time_to_open_side(),
                     Parameter.get_rani_upper_limit_to_close(),
                     Parameter.get_upper_limit_light_to_open_shade_screen_out(),
                     Parameter.get_upper_limit_light_to_open_shade_screen_in(),
                     Parameter.get_soil_humidity_to_start_irrigation(),
                     Parameter.get_soil_humidity_to_stop_irrigation(),
                     Parameter.get_temperature_to_open_fogging(),
                     Parameter.get_temperature_to_open_cooling_pad(),
                     Parameter.get_month_to_open_lighting(),
                     Parameter.get_month_to_close_lighting(),
                     Parameter.get_period_1_start_lighting(),
                     Parameter.get_period_1_stop_lighting(),
                     Parameter.get_period_2_start_lighting(),
                     Parameter.get_period_2_stop_lighting(),
                     Parameter.get_radiation_1_to_open_lighting(),
                     Parameter.get_radiation_2_to_open_lighting(),
                     Parameter.get_roof_vent_open_time(),
                     Parameter.get_side_vent_time(),
                     Parameter.get_shade_screen_out_time(),
                     Parameter.get_shade_screen_in_time(),
                     Parameter.get_thermal_screen_open_time()
                     ])
        db.commit()
        print 'parameter save success'
Пример #35
0
 def build_json(self):
     return '''
     {
 "update_time": "%s",
 "actuator": {
     "tri_state": {
         "roof_vent_south": "%s",
         "roof_vent_north": "%s",
         "side_vent": "%s",
         "shade_screen_out": "%s",
         "shade_screen_in": "%s",
         "thermal_screen": "%s"
     },
     "bi_state": {
         "cooling_pad": "%s",
         "fogging": "%s",
         "heating": "%s",
         "co2": "%s",
         "lighting_1": "%s",
         "lighting_2": "%s",
         "irrigation": "%s"
             }
         }
     }''' \
            % (get_current_time(),
               self.__roof_vent_south,
               self.__roof_vent_north,
               self.__side_vent,
               self.__shade_screen_out,
               self.__shade_screen_in,
               self.__thermal_screen,
               self.__cooling_pad,
               self.__fogging,
               self.__heating,
               self.__co2,
               self.__lighting_1,
               self.__lighting_2,
               self.__irrigation
               )
Пример #36
0
 def get_weather_from_api(self):
     try:
         data = urllib.urlopen(url).read()
     except:
         print 'Internet error'
     wea_json = json.loads(data)
     wea_json = wea_json['HeWeather data service 3.0'][0]
     update_time = get_current_time()
     temperature = str(wea_json['now']['tmp'])
     humidity = str(wea_json['now']['hum'])
     radiation = '300'
     co2 = '600'
     wind_direction = wea_json['now']['wind']['dir']
     wind_speed = str(wea_json['now']['wind']['spd'])
     rain = wea_json['now']['pcpn']
     if (float(rain)) > 1.0:
         rain = 'true'  # raining
     else:
         rain = 'false'  # no rain
     atmosphere = str(wea_json['now']['pres'])
     self.set_outdoor(update_time, temperature, humidity, radiation, co2,
                      wind_direction, wind_speed, rain, atmosphere)
Пример #37
0
    def __init__(self):
        self.__update_time = get_current_time()
        self.__time1 = "1"
        self.__temperature1 = "1"
        self.__time2 = "1"
        self.__temperature2 = "1"
        self.__time3 = "1"
        self.__temperature3 = "1"
        self.__time4 = "1"
        self.__temperature4 = "1"

        self.__co2_upper_limit = "1"
        self.__co2_lower_limit = "1"

        self.__cooling_start_temperature = "1"
        self.__cooling_stop_temperature = "1"

        self.__expect_humidity = "1"
        self.__humidity_influence_range_of_air_temperature = "1"
        self.__low_humidity_influence_on_air_temperature = "1"
        self.__high_humidity_influence_on_air_temperature = "1"
        self.__expect_light = "1"
        self.__light_influence_on_air_temperature_slope = "1"
        self.__high_light_influence_on_temperature = "1"
        self.__low_light_influence_on_temperature = "1"
        self.__frost_temperature = "1"
        self.__indoor_temperature_lower_limit = "1"
        self.__roof_vent_wind_speed_upper_limit = "1"
        self.__roof_vent_rain_upper_limit = "1"

        self.__heating_start_lowest_temperature = "1"
        self.__heating_stop_highest_temperature = "1"

        self.__month_to_open_thermal_screen = "1"
        self.__month_to_close_thermal_screen = "1"
        self.__time_to_open_thermal_screen = "1"
        self.__time_to_close_thermal_screen = "1"

        self.__temperature_to_open_side = "1"
        self.__wait_time_to_open_side = "1"
        self.__rain_upper_limit_to_close = "1"

        self.__upper_limit_light_to_open_out_shade_screen = "1"
        self.__upper_limit_light_to_open_in_shade_screen = "1"
        self.__soil_humidity_to_start_irrigation = "1"
        self.__soil_humidity_to_stop_irrigation = "1"
        self.__temperature_to_open_fogging = "1"
        self.__temperature_to_open_cooling_pad = "1"

        self.__month_to_open_lighting = "1"
        self.__month_to_close_lighting = "1"
        self.__period1_start_lighting = "1"
        self.__period1_stop_lighting = "1"
        self.__period2_start_lighting = "1"
        self.__period2_stop_lighting = "1"
        self.__radiation1_to_open_lighting = "1"
        self.__radiation2_to_open_lighting = "1"

        self.__roof_vent_open_time = "1"
        self.__side_vent_open_time = "1"
        self.__shade_screen_out_open_time = "1"
        self.__shade_screen_in_open_time = "1"
        self.__thermal_screen_open_time = "1"
Пример #38
0
def update_control():
    get_db_control_state(control)
    print 'control updated', get_current_time()
Пример #39
0
def update_indoor():
    #     save_db_indoor(node0)
    print 'indoor updated', get_current_time()
Пример #40
0
def update_control():
    """ 传感器状态更新 """
    # save_db_control(c)
    print 'control updated', get_current_time()
Пример #41
0
def update_outdoor():
    outdoor.get_weather_from_api()
    #     save_db_outdoor(outdoor)
    print 'outdoor updated', get_current_time()
Пример #42
0
# 测试节点数据
node0 = Indoor('1')

# 室外环境数据
outdoor = Outdoor()
c = Control()

# 参数数据
p = Parameter()

control_method = "computer"
isConnect = False

# 服务器url
url = "http://121.43.106.119:8090/"
start_time = get_current_time()
indoor_node_data = ''''''


def server_connect():
    """ 测试与服务器连接状况 """
    global isConnect, start_time
    try:
        data = urllib.urlopen(url).read()
        if data == 'success':
            isConnect = True
        print 'server connect success'
    except:
        start_time = get_current_time()
        isConnect = False
        print 'server disconnect'
Пример #43
0
    def build_to_json(self):
        return '''{       "update_time":"%s",
           "plant_parameter_setting":{
                                "time1":"%s", 
                                "temperature1":"%s",
                                "time2":"%s",
                                "temperature2":"%s",
                                "time3":"%s",
                                "temperature3":"%s",
                                "time4":"%s",
                                "temperature4":"%s"
                                      },
           "co2_parameter_setting":{
                                "co2_upper_limit":"%s",
                                "co2_lower_limit":"%s"
                                    },
           "cooling_fans":{
                          "cooling_start_temperature":"%s",
                          "cooling_stop_temperature":"%s"
                          },
           "roof_vent_parameter_setting":{
                                "expect_humidity":"%s",  
                                "humidity_influence_range_of_air_temperature":"%s", 
                                "low_humidity_influence_on_air_temperature":"%s",
                                "high_humidity_influence_on_air_temperature":"%s",
                                "expect_light":"%s",
                                "light_influence_on_air_temperature_slope":"%s",
                                "high_light_influence_on_temperature":"%s",
                                "low_light_influence_on_temperature":"%s",
                                "frost_temperature":"%s",
                                "indoor_temperature_lower_limit":"%s",
                                "roof_vent_wind_speed_upper_limit":"%s",
                                "roof_vent_rain_upper_limit":"%s"
                                          },
           "heating_parameter_setting":{
                                "heating_start_lowest_temperature":"%s",
                                "heating_stop_highest_temperature":"%s"
                                        },
           "thermal_screen_parameter_setting":{
                                        "month_to_open_thermal_screen":"%s",
                                        "month_to_close_thermal_screen":"%s",
                                        "time_to_open_thermal_screen":"%s",
                                        "time_to_close_thermal_screen":"%s"
                                               },
           "side_vent_parameter_setting":{
                                    "temperature_to_open_side":"%s",
                                    "wait_time_to_open_side":"%s",
                                    "rain_upper_limit_to_close":"%s"
                                          },
           "other_parameter_setting":{
                             "upper_limit_light_to_open_out_shade_screen" :"%s" ,
                             "upper_limit_light_to_open_in_shade_screen" :"%s",
                             "soil_humidity_to_start_irrigation":"%s",
                             "soil_humidity_to_stop_irrigation":"%s",
                             "temperature_to_open_fogging":"%s",
                             "temperature_to_open_cooling_pad":"%s"
                                      },
            "lighting_setting":{
                    "month_to_open_lighting":"%s",
                    "month_to_close_lighting":"%s",
                    "period1_start_lighting":"%s",
                    "period1_stop_lighting":"%s",
                    "period2_start_lighting":"%s",
                    "period2_stop_lighting":"%s",
                    "radiation1_to_open_lighting":"%s",
                    "radiation2_to_open_lighting":"%s"
                        },
             "time_that_full_open_to_full_close":{
                        "roof_vent_open_time":"%s",
                        "side_vent_open_time":"%s",
                        "shade_screen_out_open_time":"%s",
                        "shade_screen_in_open_time":"%s",
                        "thermal_screen_open_time":"%s"
                             }
           }                 
           ''' \
               % (get_current_time(),
                  self.get_time_1(),
                  self.get_temperature_1(),
                  self.get_time_2(),
                  self.get_temperature_2(),
                  self.get_time_3(),
                  self.get_temperature_3(),
                  self.get_time_4(),
                  self.get_temperature_4(),

                  self.get_co_2_upper_limit(),
                  self.get_co_2_lower_limit(),

                  self.get_cooling_start_temperature(),
                  self.get_cooling_stop_temperature(),

                  self.get_expect_humidity(),
                  self.get_humidity_influence_range_of_air_temperature(),
                  self.get_low_humidity_influence_on_air_temperature(),
                  self.get_high_humidity_influence_on_air_temperature(),
                  self.get_expect_light(),
                  self.get_light_influence_on_air_temperature_slope(),
                  self.get_high_light_influence_on_temperature(),
                  self.get_low_light_influence_on_temperature(),
                  self.get_frost_temperature(),
                  self.get_indoor_temperature_lower_limit(),
                  self.get_roof_vent_wind_speed_upper_limit(),
                  self.get_roof_vent_rain_upper_limit(),

                  self.get_heating_start_lowest_temperature(),
                  self.get_heating_stop_highest_temperature(),

                  self.get_month_to_open_thermal_screen(),
                  self.get_month_to_close_thermal_screen(),
                  self.get_time_to_open_thermal_screen(),
                  self.get_time_to_close_thermal_screen(),

                  self.get_temperature_to_open_side(),
                  self.get_wait_time_to_open_side(),
                  self.get_rain_upper_limit_to_close(),

                  self.get_upper_limit_light_to_open_out_shade_screen(),
                  self.get_upper_limit_light_to_open_in_shade_screen(),
                  self.get_soil_humidity_to_start_irrigation(),
                  self.get_soil_humidity_to_stop_irrigation(),
                  self.get_temperature_to_open_fogging(),
                  self.get_temperature_to_open_cooling_pad(),

                  self.get_month_to_open_lighting(),
                  self.get_month_to_close_lighting(),
                  self.get_period_1_start_lighting(),
                  self.get_period_1_stop_lighting(),
                  self.get_period_2_start_lighting(),
                  self.get_period_2_stop_lighting(),
                  self.get_radiation_1_to_open_lighting(),
                  self.get_radiation_2_to_open_lighting(),

                  self.get_roof_vent_open_time(),
                  self.get_side_vent_open_time(),
                  self.get_shade_screen_out_open_time(),
                  self.get_shade_screen_in_open_time(),
                  self.get_thermal_screen_open_time()
        )
Пример #44
0
def update_control():
    # save_db_control(c)
    print 'control updated', get_current_time()
Пример #45
0
def lighting_control(Control, Outdoor, Parameter):
    global lighting_stop_time, lighting_stop_time2, lighting_stop_time3
    auto_lighting_1 = Control.get_lighting_1()
    auto_lighting_2 = Control.get_lighting_2()
    if auto_lighting_1 == "off" and auto_lighting_2 == "off":
        if get_current_month() > Parameter.get_month_to_open_lighting(
        ) and get_current_month() < Parameter.get_month_to_close_lighting():
            if get_current_time() > Parameter.get_period_1_start_lighting(
            ) and get_current_time() < Parameter.get_period_1_stop_lighting():
                if Outdoor.get_radiation(
                ) < Parameter.get_radiation_1_to_open_lighting():
                    #                         Control.set_lighting_1("on")
                    bi_state_relay_output("lighting_1", "on")
                    auto_lighting_1 = "on"
                    lighting_open_time = get_time()
            elif get_current_time() > Parameter.get_period_2_start_lighting(
            ) and get_current_time() < Parameter.get_period_2_stop_lighting():
                if Outdoor.get_radiation(
                ) < Parameter.get_radiation_2_to_open_lighting():
                    #                         Control.set_lighting_1("on")
                    bi_state_relay_output("lighting_2", "on")
                    auto_lighting_2 = "on"
                    lighting_open_time2 = get_time()

    elif auto_lighting_1 == "on" and auto_lighting_2 == "off":
        t1 = int(get_time() - lighting_open_time)
        t2 = int(get_time() - lighting_open_time2)
        if t1 > 1750 and t1 < 1850:
            bi_state_relay_output("ligting_2", "on")
            auto_lighting_2 = "on"
        #                 Control.set_lighting_2("on")
        if t2 > 1750 and t2 < 1850:
            #                 Control.set_lighting_2("on")
            bi_state_relay_output("ligting_2", "on")
            auto_lighting_2 = "on"
    elif auto_lighting_1 == "on" and auto_lighting_2 == "on":
        if get_current_time() > Parameter.get_period_1_start_lighting(
        ) and get_current_time() < Parameter.get_period_1_stop_lighting():
            if Outdoor.get_radiation(
            ) > Parameter.get_radiation_1_to_open_lighting():
                #                     Control.set_lighting_1("off")
                bi_state_relay_output("ligting_1", "off")
                auto_lighting_1 = "off"
                lighting_stop_time = get_time()
        elif get_current_time() > Parameter.get_period_2_start_lighting(
        ) and get_current_time() < Parameter.get_period_2_stop_lighting():
            if Outdoor.get_radiation(
            ) > Parameter.get_radiation_2_to_open_lighting():
                #                     Control.set_lighting_1("off")
                bi_state_relay_output("ligting_1", "off")
                auto_lighting_1 = "off"
                lighting_stop_time2 = get_time()
        else:
            #                 Control.set_lighting_1("off")
            bi_state_relay_output("ligting_1", "off")
            auto_lighting_1 = "off"
            lighting_stop_time3 = get_time()

    elif auto_lighting_1 == "off" and auto_lighting_2 == "on":
        t3 = get_time() - lighting_stop_time3
        t4 = get_time() - lighting_stop_time2
        t5 = get_time() - lighting_stop_time
        if t3 > 1750 and t3 < 1850:
            bi_state_relay_output("ligting_2", "off")
        #                 Control.set_lighting_2("off")
        if t4 > 1750 and t4 < 1850:
            bi_state_relay_output("ligting_2", "off")
        #                 Control.set_lighting_2("off")
        if t5 > 1750 and t5 < 1850:
            bi_state_relay_output("ligting_2", "off")
        #                 Control.set_lighting_2("off")
    else:
        bi_state_relay_output("ligting_2", "off")
        bi_state_relay_output("ligting_1", "off")
Пример #46
0
def lighting_control(Control, Outdoor, Parameter):
    global lighting_stop_time, lighting_stop_time2, lighting_stop_time3
    auto_lighting_1 = Control.get_lighting_1()
    auto_lighting_2 = Control.get_lighting_2()
    if auto_lighting_1 == "off" and auto_lighting_2 == "off":
        if get_current_month() > Parameter.get_month_to_open_lighting() and get_current_month() < Parameter.get_month_to_close_lighting():
            if get_current_time() > Parameter.get_period_1_start_lighting() and get_current_time() < Parameter.get_period_1_stop_lighting():
                if Outdoor.get_radiation() < Parameter.get_radiation_1_to_open_lighting():
                    #                         Control.set_lighting_1("on")
                    bi_state_relay_output("lighting_1", "on")
                    auto_lighting_1 = "on"
                    lighting_open_time = get_time()
            elif get_current_time() > Parameter.get_period_2_start_lighting() and get_current_time() < Parameter.get_period_2_stop_lighting():
                if Outdoor.get_radiation() < Parameter.get_radiation_2_to_open_lighting():
                    #                         Control.set_lighting_1("on")
                    bi_state_relay_output("lighting_2", "on")
                    auto_lighting_2 = "on"
                    lighting_open_time2 = get_time()

    elif auto_lighting_1 == "on" and auto_lighting_2 == "off":
        t1 = int(get_time() - lighting_open_time)
        t2 = int(get_time() - lighting_open_time2)
        if t1 > 1750 and t1 < 1850:
            bi_state_relay_output("ligting_2", "on")
            auto_lighting_2 = "on"
        #                 Control.set_lighting_2("on")
        if t2 > 1750 and t2 < 1850:
            #                 Control.set_lighting_2("on")
            bi_state_relay_output("ligting_2", "on")
            auto_lighting_2 = "on"
    elif auto_lighting_1 == "on" and auto_lighting_2 == "on":
        if get_current_time() > Parameter.get_period_1_start_lighting() and get_current_time() < Parameter.get_period_1_stop_lighting():
            if Outdoor.get_radiation() > Parameter.get_radiation_1_to_open_lighting():
                #                     Control.set_lighting_1("off")
                bi_state_relay_output("ligting_1", "off")
                auto_lighting_1 = "off"
                lighting_stop_time = get_time()
        elif get_current_time() > Parameter.get_period_2_start_lighting() and get_current_time() < Parameter.get_period_2_stop_lighting():
            if Outdoor.get_radiation() > Parameter.get_radiation_2_to_open_lighting():
                #                     Control.set_lighting_1("off")
                bi_state_relay_output("ligting_1", "off")
                auto_lighting_1 = "off"
                lighting_stop_time2 = get_time()
        else:
            #                 Control.set_lighting_1("off")
            bi_state_relay_output("ligting_1", "off")
            auto_lighting_1 = "off"
            lighting_stop_time3 = get_time()

    elif auto_lighting_1 == "off" and auto_lighting_2 == "on":
        t3 = get_time() - lighting_stop_time3
        t4 = get_time() - lighting_stop_time2
        t5 = get_time() - lighting_stop_time
        if t3 > 1750 and t3 < 1850:
            bi_state_relay_output("ligting_2", "off")
        #                 Control.set_lighting_2("off")
        if t4 > 1750 and t4 < 1850:
            bi_state_relay_output("ligting_2", "off")
        #                 Control.set_lighting_2("off")
        if t5 > 1750 and t5 < 1850:
            bi_state_relay_output("ligting_2", "off")
        #                 Control.set_lighting_2("off")
    else:
        bi_state_relay_output("ligting_2", "off")
        bi_state_relay_output("ligting_1", "off")
Пример #47
0
    def __init__(self):
        self.__update_time = get_current_time()
        self.__time1 = "1"
        self.__temperature1 = "1"
        self.__time2 = "1"
        self.__temperature2 = "1"
        self.__time3 = "1"
        self.__temperature3 = "1"
        self.__time4 = "1"
        self.__temperature4 = "1"

        self.__co2_upper_limit = "1"
        self.__co2_lower_limit = "1"

        self.__cooling_start_temperature = "1"
        self.__cooling_stop_temperature = "1"

        self.__expect_humidity = "1"
        self.__humidity_influence_range_of_air_temperature = "1"
        self.__low_humidity_influence_on_air_temperature = "1"
        self.__high_humidity_influence_on_air_temperature = "1"
        self.__expect_light = "1"
        self.__light_influence_on_air_temperature_slope = "1"
        self.__high_light_influence_on_temperature = "1"
        self.__low_light_influence_on_temperature = "1"
        self.__frost_temperature = "1"
        self.__indoor_temperature_lower_limit = "1"
        self.__roof_vent_wind_speed_upper_limit = "1"
        self.__roof_vent_rain_upper_limit = "1"

        self.__heating_start_lowest_temperature = "1"
        self.__heating_stop_highest_temperature = "1"

        self.__month_to_open_thermal_screen = "1"
        self.__month_to_close_thermal_screen = "1"
        self.__time_to_open_thermal_screen = "1"
        self.__time_to_close_thermal_screen = "1"

        self.__temperature_to_open_side = "1"
        self.__wait_time_to_open_side = "1"
        self.__rain_upper_limit_to_close = "1"

        self.__upper_limit_light_to_open_out_shade_screen = "1"
        self.__upper_limit_light_to_open_in_shade_screen = "1"
        self.__soil_humidity_to_start_irrigation = "1"
        self.__soil_humidity_to_stop_irrigation = "1"
        self.__temperature_to_open_fogging = "1"
        self.__temperature_to_open_cooling_pad = "1"

        self.__month_to_open_lighting = "1"
        self.__month_to_close_lighting = "1"
        self.__period1_start_lighting = "1"
        self.__period1_stop_lighting = "1"
        self.__period2_start_lighting = "1"
        self.__period2_stop_lighting = "1"
        self.__radiation1_to_open_lighting = "1"
        self.__radiation2_to_open_lighting = "1"

        self.__roof_vent_open_time = "1"
        self.__side_vent_open_time = "1"
        self.__shade_screen_out_open_time = "1"
        self.__shade_screen_in_open_time = "1"
        self.__thermal_screen_open_time = "1"