When I was using the Mega as an in between for the computer and the WIFI module, I was able to read all the data from the website and display it on the serial monitor. Now when I try to read the data in through serial port1, save that to a char array, and print it to the serial monitor on Serial port0, I either don't get anythning, or just parts of if. I have not yet found a solution after several days of getting ideas from the forums and/or tweaking them with my ideas.
Does anyone have experience in reading in data from a website? Maybe even some example code? I am to the point where I don't really know what else to try haha any help is appreciated.
this is what I am trying right now and getting the first part of the data:
for(int i = 0; i<100; i++)
{
Serial.print("");
while (Serial1.available())
{
inData[inDataCount] = Serial1.read();
Serial.print(inData[inDataCount]);
inDataCount++;
}
}
The for loop actually isn't useless because there isn't a set time that I know the data will be received. So I just have it looping there for a bit until there is data available then I read it in( or try to at least). It is nearly instantaneous but if I dont have that catch there and the string hasn't been received yet then the code skips reading in the string. Yes, I know there are other ways to do it, but this works. This is what the code returns:
SEND OK
+IPD,4,757:HTTP/1.1 200 OK
Server: nginx
Date: Sat, 03 Oct 2015 19:48:54 GMT
Content-
Type: application/json; charset=utf-8
Content-Length: 469
Connection: close
X-Source: redis
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST
It's 64 bits. And I have tried many things to work around that like clearing the buffer. However I believe there's only one way to clear the read buffer and that is reading the data in. So, this could very well be the problem, however I figured people would have already worked through this because it is a pretty common application of the Arduino.
By "your buffer" I mean the array 'inData' where you store every character received. The web page you pointed to contains close to 900 characters. Have you set aside space for that many?
If you had bothered to post all of your code we would not have to waste time asking these basic questions.
You should be able to capture the incoming data from the serial port into a String variable and parse the desired data out of that. I captured the below in a String variable using some test client code and an w5100 ethernet shield.
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 04 Oct 2015 02:01:11 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: close
X-Source: redis
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST
The for loop actually isn't useless because there isn't a set time that I know the data will be received.
Nonsense. That for loop will iterate in next to no time, if there is no data to read. You must read and store the data, in a while loop, until you get all the data, regardless of how long it takes OR for some maximum period of time. Basing that time on how long it takes a for loop to iterate is nonsense.