[From QnA]RcvPacket() Function in Github Arduino Library


#1

Hello,

I was wondering if you could elaborate on how to properly use this RcvPacket() function. I am trying to use an HTTP GET request to read in a text file and store it into an array of characters, but I’m not sure how this function is used or what it does. Do I need to use the: uint8_t WizFi2x0Class::read(byte *buf) function along with this function? How are RcvPacket() and read(byte *buf) different? The example program included in the library does not make its use clear.
Thanks!


#2

RcvPacket() function is used to realize as internal function.
Read() function is used to read the information of buffer.
Therefore you are only using read function.

Thanks,


#3

If the RcvPacket() is only used as an internal function, then why is it used externally in the WizFiWebClientTest.ino example also included with the library? It seems to me that both RcvPacket() and Read() are used together, but I’m am not sure what the point of RcvPacket() is. This is the section of code in the example that uses RcvPacket(). What exactly is RcvPacket() accomplishing in this code?

Thanks

github.com/Wiznet/WizFiShield/b … ntTest.ino

[code]void loop()
{
uint8_t retval;
byte rcvdBuf[129];

memset(rcvdBuf, 0, 129);

if(Wifi_setup)
{
myWizFi.RcvPacket();

 if(myClient.available()){       
   if(myClient.read(rcvdBuf))
   {
     Serial.print((char *)rcvdBuf);
   }
 }else{
     retval = myClient.connect();
     if(retval == 1)
     {
       Serial.println("Connected! ");
       myClient.write((byte *)"GET /search?q=WizFi210 HTTP/1.0\r\n\r\n");
     }else
       Serial.println("Connection Failed");
   }

}
}
[/code]


#4

read function just is reading stored data in buffer.
and RcvPacket function is storing received data to buffer.

thanks,


#5

Hi,
I explain the difference between RcvPacket() and Read().
WizFi210 send all data including user data, notification message and reply to command which user sent via serial interface.
RcvPacket() is a function to get data from WizFi210 and parse it.
If it got data for specific socket, then copy it to common data buffer and set the specified socket’s flag to inform what it has data.
And if it got reply for any command user sent right ahead, it handle the status of corresponding socket or WizFi210 itself.
And if it got notification message like “Disassociated from AP”, “Connected” or “Disconnected”, it handle the status of corresponding socket or WizFi210 itself.
In order to miss all processing, User should track data from wizFi210 and parse it without loss.
So user must call RcvPacket() infinitely.
loop() function is called infinitely. That is the reason why I placed RcvPacket() in loop() function.

Read() is to get data from data buffer which RcvPacket() filled.
If you see inside Read(), you can find how Read() operates.
Read() check whether its data ready flag is set or not. If so, It return the pointer of buffer which data is stored in.

Thanks.

javakys.

[quote=“ssekim”]If the RcvPacket() is only used as an internal function, then why is it used externally in the WizFiWebClientTest.ino example also included with the library? It seems to me that both RcvPacket() and Read() are used together, but I’m am not sure what the point of RcvPacket() is. This is the section of code in the example that uses RcvPacket(). What exactly is RcvPacket() accomplishing in this code?

Thanks

github.com/Wiznet/WizFiShield/b … ntTest.ino

[code]void loop()
{
uint8_t retval;
byte rcvdBuf[129];

memset(rcvdBuf, 0, 129);

if(Wifi_setup)
{
myWizFi.RcvPacket();

 if(myClient.available()){       
   if(myClient.read(rcvdBuf))
   {
     Serial.print((char *)rcvdBuf);
   }
 }else{
     retval = myClient.connect();
     if(retval == 1)
     {
       Serial.println("Connected! ");
       myClient.write((byte *)"GET /search?q=WizFi210 HTTP/1.0\r\n\r\n");
     }else
       Serial.println("Connection Failed");
   }

}
}
[/code][/quote]