Can't enter network settings in ifconfig

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
Post Reply
RinusW
Posts: 9
Joined: Wed Oct 07, 2015 10:51 am

Can't enter network settings in ifconfig

Post by RinusW » Wed Oct 07, 2015 11:47 am

Hi,

I just received my WiPy. The first problem is that the IP address of the AP collide with my home network router.
So, I used the expansion board and after duplication the term to the uart I am now able to communicate with the WiPy using the Minicom terminal program on my Linux PC. The next thing I wanted to do is configuring the WiPy as another device on my home network.
So, in Minicom I entered:

Code: Select all

>>> from network import WLAN
>>> wifi = WLAN(WLAN.STA)
>>> wifi.ifconfig('192.168.1.235', '255.255.255.0', '192.168.1.1', '192.168.1.1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert to int
>>> 
As far as I can tell, nothing is wrong with the ifconfig command (it came from the example on http://micropython.org/resources/docs/e ... #wlan-wifi
What am I doing wrong?

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: Can't enter network settings in ifconfig

Post by danicampora » Wed Oct 07, 2015 1:38 pm

Hi RinusW,

Glad to see that you received your board. The new API is brifly documented here (final docs are WIP): https://github.com/micropython/micropyt ... rdware-API

So, your ifconfig line needs to be changed to:

wifi.ifconfig(0, ('192.168.1.235', '255.255.255.0', '192.168.1.1', '192.168.1.1'))

notice that it is a tuple and that you need to specify the id of the interface (WiPy only has id 0...). This also works:

wifi.ifconfig(config=('192.168.1.235', '255.255.255.0', '192.168.1.1', '192.168.1.1')) # static

wifi.ifconfig(config='dhcp') # dynamic

Cheers,
Daniel

RinusW
Posts: 9
Joined: Wed Oct 07, 2015 10:51 am

Re: Can't enter network settings in ifconfig

Post by RinusW » Wed Oct 07, 2015 9:03 pm

Hi Daniel,

Thanks. I wasn't aware of the fact that the API had changed, which apparently means that the examples in the quick refs don't work anymore.
So for all who want to connect the WiPy to there home network, use the #static or #dynamic ifconfig:
wifi.ifconfig(config=('192.168.1.235', '255.255.255.0', '192.168.1.1', '192.168.1.1')) # static
wifi.ifconfig(config='dhcp') # dynamic
followed by:
wifi.scan() # scan for available networks
wifi.connect(ssid='mynetwork', auth=(WLAN.WPA2, 'mynetworkkey')) #we all do use WPA2, don't we?

Itmt I added this to my boot.py file.

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: Can't enter network settings in ifconfig

Post by danicampora » Thu Oct 08, 2015 1:44 pm

For the record, it is not needed to do a scan before connecting, if you already know the security type, simply call the connect method directly. Otherwise:

Code: Select all

from network import WLAN
wifi = WLAN(mode=WLAN.STA)
nets = wifi.scan()
for net in nets:
    if net.ssid == 'mynetwork':
        # timeout after 5s, otherwise try until error
        wifi.connect(net.ssid, auth=(net.auth, 'mynetworkkey'), timeout=5000)
        # default ifconfig is 'dhcp', if static ip is desired, set it now
        wlan.ifconfig(config=('192.168.178.107', '255.255.255.0', '192.168.178.1', '8.8.8.8'))
        break

Post Reply