You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have Mega 2560 connected to WiFi Shield (configured as server). I am using IDE 1.8.1. In my code I want to receive say 2 bytes. The client sends 1 byte at a time. Say client sends b first and then A ideally server should read bA after the second byte sent from client. However, I notice in IDE 1.8.1 the values get corrupted. I have attached the code, also pasting it below:
`#include <SPI.h>
#include<WiFi.h>
If client send b first then rcvd 1 is printed. If client then sends A then data_s -1 -1 is printed. If I try the same code in IDE 1.6.13 data_s 98 65 is printed which is correct.
However, in both IDE 1.8.1 and IDE 1.6.13 if I use client1.read(data2, 2) instead of two back-to-back read() the Serial1 print would be data_s 98 0. The second byte can be anything random, not always 0.
I also tried out the same code in MKR1000 and IDE 1.8.1. I used size_rcvd = client1.read(data2, 2) instead of two read(). I saw the prints as data_s 65 0 even though the size_rcvd = 2. It was always neglecting the previously sent byte.
I have Mega 2560 connected to WiFi Shield (configured as server). I am using IDE 1.8.1. In my code I want to receive say 2 bytes. The client sends 1 byte at a time. Say client sends b first and then A ideally server should read bA after the second byte sent from client. However, I notice in IDE 1.8.1 the values get corrupted. I have attached the code, also pasting it below:
`#include <SPI.h>
#include<WiFi.h>
int configureSuccess = WL_IDLE_STATUS;
char ssid[] = "xyz";
char pass[] = "*******";
WiFiServer server(20000);
static uint8_t alreadyConnected = 0;
void setup() {
Serial.begin(9600);
Serial1.begin(28800);
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
while ( configureSuccess != WL_CONNECTED) {
configureSuccess = WiFi.begin(ssid, pass);
// delay 10000
unsigned long startMillis = millis();
while(millis()- startMillis < 10000)
{
};
}
server.begin();
}
void loop() {
// wait for a new client:
int avlBytes = 0;
int sizeReceived = 0;
int data2[2];
Serial1.println("loop");
WiFiClient client1 = server.available();
if (client1 == true){
if(!alreadyConnected){
client1.flush();
alreadyConnected++;
Serial1.println("Flushing");
}
avlBytes = client1.available();
if(avlBytes >= 2){
data2[0] = client1.read();
data2[1] = client1.read();
Serial1.println("data_s");
Serial1.println(data2[0]);
Serial1.println(data2[1]);
}
else{
Serial1.println("rcvd");
Serial1.println(avlBytes);
}
}
else {
alreadyConnected = 0;
Serial1.println("No client");
}
unsigned long startMillis = millis();
while(millis()- startMillis < 1000)
{
};
}`
If client send b first then rcvd 1 is printed. If client then sends A then data_s -1 -1 is printed. If I try the same code in IDE 1.6.13 data_s 98 65 is printed which is correct.
However, in both IDE 1.8.1 and IDE 1.6.13 if I use client1.read(data2, 2) instead of two back-to-back read() the Serial1 print would be data_s 98 0. The second byte can be anything random, not always 0.
wifishield1_6_13.zip
The text was updated successfully, but these errors were encountered: