I make a simple request to http://www.ipify.org/ to get my wan ip address to update to no-ip.com. My project need DDNS from no-ip.com. I use subString to get String ip begin, but end of ip, there many character “ÿ” (from Serial monitor), please take a look to my Blynk’s screen shots
Can anyone help me, I just begin start with arduino and program about 2 months. I search google many time, but can not find some help, so I post here.
Thanks for your help, this is my code to get IP address: void getIP() { if (client.connect("api.ipify.org", 80)) { terminal1.println("connected to api.ipify.org"); terminal1.println(); terminal1.flush(); client.println("GET / HTTP/1.0"); client.println("Host: api.ipify.org"); client.println(); } else { terminal1.println("connect to api.ipify.org failed"); terminal1.println(); terminal1.flush(); } while(client.connected() && !client.available()); while (client.connected() || client.available()) { char c = client.read(); //gets byte from ethernet buffer readString += c; //places captured byte in readString } client.stop(); //stop client newIP = readString.substring(153); Serial.println(newIP); Serial.println(); terminal1.println(newIP); terminal1.println(); terminal1.flush(); readString=""; }
I test in my arduino mega, It work correctly, it return new Ip as I want, no more strange Character after Ip address, everytime. But when I use same code on my nodeMCU, the String I got not only IP address, it plus some or many char " ÿ " on Serial Monitor, if I print that String to terminal , it show like my screenshot, I search Google and I found that " ÿ " is 255 (-1) , I tried to take indexOf “ÿ” to re use substring to get right String before first char “ÿ”, but didn’t work, I use int a = String.indexOf(“ÿ”); is that right code?