Printing an array to node-red text dashboard node

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.

#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.

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

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

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

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.

image

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.

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.

I'm using Arduino IDE because im using esp8266.

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 for node red dashboard.

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

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.

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

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

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:

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

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

Perhaps as an object ?

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

It gives me this error

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

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

@redlop Why did you open a second thread about the same issue? Printing WiFi networks
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

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

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