JiriBilek / WiFiSpi

SPI library for Arduino AVR and STM32F1 to connect to ESP8266
GNU Lesser General Public License v3.0
62 stars 13 forks source link

WiFiSpi.config(...) problems with number of parameters #35

Open madmetz opened 1 year ago

madmetz commented 1 year ago

Hello Jiri,

After spending an entire day to find out why I can't get the ip address passed from my Mega2560 to my ESP8266 I was about to give up. But then I made a last attempt: What I found out is that the ip address is passed when I set all of the 4 parameters at once. I.e. WifiSpi.config(local_ip) doesn't work but WifiSpi.config(local_ip, dns, gateway, subnet) works well. I had a look at the WiFiSpi.h / WiFiSpi.cpp but I couldn't find out what goes wrong here. Can you please have a look at this issue?

Best regards from Duesseldorf (Germany)

Michael

JAndrassy commented 1 year ago

you mean WiFi.config

madmetz commented 1 year ago

No, we are talking about WiFiSpi here - I thought. ;-) Pls look at file WiFiSpi.h But you are right - Of course I meant ".config" and not ".begin" Thanx anyway.

JiriBilek commented 1 year ago

Hi, I can't do any tests now. I'll be back in the middle of September. Looking at the code I am afraid the code won't work without entering a gateway address. Precisely speaking, without specifying the gateway address, the gateway IP is set to 0.0.0.0. I can't test it, I've only looked into the sources.

Look at:

  1. library WiFiSPI, file WiFiSPI.cpp, function bool WiFiSpiClass::config(IPAddress local_ip)
  2. then app WiFiSPIESP, file WiFiSPICmdGeneral.cpp, function void WiFiSpiEspCommandProcessor::cmdSetIpConfig()
  3. then library ESP8266WiFi, file ESP8266WIFISTA.cpp, function bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress arg1, IPAddress arg2, IPAddress arg3, IPAddress dns2)
  4. and finally \hardware\esp8266\esp8266\tools\sdk\lwip\src\core\netif.c, function void netif_set_addr(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw)

If it were so, I'd have to delete the function bool WiFiSpiClass::config(IPAddress local_ip) from the library.

JAndrassy commented 1 year ago

the Arduino's WiFiNINA and WiFi101 have the same error. the code to create the addresses is missing. I have a PR for booth https://github.com/arduino-libraries/WiFiNINA/pull/219 https://github.com/arduino-libraries/WiFi101/pull/326

madmetz commented 1 year ago

@JiriBilek, @JAndrassy Hi and thanx for your replies. I had a look at all the files and functions you listed and it's exactly the same on my machine. Then I tried to find a workaround and decided to take my own ip address as gateway and dns like this:

ifdef IP_ADDRESS

IPAddress local_ip(IP_ADDRESS);
#ifdef DNS_ADDRESS
  IPAddress dns_server(DNS_ADDRESS);
#else
  IPAddress dns_server(IP_ADDRESS);
#endif
#ifdef GW_ADDRESS
  IPAddress gateway(GW_ADDRESS);
#else
  IPAddress gateway(IP_ADDRESS);
#endif
#ifdef SUBNET_MASK
  IPAddress subnet(SUBNET_MASK);
#else   // if none specified we assume the smallest network class (C)
  IPAddress subnet(255, 255, 255, 0);
#endif

endif

At least it works this way and I couldn't find any problems so far. BTW: do you know if there is example code that makes the AVR (Mega) / ESP8266 work as a server that supports multiple sockets? The Ethernet library has a function "Ethernet.accept" which is missing in the WiFiSpi library.

JAndrassy commented 1 year ago

BTW: do you know if there is example code that makes the AVR (Mega) / ESP8266 work as a server that supports multiple sockets? The Ethernet library has a function "Ethernet.accept" which is missing in the WiFiSpi library.

my WiFiEspAT library with Jiri's ATMod firmware