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 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
# Uygulama Yazarı : AgustinP # https://www.hackster.io/AgustinP #!/usr/bin/python import time, mraa from ubidots import ApiClient for i in range(0, 5): try: print "Ubidots Jeton isteniyor" api = ApiClient('abebasfaf4e14d195c0044fcasdfdf9dsfab9d653af3') break # BURAYA UBIDOTS API ANAHTARINI MUTLAKA YAZIN!!!!!!!! except: print "Internet Baglantisi Yok Tekrar Baglaniyor..." time.sleep(5) a0 = mraa.Aio(0) a1 = mraa.Aio(1) while (1): api.save_collection([{ 'variable': '558073727625425555af27e4', 'value': a0.read() }, { 'variable': '5580737876254257514be1e6', 'value': a1.read() }])
Heartbeat = wdconfig['Heartbeat'] Variable_1 = wdconfig['Variable_1'] IP_1 = wdconfig['IP_1'] Variable_2 = wdconfig['Variable_2'] IP_2 = wdconfig['IP_2'] Variable_3 = wdconfig['Variable_3'] IP_3 = wdconfig['IP_3'] #Connect to Ubidots API api = ApiClient(token=API_Key) #Begin to ping with size of 64 bytes (standard) ping1 = ping(IP_1, size=64) ping2 = ping(IP_2, size=64) ping3 = ping(IP_3, size=64) #Upload ping results api.save_collection([{ 'variable': Heartbeat, 'value': 1 }, { 'variable': Variable_1, 'value': ping1.rtt_avg_ms }, { 'variable': Variable_2, 'value': ping2.rtt_avg_ms }, { 'variable': Variable_3, 'value': ping3.rtt_avg_ms }])
def start_server(): now = datetime.datetime.now() print "UDP6 server side application - " + str(now) try: s = socket(AF_INET6, SOCK_DGRAM) s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) # Replace address below with "aaaa::1" if tunslip6 has # created a tun0 interface with this address s.bind(('', PORT)) except Exception: print "ERROR: Server Port Binding Failed" return print 'UDP server ready: %s' % PORT print # Use Ubidots for testing the deployment if WITH_UBIDOTS: try: ubidots = ApiClient(UBIDOTS_API) except Exception: print "ERROR: Failed to retrieve credentials" return while True: data, addr = s.recvfrom(BUFSIZE) now = datetime.datetime.now() print str(now)[:19] + " -> " + str(addr[0]) + ":" + str( addr[1]) + " " + str(len(data)) ws = WEATHER(data) # print_recv_data(ws) # Read reference data from PWS nearby (ICERDANY6) # pws = requests.get(URL_PWS_REF).json() # pws_temp = float(pws['current_observation']['temp_c']) # pws_hum = float(pws['current_observation']['relative_humidity'][:-1]) # pws_pres = float(pws['current_observation']['pressure_mb']) if WITH_UBIDOTS: ubidots.save_collection([ { "variable": UBI_COUNTER, "value": ws.counter }, { "variable": UBI_TEMP, "value": ws.temperature / 100 }, { "variable": UBI_HUM, "value": ws.humidity / 100 }, { "variable": UBI_PRES, "value": ws.atmospheric_pressure / 10 }, { "variable": UBI_RAIN, "value": ws.rain_mm * 0.2794 }, { "variable": UBI_WIND_DIR, "value": ws.wind_dir / 10 }, { "variable": UBI_WIND_DIR_INT, "value": ws.wind_dir_avg_int / 10 }, { "variable": UBI_WIND_SP, "value": ws.wind_speed }, { "variable": UBI_WIND_SP_AVG, "value": ws.wind_speed_avg }, { "variable": UBI_WIND_SP_INT, "value": ws.wind_speed_avg_int }, { "variable": UBI_WIND_SP_MAX, "value": ws.wind_speed_max }, # Reference values using a PWS accross the street # { "variable" : UBI_ICERDANY6_TEMP, "value" : pws_temp }, # { "variable" : UBI_ICERDANY6_HUM, "value" : pws_hum }, # { "variable" : UBI_ICERDANY6_PRES, "value" : pws_pres }, ])
import tsl2591 from ubidots import ApiClient import time api = ApiClient("ubidotapiclient goes here 3973029092138321098098") #while True: tsl = tsl2591.Tsl2591() # initialize full, ir = tsl.get_full_luminosity( ) # read raw values (full spectrum and ir spectrum) lux = tsl.calculate_lux(full, ir) # convert raw values to lux # print lux, full, ir api.save_collection([ { 'variable': 'ubidot variable here 9832987397', 'value': lux }, ]) api.save_collection([ { 'variable': 'ubidot variable here 873264872364', 'value': full }, ]) api.save_collection([ { 'variable': 'ubidot variable here 1235475123', 'value': ir },
class UbidotsRenderer(Renderer): 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 _get_time(self): return int(time.time() * 1000) def _get_variable(self, label): for variable in self.variables: if str(variable.label) == label: print("Found variable %s: %s" % (variable.label, variable.id)) return variable raise Exception("Could not find variable %s!" % label) def render(self, incubator, controller): timestamp = self._get_time() data = [{ 'variable': self.temperature_1.id, 'value': incubator.temp_1, timestamp: timestamp }, { 'variable': self.temperature_2.id, 'value': incubator.temp_2, timestamp: timestamp }, { 'variable': self.humidity_1.id, 'value': incubator.hum_1, timestamp: timestamp }, { 'variable': self.humidity_2.id, 'value': incubator.hum_2, timestamp: timestamp }, { 'variable': self.heater_1.id, 'value': incubator.duty_cycle, timestamp: timestamp }, { 'variable': self.heater_2.id, 'value': incubator.duty_cycle, timestamp: timestamp }, { 'variable': self.uptime.id, 'value': incubator.uptime, timestamp: timestamp }, { 'variable': self.error.id, 'value': controller.avg_error, timestamp: timestamp }] try: self.api.save_collection(data) except: for i in data: self.backlogged_data.append(i) traceback.print_exc() if (incubator.uptime == 0): pp.pprint(self.backlogged_data)
print 'Temperature: {0:0.1f} C Humidity: {1:0.1f} %'.format( temperature, humidity) print("Light intensity:") li = rc_time(pin_to_circuit) print li #if (temperature > 28) and (humidity > 60) : # print 'Today is a Hot and wet day,please open the fan!!' #send real time data to ubidots api.save_collection([{ 'variable': '', 'value': temperature }, { 'variable': '', 'value': humidity }, { 'variable': '', 'value': li }]) print time.sleep(29) except KeyboardInterrupt: pass finally: GPIO.cleanup()
def send_data(data, assetname): print(data, assetname) import config from json import load from urllib2 import urlopen my_ip = load(urlopen('http://jsonip.com'))['ip'] lat = load( urlopen('http://api.ipstack.com/' + my_ip + '?access_key=f594d087ce71f888d826af695fecfa0a'))['latitude'] print(lat) lon = load( urlopen('http://api.ipstack.com/' + my_ip + '?access_key=f594d087ce71f888d826af695fecfa0a'))['longitude'] print(lon) print() secrets = config.get_secrets() CONNECTION_STRING = str(secrets["ubidots-string"]) print(CONNECTION_STRING) api = ApiClient(token=CONNECTION_STRING) #data_json = json.loads(data) print(data['Phase 1 Line to Neutral Volts']) print(data['Phase 2 Line to Neutral Volts']) print(data['Phase 3 Line to Neutral Volts']) print(data['Phase 1 Current']) print(data['Phase 2 Current']) print(data['Phase 3 Current']) api.save_collection([ { 'variable': '5c861e8193f3c30b1909184e', 'value': data['Phase 1 Line to Neutral Volts'], 'context': { 'lat': lat, 'lng': lon } }, { 'variable': '5c861e8293f3c30b1909184f', 'value': data['Phase 2 Line to Neutral Volts'], 'context': { 'lat': lat, 'lng': lon } }, { 'variable': '5c861e8293f3c30b19091850', 'value': data['Phase 3 Line to Neutral Volts'], 'context': { 'lat': lat, 'lng': lon } }, { 'variable': '5c861e8293f3c30b19091851', 'value': data['Phase 1 Current'], 'context': { 'lat': lat, 'lng': lon } }, { 'variable': '5c861e8293f3c30b19091852', 'value': data['Phase 2 Current'], 'context': { 'lat': lat, 'lng': lon } }, { 'variable': '5c861e8293f3c30b19091853', 'value': data['Phase 3 Current'], 'context': { 'lat': lat, 'lng': lon } }, ])
# status, pres MSB1, pres MSB, pres LSB data = bus.read_i2c_block_data(0x60, 0x00, 4) # Convert the data to 20-bits #pres = ((data[1] * 65536) + (data[2] * 256) + (data[3] & 0xF0)) / 16 #pressure = (pres / 4.0) / 100.0 # Output data to screen #print "Pressure : %.2f MBar" %pressure #print "Altitude : %.2f m" %altitude print "Temperature in Celsius : %.2f C" % cTemp #print "Temperature in Fahrenheit : %.2f F" %fTemp api.save_collection([ { 'variable': 'kjhfskjhsfd', 'value': cTemp }, ]) #api.save_collection([ # {'variable': 'kjsdkjsdhkjhasdkjh', 'value': pressure}, # ]) if cTemp > 19: r = requests.put('http://192.168.0.112:80/WebRelay/api/relays/1', verify=False, json={"state": "on"}) headers = {'Content-type': 'application/json'} r = requests.put('http://192.168.0.112:80/WebRelay/api/relays/2', verify=False,
""" __author__ = 'Ganesh' import time from ubidots import ApiClient for i in range(0, 5): # Attempting to connect to ubidots cloud try: print("Requesting Ubidots token") api = ApiClient( 'Add your client id here from ubidots cloud') # Connect to Ubidots break except: print("No internet connection, retrying...") time.sleep(5) a0 = 4 # Sample input values to write into cloud a1 = 5 # Sample input values to write into cloud while (1): api.save_collection([{ 'variable': '57a981467625425e2ffe0550', 'value': a0 }, { 'variable': '57a981507625425dae56f691', 'value': a1 }]) # Writes the data into cloud using ubidots write API
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) except ValueError: logging.error('Unable to parse message, json.loads failed') logging.debug('',exc_info=True) message_count += 1 variablesFB=varFloraBox.get_variables() data=[] for x in range(0,len(variablesFB)): data.insert(0,{'variable':variablesFB[x].id,'value':message_dict[variablesFB[x].description]}) api.save_collection(data) time.sleep(30) #{"AACR 1":1,"AAHE 1":2,"AAHU 1":3,"AAVE 1":4,"ALMI 1":5,"ALPN 1":6,"ALPN 2":7,"GEND":8,"GTYP":9,"SACO 1":10,"SAHU 1":11,"SAHU 2":12,"SATM 1":13,"SATM 2":14,"SGSO 1":15,"SGWO 1":16,"SLIN 1":18,"SLPA 1":17,"SWEC 1":19,"SWPH 1":20,"SWTM 1":21}
from ubidots import ApiClient import random import time objectapi = ApiClient( token='ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZzzzzZZz') while 1: objectapi.save_collection([{ 'variable': '5919fed37625423e468a7e74', 'value': random.random() }, { 'variable': '5919fee37625423e468a7fa4', 'value': random.random() }, { 'variable': '5919feef7625423e468a80a5', 'value': random.random() }, { 'variable': '5919fefd7625423e468a81e2', 'value': random.random() }]) print "going to sleep after pushing data to cloud" time.sleep(10)