Closed manpowre closed 1 year ago
this library doesnt support dhcp static ip config - it looks like the esp32's nina firmware supports it? but you'd have to add the capability to the library or just tell your router to only use one IP address for the MAC.
I tried openMV micropython and they implemented ifconfig() and that works. so its not the esp32 missing functionality, its the circuitpython library. (openMV doesnt support nepixel with pwm, so I cant use that). Sure setting router is fine, but this could easily be added to set the IP, subnetmask and gateway + dns.
correct, you'd have to add the capability to the driver - we have not implemented it.
I did some digging, the Nina interface has its commands and parameters here: https://github.com/arduino/nina-fw/blob/master/main/CommandHandler.cpp
I implemented into adafruit_esp32spi.py:
_SET_IP_CONFIG = const(0x14)
_SET_DNS_CONFIG = const(0x15)
_SET_HOSTNAME = const(0x16)
def set_ip_config(self, ip, gw, mask="255.255.255.0"):
"""Tells the ESP32 to set ip, gateway and network mask"""
resp = self._send_command_get_response(_SET_IP_CONFIG, [self.unpretty_ip(ip), self.unpretty_ip(gw), self.unpretty_ip(mask)])
return resp
if resp[0][0] != 1:
raise RuntimeError("Failed to set ip config with esp32")
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, [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")
the set_hostname works great, but the set_ip_config doesnt work. The ESP32 returns 0x00, which means failed.
Not submitting until I figured out why the set_ip_config function wont set the ip correctly.
nice work! looks like you've got the right direction
well the set_ip_config aint setting the ip. not sure whats going on here. getting fishy network interface for sure after I set the ip, gw and mask, and the controller is reporting 0x00, so that means fail to set it, but yea, a bit in the right direction. if we just can set the ip, then I can agree to drop the udp part hehe, even though udp to local IP works.. its just that we have to be able to set the IP atleast.
got it working: ` _SET_IP_CONFIG = const(0x14) _SET_DNS_CONFIG = const(0x15) _SET_HOSTNAME = const(0x16)
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
if resp[0][0] != 1:
raise RuntimeError("Failed to set ip config with esp32")
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")
`
I can now set ip to 192.168.2.2, gw 192.168.1.1, mask 255.255.255.0 and it recieves UDP packages at 192.168.2.2 !!
yayy
yes!!! please submit a PR :)
ip config, dns config, and hostname were implemented in this library last year, and there should be support already in the Arduino and Adafruit form of the NINA firmware. I think we can close this issue. https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI/pull/159
CircuitPython version
Code/REPL
Behavior
The interface is missing the ifconfig to set a static IP adress: esp.ifconfig = (IP_ADDRESS, SUBNET_MASK, GATEWAY_ADDRESS, DNS_SERVER)
this is critical for people wanting to use this device with circtuitpython to atleast be able to set a static IP, otherwise the DHCP will renew the IP adress from time to time.
I tested OpenMV micropython and their ifconfig works like a charm so its not the wifi chip, its the circtuitpython interface thats missing this.
Description
No response
Additional information
No response