def get_feed_data(): io = IO_HTTP(secrets["aio_username"], secrets["aio_key"], requests) feed0 = None feed1 = None feed2 = None if (feed0 is None): try: feed0 = io.get_feed(aio_feed0_name) except: print("Can't get " + aio_feed0_name + " feed.") if (feed1 is None): try: feed1 = io.get_feed(aio_feed1_name) except: print("Can't get " + aio_feed1_name + " feed.") if (feed2 is None): try: feed2 = io.get_feed(aio_feed2_name) except: print("Can't get " + aio_feed2_name + " feed.") try: t0 = io.receive_data(feed0["key"]) t1 = io.receive_data(feed1["key"]) t2 = io.receive_data(feed2["key"]) return t0["value"], t1["value"], t2["value"] except: return None, None, None
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
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!")
status_light = neopixel.NeoPixel(board.NEOPIXEL, 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.) 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:
#temperature_feed = io.get_feed("temperature") light_position_feed = io.get_feed("tiki-light-position") except AdafruitIO_RequestError: # If no 'temperature' feed exists, create one #temperature_feed = io.create_new_feed("temperature") light_position_feed = io.create_new_feed("tiki-light-position") ''' ####################### # For the feed 'tiki_light_position', # value of 0 = lights are off # value of 1 = lights are on ####################### light_value = 1 light_position_feed = io.get_feed("tiki-light-position") # 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) #io.send_data(light_position_feed["key"],25) #print("Data sent!") # Retrieve data value from the feed #print("Retrieving data from tiki_light_position feed...") #received_data = io.receive_data(light_position_feed["key"]) #print("Data from tiki_light_position feed: ", received_data["value"]) ###################### # Create buttons
"""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) 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)
#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!')
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) status_light = neopixel.NeoPixel(board.NEOPIXEL, 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 IO_HTTP client io = IO_HTTP(aio_username, aio_key, wifi) # Get the weight feed from IO weight_feed = io.get_feed('weight') # initialize the dymo scale units_pin = digitalio.DigitalInOut(board.D3) units_pin.switch_to_output() dymo = adafruit_dymoscale.DYMOScale(board.D4, units_pin) # take a reading of the current time, used for toggling the device out of sleep time_stamp = time.monotonic() while True: try: reading = dymo.weight text = "%0.1f g" % reading.weight print(text) weight_label.text = text
set_backlight(1.0) # Touchscreen setup # ------Rotate 270: screen_width = 240 screen_height = 320 ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, calibration=((5200, 59000), (5800, 57000)), size=(screen_width, screen_height)) try: temperature_feed = io.get_feed('villaastrid.tupa-bme680-temp') except AdafruitIO_RequestError: print("temperature_feed, failed") try: ldr_feed = io.get_feed('home-tampere.esp32test-ldr') except AdafruitIO_RequestError: print("ldr_feed, failed") try: water_temp_feed = io.get_feed('villaastrid.water-temp') except AdafruitIO_RequestError: print("water temp feed, failed") try: outdoor_temp_feed = io.get_feed('villaastrid.outdoor1-temp')
"""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) 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)
"""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) 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("Connected to %s!" % secrets["ssid"]) print("My IP address is", wifi.radio.ipv4_address) 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())
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)
class SensorLogger: def __init__(self, i2c_bus=None): # Get wifi details and more from a secrets.py file try: from secrets import secrets self._secrets = secrets except ImportError: raise RuntimeError( "WiFi secrets are kept in secrets.py, please add them there!") try: from settings import settings self._settings = settings except ImportError: raise RuntimeError("Settings file settings.py missing") if i2c_bus: self._i2c = i2c_bus else: self._i2c = board.I2C() self._error_log_file = settings["error_log_filename"] self.io = None self._initialize_wifi() self._initialize_sensors() self._initialize_io() # self.battery = analogio.AnalogIn(board.BATTERY) self.temperature_feed = None self.humidity_feed = None self.batt_volts_feed = None self.heater_state = False def _log_exceptions(func): # pylint:disable=protected-access def _decorator(self, *args, **kwargs): retval = None try: retval = func(self, *args, **kwargs) return retval except Exception as e: err_str = "ERROR in %s\n%s\n" % (func.__name__, e) if self._settings["log_errors_to_file"]: storage.remount("/", disable_concurrent_write_protection=False) with open(self._error_log_file, "a") as err_log: err_log.write(err_str) storage.remount("/", False) print(err_str) return retval return _decorator def _initialize_wifi(self): # Get wifi details and more from a secrets.py file try: from secrets import secrets self._secrets = secrets except ImportError as e: print( "WiFi secrets are kept in secrets.py, please add them there!") raise e from None # ESP32 Setup try: esp32_cs = DigitalInOut(board.D13) esp32_ready = DigitalInOut(board.D11) esp32_reset = DigitalInOut(board.D12) except AttributeError: esp32_cs = DigitalInOut(board.ESP_CS) esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) self._spi = busio.SPI(board.SCK, board.MOSI, board.MISO) self._esp = adafruit_esp32spi.ESP_SPIcontrol( self._spi, esp32_cs, esp32_ready, esp32_reset, service_function=self.service) status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.1) self.wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( self._esp, self._secrets, status_light) def service(self): # add touch_screen_service button_machine.service() screen_machine.service() @_log_exceptions def _initialize_io(self): aio_username = self._secrets["aio_username"] aio_key = self._secrets["aio_key"] # Create an instance of the Adafruit IO HTTP client self.io = IO_HTTP(aio_username, aio_key, self.wifi) clock = rtc.RTC() clock.datetime = self.io.receive_time() self._initialize_feeds() @_log_exceptions def _initialize_feeds(self): self.temperature_feed = self.io.get_feed( self._secrets["aio_temp_feed"]) self.humidity_feed = self.io.get_feed(self._secrets["aio_hum_feed"]) self.rssi_feed = self.io.get_feed(self._secrets["aio_rssi_feed"]) if 'aio_heater_feed' in self._secrets: self.heater_feed = self.io.get_feed( self._secrets["aio_heater_feed"]) # self.batt_volts_feed = self.io.get_feed("batt-volts") @_log_exceptions def _initialize_sensors(self): if not self.io: self._initialize_io self.temp_sensor = PHT_SENSOR(self._i2c) self.humidity_sensor = self.temp_sensor @_log_exceptions def log_sensors(self): if not (self.humidity_feed and self.temperature_feed): self._initialize_feeds() temp = self.temp_sensor.temperature hum = self.humidity_sensor.relative_humidity rssi = self.wifi.signal_strength() print("\033[1mTmemperature:\033[0m %0.3f k ºC" % temp) print("\033[1mHumidity:\033[0m %0.2f %%" % hum) print("\033[1mRSSI:\033[0m %0.2f" % rssi) if self.heater_feed: if temp < 29.0: self.heater_state = True elif temp > 31.0: self.heater_state = False print("\033[1mHeater on:\033[0m", self.heater_state) self.io.send_data(self.heater_feed["key"], self.heater_state) self.io.send_data(self.temperature_feed["key"], temp) self.io.send_data(self.humidity_feed["key"], hum) self.io.send_data(self.rssi_feed["key"], rssi)
print("initiating connection to adafruit io") want_local_feed = True # setup connection to temperature feed pixels.fill( YELLOW) # flash YELLOW/RED to say initializing Adafruit IO Temperature pixels.show() time.sleep(0.5) pixels.fill(RED) pixels.show() time.sleep(0.5) pixels.fill(BLACK) pixels.show() try: # Get the 'temperature' feed from Adafruit IO temperature_feed = io.get_feed(config['feed_T']) print("successfully setup temperature feed", temperature_feed["key"]) except AdafruitIO_RequestError: # If no 'temperature' feed exists, create one #temperature_feed = io.create_new_feed(config['feed_T']) want_local_feed = False # setup connection to humidity feed pixels.fill( YELLOW) # flash YELLOW/BLUE to say initializing Adafruit IO Temperature pixels.show() time.sleep(0.5) pixels.fill(BLUE) pixels.show() time.sleep(0.5) pixels.fill(BLACK)
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!')
wifi.radio.stop_scanning_networks() dotstar[0] = (0, 0, 0, 0.5) 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()
sensor = adafruit_sht31d.SHT31D(i2c) sensor.frequency = adafruit_sht31d.FREQUENCY_1 sensor.mode = adafruit_sht31d.MODE_PERIODIC 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")
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'])
status_light = neopixel.NeoPixel(board.NEOPIXEL, 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.) 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:
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!")
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) 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) # Get the 'enge-1216.digital' feed from Adafruit IO digital_feed = io.get_feed("enge-1216.digital") # Get the 'enge-1216.alarm' feed from Adafruit IO alarm_feed = io.get_feed("enge-1216.alarm") # Get the 'enge-1216.alarm-default-days' feed from Adafruit IO days_feed = io.get_feed("enge-1216.alarm-default-days") # Get the 'enge-1216.alarm-time' feed from Adafruit IO time_feed = io.get_feed("enge-1216.alarm-time") # Get the 'enge-1216.skip-next-alarm' feed from Adafruit IO skip_feed = io.get_feed("enge-1216.skip-next-alarm") i2c = board.I2C() display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
:param bool is_celsius: Returns temperature in degrees celsius if True, otherwise fahrenheit. """ humid = bme_sensor.humidity temp = bme_sensor.temperature if not is_celsius: temp = temp * 1.8 + 32 return temp, humid # Create an instance of the Adafruit IO HTTP client io = IO_HTTP(secrets["aio_user"], secrets["aio_key"], wifi) # Describes feeds used to hold Adafruit IO data feed_aqi = io.get_feed("air-quality-sensor.aqi") feed_aqi_category = io.get_feed("air-quality-sensor.category") feed_humidity = io.get_feed("air-quality-sensor.humidity") feed_temperature = io.get_feed("air-quality-sensor.temperature") # Set up location metadata from secrets.py file location_metadata = (secrets["latitude"], secrets["longitude"], secrets["elevation"]) elapsed_minutes = 0 prv_mins = 0 while True: try: print("Fetching time...") cur_time = io.receive_time() print("Time fetched OK!")
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 '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:
# 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)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py 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") pressure_feed = io.get_feed("pressure") humidity_feed = io.get_feed("humidity") except AdafruitIO_RequestError: # If no 'temperature' feed exists, create one temperature_feed = io.create_new_feed("temperature") pressure_feed = io.create_new_feed("pressure") humidity_feed = io.create_new_feed("humidity") # set up the connection with the bme280 i2c = busio.I2C(board.SCL, board.SDA) bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) # average global sea level pressure, for more accurate readings change this to your local sea level pressure (measured in hPa) bme280.sea_level_pressure = 1023.50