WLAN.ifconfig(

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
RobinMosedale
Posts: 40
Joined: Fri Jul 26, 2019 9:40 pm

WLAN.ifconfig(

Post by RobinMosedale » Wed Feb 24, 2021 8:59 pm

It seems that setting the IP address of a Sta isn't available for the esp32 variant:
both variants of the syntax on the Micropython reference documentation (quick reference guide etc) raise errors

wlan.ifconfig(('192.168.1.144','255.255.255.0','192.168.1,254','192.168,1,254'))
wlan.ifconfig(config=('192.168.1.144','255.255.255.0','192.168.1,254','192.168,1,254'))


'ValueError: invalid arguments'
Am I correct that this is not available for Esp32, yet documentation implies that it does.

davef
Posts: 813
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: WLAN.ifconfig(

Post by davef » Wed Feb 24, 2021 10:02 pm

Try:

Code: Select all

sta_if.ifconfig(('192.168.10.99', '255.255.255.0', '192.168.10.1', '192.168.10.1'))
Double brackets

RobinMosedale
Posts: 40
Joined: Fri Jul 26, 2019 9:40 pm

Re: WLAN.ifconfig(

Post by RobinMosedale » Wed Feb 24, 2021 10:26 pm

Thank you Dave

RobinMosedale
Posts: 40
Joined: Fri Jul 26, 2019 9:40 pm

Re: WLAN.ifconfig(

Post by RobinMosedale » Thu Feb 25, 2021 12:54 am

Isn't that identical to what I'm doing with merely a different instansiation of the wlan object name?

davef
Posts: 813
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: WLAN.ifconfig(

Post by davef » Thu Feb 25, 2021 12:58 am

Sorry, I don't know the reason ... I saw it somewhere when I had the same problem and it fixed it. I recall it has something to do with tuples.

RobinMosedale
Posts: 40
Joined: Fri Jul 26, 2019 9:40 pm

Re: WLAN.ifconfig(

Post by RobinMosedale » Thu Feb 25, 2021 1:28 am

Very odd. Looks identical

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: WLAN.ifconfig(

Post by jimmo » Thu Feb 25, 2021 2:23 am

RobinMosedale wrote:
Thu Feb 25, 2021 12:54 am
Isn't that identical to what I'm doing with merely a different instansiation of the wlan object name?
In your example, you have commas instead of dots inside the last two addresses.

Code: Select all

wlan.ifconfig(('192.168.1.144','255.255.255.0','192.168.1,254','192.168,1,254'))
                                                         ^             ^ ^

RobinMosedale
Posts: 40
Joined: Fri Jul 26, 2019 9:40 pm

Re: WLAN.ifconfig(

Post by RobinMosedale » Thu Feb 25, 2021 3:29 pm

Forgive me Jimmo. I thought that I'd corrected those:-

However the alternative syntax doesn't work, but doesn't matter.

Code: Select all

import network

wlan = network.WLAN(network.STA_IF)
print(wlan.active(True))
wlan.config(dhcp_hostname='esp32cam')
wlan.ifconfig(config=('192.168.1.144','255.255.255.0','192.168.1,254','192.168,1,254'))
wlan.connect("TP-LINK_EB850C","ju87bstuka")
print("Connected ",wlan.isconnected())
print(wlan.ifconfig())
Result:-
MicroPython v1.13-178-g21c293fbc-dirty on 2020-11-27; Camera Module (i2s) with ESP32
Type "help()" for more information.
>>> import connect_ip2
True
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "connect_ip2.py", line 6, in <module>
TypeError: function doesn't take keyword arguments
>>>


Robin

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: WLAN.ifconfig(

Post by jimmo » Thu Feb 25, 2021 11:54 pm

RobinMosedale wrote:
Thu Feb 25, 2021 3:29 pm
File "connect_ip2.py", line 6, in <module>
TypeError: function doesn't take keyword arguments
ifconfig doesn't take keyword argument.

You have

Code: Select all

wlan.ifconfig(config=('192.168.1.144','255.255.255.0','192.168.1,254','192.168,1,254'))
but it should be just

Code: Select all

wlan.ifconfig(('192.168.1.144','255.255.255.0','192.168.1.254','192.168.1.254'))
What's going on here is that ipconfig takes a single (optional) argument. That argument is a tuple of ip/mask/gateway/dns.
It's clearer if you write it as

Code: Select all

ip_config = ('192.168.1.144','255.255.255.0','192.168.1.254','192.168.1.254')
wlan.ifconfig(ip_config)
Note your code snippet also still has the commas in it.

Post Reply