ESP32 static IP doesn't work with SMARTPHONE? NO SOLUTION POSSIBLE

Hello,
When I use the " normal " ip of my ESP32 my program works when I use the wifi of my iPhone
But when I want to use a static IP the program doesn't work, even if it says " connected ".
When I use a static IP with a WIFI from a box it works.

I put the program below working with the iPhone.
I commented the static IP method

/*---------------------------------------------------------------------------------------------

  Open Sound Control (OSC) library for the ESP8266/ESP32

  Example for receiving open sound control (OSC) messages on the ESP8266/ESP32
  Send integers '0' or '1' to the address "/led" to turn on/off the built-in LED of the esp8266.

  This example code is in the public domain.

--------------------------------------------------------------------------------------------- */

#include <WiFi.h>

#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCBundle.h>
#include <OSCData.h>

char ssid[] = "Iphone de ben"; // your network SSID (name)
char pass[] = "cacaprout";  // your network password

//char ssid[] = "SFR-d078";       // your network SSID (name)
//char pass[] = "DEDW3VPARYGZ";  // your network 

//char ssid[] = "Bbox-E69F0626";       // your network SSID (name)
//char pass[] = "NKg5Ad1m3mXFgx142p";  // your network

// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;

const IPAddress outIp(172, 20, 10, 2); // node32s + battery. This is the real IP when I use iPhone

const unsigned int outPort = 9999;    // remote port (not needed for receive)
const unsigned int localPort = 8000;  // local port to listen for UDP packets (here's where we send the packets)

OSCErrorCode error;
unsigned int ledState = LOW;  // LOW means led is *on*

//------------ END  ESP and OSC setting
#include <FastLED.h>
#define NUM_LEDS 64
//#define PIN_CONTROLLING_STRIP 21 // 21 node 97 // 1 heltcec
#define PIN_CONTROLLING_STRIP 21 // 21 node 97 // 1 heltcec
CRGB leds[NUM_LEDS];
//----------- END FastLed setting
#define LED_BUILTIN 16
#define BUILTIN_LED LED_BUILTIN

int size;

// Set your Static IP address
IPAddress local_IP(192, 168, 1, 141);
// Set your Gateway IP address
IPAddress gateway(192, 168, 1, 1);

IPAddress subnet(255, 255, 0, 0);


void setup() {
  pinMode(BUILTIN_LED, OUTPUT);
  digitalWrite(BUILTIN_LED, ledState);  // turn *on* led

  Serial.begin(115200);
   delay(1000);

  // Connect to WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);

 /* I comment otherwise it doesn't work. But it works when I use an other network as SFR or Bbox
     WiFi.mode(WIFI_STA);
  if (WiFi.config(local_IP, gateway, subnet) == false) {
    Serial.print("echec de config");
  }
*/
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  Serial.println("Starting UDP");
  Udp.begin(localPort);
  Serial.print("Local port: ");
  
#ifdef ESP32
  Serial.print("LocalportESP32: ");
  Serial.println(localPort);
#else
  Serial.println(Udp.localPort());
#endif
  // control LED with FastLed NOT USED
  
  FastLED.addLeds<NEOPIXEL, PIN_CONTROLLING_STRIP>(leds, NUM_LEDS);
  FastLED.setBrightness(250);
  for (int i = 0; i <= NUM_LEDS; i++) {
      leds[i] = CRGB ( 2*i,255-(2*i), 255-(2*i));
    //leds[i] = CRGB(0, 0, 0);  // turn off all
    FastLED.show();
  }
  
}
void loop() { // no importance what is on the loop
    OSCMessage msg;
    size = Udp.parsePacket();
    
    if (size > 0) {
    while (size--) {
      msg.fill(Udp.read());
    }

    if (!msg.hasError()) { 
      msg.dispatch("/matrixdata",assignDataParsed); //
    }

    else {
      error = msg.getError();
      Serial.print("error: ");
      Serial.println(error);
    }
  }
}
void assignDataParsed(OSCMessage &msg) {
  
  for (uint8_t i = 0; i < NUM_LEDS; i++) {
      leds[i] = CRGB (msg.getInt(i*3), msg.getInt(i*3+1), msg.getInt(i*3+2)); // , msg.getInt(i*3+3)  
     digitalWrite(BUILTIN_LED, msg.getInt(i*3));  // 30 = i         
  }

  FastLED.show();
}

Without the needed information I will take a SWAG; It appears you are using IPv4 and the G4 network is restricting users to IPv6.

Try this link for a much better explanation.
https://www.uhcl.edu/information-security/tips-best-practices/ipaddressing

1 Like

I moved your topic to an appropriate forum category @bvking.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Hi,
Thank for your help, i red the paper, so I changed

with address comes from 172.

It works now, but after maybe 4 secondes, datas stop coming.

Interesting, what your question has to do with 4G GSM network?

I don't really know.
I use the wifi coming from my iPhone which is 4G.
When I use wifi coming from my iPhone and static IP to communicate with ESP32, it works only 4 sec.

When I use wifi coming from my iPhone without static IP to communicate with ESP32, it works continually.

When I use wifi coming from an internet box and static IP to communicate with ESP32 , it works continually.

iPhone (and Android too), does not allow you to change the IP address range when used as access points.

so, impossible to use a static IP with iPhone?

I wasted a lot of time for nothing.

How could I have known?

I would like to develop my projects quicker but sometimes i block with stupid things like this one. I should have ask early to this forum.

I wasted some time on it too.
I understand the frustration, but unfortunately there is no solution.

Thanks man :wink:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.