InfluxDB udp problem [Solved]

Hi,

I am trying to send some data to my InfluxDB via upd protocol.

I am able to send the data via Git Bash:

echo "HM T=22.6,H=64.4,p=962,U=3.85,C=70"> /dev/udp/dynDNSadress/4444

So I think I can assume that my Database and the Port forwarding works.
But if I would like to send the same String via my Photon it does not work:

//#define INFLUXDB_HOST   "dynDNSadress"
byte INFLUXDB_HOST[] = {90, 190, 290, 293};
int INFLUXDB_PORT = 4444;

String data = "HM T=" + String(temperature, 1) + ",H=" + String(humidity, 1) + ",p=" + String(pressure, 0) + ",U=" + String(cellVoltage, 2) + ",C=" + String(stateOfCharge, 0);
udp.beginPacket(INFLUXDB_HOST, INFLUXDB_PORT);
Particle.publish("HORSE", String(udp.print(data)), 60, PRIVATE);
udp.endPacket();
Particle.publish(eventName, data, 60, PRIVATE);

The console shows that there are 34 bytes sent, but they never arrive at my database. And it also shows that the String is the same:

HM T=22.5,H=59.1,p=965,U=3.82,C=67

I do not receive any error because of the UDP protocol. So I would be very grateful if you have an idea what I am doing wrong!

Have you tried the UDP.sendPacket() sample?

// SYNTAX
Udp.sendPacket(buffer, bufferSize, remoteIP, remotePort);

// EXAMPLE USAGE
UDP Udp;

char buffer[] = "Particle powered";

IPAddress remoteIP(192, 168, 1, 100);
int port = 1337;

void setup() {
  // Required for two way communication
  Udp.begin(8888);

  if (Udp.sendPacket(buffer, sizeof(buffer), remoteIP, port) < 0) {
    Particle.publish("Error");
  }
}

But for your original code, have you called udp.begin() to initialize the object?

Thank you very much for your reply @ScruffR!
I have tried the senPacket() sample and used

char buffer[] = "HM T=22.6,H=64.4,p=962,U=3.85,C=70";

and my dynDNS and port but with the same result as before. Tomorrow I will try to flash a Photon just with the sample code to see if the error is in the rest of my code. But everything else is working as expected.
I have also added udp.begin(8888); and I have tried udp.begin(4444); but no luck so far. :cry:

This works for me on my Photon with InfluxDB. Locally compiled using firmware 0.5.0. Change X,X,X,X to your own IP address.

#include "application.h"

IPAddress loggingIP(X,X,X,X);
unsigned int loggingPort = 4444;

char loggingBuffer[] = "HM T=22.5,H=59.1,p=965,U=3.82,C=67";
size_t bufferSize;

UDP udp;
int resp;

void setup()
{
    pinMode(D7, OUTPUT);
    digitalWrite(D7, LOW);

    resp = udp.begin(loggingPort);

    bufferSize = strlen(loggingBuffer);
    resp = udp.sendPacket((unsigned char*)loggingBuffer, bufferSize, loggingIP, loggingPort);

    delay(300);

    udp.stop();

    digitalWrite(D7, HIGH);
}

void loop()
{
    Particle.process();
}

What is also worth trying is dropping HM or changing it to something different for testing. InfluxDB can be a bit awkward when it comes to data types, setting the type according to the first value that you log and then rejecting later data because it considers it to be the wrong type.

2 Likes

Thank you very much! I think udp.stop() did the trick :smile:

1 Like