#include "WiFi.h"
#include <SPI.h>
#ifndef LED_BUILTIN
#define LED_BUILTIN 2
#endif
char ssid[] = "TP-LINK"; //WiFi 名称
char pass[] = "123456789"; //WiFi 密码
int status = WL_IDLE_STATUS; //WiFi 连接状态
char server[] = "192.168.1.6"; //服务器 IP
uint16_t port = 3310; //服务器 port
WiFiClient client;
void setup()
{
Serial.begin(115200);
//pinMode(LED_BUILTIN, OUTPUT);
//pinMode(34, INPUT);
status = WiFi.begin(ssid, pass);
delay(1000);
status = WiFi.status();
while(status != WL_CONNECTED)
{
WiFi.begin(ssid, pass);
delay(1000);
status = WiFi.status();
Serial.println("Couldn't get a wifi connection\n");
}
Serial.println("Connected to wifi");
if (client.connect(server, port))
{
Serial.println("connected");
}
}
void loop()
{
if( WiFi.status() == WL_CONNECTED)
{
if (client.available()) {
//char c = client.read();
//Serial.write(c);
client.write("I am Esp30 Arduino");
delay(1000);
}
else
{
Serial.println("disconnecting from server.\n");
client.stop();
delay(1000);
client.connect(server, port);
}
}
}