-
Notifications
You must be signed in to change notification settings - Fork 74
Static ip hostname and dns #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
09036f2
Added the ability to set static ip, set hostname, and set DNS with th…
9a40af7
Update adafruit_esp32spi.py
manpowre e433ef6
apply black and add example
Neradoc f4481be
cleanup and fix comments, cleanup examples
Neradoc ab41a20
fix ipconfig example use of encode
Neradoc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# SPDX-FileCopyrightText: 2019 ladyada for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
|
||
import time | ||
import board | ||
import busio | ||
from digitalio import DigitalInOut | ||
import adafruit_esp32spi.adafruit_esp32spi_socket as socket | ||
from adafruit_esp32spi import adafruit_esp32spi | ||
|
||
# Get wifi details and more from a secrets.py file | ||
try: | ||
from secrets import secrets | ||
except ImportError: | ||
print("WiFi secrets are kept in secrets.py, please add them there!") | ||
raise | ||
|
||
IP_ADDRESS = "192.168.1.111" | ||
GATEWAY_ADDRESS = "192.168.1.1" | ||
SUBNET_MASK = "255.255.255.0" | ||
|
||
UDP_IN_ADDR = "192.168.1.1" | ||
UDP_IN_PORT = 5500 | ||
|
||
UDP_TIMEOUT = 20 | ||
|
||
esp32_cs = DigitalInOut(board.CS1) | ||
esp32_ready = DigitalInOut(board.ESP_BUSY) | ||
esp32_reset = DigitalInOut(board.ESP_RESET) | ||
|
||
spi = busio.SPI(board.SCK1, board.MOSI1, board.MISO1) | ||
|
||
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) | ||
socket.set_interface(esp) | ||
|
||
s_in = socket.socket(type=socket.SOCK_DGRAM) | ||
s_in.settimeout(UDP_TIMEOUT) | ||
print("set hostname:") | ||
esp.set_hostname("new_hostname".encode("utf-8")) | ||
|
||
if esp.status == adafruit_esp32spi.WL_IDLE_STATUS: | ||
print("ESP32 found and in idle mode") | ||
print("Firmware vers.", esp.firmware_version) | ||
print("MAC addr:", [hex(i) for i in esp.MAC_address]) | ||
|
||
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) | ||
ip1 = esp.ip_address | ||
|
||
print("set ip dns") | ||
esp.set_dns_config("192.168.1.1", "8.8.8.8") | ||
|
||
print("set ip config") | ||
esp.set_ip_config(IP_ADDRESS, GATEWAY_ADDRESS, SUBNET_MASK) | ||
|
||
time.sleep(1) | ||
ip2 = esp.ip_address | ||
|
||
time.sleep(1) | ||
info = esp.network_data | ||
print( | ||
"get network_data: ", | ||
esp.pretty_ip(info["ip_addr"]), | ||
esp.pretty_ip(info["gateway"]), | ||
esp.pretty_ip(info["netmask"]), | ||
) | ||
|
||
IP_ADDR = esp.pretty_ip(esp.ip_address) | ||
print("ip:", IP_ADDR) | ||
print("My IP address is", esp.pretty_ip(esp.ip_address)) | ||
print("udp in addr: ", UDP_IN_ADDR, UDP_IN_PORT) | ||
|
||
socketaddr_udp_in = socket.getaddrinfo(UDP_IN_ADDR, UDP_IN_PORT)[0][4] | ||
s_in.connect(socketaddr_udp_in, conntype=esp.UDP_MODE) | ||
print("connected local UDP") | ||
|
||
while True: | ||
data = s_in.recv(1205) | ||
if len(data) >= 1: | ||
data = data.decode("utf-8") | ||
print(len(data), data) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.