# Error sending data from ESP

**URL:** <https://discourse.nodered.org/t/error-sending-data-from-esp/62654>\
**Category:** General\
**Created:** [15 May 2022 20:23 UTC](https://discourse.nodered.org/t/error-sending-data-from-esp/62654 "2022-05-15T20:23:54Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [18 May 2022 06:16 UTC](https://discourse.nodered.org/t/error-sending-data-from-esp/62654/9 "2022-05-18T06:16:01Z")

</div>

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.

> [@Controlling LEDs on a Wemos D1 Mini (Arduino code) via MQTT](https://discourse.nodered.org/t/controlling-leds-on-a-wemos-d1-mini-arduino-code-via-mqtt/62523):
>
> One of my IoT students was asking how to control a set of LEDs on a Wemos D1 Mini, that had been programmed using Arduino code, via MQTT commands from Node-RED. This is what the breadboard lash-up looks like... The red LED is connected to D8 (GPIO-15). The green LED is connected to D7 (GPIO-13) The yellow LED is connected to D6 (GPIO-12) This is the very simple test-flow we created in Node-RED. [Screen Shot 05-11-22 at 06.35 PM] [{"id":"bb2bbcc236726f09","type":"tab","label…

Here's a direct link to the [Arduino files](http://www.resources-area.co.uk/node-red-flows/mqtt_relay_controller/), 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.

```auto
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.

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

    publish_solar();

    publish_analog();

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

```

---

_[View the full topic](https://discourse.nodered.org/t/error-sending-data-from-esp/62654)._
