Post topics, source code that relate to the Arduino Platform

User avatar
By viamar
#58661 @ martinayotte
Pleas can you help me why I cant't use fromString? I have this error:

Code: Select allString ipaddr="192.168.1.63";
IPAddress ip;
ip.fromString(ipaddr.c_str());


Code: Select allerror: 'ip' does not name a type

 ip.fromString(ipaddr.c_str());

 ^

exit status 1
'ip' does not name a type

[Finished in 19.2s with exit code 1]



This code in the same program compiles correctly
Code: Select allIPAddress timeServer1(193, 204, 114, 232);
String ipAsString = timeServer1.toString();



Thanks
User avatar
By viamar
#58682 Thanks for the prompt answer, but the ESP package is the latest 2.3.0.
I've isolated the problem and is a scope issue, but I don't understand the reason.

This code works:
Code: Select all#include <ESP8266WiFi.h>

IPAddress timeServer1(193, 204, 114, 232);
IPAddress ip;

String ipaddr="192.168.1.63";
String ipAsString = timeServer1.toString();


void setup() {
  ip.fromString(ipaddr.c_str());
  Serial.begin(115200);
  Serial.println();
  Serial.println(ip);
  Serial.println(ipAsString);
}

void loop() {
 delay(100);
}


And this gives error "'ip' does not name a type"
Code: Select all#include <ESP8266WiFi.h>

IPAddress timeServer1(193, 204, 114, 232);
IPAddress ip;

String ipaddr="192.168.1.63";
String ipAsString = timeServer1.toString();
ip.fromString(ipaddr.c_str());


void setup() {
  Serial.begin(115200);
  Serial.println();
  Serial.println(ip);
  Serial.println(ipAsString);
}

void loop() {
 delay(100);
}


I need "ip" and "ipAsString" as global for this reason I put them outside.