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();
}