def update_channel(channel, value, key, feedID, at): # Connect to Xively api = xively.XivelyAPIClient(key) feed = api.feeds.get(feedID) stream = feed.datastreams.get(channel) stream.datapoints = [xively.Datapoint(at, value)] stream.update()
def update_channel(channel, value, key=p_rain_key, feedID=feed_id, at=-1): if at == -1: at = datetime.datetime.utcnow() # Connect to Xively api = xively.XivelyAPIClient(key) feed = api.feeds.get(feedID) stream = feed.datastreams.get(channel) stream.datapoints = [xively.Datapoint(at, value)] stream.update()
def xively_write(feed, data): global t006, accl_x, accl_y, accl_z, humd_t, humd_rh, baro_t, baro_p, magn_x, magn_y, magn_z, gyro_x, gyro_y, gyro_z t006.append(xively.Datapoint(datetime.datetime.utcnow(), data['t006'])) accl_x.append(xively.Datapoint(datetime.datetime.utcnow(), data['accl'][0])) accl_y.append(xively.Datapoint(datetime.datetime.utcnow(), data['accl'][1])) accl_z.append(xively.Datapoint(datetime.datetime.utcnow(), data['accl'][2])) humd_t.append(xively.Datapoint(datetime.datetime.utcnow(), data['humd'][0])) humd_rh.append(xively.Datapoint(datetime.datetime.utcnow(), data['humd'][1])) baro_t.append(xively.Datapoint(datetime.datetime.utcnow(), data['baro'][0])) baro_p.append(xively.Datapoint(datetime.datetime.utcnow(), data['baro'][1])) magn_x.append(xively.Datapoint(datetime.datetime.utcnow(), data['magn'][0])) magn_y.append(xively.Datapoint(datetime.datetime.utcnow(), data['magn'][1])) magn_z.append(xively.Datapoint(datetime.datetime.utcnow(), data['magn'][2])) #gyro_x.append(xively.Datapoint(datetime.datetime.utcnow(), data['gyro'][0])) #gyro_y.append(xively.Datapoint(datetime.datetime.utcnow(), data['gyro'][1])) #gyro_z.append(xively.Datapoint(datetime.datetime.utcnow(), data['gyro'][2])) if len(t006) < 10: return else: feed.datastreams = [ xively.Datastream(id= 't006', datapoints=t006), xively.Datastream(id= 'accl_x', datapoints=accl_x), xively.Datastream(id= 'accl_y', datapoints=accl_y), xively.Datastream(id= 'accl_z', datapoints=accl_z), xively.Datastream(id= 'humd_t', datapoints=humd_t), xively.Datastream(id= 'humd_rh', datapoints=humd_rh), xively.Datastream(id= 'baro_t', datapoints=baro_t), xively.Datastream(id= 'baro_p', datapoints=baro_p), xively.Datastream(id= 'magn_x', datapoints=magn_x), xively.Datastream(id= 'magn_y', datapoints=magn_y), xively.Datastream(id= 'magn_z', datapoints=magn_z), #xively.Datastream(id= 'gyro_x', datapoints=gyro_x), #xively.Datastream(id= 'gyro_x', datapoints=gyro_y), #xively.Datastream(id= 'gyro_x', datapoints=gyro_z), # when dealing with single data values can do this instead - # xively.Datastream(id= 't006', current_value=data['t006'], at=now), ] t006 = [] accl_x = [] accl_y = [] accl_z = [] humd_t = [] humd_rh = [] baro_t = [] baro_p = [] magn_x = [] magn_y = [] magn_z = [] gyro_x = [] gyro_y = [] gyro_z = [] feed.update()
def _create_datapoint(self, **data): datapoint = xively.Datapoint(**data) manager = xively.managers.DatapointsManager(self.datastream) datapoint._manager = manager return datapoint
def test_create_datapoint(self): now = datetime.now() datapoint = xively.Datapoint(at=now, value=123) self.assertEqual(datapoint.at, now) self.assertEqual(datapoint.value, 123)
import xively, datetime, random read_key = "GOgGb3IPwNgwyvKavBJPa1FAg1rqdkL4D0uZI2UNlLj93qWx" feed_id = 1821537225 api = xively.XivelyAPIClient(read_key) feed = api.feeds.get(feed_id) # Test 1 z_stream = feed.datastreams.get('z') z_stream.datapoints = [xively.Datapoint(datetime.datetime.utcnow(), random.random())] z_stream.update() # Test 2 streams = feed.datastreams for s in streams: print s depth = feed.datastreams.get('depth_press',end=datetime.datetime(2014,7,4,14,0,0),limit=10,interval=0,duration=600) depth.datapoints[:] depth[-1].value depth[-1].at [float(d.value) for d in depth.datapoints[-10:]] if __name__ == '__main__': print "Serving on port 8000..."