|
37 | 37 |
|
38 | 38 | _SET_NET_CMD = const(0x10)
|
39 | 39 | _SET_PASSPHRASE_CMD = const(0x11)
|
| 40 | +_SET_IP_CONFIG = const(0x14) |
| 41 | +_SET_DNS_CONFIG = const(0x15) |
| 42 | +_SET_HOSTNAME = const(0x16) |
40 | 43 | _SET_AP_NET_CMD = const(0x18)
|
41 | 44 | _SET_AP_PASSPHRASE_CMD = const(0x19)
|
42 | 45 | _SET_DEBUG_CMD = const(0x1A)
|
@@ -405,6 +408,26 @@ def scan_networks(self):
|
405 | 408 | return APs
|
406 | 409 | return None
|
407 | 410 |
|
| 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 | + |
408 | 431 | def wifi_set_network(self, ssid):
|
409 | 432 | """Tells the ESP32 to set the access point to the given ssid"""
|
410 | 433 | resp = self._send_command_get_response(_SET_NET_CMD, [ssid])
|
|
0 commit comments