Beispiel #1
0
URL = "http://api.coindesk.com/v1/bpi/currentprice.json"

uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=0.1)
resetpin = DigitalInOut(board.D5)

# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)
# Attach a 7 segment display and display -'s so we know its not live yet
display = segments.Seg7x4(i2c)
display.print('----')

print("Get bitcoin price online")

esp = adafruit_espatcontrol.ESP_ATcontrol(uart,
                                          115200,
                                          reset_pin=resetpin,
                                          debug=True)
print("Connected to AT software version", esp.get_version())

while True:
    try:
        display.print('----')
        # Connect to WiFi if not already
        print("Connected to", esp.remote_AP)
        if esp.remote_AP[0] != MY_SSID:
            esp.join_AP(MY_SSID, MY_PASS)
            print("My IP Address:", esp.local_ip)
        # great, lets get the JSON data
        print("Retrieving price...", end='')
        header, body = esp.request_url(URL)
        print("OK")
# Get wifi details and more from a settings.py file
try:
    from settings import settings
except ImportError:
    print("WiFi settings are kept in settings.py, please add them there!")
    raise

uart = busio.UART(board.TX, board.RX, timeout=0.1)
resetpin = DigitalInOut(board.D5)

URL = "http://wifitest.adafruit.com/testwifi/index.html"
print("ESP AT GET URL", URL)

esp = adafruit_espatcontrol.ESP_ATcontrol(uart,
                                          115200,
                                          run_baudrate=9600,
                                          reset_pin=resetpin,
                                          debug=False)
print("Resetting ESP module")
esp.hard_reset()

while True:
    try:
        print("Checking connection...")
        while not esp.is_connected:
            print("Connecting...")
            esp.connect(settings)
        # great, lets get the data
        print("Retrieving URL...", end='')
        header, body = esp.request_url(URL)
        print("OK")
#              CONFIGURATION
TIME_BETWEEN_QUERY = 10  # in seconds

# Cheerlights!
DATA_SOURCE = "http://api.thingspeak.com/channels/1417/feeds.json?results=1"
DATA_LOCATION = ["feeds", 0, "field2"]

uart = busio.UART(board.TX, board.RX, timeout=0.1)
resetpin = DigitalInOut(board.D5)
rtspin = DigitalInOut(board.D9)

# Create the connection to the co-processor and reset
esp = adafruit_espatcontrol.ESP_ATcontrol(uart,
                                          115200,
                                          run_baudrate=460800,
                                          reset_pin=resetpin,
                                          rts_pin=rtspin,
                                          debug=True)
esp.hard_reset()

# neopixels
pixels = neopixel.NeoPixel(board.A1, 16, brightness=0.3)
pixels.fill(0)
builtin = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.1)
builtin[0] = 0

# we'll save the value in question
last_value = value = None
the_time = None
times = 0