本文整理汇总了Python中Adafruit_IO.Client.send方法的典型用法代码示例。如果您正苦于以下问题:Python Client.send方法的具体用法?Python Client.send怎么用?Python Client.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Adafruit_IO.Client
的用法示例。
在下文中一共展示了Client.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AdafruitHandler
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
class AdafruitHandler(MessageHandler):
def __init__(self, api_key, feed, message_field = "value"):
self.message_field = message_field
self.client = Client(api_key)
self.feed = feed
def send_value(self, value):
logging.debug("Send value %s to feed %s", value, self.feed)
self.client.send(self.feed, value)
def handle(self, message):
value = message.data[self.message_field]
self.send_value(value)
示例2: AioWriter
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
class AioWriter(threading.Thread):
def __init__(self, queue):
super().__init__()
self.queue = queue
self.aio = Client(AIO_KEY)
self.daemon = False
def run(self):
while True:
# Get the reading from the queue
reading = self.queue.get()
temperature = reading['temp']
id = reading['id']
try:
self.aio.send(id, temperature)
except AdafruitIOError as e:
print(e)
示例3: IOAdafruitConnector
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
class IOAdafruitConnector(object):
def __init__(self, api_key=None):
if not api_key:
api_key = SERVICES['ADAFRUITIO_KEY']
self.aio = Client(api_key)
def send(self, data):
# send data to dweet
try:
for key, value in data.iteritems():
self.aio.send(key, value)
response = {'status': 'ok'}
except Exception as exception:
response = {'error': exception.message}
return response
示例4: Client
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
#!/usr/bin/python
# Import Library & create instance of REST client
from Adafruit_IO import Client
aio = Client('7e01e8b5e56360efc48a27682324fc353e18d14f')
# Send the value of 1 to BlockHeat02
aio.send('blockheat02',0)
# Retrieve the most recent value from 'BlockHeat02'
data = aio.receive('BlockHeat02')
print('Received Value: {0}'.format(data.value))
示例5: getCPUtemp
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
bat_shunt_mv = ina.getShuntVoltage_mV()
bat_curr_ma = ina.getCurrent_mA()
bat_volt_v = (ina.getBusVoltage_V() + ina.getShuntVoltage_mV() / 1000)
bat_power_mw = ina.getPower_mW()
return bat_volt_v, bat_curr_ma
# Main Loop
try:
while True:
# Get CPU temp and send it to aio. The value is set to two decimal places.
try:
getCPUtemp()
cels = float(getCPUtemp())
cpu_temp = cels_fahr(cels)
aio.send('greenhouse-cpu-temp', '{:.2f}'.format(cpu_temp))
except IOError:
print("Unable to connect to Adafruit.io")
finally:
checkDebug('--------------------------') # Used to separate each interval
checkDebug('CPU Temp: ' + str(cpu_temp))
# Shutdown the Raspberry Pi if the cpu temp gets to hot. If message_service is
# set to True an email message will be sent out so long as there is an Internet
# connection available. The system will wait for X number of seconds to send
# the message before shutting down.
if cpu_temp >= max_cpu_temp:
if message_service:
message = "The CPU temperature of %s has reached the maximum allowed " \
"set in the config file, the system is being shutdown. This " \
"means the heating and cooling system is no longer working " \
示例6: write_to_adafruit
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
def write_to_adafruit(t,h):
try:
aio = Client('3f755fc33a12977916bcbb1b518c8772ee16faaf')
aio.send('minion1', t)
except:
print "request error"
示例7: round
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
# Adafruit IO: Pressure feed is 'pressure'
# Adafruit IO: Humidity feed is 'humidity'
# Adafruit IO: Notification text box is 'notification'
while True:
# Get data from environmental sensors. Sensor data is of type float.
temperature = sense.get_temperature()
humidity = sense.get_humidity()
pressure = sense.get_pressure()
temperature = round(temperature, 1)
humidity = round(humidity, 1)
pressure = round(pressure, 1)
# Send sensor data to Adafruit IO.
aio.send('temperature', temperature) # in deg C
aio.send('humidity', humidity) # in %rH
aio.send('pressure', pressure) # in millibar
# Conditions for warnings
if temperature > 30: #30 deg C
aio.send('notification', 'Temperature alert')
sense.set_pixels(temp_warn)
if humidity > 80: #80% rH
aio.send('notification', 'Humidity alert')
sense.set_pixels(hum_warn)
if pressure < 900: #900 millibar
aio.send('notification', 'Pressure alert')
sense.set_pixels(pres_warn)
示例8: read_CurrentGarageTemp
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
time.sleep(1)
# Read the Current Garage Temperature
def read_CurrentGarageTemp():
f = open("/home/robin/CurrentGarageTemp", "r")
line1 = f.readlines()
f.close
line2 = line1[0]
GarageTemp = float(line2)
return GarageTemp
GarageTempRound = (round(read_CurrentGarageTemp(),2))
if DEBUG > 0:
print "Garage Temp File reads: ", read_CurrentGarageTemp()
print "Garage Temp Rounded: ", GarageTempRound
# Send the value 100 to a feed called 'Foo'.
#aio.send('basement-temp', 19.8)
aio.send('garage-temp', GarageTempRound)
# Retrieve the most recent value from the feed 'Foo'.
# Access the value by reading the `value` property on the returned Data object.
# Note that all values retrieved from IO are strings so you might need to convert
# them to an int or numeric type if you expect a number.
data = aio.receive('garage-temp')
if DEBUG > 0:
print('Received value: {0}'.format(data.value))
sys.exit()
示例9: Client
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME'
# Create an instance of the REST client
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
try: # if we have a 'analog' feed
analog = aio.feeds('analog')
except RequestError: # create a analog feed
feed = Feed(name='analog')
analog = aio.create_feed(feed)
# Create an instance of the `busio.spi` class
spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
# create the cs (chip select)
cs = digitalio.DigitalInOut(board.D12)
# create a mcp3008 object
mcp = MCP3008(spi, cs)
# create an an adc (single-ended) on pin 0
chan = AnalogIn(mcp, MCP3008.pin_0)
while True:
sensor_data = chan.value
print('Analog Data -> ', sensor_data)
aio.send(analog.key, sensor_data)
# avoid timeout from adafruit io
time.sleep(0.5)
示例10: Client
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
aio = Client('7e01e8b5e56360efc48a27682324fc353e18d14f')
last = 0
inputNum = 20
outputNum = 21
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(outputNum,GPIO.OUT)
GPIO.setup(inputNum,GPIO.IN)
while True:
if (time.time() - last) >= 7:
# Retrieve the most recent value from BlockHeat01
data = aio.receive('blockheat01')
print('Received Value: {0}'.format(data.value))
if data.value == "1":
print('data = 1')
GPIO.output(outputNum,GPIO.HIGH)
else:
print('data = 0')
GPIO.output(outputNum,GPIO.LOW)
state = GPIO.input(inputNum)
if (state):
print('Doorstate = 1')
aio.send('doorstate',1)
else:
print('Doorstate = 0')
aio.send('doorstate',0)
last = time.time()
示例11:
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
database= mysql.connector.connect(user='root', password='thermo',host='127.0.0.1',database='thermostat')
cursor = database.cursor()
room = 0
while True:
query = ("SELECT temp,on_off,heat,cool,humidity,set_temp FROM status WHERE room = '{}' ".format(room))
cursor.execute(query)
result=cursor.fetchall()
database.commit()
real_temp = result[0][0]
on_off = result[0][1]
heat = result[0][2]
cool = result[0][3]
humidity = result[0][4]
set_temp = result[0][5]
data=aio.receive('set temp')
remote_set_temp=float(data.value)
# query = ("UPDATE status SET set_temp = '{}' WHERE room = 0".format(remote_set_temp))
# cursor.execute(query)
# database.commit()
# set_temp=remote_set_temp
aio.send('real temp',real_temp)
aio.send('set temp',set_temp)
aio.send('humidity',humidity)
time.sleep(10)
示例12: read_CurrentOutsideTemp
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
time.sleep(1)
# Read the Current Garage Temperature
def read_CurrentOutsideTemp():
f = open("/home/robin/CurrentOutsideTemp", "r")
line1 = f.readlines()
f.close
line2 = line1[0]
OutsideTemp = float(line2)
return OutsideTemp
OutsideTempRound = (round(read_CurrentOutsideTemp(),2))
if DEBUG > 0:
print "Outside Temp File reads: ", read_CurrentOutsideTemp()
print "Outside Temp Rounded: ", OutsideTempRound
# Send the value 100 to a feed called 'Foo'.
#aio.send('basement-temp', 19.8)
aio.send('outside-temp', OutsideTempRound)
# Retrieve the most recent value from the feed 'Foo'.
# Access the value by reading the `value` property on the returned Data object.
# Note that all values retrieved from IO are strings so you might need to convert
# them to an int or numeric type if you expect a number.
data = aio.receive('outside-temp')
if DEBUG > 0:
print('Received value: {0}'.format(data.value))
sys.exit()
示例13: test_throttling_error_after_6_requests_in_short_period
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
def test_throttling_error_after_6_requests_in_short_period(self):
io = Client(self.get_test_key())
with self.assertRaises(ThrottlingError):
for i in range(6):
io.send("TestStream", 42)
time.sleep(0.1) # Small delay to keep from hammering network.
示例14: test_request_error_from_bad_key
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
def test_request_error_from_bad_key(self):
io = Client("this is a bad key from a test")
with self.assertRaises(RequestError):
io.send("TestStream", 42)
示例15: Client
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import send [as 别名]
import time
import Adafruit_MCP9808.MCP9808 as MCP9808
from Adafruit_IO import Client
aio = Client('SECRET')
sensor = MCP9808.MCP9808()
sensor.begin()
def get_temperature():
temp = sensor.readTempC()
return '{0:0.3F}'.format(temp)
while True:
try:
aio.send('deck-temp', get_temperature() )
except:
print "Failed to send"
time.sleep(30)