Hallo,
ich habe das jetzt mit verschiedenen Varianten probiert. Es funktioniert mit allen.
WiFi.config(STATIC_IP, SUBNET, GATEWAY, DNS); // laut c't, Reichelt
WiFi.config(STATIC_IP, GATEWAY, SUBNET, DNS);
WiFi.config(STATIC_IP, DNS, GATEWAY, SUBNET);
Da bin ich stutzig gewurden und habe mich auf die Suche begeben.
Hier steht noch nichts näheres dabei:
https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html#config
Aber wenn man in den Libs wühlt, findet man irgendwann die "ESP8266WiFiSTA" .h und .cpp. Hier drin liegt das Geheimnis. C:\Users\Doc\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries
// The argument order for ESP is not the same as for Arduino. However, there is compatibility code under the hood
// to detect Arduino arg order, and handle it correctly. Be aware that the Arduino default value handling doesn't
// work here (see Arduino docs for gway/subnet defaults). In other words: at least 3 args must always be given.
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
bzw.
/**
* Change IP configuration settings disabling the dhcp client
* @param local_ip Static ip configuration
* @param gateway Static gateway configuration
* @param subnet Static Subnet mask
* @param dns1 Static DNS server 1
* @param dns2 Static DNS server 2
*/
bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress arg1, IPAddress arg2, IPAddress arg3, IPAddress dns2) {
if(!WiFi.enableSTA(true)) {
return false;
}
//ESP argument order is: ip, gateway, subnet, dns1
//Arduino arg order is: ip, dns, gateway, subnet.
//first, check whether dhcp should be used, which is when ip == 0 && gateway == 0 && subnet == 0.
bool espOrderUseDHCP = (local_ip == 0U && arg1 == 0U && arg2 == 0U);
bool arduinoOrderUseDHCP = (local_ip == 0U && arg2 == 0U && arg3 == 0U);
if (espOrderUseDHCP || arduinoOrderUseDHCP) {
_useStaticIp = false;
wifi_station_dhcpc_start();
return true;
}
//To allow compatibility, check first octet of 3rd arg. If 255, interpret as ESP order, otherwise Arduino order.
IPAddress gateway = arg1;
IPAddress subnet = arg2;
IPAddress dns1 = arg3;
if(subnet[0] != 255)
{
//octet is not 255 => interpret as Arduino order
gateway = arg2;
subnet = arg3[0] == 0 ? IPAddress(255,255,255,0) : arg3; //arg order is arduino and 4th arg not given => assign it arduino default
dns1 = arg1;
}
//ip and gateway must be in the same subnet
if((local_ip & subnet) != (gateway & subnet)) {
return false;
}
struct ip_info info;
info.ip.addr = static_cast<uint32_t>(local_ip);
info.gw.addr = static_cast<uint32_t>(gateway);
info.netmask.addr = static_cast<uint32_t>(subnet);
wifi_station_dhcpc_stop();
if(wifi_set_ip_info(STATION_IF, &info)) {
_useStaticIp = true;
} else {
return false;
}
ip_addr_t d;
if(dns1 != (uint32_t)0x00000000) {
// Set DNS1-Server
d.addr = static_cast<uint32_t>(dns1);
dns_setserver(0, &d);
}
if(dns2 != (uint32_t)0x00000000) {
// Set DNS2-Server
d.addr = static_cast<uint32_t>(dns2);
dns_setserver(1, &d);
}
return true;
}
Wenn ich das richtig verstehe prüfen die im Code an welcher Stelle die Subnet steht und entscheiden dann welcher Parameter was ist. Abhängig ob man in der Arduino IDE oder in der der von Espressif programmiert. Irgendwie so.
Einigen wir uns darauf - es gibt kein falsch oder richtig. Es gibt eine Erkennungsautomatik.
Entschuldigung für meine kleine Überreaktion heute morgen.
Schön das es jetzt bei dir funktioniert. Das zählt.