# Printing an array to node-red text dashboard node

**URL:** <https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801>\
**Category:** General\
**Created:** [11 November 2019 16:18 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801 "2019-11-11T16:18:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![redlop](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@redlop](https://discourse.nodered.org/u/redlop)\
**Post date:** [11 November 2019 16:18 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/1 "2019-11-11T16:18:11Z")

</div>

Hi. Im currently working on a project that scans for networks, as of now i've made it print the networks all at the same time. My problem is that I can't send the data into node-red via text node. It gives me an error that involves converting the variables.

```auto
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

const int array2Size = 100;
String checkPass2[array2Size];
const int arraySize = 5;
int checkPass[arraySize]; // all elements are zero.

const char* ssid = "Tenda_FE2038";
const char* password = "huertas032793";

String sssid;
uint8_t encryptionType;
int32_t RSSI;
uint8_t* BSSID;
int32_t channel;
bool isHidden; 
uint8_t prevRssi;

const char* mqtt_server = "192.168.1.2";

// Initializes the espClient. You should change the espClient name if you have multiple ESPs running in your home automation system
WiFiClient espClient;
PubSubClient client(espClient);
// Timers auxiliar variables
long now = millis();
long lastMeasure = 0;

void callback(String topic, byte* message, unsigned int length) {
 // Serial.print("Message arrived on topic: ");
  Serial.print(topic);
  Serial.print(". Message: ");
  String messageTemp;
  
  for (int i = 0; i < length; i++) {
    Serial.print((char)message[i]);
    messageTemp += (char)message[i];
  }
  Serial.println();

  Serial.println();
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
  
    if (client.connect("ESP8266Client")) {
      Serial.println("connected");  
      // Subscribe or resubscribe to a topic
      // You can subscribe to more topics (to control more LEDs in this example)
     // client.subscribe("rssi/test");
      client.subscribe("name/test");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

void setup() {
  // put your setup code here, to run once:
      Serial.begin(115200);
   Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  // Print local IP address and start web server
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  // put your main code here, to run repeatedly:
if (!client.connected()) {
    reconnect();
  }
  if(!client.loop())
    client.connect("ESP8266Client");

   byte available_networks = WiFi.scanNetworks();
        int netnum = 0;
     for (int network = 0; network < available_networks; network++)
  {
    checkPass2[network] = WiFi.SSID(network);
    checkPass[network] = WiFi.RSSI(network);
    netnum = network;
    prevRssi = (uint8_t)WiFi.RSSI(network);
    
    //Serial.println(checkPass[network]);
   delay (1000);
  }

    Networks();
  }

  void Networks()
  {
    byte avail_net = WiFi.scanNetworks();
  for(int i = 0; i < avail_net ; i ++){
  
     Serial.println(checkPass[i]);
     Serial.println(checkPass2[i]);
     client.publish("name/test",checkPass[i]);
  }
  }

```

This is the code that i'm working on. Sorry if it's a bit messy, ive been trying a few thing to make it work. It gives me an error that says invalid conversion from int to const char\*. Im pretty new to node-red and programming at all so I can't figure out whats the problem by myself. The flow doesn't need to be elegant I just need the SSID, RSSI of each network posted and updated everytime the loop is finished.

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [11 November 2019 16:39 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/2 "2019-11-11T16:39:06Z")

</div>

So you ... your mqtt-broker receives a message for every network found? Have you checked this with mqtt explorer or any other mqtt client

If so you use the mqtt node connect to your broker and subscribe to „name/test“ or „#“ and link a debug node and see what you receive

If you receive nothing it is not a Node-RED related problem...

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 November 2019 16:39 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/3 "2019-11-11T16:39:46Z")

</div>

Is the error in node-red? That code does not look like node-red code.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 November 2019 16:41 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/4 "2019-11-11T16:41:32Z")

</div>

> [@redlop](#):
>
> const char\* ssid = "\*\*\*_"; const char_ password = "\*\*\*\*\*";

Well I think you had better change your wifi credentials, having told the whole world what they are.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [11 November 2019 16:44 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/5 "2019-11-11T16:44:30Z")

</div>

> I can't send the data into node-red via text node

What do you mean with text node. You need an mqtt node first.  
Can you show your flow ? and what is the output of the mqtt node when you receive data from the esp ?

And remove your password from your code and/or change your password.

---

<div class="post-metadata">

**Author:** ![redlop](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@redlop](https://discourse.nodered.org/u/redlop)\
**Post date:** [11 November 2019 17:13 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/6 "2019-11-11T17:13:45Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c1448e80d10d695cc379bbea71dc5aaae1ebb381.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/1f33cf77701f170db5e9682c9d1d2d01c22c5ac7.png)

Node-red receives it one by one. I need to print the full array. I can print it properly on the serial monitor in arduino, but i don't know how to properly do it via node-red.

---

<div class="post-metadata">

**Author:** ![redlop](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@redlop](https://discourse.nodered.org/u/redlop)\
**Post date:** [11 November 2019 17:15 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/7 "2019-11-11T17:15:47Z")

</div>

node red receives it. I have a flow with an mqtt node and a text/debug node. It receives the data one by one. I need to print it as an array everytime the loop finishes.

---

<div class="post-metadata">

**Author:** ![redlop](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@redlop](https://discourse.nodered.org/u/redlop)\
**Post date:** [11 November 2019 17:22 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/8 "2019-11-11T17:22:58Z")

</div>

I'm using Arduino IDE because im using esp8266.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [11 November 2019 17:26 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/9 "2019-11-11T17:26:48Z")

</div>

Look at the text node - the red triangle - this means it is not configured (correctly).

Next you want to show all networks while you only have 1 text node, you will only see 1 network.  
There is a [table node](https://flows-new.nodered.org/node/node-red-node-ui-table) for node red dashboard.

You will need to create an array with all the networks in 1 msg.payload

---

<div class="post-metadata">

**Author:** ![redlop](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@redlop](https://discourse.nodered.org/u/redlop)\
**Post date:** [11 November 2019 17:31 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/10 "2019-11-11T17:31:16Z")

</div>

How do I do that?

Also how do I tell node-red that it is the last data sent (for example there are 3 networks available), I've fiddled with split/join/batch nodes and i get inaccurate data because node-red doesn't know when to stop getting data.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [11 November 2019 17:35 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/11 "2019-11-11T17:35:56Z")

</div>

I would gather all the networks in your esp, assemble 1 message and send it to mqtt.

---

<div class="post-metadata">

**Author:** ![redlop](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@redlop](https://discourse.nodered.org/u/redlop)\
**Post date:** [11 November 2019 17:44 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/12 "2019-11-11T17:44:20Z")

</div>

do you have an idea of how to do that? I tried passing it to an array and then creating a for loop and then sending it to node-red. but it gives me an error

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [11 November 2019 17:55 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/13 "2019-11-11T17:55:10Z")

</div>

I guess you did not write the ESP code yourself.

I cannot test it, but you should be able to send the array directly as it was created in `void loop()` , something like:

```auto
void Networks()
  {
    client.publish("name/test",checkPass);
}

```

---

<div class="post-metadata">

**Author:** ![redlop](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@redlop](https://discourse.nodered.org/u/redlop)\
**Post date:** [11 November 2019 17:56 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/14 "2019-11-11T17:56:18Z")

</div>

Tried doing that. But node-red prints it one by one. It ignores the array

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [11 November 2019 17:57 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/15 "2019-11-11T17:57:42Z")

</div>

Perhaps as an object ?

```auto
 client.publish("name/test","{'networks':"+checkPass+"}");

```

---

<div class="post-metadata">

**Author:** ![redlop](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@redlop](https://discourse.nodered.org/u/redlop)\
**Post date:** [11 November 2019 18:01 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/16 "2019-11-11T18:01:47Z")

</div>

It gives me this error

invalid operands of types 'const char [13]' and 'int [5]' to binary 'operator+'

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [11 November 2019 18:07 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/17 "2019-11-11T18:07:32Z")

</div>

As I said, I cannot test it, you will need to google how to combine an int and a const char in arduino.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 November 2019 18:27 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/18 "2019-11-11T18:27:46Z")

</div>

@redlop Why did you open a second thread about the same issue? [Printing WiFi networks](https://discourse.nodered.org/t/printing-wifi-networks/17250)  
Please don't do that it wastes peoples time.

so it looks like you have three threads about the same issue [Gathering results and placing in an array](https://discourse.nodered.org/t/gathering-results-and-placing-in-an-array/17452)

---

<div class="post-metadata">

**Author:** ![redlop](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@redlop](https://discourse.nodered.org/u/redlop)\
**Post date:** [11 November 2019 18:29 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/19 "2019-11-11T18:29:05Z")

</div>

Sorry I forgot I already opened a topic. But this is a more precised and cleaner question opposed to the first one.

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [11 November 2019 19:58 UTC](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801/20 "2019-11-11T19:58:34Z")

</div>

Yor problem is that mqtt only sends string data. So you can convert your array into an json formated string send it over via mqtt to Node-RED and convert it back using the json node.  
Or combine all you single messages back into an object/array in Node Red.  
Perhaps do something like

topic=„myNetworks/„+networkSSID  
payload=yourRSSI

An then the text node is not right for your purpose. You should look into ui-list or ui-table

Have fun in learning c, JavaScript and some other tools

[Next page](https://discourse.nodered.org/t/printing-an-array-to-node-red-text-dashboard-node/17801.md?page=2)
