def reset_firebase(settings): # Nuke existing Firebase data and push default values to database
	try:
		r = firebase.put('/','settings', settings, params=fb_params)
#		r = firebase.delete('/','temp-history', params=fb_params)
		r = firebase.delete('/','PID', params=fb_params)
		r = firebase.delete('/','cook', params=fb_params)
		r = firebase.delete('/','timers', params=fb_params)
		r = firebase.delete('/','programs', params=fb_params)
	except Exception:
		SmokeLog.common.error('Failed to initialize database!')
		SmokeLog.common.error(traceback.format_exc())
		sys.exit(1)
	else:
		SmokeLog.common.notice('Successfully initialized database.')

	pid_defaults = {'Time': time.time()*1000, 'u': 0, 'P':0, 'I': 0, 'D': 0, 'PID': 0, 'Error': 0, 'Derv': 0, 'Inter': 0}

	try:
		r = firebase.post_async('/PID', pid_defaults, params=fb_params)
	except Exception:
		SmokeLog.common.error('Failed to push default values for /PID!')
		SmokeLog.common.error(traceback.format_exc())
		sys.exit(1)
	else:
		timers['LastSettingsPush'] = time.time()
		SmokeLog.common.info('Successfully pushed default values for /PID.')
Exemple #2
0
def ResetFirebase(Parameters):

    try:
        r = firebase.put('/', 'Parameters', Parameters, params=Params)
        r = firebase.delete('/', 'Temps', params=Params)
        r = firebase.delete('/', 'Controls', params=Params)
        r = firebase.delete('/', 'Program', params=Params)
    except:
        logger.info('Error initializing Firebase')

    #Post control state
    D = {
        'time': time.time() * 1000,
        'u': 0,
        'P': 0,
        'I': 0,
        'D': 0,
        'PID': 0,
        'Error': 0,
        'Derv': 0,
        'Inter': 0
    }

    try:
        r = firebase.post_async('/Controls',
                                D,
                                params=Params,
                                callback=PostCallback)
    except:
        logger.info('Error writing Controls to Firebase')
Exemple #3
0
def DoControl(Parameters, Temps):
    if (time.time() - Control.LastUpdate) > Parameters['CycleTime']:

        Avg = GetAverageSince(Temps, Control.LastUpdate)
        Parameters['u'] = Control.update(
            Avg[1])  #Grill probe is [0] in T, [1] in Temps
        Parameters['u'] = max(Parameters['u'], u_min)
        Parameters['u'] = min(Parameters['u'], u_max)
        logger.info('u %f', Parameters['u'])

        #Post control state
        D = {
            'time': time.time() * 1000,
            'u': Parameters['u'],
            'P': Control.P,
            'I': Control.I,
            'D': Control.D,
            'PID': Control.u,
            'Error': Control.error,
            'Derv': Control.Derv,
            'Inter': Control.Inter
        }

        try:
            r = firebase.post_async('/Controls',
                                    D,
                                    params=Params,
                                    callback=PostCallback)
        except:
            logger.info('Error writing Controls to Firebase')

        Parameters = WriteParameters(Parameters)

    return Parameters
def push_recent_temps(settings, entry): # Pushes temperature history to Firebase
	try:
		r = firebase.post_async('/temp-history', {'Timestamp': entry[0]*1000, 'TargetGrill': settings['TargetGrill'], 'TargetFood': settings['TargetFood'], 'Grill': entry[1], 'Food':entry[2]}, params=fb_params)
	except Exception:
		SmokeLog.common.error('Failed to push new log entry to Firebase!')
		SmokeLog.common.error(traceback.format_exc())
		sys.exit(1)
	else:
		SmokeLog.common.debug('Success.')
Exemple #5
0
def PostTemps(Parameters, Ts):
    try:
        r = firebase.post_async('/Temps', {
            'time': Ts[0] * 1000,
            'TT': Parameters['target'],
            'T1': Ts[1],
            'T2': Ts[2]
        },
                                params=Params,
                                callback=PostCallback)
    except:
        logger.info('Error writing Temps to Firebase')
def ResetFirebase(Parameters):
    try:
        r = firebase.put('/', 'Parameters', Parameters, params=Params)
        r = firebase.delete('/', 'Temps', params=Params)
        r = firebase.delete('/', 'Controls', params=Params)
        r = firebase.delete('/', 'Program', params=Params)
    except:
        logger.info('Error initializing Firebase')
        #Post control state
        D = {'time': time.time() * 1000, 'u': 0, 'P': 0, 'I': 0, 'D': 0, 'PID': 0, 'Error': 0, 'Derv': 0, 'Inter': 0}
    try:
        r = firebase.post_async('/Controls', D, params=Params, callback=PostCallback)
    except:
        logger.info('Error ResetFirebase() writing Controls to Firebase')
def DoControl(Parameters, Temps):
    if (time.time() - Control.LastUpdate) > Parameters['CycleTime']:

        Avg = GetAverageSince(Temps, Control.LastUpdate)
        Parameters['u'] = Control.update(Avg[1])  # Grill probe is [0] in T, [1] in Temps
        Parameters['u'] = max(Parameters['u'], u_min)
        Parameters['u'] = min(Parameters['u'], u_max)
        logger.info('u %f', Parameters['u'])

        #Post control state
        D = {'time': time.time() * 1000, 'u': Parameters['u'], 'P': Control.P, 'I': Control.I, 'D': Control.D, 'PID': Control.u, 'Error': Control.error, 'Derv': Control.Derv, 'Inter': Control.Inter}

        try:
            r = firebase.post_async('/Controls', D , params=Params, callback=PostCallback)
        except:
            logger.info('Error in DoControl() writing Controls to Firebase')

        Parameters = WriteParameters(Parameters)
    return Parameters
def do_control(settings, recent_temps): # PID control mode (hold)
	if (time.time() - PID.last_update) > settings['CycleTime']:
		avg = get_average_since(recent_temps, PID.last_update)
		settings['u'] = PID.update(avg[1]) # Average grill probe temp
		settings['u'] = max(settings['u'],u_min)
		settings['u'] = min(settings['u'],u_max)
		SmokeLog.common.notice('Updated u: {}'.format(settings['u']))

		# Post control state
		pid_values = {'Time': time.time()*1000, 'u': settings['u'], 'P': PID.P, 'I': PID.I, 'D': PID.D, 'PID': PID.u, 'Error': PID.error, 'Derv': PID.derv, 'Inter': PID.inter}
		try:
			r = firebase.post_async('/PID', pid_values, params=fb_params)
		except Exception:
			SmokeLog.common.error('Failed to push updated PID settings to Firebase!')
			SmokeLog.common.error(traceback.format_exc())
			sys.exit(1)
		else:
			SmokeLog.common.notice('Pushed new PID settings to Firebase: {}'.format(pid_values))

		settings = push_settings(settings)
		
	return settings
Exemple #9
0
def PostTemps(Parameters, Ts):
	try:
		r = firebase.post_async('/Temps', {'time': Ts[0]*1000, 'TT': Parameters['target'], 'T1': Ts[1], 'T2':Ts[2]} , params=Params, callback=PostCallback)
	except:
		logger.info('Error writing Temps to Firebase')
Exemple #10
0
      print(labels[i], results[i])
    firebase = firebase.FirebaseApplication('https://plant-wahid.firebaseio.com/plant-wahid')
    # res = firebase.get('/',None)
    name1 = str(labels[top_k[0]])
    value1 = str(results[top_k[0]])
    # mylist = res
    # mylist.append({name1:value1})
    # mylist = mylist[::-1]

    text_file = open("output.txt", "r")

    fileData = text_file.read()
    print(fileData)
    # print("heejsahdjkhsa")
    text_file.close()
    
    if(fileData != name1): 
      print("\n\nNew Entry\n\n\n") 
      text_file = open("output.txt", "w")
      text_file.write(name1)
      text_file.close()
      if(float(value1) > 0.70):
        myvalue = {'author':'serverside', 'name': name1,'value':value1}
        print("\n\n\n\ndisease\n\n\n\n")
      else:
        myvalue = {'author':'serverside', 'name': "I'm not sure about the result, I recommended a recapture",'value':value1}
        print("\n\n\n\nsomething else\n\n\n\n")
      firebase.put('/','/',myvalue)
    firebase.post_async('/',{})