/* 可作为AP服务,当一个客户端发来消息后,向所有客户端回发。
* 用这个服务转发所有收到的消息,客户端收到数据后,
* 通过客户端程序分析所收到的数据后有选择地进行动作,
* 同时客户端最好能回复动作成功与否,也就是结果状态。
* 这需要在客户端进行编程。
* ADUINO1.8.5下编译通过,ESP8266 01s 烧录运行。
*/
#include <ESP8266WiFi.h>
//定义可连接的客户端数目最大值
#define MAX_CLN 5
const char* ssid = "ESP8266_1";
const char* password = "88888888";
//WiFiServer server(23); // Open 23 port
WiFiServer server(8080); // Open 8080 port
WiFiClient Clients[MAX_CLN];
void HasCLN();
int ReadData(int i);
void SendData(int s);
void DoData();
const int bf = 64; //only read 64 byte
char buff[bf];
int ReadData(int i) //读取到buff[],并返回字节个数
{
int nm = 0;
while(Clients[i].available() && nm < bf)
buff[nm++] = Clients[i].read(); //ok,read a byte
return nm; //size of data byte read
}
void SendData(int s) //向所有客户端回发读取到的数据。 s is size of data byte read
{
// 将这个客户端收到的转发到各客户端和本串口
if (s !
ARDUINO 用 ESP8266 01s 做AP服务来中转数据
最新推荐文章于 2024-01-28 11:53:15 发布