I have a program which, among other things, displays the IP address to the user.
However, if a network has not been set up, requesting the IP address returns "ip unset", and I can display that.
I have not been able to get this into an "if" statement - although it seems that it should be simple.
What should I do, and why?
I cannot find the used code in your post.
What would "this" be?
May be just
if (getIPAddress() == "ip unset") {
} else {
}
if getIPAddress()
returns a String.
Hi J-M-L Jackson -
Your suggestion seemed to be exactly what I need!
I copied and pasted your suggested code:
if (getIPAddress() == "ip unset") {
}
(to be sure that I had it exactly correct)
BUT the compiler flags an error and says:
"getIPAddress" was not declared in this scope.
Apparently something else is still needed.
Incidentally, of the 3 responses I've received so far, you seem to be the only one who understands the problem!
- Matt
He Matt, I was kinda pulling your leg in a gentle way.
What the other posters were hinting was exactly what you saw when you tried to compile what I provided... We have no clue how you get your IP address, no clue about your hardware and the libraries you are using etc... So it's hard to give any meaningful answer... Mine was just "if you can get a string as an answer, then just compare it"... but I'm pretty sure you don't get a String (this is what you see when you call print()) ... (you have an isSet() method you could check if this is your library)
So give us more information and we will definitely be able to help more...
in a nutshell, help us help you...
Hi -
Thanks for your help.
My included libraries are:
#include <Wire.h>
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include "HTTPSRedirect.h"
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <EEPROM.h>
And the part that works just fine is:
// Display Local Network Name for a few seconds:
lcd.clear();
lcd.print("Local network IP=");
lcd.setCursor(0, 1); //second row
lcd.print(WiFi.localIP());
delay(3000); // show it for 3 seconds
All works fine if the IP has been set. (Displays the IP OK, although the network name would be better.)
Unfortunately, in the case where there is no IP set, I have not been able to prompt the user to set one!
This is where I currently stand.
Of course, all of the working code related to the RF transmission, etc. I've "borrowed" from others, and I have no idea how it works. In the past, I've been able to look at source documents to see what was actually going on "behind the scenes." Now, using libraries, which greatly simplifies the writing, I don't know the proper syntax nor what the various commands are doing nor what they return.
While I would like to understand more, my present task is to get things working properly.
All help will be appreciated!
Thanks again -
Matt
As @JML already suggested, check out the isSet() function provided by the IPAddress class.
Indeed isSet() is then what you are looking for
Thanks to all -
With a bit of Googling and fooling around, I found more than my original answer.
I had also wanted to display the local network name - and hadn't figured out how to do this.
Here is the code which works - and which now does everything:
if(String(WiFi.SSID() ) == ""){
lcd.clear();
lcd.print("Please select a");
lcd.setCursor(0, 1); //second row
lcd.print("Network");
}
The answer was to use upper case SSID (which is NOT defined in my program) and then the above statement WiFi.SSID returns a string which I can handle in the "if" and "print" statements.
Thanks again to all -
Matt
WiFi.SSID()
does already return a String according to the documentation so you don't need the String(...)
thingy
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.