当前位置: 首页>>代码示例>>Python>>正文


Python Client.send_data方法代码示例

本文整理汇总了Python中Adafruit_IO.Client.send_data方法的典型用法代码示例。如果您正苦于以下问题:Python Client.send_data方法的具体用法?Python Client.send_data怎么用?Python Client.send_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Adafruit_IO.Client的用法示例。


在下文中一共展示了Client.send_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: level

# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send_data [as 别名]
# We dont' have a GPS hooked up, but let's fake it for the example/test:
# (replace this data with values from a GPS hardware module)
value = 0
lat = 40.726190
lon = -74.005334
ele = 6 # elevation above sea level (meters)


while True:
    print('\nSending Values to location feed...\n')
    print('\tValue: ', value)
    print('\tLat: ', lat)
    print('\tLon: ', lon)
    print('\tEle: ', ele)
    # Send location data to Adafruit IO
    metadata = { 'lat':lat, 'lon':lon, 'ele':ele, 'created_at':time.asctime(time.gmtime()) }
    aio.send_data(location.key,value,metadata)
    # shift all values (for test/demo purposes)
    value += 1
    lat -= 0.01
    lon += -0.02
    ele += 1

    # Read the location data back from IO
    print('\nData Received by Adafruit IO Feed:\n')
    data = aio.receive(location.key)
    print('\tValue: {0}\n\tLat: {1}\n\tLon: {2}\n\tEle: {3}'
          .format(data.value, data.lat, data.lon, data.ele))
    # wait loop_delay seconds to avoid api throttle
    time.sleep(loop_delay)
开发者ID:adafruit,项目名称:io-client-python,代码行数:32,代码来源:location.py

示例2: Client

# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send_data [as 别名]
# Import Adafruit IO REST client.
from Adafruit_IO import Client, Feed

# holds the count for the feed
run_count = 0

# Set to your Adafruit IO key.
# Remember, your key is a secret,
# so make sure not to publish it when you publish this code!
ADAFRUIT_IO_KEY = 'YOUR_AIO_KEY'

# Set to your Adafruit IO username.
# (go to https://accounts.adafruit.com to find your username)
ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME'

# Create an instance of the REST client.
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

# Create a new feed named 'counter'
feed = Feed(name="Counter")
response = aio.create_feed(feed)


while True:
    print('sending count: ', run_count)
    run_count += 1
    aio.send_data('counter', run_count)
    # Adafruit IO is rate-limited for publishing
    # so we'll need a delay for calls to aio.send_data()
    time.sleep(3)
开发者ID:adafruit,项目名称:io-client-python,代码行数:32,代码来源:publish.py


注:本文中的Adafruit_IO.Client.send_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。