I am trying to read data from a server using YunClient.
I was able to get this working using the Yun's HttpClient, but I need to move to something closer to EthernetClient so I can make something that will work more generally with different devices.
Here is the working HttpClient sketch:
#include <Bridge.h>
#include <HttpClient.h>
HttpClient myClient;
char* myUrl = {"http://www.brainjar.com/java/host/test.html"};
void setup() {
Serial.begin(9600);
Bridge.begin();
while(!Serial);
}
void loop() {
call(myUrl, myClient);
delay(5000);
}
void call(char* URL, HttpClient inClient){
inClient.get(URL);
while (inClient.available())
{
Serial.print((char)inClient.read());
}
}
Here is my attempt to get the same functionality using YunClient
I am hoping to be able to read the contents of the site in the serial monitor:
#include <Bridge.h>
#include <YunClient.h>
YunClient myClient;
//this url works:
char* myUrl = {"www.brainjar.com"};
//this won't work:
char* myUrl2 = {"www.brainjar.com/java/host/test"};
void setup() {
Serial.begin(9600);
Bridge.begin();
while(!Serial);
}
void loop() {
connectTest(myUrl, myClient);
call(myUrl, myClient);
call2(myUrl, myClient);
delay(5000);
}
void connectTest(char* URL, YunClient inClient){
Serial.println(inClient.connect(URL, 80));
Serial.println(inClient.available());
}
//client.available() always returns 0
void call(char* URL, YunClient inClient){
inClient.connect(URL, 80);
while(inClient.available()){
Serial.print((char)inClient.read());
}
}
//client.read() only prints junk
void call2(char* URL, YunClient inClient){
inClient.connect(URL, 80);
for(int i = 0; i < 20; i++){
Serial.print((char)inClient.read());
} Serial.println();
}
Any help is much appreciated