def create(): name=request.args['name'] tag1=request.args['tag1'] tag2=request.args['tag2'] desc=request.args['desc'] tags=[tag1,tag2] api=ApiClient(token=tok) new=api.create_datasource({"name":name,"tags":tags,"description":desc}) return render_template('index.html',msg="success datasource creation")
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)
def make_devices(m): #apilist = [] data_sources = [] new_variable1 = [] new_variable2 = [] new_variable3 = [] new_variable4 = [] for i in range(m): api = ApiClient(token='BBFF-vwaOtO0NBWQL7oqbg7I4GAIRUs91Bo') #apilist.append(ApiClient(token = 'BBFF-vwaOtO0NBWQL7oqbg7I4GAIRUs91Bo')) #new_datasource = api.create_datasource({"name": "Health_status", "description": "Has health parameters that can depict the health status"}) data_sources.append( api.create_datasource({ "name": "Health_status", "description": "Has health parameters that can depict the health status" })) new_variable1.append(data_sources[i].create_variable({ "name": "Temperature score", "unit": "unitless" })) new_variable2.append(data_sources[i].create_variable({ "name": "Heart Rate score", "unit": "unitless" })) new_variable3.append(data_sources[i].create_variable({ "name": "Blood Pressure score", "unit": "unitless" })) new_variable4.append(data_sources[i].create_variable({ "name": "Health score", "unit": "unitless" })) return new_variable1, new_variable2, new_variable3, new_variable4, data_sources
from ubidots import ApiClient api = ApiClient(token='RBgwxE0fSTaFS7IH7EqIya2Nl6yVek') ctrlVarFloraBox=api.create_datasource({"name":"Ctrl floraBox"}) ctrlActFloraBox=api.create_datasource({"name":"Ctrl Actuators floraBox"}) varFloraBox=api.create_datasource({"name":"Variables floraBox"}) #Ctrl Actuadores ctrlActFloraBox.create_variable({"description":"CAACR 1","unit":"bool","name":"Ctrl Air Circulation"}) ctrlActFloraBox.create_variable({"description":"CAAHE 1","unit":"bool","name":"Ctrl Air Heater"}) ctrlActFloraBox.create_variable({"description":"CAAHU 1","unit":"bool","name":"Ctrl Air Humidifier"}) ctrlActFloraBox.create_variable({"description":"CAAVE 1","unit":"bool","name":"Ctrl Air Ventilation"}) ctrlActFloraBox.create_variable({"description":"CALMI 1","unit":"bool","name":"Ctrl Light Mother"}) ctrlActFloraBox.create_variable({"description":"CALPN 1","unit":"bool","name":"Ctrl Light Panel 1"}) ctrlActFloraBox.create_variable({"description":"CALPN 2","unit":"bool","name":"Ctrl Light Panel 2"}) #Ctrl Variables ctrlVarFloraBox.create_variable({"description":"CSACO 1","unit":"ppp","name":"Ctrl CO2"}) ctrlVarFloraBox.create_variable({"description":"CSAHU 1","unit":"%","name":"Ctrl Air Humidity"}) ctrlVarFloraBox.create_variable({"description":"CSATM 1","unit":"°C","name":"Ctrl Air Temp"}) ctrlVarFloraBox.create_variable({"description":"CSWEC 1","unit":"mS/cm","name":"Ctrl Water EC"}) ctrlVarFloraBox.create_variable({"description":"CSWPH 1","unit":"PH","name":"Ctrl Water PH"}) #Variables varFloraBox.create_variable({"description":"AACR 1","unit":"bool","name":"Air Circulation"}) varFloraBox.create_variable({"description":"AAHE 1","unit":"bool","name":"Air Heater"}) varFloraBox.create_variable({"description":"AAHU 1","unit":"bool","name":"Air Humidifier"}) varFloraBox.create_variable({"description":"AAVE 1","unit":"bool","name":"Air Ventilation"})
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) if mic is None: mic = dS.create_variable({"name": "Noise_level","unit": "mV"}) # Create a new Variable for noise level carbon = getVarbyNames("Carbon_monoxide_concentration",dS) if carbon is None:
from ubidots import ApiClient api = ApiClient(token='SwWv78hxFMR42afpUyIKGKtwnNBtEV') new_datasource = api.create_datasource({ "name": "third", "tags": ["a", "b"], "description": "trying" }) #create new datasource print "datasource created\n" new_variable = new_datasource.create_variable({ "name": "variable0", "unit": "kg" }) #create a new variable in the datasource print "variable0 created\n" new_variable1 = new_datasource.create_variable({ "name": "variable1", "unit": "kg" }) print "variable1 created" new_variable.save_values([ #saving multiple values { 'timestamp': 1380558972614, 'value': 2 }, { 'timestamp': 1380558972915, 'value': 4 }, { 'timestamp': 1380558973516, 'value': 5 }, { 'timestamp': 1380558973617,
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
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