Created
April 16, 2020 13:28
-
-
Save FoamyGuy/24a3b4685c96aac86d57c96c8dcb96a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# adafruit_requests usage with an esp32spi_socket | |
import board | |
import busio | |
from digitalio import DigitalInOut | |
import adafruit_esp32spi.adafruit_esp32spi_socket as socket | |
from adafruit_esp32spi import adafruit_esp32spi | |
import adafruit_requests as requests | |
from secrets import secrets | |
# If you are using a board with pre-defined ESP32 Pins: | |
esp32_cs = DigitalInOut(board.ESP_CS) | |
esp32_ready = DigitalInOut(board.ESP_BUSY) | |
esp32_reset = DigitalInOut(board.ESP_RESET) | |
# If you have an externally connected ESP32: | |
# esp32_cs = DigitalInOut(board.D9) | |
# esp32_ready = DigitalInOut(board.D10) | |
# esp32_reset = DigitalInOut(board.D5) | |
spi = busio.SPI(board.SCK, board.MOSI, board.MISO) | |
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) | |
print("Connecting to AP...") | |
while not esp.is_connected: | |
try: | |
esp.connect_AP(secrets['ssid'], secrets['password']) | |
except RuntimeError as e: | |
print("could not connect to AP, retrying: ", e) | |
continue | |
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) | |
# Initialize a requests object with a socket and esp32spi interface | |
requests.set_socket(socket, esp) | |
IFTTT_URL = "https://maker.ifttt.com/trigger/%7Bevent%7D/with/key/" + secrets["ifttt_key"] | |
data = '{ "value1" : "something", "value2" : 14.76, "value3" : "another" }' | |
print("POSTing data to {0}: {1}".format(IFTTT_URL, data)) | |
response = requests.post(IFTTT_URL, data=data) | |
print(response.text) | |
response.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment