How to print out the ESP local IP on Nextion display

Hi all

i have a simple project to control of light switches using NodeMCU connected of my network and Nextion display,

my question is how to print NodeMCU local IP on my Nextion display.

My question is how to print NodeMCU local IP on my Nextion display.

While the question is simple enough the lack of information about what you are using, what you have tried and what results you got are not at all helpful.

I would think that in the unspecified Wi-Fi library there will be a function that returns the IP address (It's an IP address, not an IP).

I'm going to assume you already know how to display a variable on a Nextion display by printing it to a text box, so you just call the function to get the IP address then print it to a text box the same as you would any other variable.

Assuming you are using the ESP8266Wifi library, I understand that you may be able to fetch the IP address allocated to the NodeMCU with:

#include <ESP8266WiFi.h>
...
  WiFi.begin(ssid, password);
...
  Serial.print("IP address:\t");
  IPAddress myIP = WiFi.localIP();
  Serial.println(myIP);

The IPAddress variable can also be indexed as an array of bytes in case that makes the display output more convenient.

From there you should be able to post the value to a Nextion text box as Perry described.

PerryBebbington:
While the question is simple enough the lack of information about what you are using, what you have tried and what results you got are not at all helpful.

I would think that in the unspecified Wi-Fi library there will be a function that returns the IP address (It’s an IP address, not an IP).

I’m going to assume you already know how to display a variable on a Nextion display by printing it to a text box, so you just call the function to get the IP address then print it to a text box the same as you would any other variable.

thanks for your reply my question relay simple or may be not complete sorry of my dereliction, any way i try to send the result of WiFi.localIP() to Nextion text control but the nextion display only as text (WiFi.localIP()) and try also with nextion number control the result is zero (0)

my code

#include “Nextion.h”
#include <ESP8266WiFi.h>
#include <SPI.h>

WiFiServer server(80);
const char* ssid = “Network_name”;
const char* password = “password”;

NexText tState = NexText(0, 4, “tState”);
NexNumber n0p0 = NexNumber(0, 9, “n0p0”);

NexTouch *nex_listen_list = {
NULL
};

void n0p0PopCallback(void *ptr)
{
dbSerialPrintln(“n0p0PopCallback”);
}

void setup() {
Serial.begin(115200);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println(“WiFi connected”);

// Start the server
server.begin();
Serial.println(“Server started”);

// Print the IP address
Serial.println(WiFi.localIP());

tState.setText(“WiFi.localIP()”); // display IP in Nextion text control
}

void loop() {

nexLoop(nex_listen_list);
n0p0.setValue(WiFi.localIP()); // display IP in Nextion number control

// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println(“new client”);
while(!client.available()){
delay(1);
}

It may be helpful to create a normal string (character array) in multi-dot notation from the address:

char buf[20];
sprintf(buf, "IP:%d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3] );
// Now pass to Nextion, eg. tState.setText(buf);

Hello Husseinsalah,

Please read 'how to use this forum - please read' and follow the instructions in there in future posts, you are more likely to get helpful answers that way.

Then read my tutorial 'Using Nextion displays with Arduino', which gives enough information to print just about anything on a Nextion display, especially with the advice just given by Impulsive. There is also a link in there to a better version of the Nextion libraries created by Ray Livingston.

PerryBebbington:
Hello Husseinsalah,

Please read 'how to use this forum - please read' and follow the instructions in there in future posts, you are more likely to get helpful answers that way.

Then read my tutorial 'Using Nextion displays with Arduino', which gives enough information to print just about anything on a Nextion display, especially with the advice just given by Impulsive. There is also a link in there to a better version of the Nextion libraries created by Ray Livingston.

PerryBebbington:
Hello Husseinsalah,

Please read 'how to use this forum - please read' and follow the instructions in there in future posts, you are more likely to get helpful answers that way.

Then read my tutorial 'Using Nextion displays with Arduino', which gives enough information to print just about anything on a Nextion display, especially with the advice just given by Impulsive. There is also a link in there to a better version of the Nextion libraries created by Ray Livingston.

Thanks for your guide i will red your said notification, i still beginner in Arduino world and this forum,

Impulsive:
It may be helpful to create a normal string (character array) in multi-dot notation from the address:

char buf[20];

sprintf(buf, "IP:%d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3] );
// Now pass to Nextion, eg. tState.setText(buf);

many thanks it is already appear in serial monitor but cannot displaying in nextion text