This repository was archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
This repository was archived by the owner on Feb 4, 2023. It is now read-only.
Stationmode Static IP changes to dhcp when esp8266 is restarted #28
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
#include <DNSServer.h> //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal
#include <ESP_WiFiManager.h> //Configuration Magic
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#if (defined(USE_STATIC_IP_CONFIG_IN_CP) && !USE_STATIC_IP_CONFIG_IN_CP)
// Force DHCP to be true
#if defined(USE_DHCP_IP)
#undef USE_DHCP_IP
#endif
#define USE_DHCP_IP true
#else
// You can select DHCP or Static IP here
#define USE_DHCP_IP false
#endif
#define USE_CONFIGURABLE_DNS false
WiFiUDP Udp;
ESP_WiFiManager wifiManager;
unsigned int localUdpPort = 5000;
char incomingPacket[256];
char replyPacket[] = "color recieved";
void setup()
{
Serial.begin(9600);
Serial.println();
wifiManager.setSTAStaticIPConfig(IPAddress(192,168,43,69),IPAddress(192,168,43,1),IPAddress(255, 255, 255, 0));
if (!wifiManager.autoConnect("rgbTower", "S1o2m3u4@")) {
Serial.println("failed to connect, we should reset as see if it connects");
delay(3000);
ESP.reset();
delay(5000);
}
Serial.println(" connected");
Udp.begin(localUdpPort);
Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);
}
void loop()
{
int packetSize = Udp.parsePacket();
if (packetSize)
{
// receive incoming UDP packets
Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
int len = Udp.read(incomingPacket, 255);
if (len > 0)
{
incomingPacket[len] = 0;
}
Serial.printf("UDP packet contents: %s\n", incomingPacket);
// send back a reply, to the IP address and port we got the packet from
Udp.beginPacket(Udp.remoteIP(), 5000);
Udp.write(replyPacket);
Udp.endPacket();
}
}
im very new to arduino and stuff, i made a code but i'm unable to keep the static IP persistent. it changes to dhcp as soon as i restart the esp. please correct me if i'm doing something wrong.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working