MKR1010 HTTPS POST fails when post size is to big

I am trying to send ±5500 bytes via an HTTPS POST using the Arduino MKR1010. The code is working if I only include the first four FFT strings (runout_fft1, runout_fft2, runout_fft3, runout_fft4). If I try to send the "runout_fft5" the client.print command returns 0. Meaning it did not send the last string. And I don't see any incoming request on:

runout.requestcatcher.com

I don't see the problem with sending the last FFT string (runout_fft5).

The response when sending 4 FFT strings is:

postByteCount: 4426
Attempting to connect to SSID: IoT
Connected to wifi
SSID: IoT
IP Address: 192.168.11.154
signal strength (RSSI):-57 dBm
800
800
842
880
Server response:

Stop the client

When I send 5 FFT strings:

postByteCount: 5283
Attempting to connect to SSID: IoT
Connected to wifi
SSID: IoT
IP Address: 192.168.11.154
signal strength (RSSI):-48 dBm
800
800
842
880
0
Server response:

Stop the client

When I test the functionality with an online API tester reqbin.com/ I can send up to 6869 bytes.

My code:

#include <SPI.h>
#include <WiFiNINA.h>
#include "arduino_secrets_ldm.h"

///////please enter your sensitive data in the Secret tab/arduino_secrets.h
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 status = WL_IDLE_STATUS;
char server[] = "runout.requestcatcher.com";  // name address for aeuw-prod (using DNS)

WiFiSSLClient client;

// POST DATA
String runout = "bench=ABC-DEF-001&"
  "scaife=ABC-DEF-001&"
  "delta=8.01&"
  "fft_peak_hz=50.02&"
  "fft_peak_mag=200.12&"
  "rssi=-81&"
  "ip=192.168.178.55&"
  "snm=255.255.255.0&"
  "gw=192.168.178.1&"
  "ssid=SSIDname&"
  "battery=1435.23&";

String runout_data = "ro0=15.10&ro1=15.10&ro2=15.10&ro3=15.10&ro4=15.10&ro5=15.10&ro6=15.10&ro7=15.10&ro8=15.10&"
  "ro9=15.10&ro10=15.10&ro11=15.10&ro12=15.10&ro13=15.10&ro14=15.10&ro15=15.10&ro16=15.10&ro17=15.10&ro18=15.10&ro19=15.10&"
  "ro20=15.10&ro21=15.10&ro22=15.10&ro23=15.10&ro24=15.10&ro25=15.10&ro26=15.10&ro27=15.10&ro28=15.10&ro29=15.10&ro30=15.10&"
  "ro31=15.10&ro32=15.10&ro33=15.10&ro34=15.10&ro35=15.10&ro36=15.10&ro37=15.10&ro38=15.10&ro39=15.10&ro40=15.10&ro41=15.10&"
  "ro42=15.10&ro43=15.10&ro44=15.10&ro45=15.10&ro46=15.10&ro47=15.10&ro48=15.10&ro49=15.10&ro50=15.10&ro51=15.10&ro52=15.10&"
  "ro53=15.10&ro54=15.10&ro55=15.10&ro56=15.10&ro57=15.10&ro58=15.10&ro59=15.10&ro60=15.10&ro61=15.10&ro62=15.10&ro63=15.10&"
  "ro64=15.10&ro65=15.10&ro66=15.10&ro67=15.10&ro68=15.10&ro69=15.10&ro70=15.10&ro71=15.10&ro72=15.10&ro73=15.10&ro74=15.10&"
  "ro75=15.10&ro76=15.10&ro77=15.10&ro78=15.10&ro79=15.10&ro80=15.10&ro81=15.10&ro82=15.10&ro83=15.10&ro84=15.10&";

String runout_fft1 = "x0=12.34&y0=56.78&x1=12.34&y1=56.78&x2=12.34&y2=56.78&x3=12.34&y3=56.78&x4=12.34&y4=56.78"
  "&x5=12.34&y5=56.78&x6=12.34&y6=56.78&x7=12.34&y7=56.78&x8=12.34&y8=56.78&x9=12.34&y9=56.78&x10=12.34&y10=56.78&x11=12.34"
  "&y11=56.78&x12=12.34&y12=56.78&x13=12.34&y13=56.78&x14=12.34&y14=56.78&x15=12.34&y15=56.78&x16=12.34&y16=56.78&x17=12.34"
  "&y17=56.78&x18=12.34&y18=56.78&x19=12.34&y19=56.78&x20=12.34&y20=56.78&x21=12.34&y21=56.78&x22=12.34&y22=56.78&x23=12.34"
  "&y23=56.78&x24=12.34&y24=56.78&x25=12.34&y25=56.78&x26=12.34&y26=56.78&x27=12.34&y27=56.78&x28=12.34&y28=56.78&x29=12.34"
  "&y29=56.78&x30=12.34&y30=56.78&x31=12.34&y31=56.78&x32=12.34&y32=56.78&x33=12.34&y33=56.78&x34=12.34&y34=56.78&x35=12.34"
  "&y35=56.78&x36=12.34&y36=56.78&x37=12.34&y37=56.78&x38=12.34&y38=56.78&x39=12.34&y39=56.78&x40=12.34&y40=56.78&";

String runout_fft2 =  "x41=12.34&y41=56.78&x42=12.34&y42=56.78&x43=12.34&y43=56.78&x44=12.34&y44=56.78&x45=12.34&y45=56.78&"
  "x46=12.34&y46=56.78&x47=12.34"
  "&y47=56.78&x48=12.34&y48=56.78&x49=12.34&y49=56.78&x50=12.34&y50=56.78&x51=12.34&y51=56.78&x52=12.34&y52=56.78&x53=12.34&"
  "y53=56.78&x54=12.34&y54=56.78&x55=12.34&y55=56.78&"
  "x56=12.34&y56=56.78&x57=12.34&y57=56.78&x58=12.34&y58=56.78&x59=12.34&y59=56.78&x60=12.34&y60=56.78&x61=12.34&y61=56.78&"
  "x62=12.34&y62=56.78&x63=12.34&y63=56.78&x64=12.34&y64=56.78&x65=12.34&y65=56.78&x66=12.34&y66=56.78&x67=12.34&y67=56.78&"
  "x68=12.34&y68=56.78&x69=12.34&y69=56.78&x70=12.34&y70=56.78&x71=12.34&y71=56.78&x72=12.34&y72=56.78&x73=12.34&y73=56.78&"
  "x74=12.34&y74=56.78&x75=12.34&y75=56.78&x76=12.34&y76=56.78&x77=12.34&y77=56.78&x78=12.34&y78=56.78&x79=12.34&y79=56.78&"
  "x80=12.34&y80=56.78&";
  
String runout_fft3 = "x81=12.34&y81=56.78&x82=12.34&y82=56.78&x83=12.34&y83=56.78&x84=12.34&y84=56.78&x85=12.34&y85=56.78&"
  "x86=12.34&y86=56.78&x87=12.34&y87=56.78&x88=12.34&y88=56.78&x89=12.34&y89=56.78&x90=12.34&y90=56.78&x91=12.34&y91=56.78&"
  "x92=12.34&y92=56.78&x93=12.34&y93=56.78&x94=12.34&y94=56.78&x95=12.34&y95=56.78&x96=12.34&y96=56.78&x97=12.34&y97=56.78&"
  "x98=12.34&y98=56.78&x99=12.34&y99=56.78&x100=12.34&y100=56.78&x101=12.34&y101=56.78&x102=12.34&y102=56.78&x103=12.34&y"
  "103=56.78&x104=12.34&y104=56.78&x105=12.34&"
  "y105=56.78&x106=12.34&y106=56.78&x107=12.34&y107=56.78&x108=12.34&y108=56.78&x109=12.34&y109=56.78&x110=12.34&y110=56.78&"
  "x111=12.34&y111=56.78&x112=12.34&y112=56.78&x113=12.34&y113=56.78&x114=12.34&y114=56.78&x115=12.34&y115=56.78&x116=12.34&"
  "y116=56.78&x117=12.34&y117=56.78&x118=12.34&y118=56.78&x119=12.34&y119=56.78&x120=12.34&y120=56.78&";
  
String runout_fft4 = "x121=12.34&y121=56.78&"
  "x122=12.34&y122=56.78&x123=12.34&y123=56.78&x124=12.34&y124=56.78&x125=12.34&y125=56.78&x126=12.34&y126=56.78&x127=12.34&"
  "y127=56.78&x128=12.34&y128=56.78&x129=12.34&y129=56.78&x130=12.34&y130=56.78&x131=12.34&y131=56.78&x132=12.34&y132=56.78&"
  "x133=12.34&y133=56.78&x134=12.34&y134=56.78&x135=12.34&y135=56.78&x136=12.34&y136=56.78&x137=12.34&y137=56.78&x138=12.34&"
  "y138=56.78&x139=12.34&y139=56.78&x140=12.34&y140=56.78&x141=12.34&y141=56.78&x142=12.34&y142=56.78&x143=12.34&y143=56.78&"
  "x144=12.34&y144=56.78&x145=12.34&y145=56.78&x146=12.34&y146=56.78&x147=12.34&y147=56.78&x148=12.34&y148=56.78&x149=12.34&"
  "y149=56.78&x150=12.34&y150=56.78&"
  "x151=12.34&y151=56.78&x152=12.34&y152=56.78&x153=12.34&y153=56.78&x154=12.34&y154=56.78&x155=12.34&"
  "y155=56.78&x156=12.34&y156=56.78&x157=12.34&y157=56.78&x158=12.34&y158=56.78&x159=12.34&y159=56.78&x160=12.34&y160=56.78&";

String runout_fft5 = "x161=12.34&y161=56.78&x162=12.34&y162=56.78&x163=12.34&y163=56.78&x164=12.34&y164=56.78&x165=12.34&y165=56.78&x166=12.34&"
  "y166=56.78&x167=12.34&y167=56.78&x168=12.34&y168=56.78&x169=12.34&y169=56.78&x170=12.34&y170=56.78&x171=12.34&y171=56.78&"
  "x172=12.34&y172=56.78&x173=12.34&y173=56.78&x174=12.34&y174=56.78&x175=12.34&y175=56.78&x176=12.34&y176=56.78&x177=12.34&"
  "y177=56.78&x178=12.34&y178=56.78&x179=12.34&y179=56.78&x180=12.34&y180=56.78&x181=12.34&y181=56.78&x182=12.34&y182=56.78&"
  "x183=12.34&y183=56.78&x184=12.34&y184=56.78&x185=12.34&y185=56.78&x186=12.34&y186=56.78&x187=12.34&y187=56.78&x188=12.34&"
  "y188=56.78&x189=12.34&y189=56.78&x190=12.34&y190=56.78&x191=12.34&y191=56.78&x192=12.34&y192=56.78&x193=12.34&y193=56.78&"
  "x194=12.34&y194=56.78&x195=12.34&y195=56.78&x196=12.34&y196=56.78&x197=12.34&y197=56.78&x198=12.34&y198=56.78&x199=12.34&"
  "y199=56.78";

int postByteCount = 0;
//####################################################################################################
// SETUP
//####################################################################################################
void setup() {

  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // POST LENGTH
  postByteCount = runout.length() + runout_data.length() +
    runout_fft1.length() +
    runout_fft2.length() +
    runout_fft3.length() +
    runout_fft4.length() +
    0;
  Serial.print("postByteCount: ");
  Serial.println(postByteCount);

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }

  Serial.println("Connected to wifi");
  printWiFiStatus();

  // POST
  https_post(postByteCount);
}

//####################################################################################################
// LOOP
//###################################################################################################
void loop() {
  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("Stop the client");
    client.stop();

    // do nothing forevermore:
    while (true);
  }
  delay(500);
}
//####################################################################################################
// FUNCTIONS
//####################################################################################################
void https_post(int bytes_in_post) {
  if (client.connectSSL(server, 443)) { 
    // Make a HTTP request:
    client.println("POST /test HTTP/1.1");
    client.println("Host: runout.requestcatcher.com");
    client.println("Accept: */*");
    client.println("Accept-Encoding: deflate, gzip");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.print("Content-Length: ");
    client.println(bytes_in_post);
    client.println(); // empty line

    // POST 
    client.print(runout);
    // Serial.println(runout);

    // POST DATA
    client.print(runout_data);

    // POST FFT
    Serial.println(client.print(runout_fft1));
    Serial.println(client.print(runout_fft2));
    Serial.println(client.print(runout_fft3));
    Serial.println(client.print(runout_fft4));
    // Serial.println(client.print(runout_fft5));
    
    // READ RESPONSE
    Serial.println("Server response: ");
    char c = client.read();
    Serial.println(c);

    // STOP CLIENT
    client.stop();
  }
}

void printWiFiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print your board's GW IP address:
  // IPAddress gw_ip = WiFi.gatewayIP();
  // Serial.print("GW IP Address: ");
  // Serial.println(gw_ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Any help is welcome!

Is it possible you're running out of memory? Try sending fft5 without fft4, will that work? Wifi client may be trying to allocate dynamic memory but is unable to.. If this is memory related you can try not using the String class for starters, because it makes a copy of all your strings in dynamic memory, but your strings are constants so they should actually live in PROGMEM maybe..

The WiFiNINA module used in the MKR1010 is based on an ESP32 with a special software running on it. This software may pose some limitation on the amount of bytes you may send. It's even possible that the module buffers the data internally and it returns an error only if you spit the data too fast to it. Have you tried to wait for a few milliseconds until you send the last string?

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