Skip to content

Added the ability to set static ip, set hostname, and set DNS #141

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions adafruit_esp32spi/adafruit_esp32spi.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@

_SET_NET_CMD = const(0x10)
_SET_PASSPHRASE_CMD = const(0x11)
_SET_IP_CONFIG = const(0x14)
_SET_DNS_CONFIG = const(0x15)
_SET_HOSTNAME = const(0x16)
_SET_AP_NET_CMD = const(0x18)
_SET_AP_PASSPHRASE_CMD = const(0x19)
_SET_DEBUG_CMD = const(0x1A)
Expand Down Expand Up @@ -404,6 +407,26 @@ def scan_networks(self):
return APs
return None

def set_ip_config(self, new_ip, new_gw, new_mask="255.255.255.0"):
"""Tells the ESP32 to set ip, gateway and network mask b"\xFF" """
resp = self._send_command_get_response(_SET_IP_CONFIG,
params= [b"\x00",self.unpretty_ip(new_ip),self.unpretty_ip(new_gw), self.unpretty_ip(new_mask)],
sent_param_len_16=False)
return resp

def set_dns_config(self, dns1, dns2="8.8.8.8"):
"""Tells the ESP32 to set DNS, with dns2 default to google dns=8.8.8.8"""
resp = self._send_command_get_response(_SET_DNS_CONFIG, [b"\x00", self.unpretty_ip(dns1), self.unpretty_ip(dns2)])
if resp[0][0] != 1:
raise RuntimeError("Failed to set dns with esp32")

def set_hostname(self, hostname):
"""Tells the ESP32 to set hostname"""
resp = self._send_command_get_response(_SET_HOSTNAME, [hostname])
return resp
if resp[0][0] != 1:
raise RuntimeError("Failed to set hostname with esp32")

def wifi_set_network(self, ssid):
"""Tells the ESP32 to set the access point to the given ssid"""
resp = self._send_command_get_response(_SET_NET_CMD, [ssid])
Expand Down