Reply from DBInflux Server not correct in Arduino sketch Serial Monitor

I already try to exchange data with the DBInflux server from a nodemcu
There is a sort of standard sketch available on GitHub

I am able to create data withg this sketch but I still have problems with the POST to the DBInflux Server. But I keep getting the Serial Monitor message "DId not get EXPECTED responbs from InfluxDB" which means that the reply from the DBInflux Server is not equal to "HTTP/1.1 204 No Content"

To ensure that there is no issue with the DBInflux Server I tested sending data also with a curl XPOST

curl -i -XPOST 'http://server.ask.rivm:8086/write?db=dbname&u=user&p=password

And it return the success reply "HTTP/1.1 204 No Content"

xxxx@xxxxx-L500:~$ curl -i -XPOST 'http://server.ask.rivm:8086/write?db=sbname&u=usern&p=password' --data-binary 'vuurwerk,id=2632477 Temp=21.83,Pres=1010.60,Hum=44.67,PM25=4.26,PM10=5.00,RSSI=-60.00,ERROR=1.00,ECOUNT=9.00,SMPLS=149.00'
HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: ddf9171d-7973-11e9-b1a4-000000000000
X-Influxdb-Version: 1.0.2
Date: Sat, 18 May 2019 13:50:16 GMT

In the serial monitor (after adding the actual reply from the server in the sketch (value of the sret*) it returns "*

  • �����������". Clearly not equal to "HTTP/1.1 204 No Content". As we know from the curl POST test that the reply is okay, there must be something wrong with the interpretation of the reply. It works with hunderds of others so it is kind of strange that it does not work for me....*
    What can I do to get it working.....??
    ```
    *void DoInfluxdbPost() {

int i, j, ii;

char  sret[IIMAX];

char  *sok = "HTTP/1.1 204 No Content";

WiFiClient client;

const char* host = "#HOST_NAME_ASK_RIVM#";

//---------------------------------------

// The actual data package to the server:

String PostData = InfluxThing + ",id=" + String( chipid ) ;

PostData += " Temp=";

PostData += x0;

PostData += ",Pres=";

PostData += x1;

PostData += ",Hum=";

PostData += x2;

PostData += ",PM25=";

PostData += x3;

PostData += ",PM10=";

PostData += x4;

PostData += ",RSSI=";

PostData += x5;

PostData += ",ERROR=";

PostData += x6;

PostData += ",ECOUNT=";

PostData += x7;

PostData += ",SMPLS=";

PostData += x8;

// Both ON

if (DoBlinkStatus > 1) {

Serial.println("\nInfluxdbPost");

digitalWrite(RED_LED_PIN, LOW); // on

digitalWrite(BLUE_LED_PIN, LOW); // on

}

Serial.println("\n\n");

Serial.println(PostData);

Serial.println("\n\n");

Serial.println("Ready for InfluxdbPost");

int iret = client.connect(host, 8086);

// Problem connecting to WiFi:  RED ON

if (iret < 0) {

Serial.println("\nNO client.connect ??" );

if (DoBlinkStatus > 0) {

digitalWrite(RED_LED_PIN, LOW);

}

Serial.println("\n=====================================================\n");

Serial.print("FAILED CONNECT InfluxdbPost, code = ");

Serial.println( iret);

Serial.println("TIMED_OUT -1 ");

Serial.println("INVALID_SERVER -2 ");

Serial.println("TRUNCATED -3 ");

Serial.println("INVALID_RESPONSE -4 ");

Serial.println("=====================================================\n");

Serial.println(" ");

delay(20);

return;

}

//#######################################################################

//

// IF YOU WANT TO SEND YOUR DATA TO THE RIVM DATA PORTAL PLEASE CONTACT

//

// SAMENMETEN@RIVM.NL

//

// FOR CREDENTIALS AND IMPLEMENTATION !!!

//

client.println("POST /write?db=#DBNAME#&u=#UNAME#&p=#PASSWRD# HTTP/1.1");

client.println("Host: #HOST_NAME_ASK_RIVM#:8086");

client.println("Cache-Control: no-cache");

client.println("Content-Type: application/x-www-form-urlencoded");

client.print("Content-Length: ");

client.println(PostData.length());

client.println();

client.println(PostData);

ii = 0;

while (client.available()) {

char c = client.read();

if (ii < IIMAX) {

sret[ii++] = c;

}

Serial.print(c);

}

sret[ii] = '\n';

int sdif = 0;

for (i = 0 ; i < strlen(sok) ; i++) {

if (sret[i] != *(sok + i)) {

sdif++;

}

}

//----------------------------------

// Respons InFluxDB not OK

if (sdif > 0) {

iret = -100 * sdif;

Serial.print("\nDId not get EXPECTED respons from InFluxDB ");

Serial.println(iret);

Serial.print("[");
   Serial.print(sret);
   Serial.println("]");

Serial.println(PostData);

digitalWrite(RED_LED_PIN, HIGH); // off

if (DoBlinkStatus > 0) {

// BLUE BLINK 15

for (i = 0 ; i < 15 ; i++) {

digitalWrite(BLUE_LED_PIN, LOW); // off

delay(450);

digitalWrite(BLUE_LED_PIN, HIGH); // off

delay(150);

}

// BLUE ON

digitalWrite(BLUE_LED_PIN, LOW); // off

}

}

//----------------------------------

// UNDEFINED issue, BLUE BLINK 15

if (iret == 0 && DoBlinkStatus > 0) {

Serial.print("Did not get ANY respons from InFluxDB ");

digitalWrite(RED_LED_PIN, HIGH); // off

for (i = 0 ; i < 15 ; i++) {

digitalWrite(BLUE_LED_PIN, LOW); // off

delay(150);

digitalWrite(BLUE_LED_PIN, HIGH); // off

delay(150);

}

}

if (iret > 0 && DoBlinkStatus > 1) {

// Communication OK, BLINK RED/BLUE 15

Serial.print("\nEverything seems OK ... ");

for (i = 0 ; i < 15 ; i++) {

digitalWrite(BLUE_LED_PIN, LOW); // off

digitalWrite(RED_LED_PIN, HIGH); // off

delay(150);

digitalWrite(BLUE_LED_PIN, HIGH); // off

digitalWrite(RED_LED_PIN, LOW); // off

delay(150);

}

digitalWrite(RED_LED_PIN, HIGH); // on

digitalWrite(BLUE_LED_PIN, HIGH); // on

}

if (iret > 0) {

digitalWrite(RED_LED_PIN, HIGH); // off

digitalWrite(BLUE_LED_PIN, HIGH); // off

}

Serial.print("\nSDif, IRet =  ");

Serial.print(sdif);

Serial.print(",  ");

Serial.print(iret);

}*
```

This code

  client.println("POST /write?db=#DBNAME#&u=#UNAME#&p=#PASSWRD# HTTP/1.1");
  client.println("Host: #HOST_NAME_ASK_RIVM#:8086");

uses placeholders that you need to change to your actual values (DBNAME, UNAME, etc.) just like you did with your curl example.

I replaced the placeholder, but I did not want to share on the internet
Issue is the unreadable reply, it look some binary reply or different font.....

I tested databasename, username and password with the curl XPOST command on my Ubuntu computer in the terminal window and it works fine. It also seems that there is connection to the DBInflux server in the Arduino sketch otherwise I would not get any reply....

I do not understand what I can do about it....

That's good. You did not show what these lines print

 Serial.println("\n\n");
 Serial.println(PostData);
 Serial.println("\n\n");

I'd change that to

 Serial.print("PostData='");
 Serial.print(PostData);
 Serial.println("'");

and make sure it matches EXACTLY what you have in your curl command (same commas, same number of decimal places on the variabes, EVERYTHING.)

You can also change

 while (client.available()) {
   char c = client.read();
   if (ii < IIMAX) {
     sret[ii++] = c;
   }
   Serial.print(c);

to

 while (client.available()) {
   char c = client.read();
   if (ii < IIMAX) {
     sret[ii++] = c;
   }
   Serial.print( "Got 0x" ); Serial.println(c, HEX);

to better understand what you are receiving.

Thanks for your help !
I am going to try !!!!

Let you know what the results are

It appears that the client.available is not TRUE and there is thus nothing to read.
I added a few Serial.print text lines between the {} but nothing is printed in the Serial monitor
I found that that adding some delay before the client.available() could help....but it did not.

Also I learnt that the receiving institute (RIVM) is receiving data so I should get the correct reply back

Any other tips ?

Eddy