Hi all,
I’m working on a huge network project which has wearables with an ESP8266 NodeMCU.
Unfortunately, the devices won’t send/receive, or sometimes when sending the packet 4 or more times unless you disable the IP config, or if you put the IP in a 192.168.1.100 range.
However, I prefer the IP in a 10.0.0.1 range – or 172.16.1.1
So I’ve tried a couple of things.
I’m almost certain the issue is IP related.
So I’ve hooked one of my own routers to the network and created a separate network - no succes
Then I pulled the ‘main’- network out of my router (so a standalone router) - no succes
Then I configured the router even more with disabling all of the filters that I could find, then tried again with ‘main’-network and without…
Normally I use PacketSender to send and receive UDP, however, PacketSender is not 100% reliable, so I’ve also tested with Hercules.
Also used PING to ping my device, if using my desired IP - I get a ‘request timed out’ back.
I’m really curious if someone knows how to fix this issue, it is the first time I do a network project with ESP8266 module, so maybe I’m missing something
Some explanation for the code;
I have a V1, which is almost my completed code. When I did some testing I had these problems but ignored it for ‘to be solved later’. Also, I was not sure yet was caused the issue.
Today was my intention to fix the issue, I did first a V2 with removing stuff from my V1 code, then did a V3, where I wrote my code again but checked it piece by piece, then I discovered it was the IP adress.
So this is the V3 code — do notice: it is the Udp example code from the ESP8266 library, with minor changes.
/*
THEBULB.
TERRASLAMP
V1.0b
08-2020
Budget version.
Please refer to version a for extra functionalities such as:
- check firmware version
- detection of connection loss
Based on nano 33 IoT
*/
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <FastLED.h>
#include "secret.h"
#define LED_PIN 6
#define COLOR_ORDER GRB
#define CHIPSET WS2812B
#define NUM_LEDS 3
CRGB leds[NUM_LEDS];
/* Unique ID AND IP */
IPAddress staticIP(172, 16, 1, 101); <----- IF I DISABLE THESE LINES THE UPD WORKS GREAT
IPAddress gateway(172,16,1,1); <----- OR IF I SET THE IP IN A 192.168.1.100-255 range
IPAddress subnet(255,255,255,0); <----- THEN IT ALSO WORKS
//int tableID = 01; <--- to be added in later, packetbuffer should contain variable tableID
/* END */
int status = WL_IDLE_STATUS;
/* BOOLEANS */
bool candleAllowance = false;
bool connectionLive = false;
bool dark = false;
bool light = false;
bool stateIdle = false;
bool stateAvailable = false;
bool stateOrdered = false;
bool stateOff = true;
/* END */
/* LIGHT SENSOR */
int lightSensor;
long makingSureItIsDark = 0;
/* END */
/* BLINK LED VARIABLES */
const int ledPin = LED_BUILTIN;// the number of the LED pin
int ledState = HIGH; // ledState used to set the LED
unsigned long previousMillis = 0; // will store last time LED was updated
unsigned long interval = 5000; // interval at which to blink (milliseconds)
/* END */
/* WiFi TESTER VARIABLES */
unsigned long startTime;
unsigned long comparisonTime = 0;
/* END */
/*Data is stored in Secret tab*/
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)
unsigned int localPort = 7001; // local port to listen on
char packetBuffer[256]; //buffer to hold incoming packet
char ReplyBuffer[] = "table 01: acknowledged"; // a string to send back
WiFiUDP Udp;
void setup() {
pinMode(ledPin, OUTPUT);
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.clear(true);
// FastLED.setBrightness( BRIGHTNESS );
//Initialize serial and wait for port to open:
Serial.begin(115200);
delay(1000);
Serial.println();
Serial.println("******* NEW SESSION STARTED *******");
Serial.println("THE BULB. terraslamp -- V01 2020");
Serial.println("Setting up network now, hold your drinks high..!");
Serial.println();
delay(100);
Serial.print("MAC: ");
Serial.println(WiFi.macAddress());
delay(100);
WiFi.mode(WIFI_STA);
WiFi.config(staticIP, gateway, subnet); <----- THIS LINE SHOULD BE DISABLED AS WELL
WiFi.begin(ssid, pass);
Serial.println();
delay(100);
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.print("Connected! IP address: ");
Serial.println(WiFi.localIP());
Serial.printf("UDP server on port %d\n", localPort);
Udp.begin(localPort);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
Serial.printf("Received packet of size %d from %s:%d\n (to %s:%d, free heap = %d B)\n",
packetSize,
Udp.remoteIP().toString().c_str(), Udp.remotePort(),
Udp.destinationIP().toString().c_str(), Udp.localPort(),
ESP.getFreeHeap());
// read the packet into packetBufffer
int n = Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
packetBuffer[n] = 0;
Serial.println("Contents:");
Serial.println(packetBuffer);
// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
}
/*
test (shell/netcat):
--------------------
nc -u 192.168.esp.address 8888
*/