def push_to_io(self, feed_key, data):
        # pylint: disable=line-too-long
        """Push data to an adafruit.io feed

        :param str feed_key: Name of feed key to push data to.
        :param data: data to send to feed
        """
        # pylint: enable=line-too-long

        try:
            aio_username = secrets["aio_username"]
            aio_key = secrets["aio_key"]
        except KeyError:
            raise KeyError(
                "Adafruit IO secrets are kept in secrets.py, please add them there!\n\n"
            ) from KeyError

        # This may need a fake wrapper written to just use onboard eth0 or whatever
        # wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(
        #    self._esp, secrets, None
        # )
        wifi = None
        io_client = IO_HTTP(aio_username, aio_key, wifi)

        while True:
            try:
                feed_id = io_client.get_feed(feed_key)
            except AdafruitIO_RequestError:
                # If no feed exists, create one
                feed_id = io_client.create_new_feed(feed_key)
            except RuntimeError as exception:
                print("An error occured, retrying! 1 -", exception)
                continue
            break

        while True:
            try:
                io_client.send_data(feed_id["key"], data)
            except RuntimeError as exception:
                print("An error occured, retrying! 2 -", exception)
                continue
            except NameError as exception:
                print(feed_id["key"], data, exception)
                continue
            break
Example #2
0
#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(
    esp, secrets, status_light)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets['aio_username']
aio_key = secrets['aio_key']

# Create an instance of the Adafruit IO HTTP client
io = IO_HTTP(aio_username, aio_key, wifi)

try:
    # Get the 'location' feed from Adafruit IO
    location_feed = io.get_feed('location')
except AdafruitIO_RequestError:
    # If no 'location' feed exists, create one
    location_feed = io.create_new_feed('location')

# Set data
data_value = 42

# Set up metadata associated with data_value
metadata = {'lat': 40.726190, 'lon': -74.005334, 'ele': -6, 'created_at': None}

# Send data and location metadata to the 'location' feed
print('Sending data and location metadata to IO...')
io.send_data(location_feed['key'], data_value, metadata)
print('Data sent!')
Example #3
0
socket.set_interface(esp)
requests.set_socket(socket, esp)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]

# Initialize an Adafruit IO HTTP API object
io = IO_HTTP(aio_username, aio_key, requests)

try:
    # Get the 'location' feed from Adafruit IO
    location_feed = io.get_feed("location")
except AdafruitIO_RequestError:
    # If no 'location' feed exists, create one
    location_feed = io.create_new_feed("location")

# Set data
data_value = 42

# Set up metadata associated with data_value
metadata = {"lat": 40.726190, "lon": -74.005334, "ele": -6, "created_at": None}

# Send data and location metadata to the 'location' feed
print("Sending data and location metadata to IO...")
io.send_data(location_feed["key"], data_value, metadata)
print("Data sent!")
                                          debug=False)
wifi = adafruit_espatcontrol_wifimanager.ESPAT_WiFiManager(
    esp, secrets, status_light)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets['aio_username']
aio_key = secrets['aio_key']

# Create an instance of the Adafruit IO HTTP client
io = IO_HTTP(aio_username, aio_key, wifi)

try:
    # Get the 'temperature' feed from Adafruit IO
    temperature_feed = io.get_feed('temperature')
except AdafruitIO_RequestError:
    # If no 'temperature' feed exists, create one
    temperature_feed = io.create_new_feed('temperature')

# Send random integer values to the feed
random_value = randint(0, 50)
print('Sending {0} to temperature feed...'.format(random_value))
io.send_data(temperature_feed['key'], random_value)
print('Data sent!')

# Retrieve data value from the feed
print('Retrieving data from temperature feed...')
received_data = io.receive_data(temperature_feed['key'])
print('Data from temperature feed: ', received_data['value'])
Example #5
0
print("try first connect")
dotstar[0] = (0, 255, 0, 0.5)
print(wifi.radio.connect(ssid, ssid_pass))
dotstar[0] = (0, 0, 0, 0.5)
print("wifi connected")
pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())
io = IO_HTTP(aio_username, aio_key, requests)

dotstar[0] = (255, 0, 0, 0.5)
feed = None
try:
    feed = io.get_feed(aio_feed_name)
except AdafruitIO_RequestError:
    feed = io.create_new_feed(aio_feed_name)

while True:
    try:
        dotstar[0] = (0, 0, 0, 0.5)
        t = sensor.temperature * (9.0 / 5.0) + 32.0
        temperature = '%.1f' % (t)

        if (wifi.radio.ap_info is None):

            dotstar[0] = (0, 255, 0, 0.5)
            for network in wifi.radio.start_scanning_networks():
                print(network, network.ssid, network.rssi, network.channel)
            wifi.radio.stop_scanning_networks()

            dotstar[0] = (255, 0, 0, 0.5)
Example #6
0
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1,
                                 brightness=0.2)  # Uncomment for Most Boards
"""Uncomment below for ItsyBitsy M4"""
#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(
    esp, secrets, status_light)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets['aio_username']
aio_key = secrets['aio_key']

# Create an instance of the Adafruit IO HTTP client
io = IO_HTTP(aio_username, aio_key, wifi)

# Create a new 'circuitpython' feed with a description
print('Creating new Adafruit IO feed...')
feed = io.create_new_feed('circuitpython', 'a Adafruit IO CircuitPython feed')

# List a specified feed
print('Retrieving new Adafruit IO feed...')
specified_feed = io.get_feed('circuitpython')
print(specified_feed)

# Delete a specified feed by feed key
print('Deleting feed...')
io.delete_feed(specified_feed['key'])
print('Feed deleted!')
    except RuntimeError as e:
        print("could not connect to AP, retrying: ", e)
        continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)

socket.set_interface(esp)
requests.set_socket(socket, esp)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]

# Initialize an Adafruit IO HTTP API object
io = IO_HTTP(aio_username, aio_key, requests)

# Create a new 'circuitpython' feed with a description
print("Creating new Adafruit IO feed...")
feed = io.create_new_feed("circuitpython", "a Adafruit IO CircuitPython feed")

# List a specified feed
print("Retrieving new Adafruit IO feed...")
specified_feed = io.get_feed("circuitpython")
print(specified_feed)

# Delete a specified feed by feed key
print("Deleting feed...")
io.delete_feed(specified_feed["key"])
print("Feed deleted!")
Example #8
0
pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())

#test chunk
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]

# Initialize an Adafruit IO HTTP API object
io = IO_HTTP(aio_username, aio_key, requests)

try:
    # Get the 'temperature' feed from Adafruit IO
    temperature_feed = io.get_feed("gardentemp")
except AdafruitIO_RequestError:
    # If no 'temperature' feed exists, create one
    temperature_feed = io.create_new_feed("gardentemp")

#turn the backlight off
backlight = DigitalInOut(board.TFT_BACKLIGHT)
backlight.direction = Direction.OUTPUT

select = DigitalInOut(board.BUTTON_SELECT)
select.direction = Direction.INPUT

# Create the sensor object using I2C
sensor = adafruit_ahtx0.AHTx0(board.I2C())
dps310 = adafruit_dps310.DPS310(board.I2C())

loop_count = 0
while True:
    loop_count = (loop_count + 1) % 60
Example #9
0
# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]

# Initialize an Adafruit IO HTTP API object
io = IO_HTTP(aio_username, aio_key, requests)

try:
    # Get the 'digital' feed from Adafruit IO
    digital_feed = io.get_feed("digital")
except AdafruitIO_RequestError:
    # If no 'digital' feed exists, create one
    digital_feed = io.create_new_feed("digital")

# Set up LED
LED = DigitalInOut(board.D13)
LED.direction = Direction.OUTPUT

while True:
    # Get data from 'digital' feed
    print("getting data from IO...")
    feed_data = io.receive_data(digital_feed["key"])

    # Check if data is ON or OFF
    if int(feed_data["value"]) == 1:
        print("received <- ON\n")
    elif int(feed_data["value"]) == 0:
        print("received <= OFF\n")
Example #10
0
# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
ADAFRUIT_IO_USER = secrets['aio_username']
ADAFRUIT_IO_KEY = secrets['aio_key']

# Create an instance of the Adafruit IO HTTP client
io = IO_HTTP(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi)

try:
    # Get the 'temperature' feed from Adafruit IO
    temperature_feed = io.get_feed('temperature')
    light_feed = io.get_feed('light')
except AdafruitIO_RequestError:
    # If no 'temperature' feed exists, create one
    temperature_feed = io.create_new_feed('temperature')
    light_feed = io.create_new_feed('light')

# Set up ADT7410 sensor
i2c_bus = busio.I2C(board.SCL, board.SDA)
adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48)
adt.high_resolution = True

# Set up an analog light sensor on the PyPortal
adc = AnalogIn(board.LIGHT)

while True:
    try:
        light_value = adc.value
        print('Light Level: ', light_value)
Example #11
0
sensor.heater = True
time.sleep(1)
sensor.heater = False
print("Sensor Heater OK")

# Setup Adafruit IO
io = IO_HTTP(secrets["aio_username"], secrets["aio_key"], wifi)

print("i2c, SPI, In Out Made")

try:
    # Get the 'digital' feed from Adafruit IO
    digital_feed = io.get_feed("led-dot")
except AdafruitIO_RequestError:
    # If no 'digital' feed exists, create one
    digital_feed = io.create_new_feed("led-dot")
try:
    # get time from wifi
    ntp = NTP(esp)
    ntp.set_time()
    start_time = time.time()
except (ValueError, RuntimeError) as e:
    print("Failed to set time\n", e)
    wifi.reset()
esp32_cs.value = False
print("wifi tested")


# calculate current Vapour-pressure deficit
def vpd(temp, rh):
    # Estimated Saturation Pressures
Example #12
0
#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets['aio_username']
aio_key = secrets['aio_key']

# Create an instance of the Adafruit IO HTTP client
io = IO_HTTP(aio_username, aio_key, wifi)

try:
    # Get the 'light' feed from Adafruit IO
    light_feed = io.get_feed('light')
except AdafruitIO_RequestError:
    # If no 'light' feed exists, create one
    light_feed = io.create_new_feed('light')

# Set up an analog light sensor on the PyPortal
adc = AnalogIn(board.LIGHT)

while True:
    light_value = adc.value
    print('Light Level: ', light_value)
    print('Sending to Adafruit IO...')
    io.send_data(light_feed['key'], light_value)
    print('Sent!')
    # delay sending to Adafruit IO
    time.sleep(SENSOR_DELAY)
# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets['aio_username']
aio_key = secrets['aio_key']

# Create an instance of the Adafruit IO HTTP client
io = IO_HTTP(aio_username, aio_key, wifi)

try:
    # Get the 'digital' feed from Adafruit IO
    digital_feed = io.get_feed('digital')
except AdafruitIO_RequestError:
    # If no 'digital' feed exists, create one
    digital_feed = io.create_new_feed('digital')

# Set up LED
LED = DigitalInOut(board.D13)
LED.direction = Direction.OUTPUT

while True:
    # Get data from 'digital' feed
    print('getting data from IO...')
    feed_data = io.receive_data(digital_feed['key'])

    # Check if data is ON or OFF
    if int(feed_data['value']) == 1:
        print('received <- ON\n')
    elif int(feed_data['value']) == 0:
        print('received <= OFF\n')
Example #14
0
# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]

# Create an instance of the Adafruit IO HTTP client
io = IO_HTTP(aio_username, aio_key, wifi)

try:
    # Get the 'temperature' feed from Adafruit IO
    temperature_feed = io.get_feed("temperature")
except AdafruitIO_RequestError:
    # If no 'temperature' feed exists, create one
    temperature_feed = io.create_new_feed("temperature")

# Set up ADT7410 sensor
i2c_bus = busio.I2C(board.SCL, board.SDA)
adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48)
adt.high_resolution = True

while True:
    try:
        temperature = adt.temperature
        # set temperature value to two precision points
        temperature = "%0.2f" % (temperature)

        print("Current Temperature: {0}*C".format(temperature))
        print("Sending to Adafruit IO...")
        io.send_data(temperature_feed["key"], temperature)
    esp, secrets, status_light)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
ADAFRUIT_IO_USER = secrets["aio_username"]
ADAFRUIT_IO_KEY = secrets["aio_key"]

# Create an instance of the Adafruit IO HTTP client
io = IO_HTTP(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi)

try:
    # Get the 'temperature' feed from Adafruit IO
    neopixel_feed = io.get_feed("neopixel")
except AdafruitIO_RequestError:
    neopixel_feed = io.create_new_feed("neopixel")

board.DISPLAY.show(group)
print("ready")
last_color = 257
last_index = 0
while True:
    p = ts.touch_point
    if p:
        x = math.floor(p[0] / 80)
        y = math.floor(p[1] / 80)
        index = 6 * y + x
        # Used to prevent the touchscreen sending incorrect results
        if last_index == index:
            color = colors[index]
            if colors[index]:
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(
    esp, secrets, status_light)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]

# Create an instance of the Adafruit IO HTTP client
io = IO_HTTP(aio_username, aio_key, wifi)

try:
    # Get the 'light' feed from Adafruit IO
    light_feed = io.get_feed("light")
except AdafruitIO_RequestError:
    # If no 'light' feed exists, create one
    light_feed = io.create_new_feed("light")

# Set up an analog light sensor on the PyPortal
adc = AnalogIn(board.LIGHT)

while True:
    light_value = adc.value
    print("Light Level: ", light_value)
    print("Sending to Adafruit IO...")
    io.send_data(light_feed["key"], light_value)
    print("Sent!")
    # delay sending to Adafruit IO
    time.sleep(SENSOR_DELAY)
status_light = neopixel.NeoPixel(
    board.NEOPIXEL, 1, brightness=0.2
)  

wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)

# Set Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]

# Create an instance of the Adafruit IO HTTP client
io = IO_HTTP(aio_username, aio_key, wifi)

try:
    # Get the test feed from Adafruit IO
    test_feed = io.get_feed("random")
except AdafruitIO_RequestError:
    # If no test feed exists, create one
    test_feed = io.create_new_feed("random")

while True:
    # Send random integer values to the feed
    random_value = random.randint(0, 50)
    print("Sending {0} to random feed - key: {1}".format(random_value, "key"))
    io.send_data(test_feed["key"], random_value)

    time.sleep(20)