Get a webpage with ESP32

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
AwesomeCronk
Posts: 33
Joined: Fri Oct 11, 2019 1:24 am

Get a webpage with ESP32

Post by AwesomeCronk » Fri Oct 11, 2019 1:33 am

I would like to connect an ESP32 to a server hosting the webpage ‘example.com’. I am using an Adafruit HUZZAH32 and Thonny IDE.
Thanks!

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Get a webpage with ESP32

Post by jimmo » Fri Oct 11, 2019 2:40 am

Hi,

Are you using CircuitPython or MicroPython.

The easiest way to do this is with urequests. On MicroPython for ESP32, this is included in the default firmware. It works a lot like the Python "requests" library.

Code: Select all

import urequests

r = requests.get("http://example.com/")
# Use one of these depending on what your response looks like:
print(r.content)
print(r.text)
print(r.json())
r.close()
On CircuitPython, take a look at https://circuitpython.readthedocs.io/pr ... t/api.html

AwesomeCronk
Posts: 33
Joined: Fri Oct 11, 2019 1:24 am

Re: Get a webpage with ESP32

Post by AwesomeCronk » Fri Oct 11, 2019 5:52 pm

I presume I can connect to my network, then call this?

Yes, micro python for ESP32.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Get a webpage with ESP32

Post by jimmo » Sun Oct 13, 2019 11:42 pm

Yes, use the instructions here http://docs.micropython.org/en/latest/e ... networking for connecting to the network first.

Post Reply