Unable to assign a static IP address

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
Geert
Posts: 3
Joined: Thu Dec 17, 2015 12:31 pm

Unable to assign a static IP address

Post by Geert » Thu Dec 17, 2015 12:49 pm

[First: thank you very much for wipy, very nice stuff!]

I tried to assign a static IP address to my wipy. To do so, I have the following code (inspired by tutorial in docs):

Code: Select all

import machine
from network import WLAN
wlan = WLAN()  # get current object, without changing the mode

if machine.reset_cause() != machine.SOFT_RESET:
    wlan.init(WLAN.STA)
    wlan.ifconfig(config=('192.168.0.20','255.255.255.0','0.0.0.0','127.0.1.1'))

if not wlan.isconnected():
    wlan.connect('my_ssid', auth=(WLAN.WPA2, 'my_pass'), timeout=5000)
    while not wlan.isconnected():
        machine.idle()
Regarding the

Code: Select all

ifconfig
-bit, I just selected a ip-address, on the basis of the network ID: 192.168.0.xx, the subnet mask was retreived from

Code: Select all

ifconfig
in terminal, the gateway was found from

Code: Select all

route -n
in terminal, and dns server from

Code: Select all

cat /etc/resolv.conf
.

I was succesful in just connecting to my home router (the exercise before that in the docs). So the wlan.connect() line should work on its own.

I then connect to wifi set up by the wipy (still in acces point mode)
I saved above code in boot.py and uploaded that file to the ftp://192.168.1.1/flash/
Then I connect to my home wifi network and push the reset button on the wipy.

I then hoped to find the wipy as a station connected to my home access point, at ip 192.168.0.20. But no luck...

Does anyone have a clue what I'm doing wrong?
Thank you very much in advance!
Geert

gpshead
Posts: 6
Joined: Tue Nov 03, 2015 5:12 am
Contact:

Re: Unable to assign a static IP address

Post by gpshead » Thu Dec 17, 2015 5:04 pm

I believe you need to do wlan.connect before you do wlan.ifconfig.

Move your whole "if not wlan.isconnected():" block up as the first thing inside of your reset_cause checking block.

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

Re: Unable to assign a static IP address

Post by danicampora » Thu Dec 17, 2015 7:45 pm

Hi,

You can do wlan.conenct() before or after ifconfig, it doesn't matter. The problem I see is that you have set your Gateway to '0.0.0.0', that's not correct. You need to set it to an appropriate value.

Cheers,
Daniel

Geert
Posts: 3
Joined: Thu Dec 17, 2015 12:31 pm

Re: Unable to assign a static IP address

Post by Geert » Sun Dec 20, 2015 9:38 pm

I rewrote boot.py to just connect to the home network. Afterwards, I retrieve the ifconfig tuple, and just change the first element to the static ip of my choosing. It works!

Code: Select all

import machine
from network import WLAN
wlan = WLAN()  # get current object, without changing the mode

if machine.reset_cause() != machine.SOFT_RESET:
    wlan.init(WLAN.STA)
    if not wlan.isconnected():
        wlan.connect('my_ssid', auth=(WLAN.WPA2, 'my_pass'), timeout=5000)
        while not wlan.isconnected():
            machine.idle()
            
    # ifconfig(config=('ip','subnet_mask','gateway','dns_server'))
    myconfig = wlan.ifconfig()
    lst_myconfig = list(myconfig)
    lst_myconfig[0] = '192.168.0.20'
    myconfig = tuple(lst_myconfig)
    wlan.ifconfig(config=myconfig)

Post Reply