def temper(): fan_flg = 0 while (1): time.sleep(1) #not needed given only for checking value #reading RTC value t = i2c.i2c_time() os.system("clear") print "Time : ", t #not needed given for testing code #reading temperature value tem = temp.read_temp() print "Temperature : ", tem, " c" #not needed given for testing code if tem > 29.0 and fan_flg == 0: time.sleep(3) tem = temp.read_temp() if tem > 29.0: data = {'FAN': 'ON'} pubnub.publish(channel1, data, callback=callback, error=callback) GPIO.output(FAN, False) message = client.messages.create( to="+919446047003", from_="+14xxxxxxx2", body="AC is turning on at " + t + "\ntemperature : " + str(tem)) print message.sid fan_flg = 1 elif tem <= 29.0 and fan_flg == 1: GPIO.output(FAN, True) fan_flg = 0
def temper(): fan_flg = 0 while (1): time.sleep(2) #reading RTC value t = i2c.i2c_time() os.system("clear") print "Time : ", t #reading temperature value tem = temp.read_temp() print "Temperature : ", tem, " c" if int(tem) > 28 and fan_flg == 0: time.sleep(3) tem = temp.read_temp() if int(tem) > 28: data = {'FAN': 'ON'} pubnub.publish(channel1, data, callback=callback, error=callback) GPIO.output(FAN, False) message = client.messages.create( to="+918075946770", from_="+14xxxxxxxxxxxxxxxxx32", body="AC is turning on at " + t + "\ntemperature : " + str(tem)) print message.sid fan_flg = 1 elif int(tem) <= 28 and fan_flg == 1: GPIO.output(FAN, True) fan_flg = 0
def program(pirPin, pirLight, trigL, echoL, trigR, echoR): pirState = 0 while True: state = pir.getPir(pirState, pirPin, pirLight) pirState = state threading.Thread(target=dist.getDist, args=(trigL, echoL)).start() time.sleep(2) threading.Thread(target=dist.getDist, args=(trigR, echoR)).start() time.sleep(2) print(temp.read_temp())
def read_do(read_arduino, slave_addr, sensor_type, *args): try: adc_raw = read_arduino(slave_addr, sensor_type)[1] adc_voltage = round(adc_raw) * reference / resolution print("adc raw DO: ", adc_raw) print("mv: ", adc_voltage) temp = read_temp() rounded_temp = round(temp[1]) V_saturation = (temp[1] - cal2_t) * (cal1_v - cal2_v) / ( cal1_t - cal2_t) + cal2_v do = round(adc_voltage * do_table[rounded_temp] / V_saturation, 2) if do > 20: do = 20 elif do < 0: do = 0 print("do: ", do) return "ok", do except: print(traceback.format_exc()) return "error", traceback.format_exc()
return con except Error: print(Error) def sql_table(con): cursorObj = con.cursor() cursorObj.execute("create table if not exists reading(id integer PRIMARY KEY AUTOINCREMENT, sensor text, raw_value real, created_at datetime)") con.commit() def drop_table(con): cursorObj = con.cursor() cursorObj.execute("drop table if exists reading") con.commit() def insert_record(con, entities): cursorObj = con.cursor() cursorObj.execute('INSERT INTO reading(sensor, raw_value, created_at) VALUES(?, ?, ?)', entities) con.commit() con = sql_connection() # drop_table(con) sql_table(con) while True: #print(read_temp()) entities = ('INSIDE_TEMP', temp.read_temp()[0], datetime.datetime.now()) insert_record(con,entities) time.sleep(30)
def temperature(): print("Температурата е: " + temp.read_temp() + " градуса") writeOnLCD(str(temp.read_temp())) talk("Температурата е" + temp.read_temp() + " градуса")
GPIO.setup(26, GPIO.OUT) def on(): GPIO.output(26, GPIO.LOW) def off(): GPIO.output(26, GPIO.HIGH) t = weather.get_temperature() try: while True: time_now = datetime.datetime.now() if (time_now.minute == 0 and time_now.second == 0): t = weather.get_temperature() if (t[0] >= 30): set_temp = (t[0] * 0.9) + (t[1] * 0.05) else: set_temp = (t[0] * 1.1) + (t[1] * 0.05) read = temp.read_temp() print(set_temp, read) sleep_time = 1 - (1 / (set_temp - read)) on() time.sleep(sleep_time) off() except KeyboardInterrupt: off()
def temp_display(): # Return the current temperature return msg_tmpl('temp is ' + '{:.1f}'.format(temp.read_temp(temp.setup())) + ' C', 100)
def temp(): while True: temp = read_temp() yield temp
# coding=utf-8 import time import temp, led while True: total_temp = 0 for sensor in temp.sensors: sensor_temp = temp.read_temp(sensor) #print "{} -- {}".format(sensor["code"],sensor_temp) total_temp += sensor_temp total_temp = total_temp / len(temp.sensors) print u"TEMPERATURE => {} ºC".format(total_temp) led.all_off() led.show_value(total_temp) time.sleep(1)
return "ok", do except: print(traceback.format_exc()) return "error", traceback.format_exc() # do_table = [14460, 14220, 13820, 13440, 13090, 12740, 12420, 12110, 11810, 11530, # 11260, 11010, 10770, 10530, 10300, 10080, 9860, 9660, 9460, 9270, # 9080, 8900, 8730, 8570, 8410, 8250, 8110, 7960, 7820, 7690, # 7560, 7430, 7300, 7180, 7070, 6950, 6840, 6730, 6630, 6530, 6410] # def read_do(read_arduino, slave_addr, sensor_type, *args): # try: # adc_raw = read_arduino(slave_addr, sensor_type)[1] # adc_voltage = round(adc_raw)*reference/resolution # print("adc raw DO: ", adc_raw) # print("mv: ", adc_voltage) # temp = read_temp() # rounded_temp = round(temp[1]) # V_saturation = cal1_v + (35 * temp[1]) - (cal1_v * 35); # print("do" , round(adc_voltage * do_table[rounded_temp] / V_saturation, 2)) # return "ok", round(adc_voltage * do_table[rounded_temp] / V_saturation, 2) # except: # print(traceback.format_exc()) # return "error", traceback.format_exc() if __name__ == "__main__": from i2c import read_arduino print("dissolved oxygen: ", read_do(read_arduino, 11, 3)) print("temp: ", read_temp())
i = 1 while i <= length: bed = beds[i] # get moisture reading CHANNEL = bed['moisture']['CHANNEL'] CLK = bed['moisture']['CLK'] MISO = bed['moisture']['MISO'] MOSI = bed['moisture']['MOSI'] CS = bed['moisture']['CS'] moisture = adc.read_moisture(CHANNEL, CLK, MISO, MOSI, CS) # get temp readings temp_id = bed['temp_id'] temperature = temp.read_temp(temp_id) # create timestamp # timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') timestamp = int(time.time()) #create objects for request data = { 'timestamp': timestamp, 'temp': temperature, 'moisture': moisture } url = base_url + '/d/' + bed['url']['location'] + '/' + bed['url'][ 'plot'] + '/' + 'add-data' # send request
import time from datetime import datetime from azure.storage.table import TableService import temp table_service = TableService(account_name='<AZURE_NAME_HERE>', account_key='<KEY_HERE>') table_name = 'tempData' partition_key = 'central' table_service.create_table(table_name, False) date = datetime.now() iso_date = date.isoformat() tempRecord = temp.read_temp() entry = {'PartitionKey': partition_key, 'RowKey': iso_date, 'Temperature': tempRecord} table_service.insert_entity(table_name, entry) print("SENT", tempRecord)
os.system('clear') led_data(False); print print ' GPS reading' print '----------------------------------------' print 'latitude ' , gpsd.fix.latitude print 'longitude ' , gpsd.fix.longitude print 'time utc ' , gpsd.utc print 'altitude (m)' , gpsd.fix.altitude print 'speed (m/s) ' , gpsd.fix.speed print 'mode ' , gpsd.fix.mode print ' ' # Get Temperature temp = read_temp() print ("Temperature: %.2f" % temp[0]) # Build filename to save data file_name = get_file_name(gpsd.utc) # Save the picture args = [] args.append({"name": "width" , "argument": "1920"}); args.append({"name": "height", "argument": "1080"}); args.append({"name": "exposure", "argument": "sports"}); args.append({"name": "hflip", "argument": "true"}); args.append({"name": "vflip", "argument": "true"});
# -*- coding: utf-8 -*- import gspread import datetime import time from temp import read_temp while True: gc = gspread.login('...', '...') values = [datetime.datetime.now(), read_temp()] wks = gc.open("...").sheet1 wks.append_row(values) time.sleep(600)