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.