简体   繁体   English

带有PHP WebSockets服务器的Arduino WebSockets客户端

[英]Arduino WebSockets Client with PHP WebSockets server

I'm developing a system that requires Websockets establishment between the client and the server. 我正在开发一个需要在客户端和服务器之间建立Websockets的系统。 I followed this example: 我按照这个例子:

https://github.com/krohling/ArduinoWebsocketClient https://github.com/krohling/ArduinoWebsocketClient

The echo server is not replying back. echo服务器没有回复。 This is my code: 这是我的代码:

#include "Arduino.h"
#include <Ethernet.h>
#include <SPI.h>
#include <WebSocketClient.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "echo.websocket.org";
WebSocketClient client;

void setup() {
  Serial.begin(9600);
  Ethernet.begin(mac);
  client.connect(server);
  client.setDataArrivedDelegate(dataArrived);
  client.send("Hello World!");
}

void loop() {
  client.monitor();
}

void dataArrived(WebSocketClient client, String data) {
  Serial.println("Data Arrived: " + data);
}

Can anybody tell me why this isn't working? 谁能告诉我为什么这不起作用?

Depending on the Ethernet shield you are using, you should replace #include <Ethernet.h> by #include <Ethernet2.h> . 根据您使用的以太网屏蔽,您应该用#include <Ethernet.h>替换#include <Ethernet2.h>

Ethernet 以太网络

Ethernet2 接口Ethernet2

The Ethernet2 library is only on the arduino IDE from arduino.org and not from arduino.cc Ethernet2库仅在arduino.org的arduino IDE上,而不在arduino.cc上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM