Sending UDP Packets from AN ESP8266 NodeMCU

I am trying to send UDP packets to an InfluxDB but can't seem to get it to work. The influx instance is setup properly and can receive packets when I send from another PC. The code below is simply sending the same data point every 5 seconds but it does not seem to work. The ESP8266 is online, has an IP address and can be pinged. Any ideas?

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

const char* ssid = "SSID";
const char* password = "PASS";
WiFiUDP Udp;

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED){
    delay(500);
    Serial.print(".");
  }
}

void loop() {
 delay(10);
 Udp.beginPacket("192.168.4.1", 8888);
 Udp.write("voltage value=20");
 Udp.endPacket();
 delay(5000);
}

What is the ip address of the PC when it is connected to the ESP8266? If the PC is running windows use ipconfig from the command prompt, if Linux use ifconfig.
What is the IP address of the ESP8266 when it is trying to contact the PC? You may have to put a call into serial.println(Udp.Local());

The address in your code of 192.168.4.1 is the default address of the ESP8266 I believe, so using that in your code may be the problem.

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