MKR WiFi 1010 or MKR1000 Fixed IP Adresse


#1

Hello,

How to use fixed IP with the Arduino library ?

Any help is greatly appreciated.
thanks


#2

Hi, do you have a simple example for setting a fixed IP address for the device (without thinger)? Maybe we can find a simple way to add this feature.

Best.


#3

Hi, you can use : https://www.arduino.cc/en/Reference/WiFiConfig


#4

Then, based on these examples, you can safely call directly Wifi.config before any other call:

#include <WiFiNINA.h>
#include <ThingerWifi101.h>

#define USERNAME "your_user_name"
#define DEVICE_ID "your_device_id"
#define DEVICE_CREDENTIAL "your_device_credential"

#define SSID "your_wifi_ssid"
#define SSID_PASSWORD "your_wifi_ssid_password"

ThingerWifi101 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {

  // set local ip address
  WiFi.config(IPAddress(192, 168, 0, 177));    

  // configure wifi network
  thing.add_wifi(SSID, SSID_PASSWORD);

  pinMode(LED_BUILTIN, OUTPUT);

  // pin control example (i.e. turning on/off a light, a relay, etc)
  thing["led"] << digitalPin(LED_BUILTIN);

  // resource output example (i.e. reading a sensor value, a variable, etc)
  thing["millis"] >> outputValue(millis());

  // more details at http://docs.thinger.io/arduino/
}

void loop() {
  thing.handle();
}

#5

I also use this command WiFi.config().
But when I add it, I have a connection to SSID but not to Thinger.IO
Of course, it’s work with DHCP IP adress.

[NETWORK] Starting connection…
[NETWORK] Connecting to network xxxxxxxx
[NETWORK] Connected to WiFi!
[NETWORK] Getting IP Address…
[NETWORK] Got IP Address: 192.168.0.177
[NETWORK] Connected!
[_SOCKET] Connecting to iot.thinger.io:25202
[_SOCKET] Using secure TLS/SSL connection: yes
[_SOCKET] Error while connecting!
[_SOCKET] Connecting to iot.thinger.io:25202
[_SOCKET] Using secure TLS/SSL connection: yes
[_SOCKET] Error while connecting!
[_SOCKET] Connecting to iot.thinger.io:25202
[_SOCKET] Using secure TLS/SSL connection: yes
[_SOCKET] Error while connecting!
[_SOCKET] Connecting to iot.thinger.io:25202
[_SOCKET] Using secure TLS/SSL connection: yes
[_SOCKET] Error while connecting!
[_SOCKET] Connecting to iot.thinger.io:25202
[_SOCKET] Using secure TLS/SSL connection: yes
[_SOCKET] Error while connecting!


#6

Hi, you should use a fixed IP address that is valid for your local network (the one in the example may not apply for you). Moreover, you may require to set the gateway/DNS manually. So, please, test before with a simple example.


#7

I am using your example and the IP address is valid for my local network.
Serial debugging seems to indicate that the connection is working, right?

[NETWORK] Connected to WiFi!
[NETWORK] Getting IP Address…
[NETWORK] Got IP Address: 192.168.0.177
[NETWORK] Connected!


#8

Does the WiFi 1010 requires upload a SSL certificate? Take a look to the documentation where SSL is used in MKR 1000.


#9

Yes the MKR FiFi1010 requires a SSL certificate and I did it.

But I don’t understand…

With the example as below, the connection to Thinger.IO works without WiFi.config() and don’t work with it.


#10

Are you setting your gateway / DNS?

It is quite probable you need to set up your DNS manually, and also your default gateway (maybe 192.168.0.1), and set up them using the proper config:

WiFi.config(ip); 
WiFi.config(ip, dns); 
WiFi.config(ip, dns, gateway); 
WiFi.config(ip, dns, gateway, subnet); 

#11

WiFi.config(IPAddress(192,168,0,177),IPAddress(109,0,66,20),IPAddress(192,168,0,1),IPAddress(255,255,255,0));

Even with DNS, Gateway and Subnet, the response is always :

[_SOCKET] Connecting to iot.thinger.io:25200
[_SOCKET] Using secure TLS/SSL connection: yes
[_SOCKET] Error while connecting!


#12

I recommend you to test with a basic example like doing an HTTP request. Did you tried to also disable the SSL/TLS to see if it affects in some way?


#13

Do you test it with WifiNINA ?

For me, it’s all right with WiFi101 (MKR1000) but not with WiFiNINA (MKR WiFi1010)
it seems that the assignment of DNS server by WiFi.config(ip, dns, gateway, subnet) don’t work with Static IP.


#14

Hello,

I confirm the problem with WiFiNINA Library for the DNS server : https://github.com/arduino-libraries/WiFiNINA/issues/31#issuecomment-431783416
But the workaround proposed is not usable with a thinger.IO direct connection.


#15

Hi @grezco, thanks for the feedback.

You can still handle the Wifi connection directly by yourself in the setup, just as recommended in the github link.