def postVmp(self,Vmp_Data): api = ApiClient(token='wseZ3mpbc7vPzM4tlANdLo5Tqngf48') Vmp_variable = api.get_variable('581b2f887625420434ecd29c') time.sleep(1) Vmp_response = Vmp_variable.save_value({"value": Vmp_Data}) print Vmp_response time.sleep(3)
def setup(): global api, bw, fw, buzzer, led_green, led_red, mqtt_distance, mqtt_speed, ua # 1. PiCar setup. picar.setup() ua = Ultrasonic_Avoidance.Ultrasonic_Avoidance(20) fw = front_wheels.Front_Wheels(db='config') bw = back_wheels.Back_Wheels(db='config') fw.turning_max = 45 # 2. GPIO pins for buzzer and LED. GPIO.setmode(GPIO.BCM) # GPIO.BCM mode. GPIO.setup(PIN_BUZZER, GPIO.OUT) # Buzzer pin. GPIO.setup(PIN_LED, GPIO.OUT) # LED pins. GPIO.output(PIN_LED, GPIO.LOW) # Set LED pins to low to turn off LEDs. buzzer = GPIO.PWM(PIN_BUZZER, 440) # Set buzzer frequency to 440Hz. led_red = GPIO.PWM(PIN_LED[0], 2000) # Set LED frequencies to 2KHz. led_green = GPIO.PWM(PIN_LED[1], 2000) buzzer.start(0) led_red.start(0) led_green.start(0) # 3. Ubidots. api = ApiClient(token='A1E-priJupwmfAGtVeOjcslK9wAW16HJzO') mqtt_distance = api.get_variable('59e93a20c03f9748c6bc3d54') mqtt_speed = api.get_variable('5a092816c03f9706c0205e88')
def ubi_connect(): print('ubi_connect()') api = ApiClient(token="BBFF-PF7xbbrjhnRpBGjLioQXEhGPWlLtiV") # user values userHumidity = api.get_variable('5bdfc9511d8472353149343c') # humidity = userHumidity.get_values(1) userLight = api.get_variable('5bdfc5db1d84723057db692f') # light = userLight.get_values(1) userLightColor = api.get_variable('5bdfc98d1d847234fe29e864') # lightColor = userLightColor.get_values(1) userTemperature = api.get_variable('5bdfc9441d84723531493427') # temperature = userTemperature.get_values(1) userSleepTime = api.get_variable('5be171331d8472057999d414') # sleepTime = userSleepTime.get_values(1) userId = api.get_variable('5bdfc97c1d8472353149348d') # id = userId.get_values(1) # onOff = api.get_variable('5be2bb631d84723ffefdcb97') # datas dictionary ubi_datas = { 'userId': userId, 'userHumidity': userHumidity, 'userLight': userLight, 'userLightColor': userLightColor, 'userTemperature': userTemperature, 'userSleepTime': userSleepTime, } return ubi_datas
def postImp(self,Imp_Data): api = ApiClient(token='wseZ3mpbc7vPzM4tlANdLo5Tqngf48') Imp_variable = api.get_variable('581b2f957625420481362b11') time.sleep(1) Imp_response = Imp_variable.save_value({"value": Imp_Data}) print Imp_response time.sleep(3)
def postStatus(self,Status_Data): api = ApiClient(token='wseZ3mpbc7vPzM4tlANdLo5Tqngf48') Status_variable = api.get_variable('58466a2e7625420ada1399c4') time.sleep(1) Status_response = Status_variable.save_value({"value": Status_Data}) print Status_response time.sleep(3)
def postPower(self,Power_Data): api = ApiClient(token='wseZ3mpbc7vPzM4tlANdLo5Tqngf48') Power_variable = api.get_variable('58466a2e7625420ada1399c4') time.sleep(1) Power_response = Power_variable.save_value({"value": Power_Data}) print Power_response time.sleep(3)
def postIrr(self,Irr_Data): api = ApiClient(token='wseZ3mpbc7vPzM4tlANdLo5Tqngf48') Irr_variable = api.get_variable('58466add7625420de33bedcd') time.sleep(1) Irr_response = Irr_variable.save_value({"value": Irr_Data}) print Irr_response time.sleep(3)
def setup(): global people global peoplecounter global PEOPLECOUNT_ID global TEMPCOUNT_ID global HUMIDITYCOUNT_ID global templevel global humiditylevel API_KEY = "BBFF-b324f9278c9dd3b78728cd92f16ac5e527e" PEOPLECOUNT_ID = "6068cc8a1d847201e0d016f9" TEMPCOUNT_ID = "60a990d81d84723522cb7ba4" HUMIDITYCOUNT_ID = "60a990de1d847235aae670aa" try: api = ApiClient(apikey=API_KEY) people = api.get_variable(PEOPLECOUNT_ID) templevel= api.get_variable(TEMPCOUNT_ID) humiditylevel = api.get_variable(HUMIDITYCOUNT_ID) peoplecounter = people.get_values()[0]['value'] except: print("Couldn't connect to the API, check your Internet connection") print (error) exit() GPIO.setmode(GPIO.BCM) GPIO.setup(ENTER_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(EXIT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) tm.number(int(peoplecounter))
def reconnectUbidots(): clarityAPI = ApiClient("2331f6fb5568a0de255024aa024b2ec20f2e6e1d") c101 = clarityAPI.get_variable("56a00b1976254252dfa19fa8") c102 = clarityAPI.get_variable("56a00b5776254254a47b1bbc") c103 = clarityAPI.get_variable("56a00b6276254253988bc701") c104 = clarityAPI.get_variable("56a00b6d7625425626da050e") c105 = clarityAPI.get_variable("56a00b7876254254a47b1c1a") connTimer = time.time()
def save_count_ubidots(count, startTime): api = ApiClient(token='A1E-CxwT7tKlYBQD5tbTOWpVAOzOxjbIha') ubidotsCount = api.get_variable('5d074d92c03f970688cf8483') while True: currentTime = time.time() if currentTime - startTime.value > 120: startTime.value = time.time() savedValue = ubidotsCount.save_value({'value': count.value}) print("Saved count in ubidots: ", savedValue)
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 postTemp(self,Temp_Data): api = ApiClient(token='wseZ3mpbc7vPzM4tlANdLo5Tqngf48') # Get a Ubidots Variable Temp_variable = api.get_variable('581b254f76254250326a2d51') time.sleep(1) # Here is where you usually put the code to capture the data, either through your GPIO pins or as a calculation. We'll simply put an artificial signal here: Temp_response = Temp_variable.save_value({"value": Temp_Data}) print (Temp_response) time.sleep(3)
def Update_Average(self): f = open('Ubidots_APIkey.txt', 'r') apikey = f.readline().strip() f.close() api = ApiClient(token=apikey) try: temp = api.get_variable("58d76383762542260cf36d8f") cloud_cover = api.get_variable("58d76394762542260a851a05") batt = api.get_variable("58d763aa762542260cf36f24") except ValueError: print('Unable to obtain variable') f = open('DS_APIkey.txt', 'r') apikey = f.read() f.close() Bangalore = [12.9716, 77.5946] fio = ForecastIO.ForecastIO( apikey, units=ForecastIO.ForecastIO.UNITS_SI, lang=ForecastIO.ForecastIO.LANG_ENGLISH, latitude=Bangalore[0], longitude=Bangalore[1], ) tempc = 0 clouds = 0 if fio.has_hourly() is True: hourly = FIOHourly.FIOHourly(fio) for hour in range(0, 48): tempc = tempc + float(str( hourly.get_hour(hour)['temperature'])) clouds = clouds + float( str(hourly.get_hour(hour)['cloudCover'])) else: print('No Hourly data') self.t = round(tempc / 48, 2) self.c = round(clouds / 48, 2) self.b = 40 try: temp.save_value({'value': self.t}) cloud_cover.save_value({'value': self.c}) batt.save_value({'value': self.b}) time.sleep(1) except: print('Value not sent') self.avg_temp.setText('{:0.01f}°'.format(self.t)) self.avg_cc.setText('{}%'.format(int(self.c * 100))) self.avg_batt.setText('{}%'.format(self.b)) self.done1 = True
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")
def ubidots_send(hum_value, temp_value): api = ApiClient(token=UBIDOTS_API_KEY_TOKEN) post_data_ubi = [{ 'variable': UBIDOTS_VARIABLE_TEMP, 'value': temp_value }, { 'variable': UBIDOTS_VARIABLE_HUM, 'value': hum_value }] api.save_collection(post_data_ubi)
def ubidots_get_value(api_key='A1E-09d8db204cf11e8edbbe3e71e0eedfd61b6f', variable_key='5a46431e76254254b5ae38dd'): try: api = ApiClient(api_key) output2_control = api.get_variable(variable_key) lastValue2 = output2_control.get_values(1) temp = lastValue2[0]['value'] print temp return temp except: print "No internet connection"
def postGPS(self,GPS_Data): api = ApiClient(token='wseZ3mpbc7vPzM4tlANdLo5Tqngf48') GPS_variable = api.get_variable('582288d27625427f1c7f729b') time.sleep(1) GPS_response = GPS_variable.save_value({"value":21, "context": { "lat": GPS_Data[0], "lng": GPS_Data[1]} }) print GPS_response time.sleep(3)
def __init__(self, interval=2): self.logger = logging.getLogger(__name__) # Ubidots Create an "API" object and variable object try: api = ApiClient(keys.ubidots_api_key) self.test_variable = api.get_variable( keys.ubidots_bench_variable_key) self.logger.info('Ubidots initialised.') except: self.logger.error('Ubidots failed to initialise.') self.ubidots_interval = datetime.timedelta(minutes=interval) self.last_time = datetime.datetime.now()
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))
def process_data(raw): print 'entrou' # Search for start and end of frame and slice, discard incomplete if "\r\n" in raw: raw = raw.split("\r\n") print 'raw: ' print raw[0] try: api = ApiClient(token='TOKEN') # Replace with your Ubidots Token here api.save_collection([{'variable': 'VARIABLE_ID','value':raw[0]}]) print 'sent to ubidots' except: print 'problem in ubidots' return
def loadApi(): global api, tempVar, humidVar try: #Create an "API" object api = ApiClient("xxxxxxxxxxxxxxxxxxxxxxxxxx") #Create a "Variable" object tempVar = api.get_variable("xxxxxxxxxxxxxxxxxxxxxxx") humidVar = api.get_variable("xxxxxxxxxxxxxxxxxxxxxxx") except: e = sys.exc_info()[0] print("Loading ubidots api failed with exception", e, "... will retry later") api = 0
def __init__(self): Thread.__init__(self) api = ApiClient(token='BBFF-YTny7Ru968fIz6EHhT3P8mRgLDiIXp') # Get cloud variables self.tempact = api.get_variable('5e8d31b51d84726d64f4a1e7') self.presact = api.get_variable('5e8d31cc1d84726e869ab59e') self.humact = api.get_variable('5e8d31c21d84726e88d71d66') self.getData() # Get data from variables # Check the timestamp if self.tLast is not None: self.tstamp = self.tLast[0]['timestamp'] if self.pLast is not None: self.pstamp = self.pLast[0]['timestamp'] if self.hLast is not None: self.hstamp = self.hLast[0]['timestamp']
def start_client(): now = datetime.datetime.now() print "UDP6 server side application " + ID_STRING print "Started " + str(now) try: s = socket(AF_INET6, SOCK_DGRAM) s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) s.bind(('', PORT)) except Exception: print "ERROR: Server Port Binding Failed" return print 'UDP server ready: %s' % PORT print "msg structure size: ", sizeof(SENSOR) print if ENABLE_CLOUD: try: client = ApiClient(API_KEY) except Exception as error: print error raise print "Connected to Ubidots, retrieving variables..." tmp102_var = get_ubidots_holders(client, TMP102_KEY) accel_x_var = get_ubidots_holders(client, ACCEL_X_KEY) accel_y_var = get_ubidots_holders(client, ACCEL_Y_KEY) accel_z_var = get_ubidots_holders(client, ACCEL_Z_KEY) print "Done, looping forever now\n" while True: data, addr = s.recvfrom(BUFSIZE) now = datetime.datetime.now() print str(now)[:19] + " -> " + str(addr[0]) + ":" + \ str(addr[1]) + " " + str(len(data)) msg_recv = SENSOR(data) if ENABLE_LOG: print_recv_data(msg_recv) if ENABLE_CLOUD: tmp102_var.save_value({'value': int(msg_recv.temperature)}) accel_x_var.save_value({'value': int(msg_recv.x_axis)}) accel_y_var.save_value({'value': int(msg_recv.y_axis)}) accel_z_var.save_value({'value': int(msg_recv.z_axis)}) sleep(0.2)
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)
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 __init__(self): super(UbidotsRenderer, self).__init__() self.api = ApiClient(token=master_incubator_token) self.incubator_endpoint = self.api.get_datasource( '5a224554c03f9721f59934ff') self.variables = self.incubator_endpoint.get_variables() self.temperature_1 = self._get_variable('temperature-1') self.temperature_2 = self._get_variable('temperature-2') self.humidity_1 = self._get_variable('humidity-1') self.humidity_2 = self._get_variable('humidity-2') self.heater_1 = self._get_variable('heater-1') self.heater_2 = self._get_variable('heater-2') self.uptime = self._get_variable('uptime') self.error = self._get_variable('error') self.backlogged_data = []
def getsettings(): print('start') api = ApiClient(token="A1E-oBMSdNRG2Z2lkXagXnf16Ho2Hwfond") red_level = api.get_variable("59ed72b1c03f974402f76f19") time.sleep(0.1) blue_level = api.get_variable("59ed72a3c03f97446655eed3") time.sleep(0.1) on_cycle = api.get_variable("59ed575ac03f972b1414fb30") time.sleep(0.1) period = api.get_variable("59ed6fb0c03f9740d1c3e48d") time.sleep(0.1) red_level_setting = red_level.get_values(1)[0]['value'] blue_level_setting = blue_level.get_values(1)[0]['value'] on_cycle_setting = on_cycle.get_values(1)[0]['value'] period_setting = period.get_values(1)[0]['value'] print('red:', red_level_setting, 'blue:', blue_level_setting, 'on:', on_cycle_setting) return (red_level_setting, blue_level_setting, on_cycle_setting, period_setting)
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)
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)
def obtener_instancias(): global api, token global diccionario_valores global instancias_ubidots, nombre_dispositivos if token is "": token = crear_token() if api is None: api = ApiClient(token=token, base_url="http://industrial.api.ubidots.com/api/v1.6/") try: nombre_dispositivos = get_nombre_dispositivos() if len(instancias_ubidots) > 0: return for nombre_dispositivo in nombre_dispositivos: instancias_ubidots.append(api.get_variable(get_ids().get(nombre_dispositivo))) except Exception as e: error = "Hubo un error obteniendo las instancias de ubidots." return redirect(url_for("error", error=error))