WiFi Client return Strange Characters!!

Hi Guys,

I tried to modify the WiFi example “WiFIClientRepeater” and use it with my page (the original IP address was modified for our security… if you want to know the real IP write to me…)
http://94.110.147.28/ard.aspx?user=admin&pwd=luca&mac=7ac4e1dfbba .

If you see the URL I pass 3 parameters (user, pwd and mac).
My ASP.NET page return a number (the content type is “TEXT”) that could be 1, or 0 or -1.

So it’s simple! I Thought!
Noooo!!!

The result of my sketch launched in monitor on Arduino2560 is a strange character ( ÿ ).
See below please!!
If I visit the page with a browser on a PC it works fine!!
What I wrong???
Thank you
bye

Attempting to connect to SSID: WiFiSSID
Connected to wifi
SSID: WiFiSSID
IP Address: 192.168.1.120
signal strength (RSSI):-68 dBm

connecting…
connected
disconnecting.
ÿ

connecting…
connected
disconnecting.
ÿ

connecting…
connected
disconnecting.
ÿ

and this is the sketch:

#include <SPI.h>
#include <WiFi.h>

char ssid = “WiFiSSID”;
char pass = “mypassword”;
//int keyIndex = 0;
int status = WL_IDLE_STATUS;
IPAddress server(94,110,147,28);
WiFiClient client;
String location = “”;

void setup() {
Serial.begin(9600);
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println(“WiFi shield not present”);
while(true);
}

while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(5000);
}
Serial.println(“Connected to wifi”);
printWifiStatus();
}

void loop() {
String pageValue = connectAndRead();
Serial.println(pageValue);
delay(5000);
}

String connectAndRead(){
Serial.println(“connecting…”);
if (client.connect(server, 80)) {
Serial.println(“connected”);

client.println(“GET /ard.aspx?user=admin&pwd=luca&mac=7ac4e1dfbba HTTP/1.1”);
client.println(“Host: 94.110.147.28”);
client.println(“Connection: close”);
client.println();
char pag = client.read();
client.stop();
client.flush();
Serial.println(“disconnecting.”);
return String(pag);

}else{
return “connection failed”;
}
}

void printWifiStatus() {
// print the SSID of the network you’re attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print your WiFi shield’s IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print(“signal strength (RSSI):”);
Serial.print(rssi);
Serial.println(" dBm");
}

Hi Guys,
In my code below the goal is to pass parameters to an ASP.NET page and read his answer (that could be the character “1” or the character “0”, even if “-1” for error situation).
The url is http://95.110.147.28/ard.aspx?user=admin&pwd=luca&mac=7ac4e1dfbba .

The use: when arduino if receives “0” do something, if receives “1” do another thing.

The problem is that arduino receives strange character “ÿ”.
Why? What I wrong?
Could you help me please?
Thank you
bye

This is the serial monitor screen:
Attempting to connect to SSID: WiFiSSID
Connected to wifi
SSID: WiFiSSID
IP Address: 192.168.1.120
signal strength (RSSI):-72 dBm
connecting…
connected
disconnecting.
ÿ
connecting…
connected
disconnecting.
ÿ
connecting…
connected
disconnecting.
ÿ

This is the code:

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "WiFiSSID"; 
char pass[] = "mypassword"; 
//int keyIndex = 0;
int status = WL_IDLE_STATUS;
IPAddress server(95,110,147,28);  
WiFiClient client;
String location = "";

void setup() {
  Serial.begin(9600); 
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    while(true);
  } 
  
  while (status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    delay(5000);
  } 
  Serial.println("Connected to wifi");
  printWifiStatus();
}

void loop() {
  String pageValue = connectAndRead(); 
  Serial.println(pageValue); 
  delay(5000);
}

String connectAndRead(){
  Serial.println("connecting...");
  if (client.connect(server, 80)) {
    Serial.println("connected");

    client.println("GET /ard.aspx?user=admin&pwd=luca&mac=7ac4e1dfbba HTTP/1.1");
    client.println("Host: 95.110.147.28");
    client.println("Connection: close");
    client.println();
    char pag = client.read();
    client.stop();
    client.flush();
    Serial.println("disconnecting.");
    return String(pag);

  }else{
    return "connection failed";
  }
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

The character ÿ has the ascii code -1 (0xFF) which is what you receive when you try to read a character from a stream when there is no character available. In your code you should not attempt to read from a stream unless/until available() returns a value greater than zero.

For future reference, please use code tags when posting code. It's explained in the sticky at the top of this forum.

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

Read this before posting a programming question

How to use this forum

  • Moderator