'How to retrieve a value by using get method ( /get ) on Micropython Webserver?
On Webserver, basically, I would like to take a value from the user and process it in the programme. I use Micropython on Thonny IDE with a Raspberry Pi Pico. TCP/IP communication protocol is used with a W5500 chip. I used /get format to take inputs. But, I cant reach the corresponding value which comes after '' get?Value= '' on search bar. Can you help me ?
import board
import busio
import digitalio
import time
import adafruit_requests as requests
from adafruit_wiznet5k.adafruit_wiznet5k import *
from adafruit_wsgi.wsgi_app import WSGIApp
import adafruit_wiznet5k.adafruit_wiznet5k_wsgiserver as server
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
##SPI Communication Connections
SPI0_SCK = board.GP18
SPI0_TX = board.GP19
SPI0_RX = board.GP16
SPI0_CSn = board.GP17
##reset
W5x00_RSTn = board.GP20
print("Wiznet5k HTTP Test (no DHCP)")
MY_MAC = (0x00, 0x01, 0x02, 0x03, 0x04, 0x05) #My Own IP Credentials
IP_ADDRESS = (10, 0, 0, 197)
SUBNET_MASK = (255, 255, 254, 0)
GATEWAY_ADDRESS = (10, 0, 0, 254)
DNS_SERVER = (10, 0, 0, 1)
led = digitalio.DigitalInOut(board.GP25)
led.direction = digitalio.Direction.OUTPUT
ethernetRst = digitalio.DigitalInOut(W5x00_RSTn)
ethernetRst.direction = digitalio.Direction.OUTPUT
# For Adafruit Ethernet FeatherWing
cs = digitalio.DigitalInOut(SPI0_CSn)
spi_bus = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX)
# Reset W5500 first
ethernetRst.value = False
time.sleep(1)
ethernetRst.value = True
# Initialize ethernet interface without DHCP
eth = WIZNET5K(spi_bus, cs, is_dhcp=False, mac=MY_MAC, debug=False)
# Set network configuration
eth.ifconfig = (IP_ADDRESS, SUBNET_MASK, GATEWAY_ADDRESS, DNS_SERVER)
print("My IP address is:", eth.pretty_ip(eth.ip_address))
# Initialize a requests object with a socket and ethernet interface
requests.set_socket(socket, eth)
# Here we create our application, registering the
# following functions to be called on specific HTTP GET requests routes
web_app = WSGIApp()
html_string = '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Raspberry Pi Pico</title>
</head>
<body>
<div align="center">
<H1>Raspberry Pi Pico Web Server</H1>
<form action="/get">
IP ADRESS: <input type="text" name="Value">
<input type="submit" value="Submit">
</form><br>
</div>
</body>
</html>
'''
html_string = html_string.replace("$CHIPNAME",eth.chip)
html_string = html_string.replace("$IPADDRESS",eth.pretty_ip(eth.ip_address))
@web_app.route("/") # Problem is here, How to get entered input ?
def root(request):
print("Value is Taken")
return ("200 OK", [], [html_string])
server.set_interface(eth)
wsgiServer = server.WSGIServer(80, application=web_app)
print("Open this IP in your browser: ", eth.pretty_ip(eth.ip_address))
# Start the server
wsgiServer.start()
while True:
# Our main loop where we have the server poll for incoming requests
wsgiServer.update_poll()
# Maintain DHCP lease
eth.maintain_dhcp_lease()
Solution 1:[1]
Please refer to the below link about pi pico, wiznet chip, micropython and http client.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KevinLab |
