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,46 @@ def scan_networks(self):
405
408
return APs
406
409
return None
407
410
411
+ def set_ip_config (self , ip_address , gateway , mask = "255.255.255.0" ):
412
+ """Tells the ESP32 to set ip, gateway and network mask b"\xFF "
413
+
414
+ :param str ip_address: IP address (as a string).
415
+ :param str gateway: Gateway (as a string).
416
+ :param str mask: Mask, defaults to 255.255.255.0 (as a string).
417
+ """
418
+ resp = self ._send_command_get_response (
419
+ _SET_IP_CONFIG ,
420
+ params = [
421
+ b"\x00 " ,
422
+ self .unpretty_ip (ip_address ),
423
+ self .unpretty_ip (gateway ),
424
+ self .unpretty_ip (mask ),
425
+ ],
426
+ sent_param_len_16 = False ,
427
+ )
428
+ return resp
429
+
430
+ def set_dns_config (self , dns1 , dns2 ):
431
+ """Tells the ESP32 to set DNS
432
+
433
+ :param str dns1: DNS server 1 IP as a string.
434
+ :param str dns2: DNS server 2 IP as a string.
435
+ """
436
+ resp = self ._send_command_get_response (
437
+ _SET_DNS_CONFIG , [b"\x00 " , self .unpretty_ip (dns1 ), self .unpretty_ip (dns2 )]
438
+ )
439
+ if resp [0 ][0 ] != 1 :
440
+ raise RuntimeError ("Failed to set dns with esp32" )
441
+
442
+ def set_hostname (self , hostname ):
443
+ """Tells the ESP32 to set hostname for DHCP.
444
+
445
+ :param str hostname: The new host name.
446
+ """
447
+ resp = self ._send_command_get_response (_SET_HOSTNAME , [hostname .encode ()])
448
+ if resp [0 ][0 ] != 1 :
449
+ raise RuntimeError ("Failed to set hostname with esp32" )
450
+
408
451
def wifi_set_network (self , ssid ):
409
452
"""Tells the ESP32 to set the access point to the given ssid"""
410
453
resp = self ._send_command_get_response (_SET_NET_CMD , [ssid ])
@@ -518,8 +561,7 @@ def connect(self, secrets):
518
561
self .connect_AP (secrets ["ssid" ], secrets ["password" ])
519
562
520
563
def connect_AP (self , ssid , password , timeout_s = 10 ): # pylint: disable=invalid-name
521
- """
522
- Connect to an access point with given name and password.
564
+ """Connect to an access point with given name and password.
523
565
Will wait until specified timeout seconds and return on success
524
566
or raise an exception on failure.
525
567
@@ -552,8 +594,7 @@ def connect_AP(self, ssid, password, timeout_s=10): # pylint: disable=invalid-n
552
594
def create_AP (
553
595
self , ssid , password , channel = 1 , timeout = 10
554
596
): # pylint: disable=invalid-name
555
- """
556
- Create an access point with the given name, password, and channel.
597
+ """Create an access point with the given name, password, and channel.
557
598
Will wait until specified timeout seconds and return on success
558
599
or raise an exception on failure.
559
600
@@ -814,8 +855,7 @@ def set_esp_debug(self, enabled):
814
855
raise RuntimeError ("Failed to set debug mode" )
815
856
816
857
def set_pin_mode (self , pin , mode ):
817
- """
818
- Set the io mode for a GPIO pin.
858
+ """Set the io mode for a GPIO pin.
819
859
820
860
:param int pin: ESP32 GPIO pin to set.
821
861
:param value: direction for pin, digitalio.Direction or integer (0=input, 1=output).
@@ -831,8 +871,7 @@ def set_pin_mode(self, pin, mode):
831
871
raise RuntimeError ("Failed to set pin mode" )
832
872
833
873
def set_digital_write (self , pin , value ):
834
- """
835
- Set the digital output value of pin.
874
+ """Set the digital output value of pin.
836
875
837
876
:param int pin: ESP32 GPIO pin to write to.
838
877
:param bool value: Value for the pin.
@@ -844,8 +883,7 @@ def set_digital_write(self, pin, value):
844
883
raise RuntimeError ("Failed to write to pin" )
845
884
846
885
def set_analog_write (self , pin , analog_value ):
847
- """
848
- Set the analog output value of pin, using PWM.
886
+ """Set the analog output value of pin, using PWM.
849
887
850
888
:param int pin: ESP32 GPIO pin to write to.
851
889
:param float value: 0=off 1.0=full on
@@ -858,8 +896,7 @@ def set_analog_write(self, pin, analog_value):
858
896
raise RuntimeError ("Failed to write to pin" )
859
897
860
898
def set_digital_read (self , pin ):
861
- """
862
- Get the digital input value of pin. Returns the boolean value of the pin.
899
+ """Get the digital input value of pin. Returns the boolean value of the pin.
863
900
864
901
:param int pin: ESP32 GPIO pin to read from.
865
902
"""
@@ -877,8 +914,7 @@ def set_digital_read(self, pin):
877
914
)
878
915
879
916
def set_analog_read (self , pin , atten = ADC_ATTEN_DB_11 ):
880
- """
881
- Get the analog input value of pin. Returns an int between 0 and 65536.
917
+ """Get the analog input value of pin. Returns an int between 0 and 65536.
882
918
883
919
:param int pin: ESP32 GPIO pin to read from.
884
920
:param int atten: attenuation constant
@@ -914,6 +950,7 @@ def get_time(self):
914
950
def set_certificate (self , client_certificate ):
915
951
"""Sets client certificate. Must be called
916
952
BEFORE a network connection is established.
953
+
917
954
:param str client_certificate: User-provided .PEM certificate up to 1300 bytes.
918
955
"""
919
956
if self ._debug :
@@ -936,6 +973,7 @@ def set_certificate(self, client_certificate):
936
973
def set_private_key (self , private_key ):
937
974
"""Sets private key. Must be called
938
975
BEFORE a network connection is established.
976
+
939
977
:param str private_key: User-provided .PEM file up to 1700 bytes.
940
978
"""
941
979
if self ._debug :
0 commit comments