From c557537ec6f8da522ae8cd0776e9397475fe3d78 Mon Sep 17 00:00:00 2001 From: sdfsdf Date: Sat, 23 Oct 2021 17:52:35 +0200 Subject: [PATCH 1/2] Added the ability to set static ip, set hostname, and set DNS with the esp32spi interface as the esp32SPI interface supports this --- adafruit_esp32spi/adafruit_esp32spi.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/adafruit_esp32spi/adafruit_esp32spi.py b/adafruit_esp32spi/adafruit_esp32spi.py index c827408..bc9147c 100644 --- a/adafruit_esp32spi/adafruit_esp32spi.py +++ b/adafruit_esp32spi/adafruit_esp32spi.py @@ -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) @@ -404,6 +407,26 @@ def scan_networks(self): return APs return None + def set_ip_config(self, ip, gw, 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(ip),self.unpretty_ip(gw), self.unpretty_ip(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]) From d2ace376667d2e5e86a76e1819440418cf479f50 Mon Sep 17 00:00:00 2001 From: manpowre Date: Sat, 23 Oct 2021 19:57:12 +0200 Subject: [PATCH 2/2] Update adafruit_esp32spi.py --- adafruit_esp32spi/adafruit_esp32spi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_esp32spi/adafruit_esp32spi.py b/adafruit_esp32spi/adafruit_esp32spi.py index bc9147c..332161a 100644 --- a/adafruit_esp32spi/adafruit_esp32spi.py +++ b/adafruit_esp32spi/adafruit_esp32spi.py @@ -407,10 +407,10 @@ def scan_networks(self): return APs return None - def set_ip_config(self, ip, gw, mask="255.255.255.0"): + 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(ip),self.unpretty_ip(gw), self.unpretty_ip(mask)], + 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