Error sending data from ESP

You obviously didn't follow the link to this article/thread (I posted above) as if you had read it you would have seen the link to the Arduino files that work for me and my IoT students.

Here's a direct link to the Arduino files, but I would encourage you to read the article I posted.

I've just found some code to 'publish' values from a temperature/humidity/pressure (thp) BME280 sensor.
You will have to edit the code to remove all the bits (my variables) you don't need. Hope this helps.

void publish_thp()
{
  status = "fail";
  if (bitRead(status_register, thp_pos))
    status = "good";

  StaticJsonDocument<256> doc; // The names in doc["xxx"] have been shortened to fit within the char limit !!!
  doc["remote"] = "node" + String(remote_node_ref);
  doc["src"] = "ws_pcb"; //Tag for Node-RED to indicate the data-source (e.g. "rf24", "lora", "wsv1", "wsv2")
  doc["type"] = "bme280";
  doc["sensor_st"] = status;
  doc["t"] = temperatureValue;
  doc["h"] = humidityValue;
  doc["p"] = pressureValue;

  doc["base"] = "node98";
  doc["ssid"] = WiFi.SSID();
  doc["rssi"] = WiFi.RSSI();

  char topic[30]; // 30 chars wide
  strcpy(topic, mqtt_publish_topic);
  strcat(topic, "/");
  strcat(topic, thisNodeID);

  char buffer[256];
  size_t n = serializeJson(doc, buffer);
  mqtt_client.publish(topic, buffer, n);
} //------------ End of publish_thp()

To overcome the limit on length of MQTT messages we decided to publish readings in sequence.
E.g. BME280, solar panel data, DS18B20.

void transmit_data_to_mqtt_broker()
{
  if (newData == true)
  {
    publish_thp();

    publish_solar();

    publish_analog();

    newData = false;
  }
} //============ End of transmit_data_to_mqtt_broker()