-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <WiFi.h> | ||
#include <AsyncTCP.h> | ||
#include <AsyncWebSocket.h> | ||
|
||
const char* ssid = "YourWiFiSSID"; | ||
const char* password = "YourWiFiPassword"; | ||
|
||
AsyncWebSocket ws("/ws"); | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
WiFi.begin(ssid, password); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.println("Connecting to WiFi..."); | ||
} | ||
Serial.println("Connected to WiFi"); | ||
|
||
ws.onEvent([](AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) { | ||
if (type == WS_EVT_CONNECT) { | ||
Serial.println("WebSocket client connected"); | ||
} | ||
}); | ||
|
||
ws.begin(); | ||
} | ||
|
||
void loop() { | ||
// Send data to WebSocket server periodically | ||
ws.textAll("Hello from ESP32!"); | ||
delay(5000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
REST API (HTTP): | ||
RESTful APIs are widely used for communication between clients and servers over HTTP. | ||
They are well-suited for request-response interactions and are easy to understand and implement. | ||
However, they may not be the best choice for real-time communication as they are based on the request-response model, which can introduce latency and overhead for real-time updates. | ||
REST APIs are suitable for scenarios where real-time updates are not critical or where the frequency of updates is low. | ||
|
||
WebSockets: | ||
WebSockets provide full-duplex communication channels over a single TCP connection, enabling real-time, bidirectional communication between clients and servers. | ||
They offer low-latency, high-performance communication and are well-suited for applications requiring real-time updates, such as chat applications, live dashboards, and multiplayer games. | ||
WebSockets can be more complex to implement compared to REST APIs, but they offer significant benefits for real-time applications. | ||
|
||
MQTT (Message Queuing Telemetry Transport): | ||
MQTT is a lightweight, publish-subscribe messaging protocol designed for constrained devices and low-bandwidth, high-latency or unreliable networks. | ||
It provides a flexible and efficient mechanism for asynchronous, real-time communication between clients and servers. | ||
MQTT is commonly used in IoT (Internet of Things) applications, telemetry systems, and messaging applications where real-time data streams need to be transmitted reliably and efficiently. | ||
While MQTT can be used for real-time communication in various scenarios, it may not be as widely supported or as easy to integrate as REST APIs or WebSockets in certain contexts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters