UDP and Static IP

I’m trying to send OSC messages via UDP between my Feather Huzzah and my computer. If I allow the WiFi setup to get a local IP from my router, everything works fine, but want to create a static IP on both the sending and receiving ends. I keep getting a “WiFi does not name a type” message. I have a sense that I’m getting something mixed up between the UDP and WiFi IP declarations. Here’s the code. Any help will be much appreciated!

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <WiFi.h>

char ssid = “MySSID”; //network SSID (name)
char pass = “MyPassword”; // network password

// This is the code that throws the error:

IPAddress ip(10, 10, 10, 100); // desired IP address
IPAddress gateway(10, 10, 10, 254); // gateway of my network
IPAddress subnet(255, 255, 255, 0); // subnet mask of my network
WiFi.config(ip, gateway, subnet);

//If I take the above out, things work fine

WiFiUDP Udp; // A UDP instance to let me send and receive packets over UDP
const IPAddress outIp(10,10,10,10); // remote IP of my computer (fixed on computer)
const unsigned int outPort = 9999; // remote port to send OSC to
const unsigned int localPort = 8888; // local port to listen for OSC packets (not yet tested)

I keep getting a "WiFi does not name a type" message.

Your COMPLETE code generates a COMPLETE message that includes the file name, the line number, the column number, and the exact text with proper case.

Provide the COMPLETE code and the COMPLETE message(s) if you really want help.

I have the same question. You use the library https://github.com/stahlnow/OSCLib-for-ESP8266
It works well for tx and rx OSC messages.
A work around could be, to set in the Wifi router a fix IP according to the MAC address of each WeMos.

WiFi.config(ip, gateway, subnet);

I had the same problem and solved it by providing all 4 Parameters:

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

The missing parameters are not replaced by default-values, so if You use:

WiFi.config(ip, dns)

the gateway parameter is set to 0.0.0.0 and the packet is not sent.

Happy Holydays

hjw

HJWalter's response was also the clue that I needed to use UDP with a Static IP address. Thank You.

But how to get the local DNS and what if it changes? In my case, ipconfig listed 2 DNS Servers.

My solution is to connect to the local network with a dynamic IP address, gather the needed information, then set the WiFi.config() with the desired Fixed IP Address and the 'learned' Local DNS, Subnet, and Gateway.

    //  Connect to Local Network with credentials
    WiFi.begin( NVM_Data.Network, NVM_Data.Password );

    //  Wait for WiFi connection, or TimeOut
    while( WiFi.status() != WL_CONNECTED )
    {
      Serial.print( "." );
      delay( 500 );
      
      if( Init )
      {
        if( ++Trys >= WIFI_STA_TRYS )
        {
          /*  Unable to connect to Local Network at Initialization.
              Assume bad credentials. Exit loop so changes can be made via
              Access Point; 
          */
          WiFiMode = WIFI_AP;
          WiFi.mode( WiFiMode );
          break;
        }
      }
    }
    
    if( WiFi.status() == WL_CONNECTED )
    {
      //  Connection made to Local Network
      Serial.printf( "\r\nConnected to " );
      Serial.println( WiFi.SSID() );
      Serial.println( "  IP Address: " + WiFi.localIP().toString() );
      Serial.println( "  Local DNS: " + WiFi.dnsIP().toString() );
      Serial.println( "  Subnet Mask: " + WiFi.subnetMask().toString() );
      Serial.println( "  Gateway: " + WiFi.gatewayIP().toString() );

      if( DeviceIP.fromString( NVM_Data.DeviceIP ) )
      {
        //  DeviceIP is valid, now set Fixed device IP Address with Network info learned at connection        
        Serial.printf( "\r\nSetting Fixed IP Address %s\r\n", NVM_Data.DeviceIP );
        WiFi.config( DeviceIP, WiFi.dnsIP(), WiFi.gatewayIP(), WiFi.subnetMask() );
        
        //  Local Network Info
        Serial.println( "  IP Address: " + WiFi.localIP().toString() );
        Serial.println( "  Local DNS: " + WiFi.dnsIP().toString() );
        Serial.println( "  Subnet Mask: " + WiFi.subnetMask().toString() );
        Serial.println( "  Gateway: " + WiFi.gatewayIP().toString() );
      }
      else
      {
        Serial.println( "Invalid Fixed Device IP Address" );
      }
      EventLogAdd( EVENT_WIFI_STA_CONNECT_OK );
    }
    else
    {
      //  Connection to Local Network Failed
      Serial.printf( "\r\nConnection to %s Failed\r\n", NVM_Data.Network );
           
      EventLogAdd( EVENT_WIFI_STA_CONNECT_FAIL );
    }
  }
  else
  {
    //  Local Network Credentials are invalid, just start Access Point
    WiFiMode = WIFI_AP;
    WiFi.persistent(false); // Do not write new connections to FLASH
  }

GregryCM