我有一个基本的 websocket 代码,我在 8266 d1 minis 之间使用了几年。我想在 d1 mini 和通用 8285 板之间使用它,但是当我尝试时,websocket 无法连接。我尝试了几种不同的板,结果相同。8285 以 softap 模式作为 websocket 服务器运行的 8266 作为客户端运行。
我正在使用 aurdino IDE。
这是客户端代码(它只是一个测试例程。)
代码:
全选#include
#include
//#include ti.h>
#include
//#include
IPAddress remoteip(192,168,4,1);
//ESP8266WiFiMulti WiFiMulti;
WebSocketsClient webSocket;
static uint8_t bssid[]{0xA8, 0x48, 0xFA, 0xDC, 0xAC, 0xB8};
const char *ssid = "Universal"; //Name of the access point
const char *password = "lo******te"; //Password for the access point
IPAddress local_IP(192,168,8,22);
IPAddress gateway(192,168,8,9);
IPAddress subnet(255,255,255,0);
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
switch(type) {
case WStype_DISCONNECTED:
Serial.printf("[WSc] Disconnected!n");
break;
case WStype_CONNECTED: {
Serial.printf("[WSc] Connected to url: %sn", payload);
// send message to server when Connected
webSocket.sendTXT("*Dolgoch");
}
break;
case WStype_TEXT:
Serial.printf("[WSc] get text: %sn", payload);
break;
case WStype_BIN:
Serial.printf("bin recieved");Serial.println("");
break;
case WStype_PING:
Serial.printf("[WSc] get pingn");
break;
case WStype_PONG:
Serial.printf("[WSc] get pongn");
break;
}
}
void setup()
{
Serial.begin(115200);
Serial.println();
// Serial.print("Setting soft-AP configuration ... ");
// Serial.println(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Ready" : "Failed!");
// Serial.print("Setting soft-AP ... ");
// Serial.println(WiFi.softAP("ESPsoftAP_01") ? "Ready" : "Failed!");
// Serial.print("Soft-AP IP address = ");
// Serial.println(WiFi.softAPIP());
// WiFi.begin(ssid, password,11, bssid, true);
WiFi.begin(ssid, password);
while (WiFi.status() != 3)
{
delay(500);
Serial.print(WiFi.status());
}
delay(100);
webSocket.begin("192.168.4.1", 701, "/");
// event handler
webSocket.onEvent(webSocketEvent);
// try ever 5000 again if connection has failed
webSocket.setReconnectInterval(5000);
// start heartbeat (optional)
// ping server every 15000 ms
// expect pong from server within 3000 ms
// consider connection disconnected if pong is not received 2 times
webSocket.enableHeartbeat(15000, 3000, 2);
delay(2000);
}
void loop(){
webSocket.loop();
}
在 8266 上运行它给出:-
7777773[WSc] 连接到 url: /
[WSc] get ping
bin
received [WSc] get pong
[WSc] get pong
bin received bin
recieved
bin received
但在 8285 上与服务器相同的 8266给出:-
7777711111111111111111111
并且不连接。
status 1 is no ssid found
the signal strength is very good (-25db) on both d1 mini and 8285 (I use a 5/8 dipole as standard.)
我完全没有想法了。很高兴收到任何帮助。