Show minor edits - Show changes to markup
None
byte : the number of bytes written. It is not necessary to read this.
[@
(:source lang=arduino tabwrite=4:)
byte mac[6] = { 0 }; IPAddress ip; IPAddress gateway; IPAddress subnet; byte dataBuf[80] = { 0 }; char ssid[32] = { 0 };
char ssid[] = "yourNetwork"; char pass[] = "yourPassword";
Server server(23);
void setup() {
WiFiServer server(80);
void setup() {
// initialize serial:
Serial.println("Setup WiFi...");
strcpy(ssid, "Vodafone-10289870");
Serial.println("Attempting to connect to WPA network...");
Serial.print("SSID: ");
int status = WiFi.begin(ssid);
Serial.println("Wifi Connected!");
Serial.println("Starting server...");
server.begin();
delay(1000);
status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true);
}
else {
server.begin();
}
void loop() {
static uint8_t count = 0;
Serial.println("Retry connect...");
status = WiFi.begin(ssid);
if (status == WL_CONNECTED)
{
byte status = 0;
Client client = server.available(&status);
if (client) {
byte idx = 0;
while (client.available())
{
dataBuf[idx++] = client.read();
}
if (idx>0)
{
dataBuf[idx]=0;
server.write((char*)&dataBuf[0]);
}
return;
}
void loop() {
// listen for incoming clients
WiFiClient client = server.available();
if (client == true) {
// read bytes from the incoming client and write them back
// to any clients connected to the server:
server.write(client.read());
@]
(:sourceend:)
WiFi : Server class
Write data to all the clients connected to a server.
server.write(data)
data: the value to write (byte or char)
None
#include <WiFi.h>
#include <IPAddress.h>
byte mac[6] = { 0 };
IPAddress ip;
IPAddress gateway;
IPAddress subnet;
byte dataBuf[80] = { 0 };
char ssid[32] = { 0 };
int status = WL_IDLE_STATUS;
Server server(23);
void setup()
{
Serial.begin(9600);
Serial.println("Setup WiFi...");
strcpy(ssid, "Vodafone-10289870");
Serial.println(ssid);
int status = WiFi.begin(ssid);
Serial.println("Wifi Connected!");
Serial.println("Starting server...");
server.begin();
delay(1000);
}
void loop()
{
static uint8_t count = 0;
Serial.println("Retry connect...");
status = WiFi.begin(ssid);
if (status == WL_CONNECTED)
{
byte status = 0;
Client client = server.available(&status);
if (client) {
byte idx = 0;
while (client.available())
{
dataBuf[idx++] = client.read();
}
if (idx>0)
{
dataBuf[idx]=0;
server.write((char*)&dataBuf[0]);
}
return;
}
}
}