Static IP Possibility
-
- Posts: 28
- Joined: Wed Mar 30, 2016 4:09 pm
Static IP Possibility
Hello all,
I'm building a Temperature and Humidity server that I want to monitor from work but I'm not able to set a static or fixed IP.
Is there a possibility to set Fixed IP on MicroPython for ESP8266? I have found some info but only for the WiPy.
Ohh I almost forgot, I'm running Version 1.8.3
Thanks!
I'm building a Temperature and Humidity server that I want to monitor from work but I'm not able to set a static or fixed IP.
Is there a possibility to set Fixed IP on MicroPython for ESP8266? I have found some info but only for the WiPy.
Ohh I almost forgot, I'm running Version 1.8.3
Thanks!
Re: Static IP Possibility
What did you try already and how it didn't work?
Re: Static IP Possibility
Looking at the code, you should be able to set the address with network.ifconfig, passing it a tuple of four values: the address, the network mask, the gateway address and the dns server address.
-
- Posts: 28
- Joined: Wed Mar 30, 2016 4:09 pm
Re: Static IP Possibility
[quote="deshipu"]Looking at the code, you should be able to set the address with network.ifconfig, passing it a tuple of four values: the address, the network mask, the gateway address and the dns server address.[/quote]
You meant something like this:
[code]network.ifconfig ('192.168.1.30', '255.255.255.0', '10.1.1.7', '8.8.8.8')[/code]
You meant something like this:
[code]network.ifconfig ('192.168.1.30', '255.255.255.0', '10.1.1.7', '8.8.8.8')[/code]
Last edited by yeyeto2788 on Wed Sep 14, 2016 11:05 am, edited 1 time in total.
Re: Static IP Possibility
Well, the gateway IP usually has to be in the same subnetwork as your normal IP for it to function properly. Otherwise, how it didn't work?
-
- Posts: 28
- Joined: Wed Mar 30, 2016 4:09 pm
Re: Static IP Possibility
Hello, sorry for the late reply
This is my code to setup the Static IP but it seems not to be working
This is the error I get when I input the data
It seems to be expecting a str instead of a tuple or a list.
deshipu wrote:Well, the gateway IP usually has to be in the same subnetwork as your normal IP for it to function properly. Otherwise, how it didn't work?
This is my code to setup the Static IP but it seems not to be working
Code: Select all
import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.ifconfig('xxx.xxx.xxx.xxx','255.255.255.0','192.168.1.1','xxx.xxx.xxx.xxx')
sta_if.connect('SSID','Password')
This is the error I get when I input the data
Code: Select all
Traceback (most recent call last):
File "<stdin>", line 9, in <module>
TypeError: function expected at most 2 arguments, got 5
Re: Static IP Possibility
You have to put the parameters in a tuple:
Like shown in the docs.
Code: Select all
sta_if.ifconfig(('xxx.xxx.xxx.xxx','255.255.255.0','192.168.1.1','xxx.xxx.xxx.xxx'))
-
- Posts: 28
- Joined: Wed Mar 30, 2016 4:09 pm
Re: Static IP Possibility
Code: Select all
import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.ifconfig(('xxx.xxx.xxx.xxx','255.255.255.0','192.168.1.1','xxx.xxx.xxx.xxx'))
sta_if.connect('SSID','Password')
The problem was that I had to do it this way:
Code: Select all
network.ifconfig(('xxx.xxx.xxx.xxx','255.255.255.0','192.168.1.1','xxx.xxx.xxx.xxx'))
Why is this? maybe is a silly question but I don't get it.
Re: Static IP Possibility
As said in the documentation,
is a 4-tuple.
Maybe you should look here http://www.tutorialspoint.com/python/python_tuples.htm
SoTo set the above values, pass a 4-tuple with the required information.
Code: Select all
('xxx.xxx.xxx.xxx','255.255.255.0','192.168.1.1','xxx.xxx.xxx.xxx')
Maybe you should look here http://www.tutorialspoint.com/python/python_tuples.htm
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Static IP Possibility
Code: Select all
a = (1,2,3)
Code: Select all
func(a)
func((6,7,8))
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.