Пример #1
0
def insert():
		vname=request.args['vname']
		val1=request.args['val1']
		val2=request.args['val2']
		unit=request.args['unit']
		values=[val1,val2]
		api=ApiClient(token=tok)
		newvar=api.get_datasources()[0].create_variable({"name":vname,"unit":unit})
		newvar.save_values([{"timestamp":12345,"value":values[0]},{"timestamp":12346,"value":values[1]}])
		return render_template('index.html',msg="variable created")
Пример #2
0
def getvalues():
		
		api=ApiClient(token=tok)

		datasource=api.get_datasources()[0]
		variable=datasource.get_variables()[0]
		value=variable.get_values()[0]['value']
	
		#print api.get_datasources()[0].get_variables()[0].get_values()[0]['value']
		print datasource
		print variable
		print value
		return render_template('index.html',msg="got values "+str(value))
Пример #3
0
def getvalues():
		api=ApiClient(token='3tC3qYIDnOh4eNqOoGXZMzBUsAnjfH')
		all_datasources=api.get_datasources()
		variables=all_datasources[0].get_variables()
		var=[]
		count=0
		length=[]
		for i in variables:
			val=[]
			c=i.get_values()
			for i in range(2):
				val.append(c[i]['value'])
			length.append(count)
			count+=1
			var.append(val)
		print var
		return render_template('var.html',name=all_datasources[0],variables=variables,values=var,length=length)
Пример #4
0
def create_datasource():
    name=request.form['name']
    tags=[request.form['tag1'],request.form['tag2']]
    description=request.form['description']
    print name,str(tags),description

    already_present=''
    api = ApiClient(token='4L4TakYO3sro5gmwWS5KDPztF8WTRq')
    all_datasources = api.get_datasources()
    print type(all_datasources)
    for i in all_datasources:
        if str(i) == name:
            print name+' is there'
            already_present='yes'
    if not already_present:
        new_datasource = api.create_datasource({"name": name, "tags": tags, "description": description}) 	#create new datasource
        print "datasource created\n"
    return render_template('datasource.html',name=name,tags=str(tags),description=description,already_present=already_present)
Пример #5
0
def get_value_variable():
    api = ApiClient(token='4L4TakYO3sro5gmwWS5KDPztF8WTRq')
    all_datasources = api.get_datasources()
    print all_datasources 
    name=all_datasources[0]
    variables=all_datasources[0].get_variables()	#all values
    print variables
    values_all=[]
    length=[]
    count=0
    for i in variables:
        values=[]
    	c=i.get_values()
        for k in range(3):
            values.append(c[k]['value'])
        length.append(count)
        count+=1
        values_all.append(values)
    print values_all

    return render_template('get_variables.html',name=name,variables=variables,values=values_all,length=length)    
Пример #6
0
def get_value_variable():
    api = ApiClient(token='s4d6ZNJZ7snnwpQhm4EGlscRJwtPvG')
    all_datasources = api.get_datasources()
    print all_datasources 
    name=all_datasources[0]
    variables=all_datasources[0].get_variables()	#all values
    print variables
    values_all=[]
    length=[]
    count=0
    for i in variables:
        values=[]
    	c=i.get_values()
        for k in range(3):
            values.append(c[k]['value'])
        length.append(count)
        count+=1
        values_all.append(values)
    print values_all

    return render_template('get_variables.html',name=name,variables=variables,values=values_all,length=length)    
Пример #7
0
def insert_variable():
    vname=request.form['vname']
    unit=request.form['unit']
    v1=request.form['value1']
    v2=request.form['value2']
    v3=request.form['value3']
    values=[ v1,v2,v3 ]

    api = ApiClient(token='4L4TakYO3sro5gmwWS5KDPztF8WTRq')
    all_datasources = api.get_datasources()
    print all_datasources 
    name=all_datasources[0]

    new_variable = all_datasources[0].create_variable({"name": vname, "unit": unit})					#create a new variable in the datasource
    print "variable0 created\n"

    new_variable.save_values([												#saving multiple values
    {'timestamp': 1380558972614, 'value': values[0]},
    {'timestamp': 1380558972915, 'value': values[1]},
    {'timestamp': 1380558973516, 'value': values[2]},])
    print "value saved to variable"

    return render_template('create_variable.html',name=name    ,variable=vname,unit=unit,values=values)
Пример #8
0
                GPIO.output(clockpin, True)
                GPIO.output(clockpin, False)
                adcout <<= 1
                if (GPIO.input(misopin)):
                        adcout |= 0x1
        GPIO.output(cspin, True)
        
        adcout >>= 1       					# first bit is 'null' so drop it
        return adcout
 
# Code to connect a Ubidots
 
try:
   api = ApiClient("75617caf2933588b7fd0da531155d16035138535") # Connect to Ubidots. Don't forget to put your own apikey
   
   for curDs in api.get_datasources():						# Check if there's any Data Source with the name AirPi
	if curDs.name == "AirPi":
		dS = curDs
		break
   if dS is None:
   	  dS = api.create_datasource({"name":"AirPi"})			# If doesn't exist it'll create a Data Source with the name Airpi
  
   lightValue = getVarbyNames("Light_level",dS)
   if lightValue is None:
	  lightValue = dS.create_variable({"name": "Light_level","unit": "lux"}) # Create a new Variable for light
 
   nitrogen = getVarbyNames("Nitrogen_dioxide_concentration",dS)
   if nitrogen is None:
	  nitrogen = dS.create_variable({"name": "Nitrogen_dioxide_concentration", "unit": "ppm"}) # Create a new Variable for NO2 level
 
   mic = getVarbyNames("Noise_level", dS)
Пример #9
0
def main():
    #global last_temp
    
    # initialize the lastMinute variable to the current time to start
    last_minute = datetime.datetime.now().minute
    # on startup, just use the previous minute as lastMinute
    last_minute -= 1
    if last_minute == 0:
        last_minute = 59

    # ========================================================
    # Code to connect a Ubidots
    # ========================================================
    try:
        api = ApiClient("A1E-baee7da49300eee20eb148229cf1ead45d71") # Connect to Ubidots. Don't forget to put your own apikey
        #api = ApiClient("A1E-6ea6e644f236c649a0a43105e276658540d9") # Connect to Ubidots. Don't forget to put your own apikey

        print("Inizializza Ubidots")

        for curDs in api.get_datasources():                        # Check if there's any Data Source with the name AirPi
            print("Inizializza Ubidots for get_datasources")
            if curDs.name == "PiSenseHat":
                dS = curDs
                break

        print("Inizializza Ubidots get_datasources")

        if dS is None:
            dS = api.create_datasource({"name":"PiSenseHat"})            # If doesn't exist it'll create a Data Source with the name Airpi

        print("Inizializza Ubidots dS")

        temp_ds = getVarbyNames("Temperature",dS)
        if temp_ds is None:
            temp_ds = dS.create_variable({"name": "Temperature", "unit": "C"})    #Create a new Variable for temperature

        print("Inizializza Ubidots temp_c")

        humidity_ds = getVarbyNames("Humidity",dS)
        if humidity_ds is None:
            humidity_ds = dS.create_variable({"name": "Humidity","unit": "%"}) # Create a new Variable for humidity

        print("Inizializza Ubidots humidity")

        pressure_ds = getVarbyNames("Pressure",dS)
        if pressure_ds is None:
            pressure_ds = dS.create_variable({"name": "Pressure","unit": "hPa"}) # Create a new Variable for temperature

        print("Ubidots Initialization complete")
    except:
        print("Can't connect to Ubidots")
        return

    # infinite loop to continuously check weather values
    while 1:
        # The temp measurement smoothing algorithm's accuracy is based
        # on frequent measurements, so we'll take measurements every 5 seconds
        # but only upload on measurement_interval
        current_second = datetime.datetime.now().second
        # are we at the top of the minute or at a 5 second interval?
        if (current_second == 0) or ((current_second % 5) == 0):
            # ========================================================
            # read values from the Sense HAT
            # ========================================================
            # Calculate the temperature. The get_temp function 'adjusts' the recorded temperature adjusted for the
            # current processor temp in order to accommodate any temperature leakage from the processor to
            # the Sense HAT's sensor. This happens when the Sense HAT is mounted on the Pi in a case.
            # If you've mounted the Sense HAT outside of the Raspberry Pi case, then you don't need that
            # calculation. So, when the Sense HAT is external, replace the following line (comment it out  with a #)
            calc_temp = get_temp()
            # with the following line (uncomment it, remove the # at the line start)
            # calc_temp = sense.get_temperature_from_pressure()
            # or the following line (each will work)
            # calc_temp = sense.get_temperature_from_humidity()
            # ========================================================
            # At this point, we should have an accurate temperature, so lets use the recorded (or calculated)
            # temp for our purposes
            temp_c = round(calc_temp, 1)
            temp_f = round(c_to_f(calc_temp), 1)
            humidity = round(sense.get_humidity(), 0)
            # convert pressure from millibars to inHg before posting
            pressure = round(sense.get_pressure(), 1) # * 0.0295300
            print("Temp: %sF (%sC), Pressure: %s mbar, Humidity: %s%%" % (temp_f, temp_c, pressure, humidity))

            # get the current minute
            current_minute = datetime.datetime.now().minute
            # is it the same minute as the last time we checked?
            if current_minute != last_minute:
                # reset last_minute to the current_minute
                last_minute = current_minute
                # is minute zero, or divisible by 10?
                # we're only going to take measurements every MEASUREMENT_INTERVAL minutes
                if (current_minute == 0) or ((current_minute % MEASUREMENT_INTERVAL) == 0):
                    # get the reading timestamp
                    now = datetime.datetime.now()
                    print("\n%d minute mark (%d @ %s)" % (MEASUREMENT_INTERVAL, current_minute, str(now)))
                    # did the temperature go up or down?
                    
                    celcius = temp_c
                    humpercent = humidity

                    celcius_color = [0,255,0] # Green
                    humpercent_color = [0,255,255] # Cyan
                    negative_celcius_color = [0,0,255] # Blue
                    negative_humpercent_color = [255,0,0] # Red
                    empty = [0,0,0] # Black

                    if celcius < 0:
                        celcius = abs(celcius)
                        celcius_color = negative_celcius_color
                    if humpercent < 0:
                        humpercent = abs(humpercent)
                        humpercent_color = negative_humpercent_color

                    # Map digits to the display array
                    pixel_offset = 0
                    index = 0
                    for index_loop in range(0, 4):
                        for counter_loop in range(0, 4):
                            display[index] = number[int(celcius/10)*16+pixel_offset]
                            display[index+4] = number[int(celcius%10)*16+pixel_offset]
                            display[index+32] = number[int(humpercent/10)*16+pixel_offset]
                            display[index+36] = number[int(humpercent%10)*16+pixel_offset]
                            pixel_offset = pixel_offset + 1
                            index = index + 1
                        index = index + 4

                    # Color the temperatures
                    for index in range(0, 64):
                        if display[index]:
                            if index < 32:
                                display[index] = celcius_color
                            else:
                                display[index] = humpercent_color
                        else:
                            display[index] = empty

                    # Clear the display
                    sense.low_light = True # Optional
                    sense.clear()
                    
                    # Display scroll messagge with temp hum and pressure
                    msg = "Temp: %sC Hum: %s%% Press: %s mbar" % (temp_c, humidity, pressure)
                    sense.show_message(msg, text_colour=[0,255,255], scroll_speed=0.1)

                    # set last_temp to the current temperature before we measure again
                    #last_temp = temp_c
                    
                    # Post values to Ubidots
                    print("Upload dei valori su Ubidots...")
                    try:
                        temp_ds.save_value({'value':temp_c})
                        humidity_ds.save_value({'value':humidity})
                        pressure_ds.save_value({'value':pressure})
                    except:
                        print("Upload dei valori su Ubidots... Failed; retry later")    
                    
                    sense.clear()
                    # Display temperature and humidity
                    sense.set_pixels(display)
                    
        # wait a second then check again
        # You can always increase the sleep value below to check less often
        time.sleep(1)  # this should never happen since the above is an infinite loop
Пример #10
0
message_count = 0

# Main Code
if __name__ == "__main__":
	
	cmdargs_dict = commandLineInit()
	
	serial_params = SerialParameters()
	groduino = hwInit(port=cmdargs_dict['port'], serial_parameters=serial_params)
	# TODO just init the server inside bot. Bot should take ip of server to connect to
	
	api = ApiClient(token='RBgwxE0fSTaFS7IH7EqIya2Nl6yVek') #TODO leer desde txt
	
	#Create a "Variable" object

	datas= api.get_datasources ()      

        dic={datas[0].name:datas[0],datas[1].name:datas[1],datas[2].name:datas[2]} # learning not to use Switchs fking Py...

        ctrlActFloraBox=dic['Ctrl Actuators floraBox']
        ctrlVarFloraBox=dic['Ctrl floraBox']
        varFloraBox=dic['Variables floraBox']
        
	while 1:
		message = groduino.receive(blocking=True)
		if not message:
			print ("No message")
		logging.debug('Handling: %s',message)
	
		try:
			message_dict =json.loads(message)
Пример #11
0
def main():
    global last_temp

    # initialize the lastMinute variable to the current time to start
    last_minute = datetime.datetime.now().minute
    # on startup, just use the previous minute as lastMinute
    last_minute -= 1
    if last_minute == 0:
        last_minute = 59

    # ========================================================
    # Code to connect a Ubidots
    # ========================================================
    try:
        api = ApiClient(
            "A1E-baee7da49300eee20eb148229cf1ead45d71"
        )  # Connect to Ubidots. Don't forget to put your own apikey
        #api = ApiClient("A1E-6ea6e644f236c649a0a43105e276658540d9") # Connect to Ubidots. Don't forget to put your own apikey

        print("Inizializza Ubidots")

        for curDs in api.get_datasources(
        ):  # Check if there's any Data Source with the name AirPi
            print("Inizializza Ubidots for get_datasources")
            if curDs.name == "PiSenseHat":
                dS = curDs
                break

        print("Inizializza Ubidots get_datasources")

        if dS is None:
            dS = api.create_datasource(
                {"name": "PiSenseHat"}
            )  # If doesn't exist it'll create a Data Source with the name Airpi

        print("Inizializza Ubidots dS")

        temp_ds = getVarbyNames("Temperature", dS)
        if temp_ds is None:
            temp_ds = dS.create_variable({
                "name": "Temperature",
                "unit": "C"
            })  #Create a new Variable for temperature

        print("Inizializza Ubidots temp_c")

        humidity_ds = getVarbyNames("Humidity", dS)
        if humidity_ds is None:
            humidity_ds = dS.create_variable({
                "name": "Humidity",
                "unit": "%"
            })  # Create a new Variable for humidity

        print("Inizializza Ubidots humidity")

        pressure_ds = getVarbyNames("Pressure", dS)
        if pressure_ds is None:
            pressure_ds = dS.create_variable({
                "name": "Pressure",
                "unit": "hPa"
            })  # Create a new Variable for temperature

        print("Ubidots Initialization complete")
    except:
        print("Can't connect to Ubidots")
        return

    # infinite loop to continuously check weather values
    while 1:
        # The temp measurement smoothing algorithm's accuracy is based
        # on frequent measurements, so we'll take measurements every 5 seconds
        # but only upload on measurement_interval
        current_second = datetime.datetime.now().second
        # are we at the top of the minute or at a 5 second interval?
        if (current_second == 0) or ((current_second % 5) == 0):
            # ========================================================
            # read values from the Sense HAT
            # ========================================================
            # Calculate the temperature. The get_temp function 'adjusts' the recorded temperature adjusted for the
            # current processor temp in order to accommodate any temperature leakage from the processor to
            # the Sense HAT's sensor. This happens when the Sense HAT is mounted on the Pi in a case.
            # If you've mounted the Sense HAT outside of the Raspberry Pi case, then you don't need that
            # calculation. So, when the Sense HAT is external, replace the following line (comment it out  with a #)
            calc_temp = get_temp()
            # with the following line (uncomment it, remove the # at the line start)
            # calc_temp = sense.get_temperature_from_pressure()
            # or the following line (each will work)
            # calc_temp = sense.get_temperature_from_humidity()
            # ========================================================
            # At this point, we should have an accurate temperature, so lets use the recorded (or calculated)
            # temp for our purposes
            temp_c = round(calc_temp, 1)
            temp_f = round(c_to_f(calc_temp), 1)
            humidity = round(sense.get_humidity(), 0)
            # convert pressure from millibars to inHg before posting
            pressure = round(sense.get_pressure(), 1)  # * 0.0295300
            print("Temp: %sF (%sC), Pressure: %s mbar, Humidity: %s%%" %
                  (temp_f, temp_c, pressure, humidity))

            # get the current minute
            current_minute = datetime.datetime.now().minute
            # is it the same minute as the last time we checked?
            if current_minute != last_minute:
                # reset last_minute to the current_minute
                last_minute = current_minute
                # is minute zero, or divisible by 10?
                # we're only going to take measurements every MEASUREMENT_INTERVAL minutes
                if (current_minute == 0) or ((current_minute %
                                              MEASUREMENT_INTERVAL) == 0):
                    # get the reading timestamp
                    now = datetime.datetime.now()
                    print("\n%d minute mark (%d @ %s)" %
                          (MEASUREMENT_INTERVAL, current_minute, str(now)))
                    # did the temperature go up or down?
                    if last_temp != temp_f:
                        if last_temp > temp_f:
                            # display a blue, down arrow
                            sense.set_pixels(arrow_down)
                        else:
                            # display a red, up arrow
                            sense.set_pixels(arrow_up)
                    else:
                        # temperature stayed the same
                        # display red and blue bars
                        sense.set_pixels(bars)
                    # set last_temp to the current temperature before we measure again
                    last_temp = temp_f

                    # Post values to Ubidots
                    print("Upload dei valori su Ubidots...")
                    try:
                        temp_ds.save_value({'value': temp_c})
                        humidity_ds.save_value({'value': humidity})
                        pressure_ds.save_value({'value': pressure})
                    except:
                        print(
                            "Upload dei valori su Ubidots... Failed; retry later"
                        )

        # wait a second then check again
        # You can always increase the sleep value below to check less often
        time.sleep(
            1)  # this should never happen since the above is an infinite loop