Skip to content

Commit 09036f2

Browse files
sdfsdfNeradoc
sdfsdf
authored andcommitted
Added the ability to set static ip, set hostname, and set DNS with the esp32spi interface as the esp32SPI interface supports this
1 parent 971d361 commit 09036f2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

adafruit_esp32spi/adafruit_esp32spi.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737

3838
_SET_NET_CMD = const(0x10)
3939
_SET_PASSPHRASE_CMD = const(0x11)
40+
_SET_IP_CONFIG = const(0x14)
41+
_SET_DNS_CONFIG = const(0x15)
42+
_SET_HOSTNAME = const(0x16)
4043
_SET_AP_NET_CMD = const(0x18)
4144
_SET_AP_PASSPHRASE_CMD = const(0x19)
4245
_SET_DEBUG_CMD = const(0x1A)
@@ -405,6 +408,26 @@ def scan_networks(self):
405408
return APs
406409
return None
407410

411+
def set_ip_config(self, ip, gw, mask="255.255.255.0"):
412+
"""Tells the ESP32 to set ip, gateway and network mask b"\xFF" """
413+
resp = self._send_command_get_response(_SET_IP_CONFIG,
414+
params= [b"\x00",self.unpretty_ip(ip),self.unpretty_ip(gw), self.unpretty_ip(mask)],
415+
sent_param_len_16=False)
416+
return resp
417+
418+
def set_dns_config(self, dns1, dns2="8.8.8.8"):
419+
"""Tells the ESP32 to set DNS, with dns2 default to google dns=8.8.8.8"""
420+
resp = self._send_command_get_response(_SET_DNS_CONFIG, [b"\x00", self.unpretty_ip(dns1), self.unpretty_ip(dns2)])
421+
if resp[0][0] != 1:
422+
raise RuntimeError("Failed to set dns with esp32")
423+
424+
def set_hostname(self, hostname):
425+
"""Tells the ESP32 to set hostname"""
426+
resp = self._send_command_get_response(_SET_HOSTNAME, [hostname])
427+
return resp
428+
if resp[0][0] != 1:
429+
raise RuntimeError("Failed to set hostname with esp32")
430+
408431
def wifi_set_network(self, ssid):
409432
"""Tells the ESP32 to set the access point to the given ssid"""
410433
resp = self._send_command_get_response(_SET_NET_CMD, [ssid])

0 commit comments

Comments
 (0)