Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

http server on a pyportal
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

http server on a pyportal

by MVB57 on Sun Aug 02, 2020 2:27 am

Hi there,

For my pyportal I am trying to add a http server so I can interact with it remotely. I am working with the Adafruit_CircuitPython_ESP32SPI library and Circuitpython 5.3.1. I am using the "start_server(port, socket_num, conn_mode=0, ip=None)" function to set up a server on port 80 of my board. The server can be seen in my local network when I scan for open ports on the IP address of the pyportal.

How can I check if a request is made by a client and send a response in return? I have not been able to find any example online sofar.

Thanks in advance,

Michiel


PS Here is the code I have been working with so far:

Code: Select all | TOGGLE FULL SIZE
import time
import board
import busio
from digitalio import DigitalInOut

import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
from secrets import secrets

esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)

if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
    print("ESP32 found and in idle mode")

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("My IP address is", esp.pretty_ip(esp.ip_address))

socketnumber = esp.get_socket()
esp.start_server(80, socketnumber)

while True:
    print(esp.server_state(socketnumber))
    time.sleep(2)

MVB57
 
Posts: 1
Joined: Sat Aug 01, 2020 3:48 pm

Re: http server on a pyportal

by tannewt on Mon Aug 03, 2020 10:51 am


tannewt
 
Posts: 1795
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.