-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Wiz Smart Remote using
#define USE_WIZMOTE
and comm…
…and `SetOption164 1`
- Loading branch information
Showing
27 changed files
with
2,255 additions
and
13 deletions.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) 2022 gmag11@github | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | ||
OR OTHER DEALINGS IN THE SOFTWARE. |
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,80 @@ | ||
# Quick ESP-NOW | ||
|
||
[](https://registry.platformio.org/libraries/gmag11/QuickEspNow) | ||
|
||
## Introduction | ||
|
||
This fork includes a change to the rx_cb signature for compatibility with the 5.x Espressif IDF. | ||
|
||
This is a library for Arduino framework to be used with Espressif ESP8266 and ESP32 series microcontrollers. | ||
|
||
ESP-NOW is a wireless communication protocol that allows two devices to send data to each other without the need for a wireless network. You can read more about it here [https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_now.html](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_now.html) | ||
|
||
## Benefits | ||
|
||
Usage of ESP-NOW may not be straightforward. There are some restrictions that has to be considered, as limit of number of devices, WiFi channel selection, and other factors. | ||
|
||
This library pretends to hide all that restrictions so that it can be used with just a few lines of code. | ||
|
||
Besides, it removes some limitations: | ||
|
||
- No more 20 devices limit. You can use ESP-NOW with **any number of devices**. Library takes control of peer registration and makes it transparent to you. | ||
- Channel selection is not required for WiFi coexistence. | ||
- No need to assign a role to each device. Just use it for peer to peer communication. | ||
- **RSSI** information of every message, so that receiver can estimate how close the sender is. | ||
- Receiver can distiguish between broadcast and unicast messages. | ||
- Tested maximum througput, about 600 kbps continuous with default parameters. | ||
- Encryption is not supported. Usage of ESP-NOW encryption restrict system to 6 devices. You can implement data encryption in a higher layer. | ||
- Asynchronous Sending Mode: The send method now supports a blocking mode, returning a value only after the message send has been confirmed. It returns 0 if the message was sent successfully and a different value if there was an error. This feature ensures reliable message delivery by waiting for confirmation before proceeding withour the user needing to implement a TX callback function. | ||
It is importatnt to know that the best performance is achieved when using asynchronous mode, as it allows the library to send messages in the background while the user code continues to run. The synchronous mode is provided for users who require a blocking send method for ease of use. | ||
- Default Mode Change: For ease of use, the asynchronous mode is now the default configuration. This mode can be set during the `begin` function call, streamlining the setup process for new projects. This change aims to simplify the initial configuration for developers by automatically opting for the more user-friendly synchronous sending mode. If you require best performance, you can still change the mode to asynchronous by calling `begin` function with the proper parameter. | ||
|
||
## Performance | ||
|
||
I include this table to show the performance of the library. It was tested with ESP32 and ESP8266, sending messages as fastest as possible. The test has been repeated with different message lengths and using synchronous and asynchronous modes. | ||
|
||
| Device | broadcast/unicast | sync/async | 250 bytes | 125 bytes | 75 bytes | 35 bytes | 12 bytes | | ||
|--------|-------------------|------------|-----------|-----------|----------|----------|-----------| | ||
| ESP32 | broadcast | async | 640 kbps | 450 kbps | 340 kbps | 190 kbps | 75 kbps | | ||
| ESP32 | broadcast | sync | 615 kbps | 440 kbps | 320 kbps | 180 kbps | 73 kbps | | ||
| ESP8266| broadcast | async | 200 kbps | 100 kbps | 60 kbps | 28 kbps | 9.5 kbps | | ||
| ESP8266| broadcast | sync | 200 kbps | 100 kbps | 60 kbps | 28 kbps | 9.5 kbps | | ||
| ESP32 | unicast | async | 570 kbps | 400 kbps | 285 kbps | 160 kbps | 60 kbps | | ||
| ESP32 | unicast | sync | 550 kbps | 375 kbps | 270 kbps | 150 kbps | 57 kbps | | ||
| ESP8266| unicast | async | 200 kbps | 100 kbps | 60 kbps | 28 kbps | 9.5 kbps | | ||
| ESP8266| unicast | sync | 200 kbps | 100 kbps | 60 kbps | 28 kbps | 9.5 kbps | | ||
|
||
**Note** : In previous versions of the library, esp8266 was able to send messages at 600 kBps, but it was a mistake. The actual performance is 200 kbps. The table has been updated to reflect the correct values. It was due a to a missing check to avoid sending a message before the previous one was confirmed. This check has been added in version 0.8.1. | ||
It seems that this check is not completely mandarory and both ESP8266 and ESP32 are able to send messages correctly even if latest one has not been confirmed. I will investigate what implications this may have and if it is possible to (optionally) remove this check in future versions. | ||
|
||
Please note that these maximum values represent the best-case scenario without any message loss, assuming the microcontroller is not running any other tasks. | ||
|
||
However, it's important to consider that in synchronous mode, where the user code is blocked until the message is sent (which can take from 1 to 20 ms), the actual performance may be significantly lower depending on the rest of the code. | ||
|
||
On the other hand, in asynchronous mode, the `send` function returns in just 22us for both ESP32 and ESP8266, so it is not expected to have a significant impact on the rest of the code. | ||
|
||
Please note that the performance of ESP8266 is lower than ESP32. This may cause problems if an ESP32 is sending messages at a higher rate than the ESP8266 can handle. In such cases, the receiver may lose messages or even crash. If you need to use both devices in the same network, it is recommended to keep the message rate at a safe level for the slowest device. | ||
|
||
## Usage | ||
|
||
To get started with Quick ESP-NOW, simply call the `begin` function and set a receiving callback function if you need to receive data. Then, you can use the `send` function to send data to a specific device or use `ESPNOW_BROADCAST_ADDRESS` to send data to all listening devices on the same channel. | ||
|
||
```C++ | ||
void dataReceived (uint8_t* address, uint8_t* data, uint8_t len, signed int rssi, bool broadcast) { | ||
Serial.printf("Received message: %.*s\n", len, data); | ||
} | ||
|
||
void setup () { | ||
Serial.begin (115200); | ||
WiFi.mode (WIFI_MODE_STA); | ||
WiFi.disconnect (false); | ||
quickEspNow.onDataRcvd (dataReceived); | ||
quickEspNow.begin (1); // If you are not connected to WiFi, channel should be specified | ||
} | ||
|
||
void loop () { | ||
String message = "Hello, world!"; | ||
quickEspNow.send (DEST_ADDR, (uint8_t*)message.c_str (), message.length ()); | ||
delay (1000); | ||
} | ||
``` |
Binary file not shown.
78 changes: 78 additions & 0 deletions
78
lib/lib_div/QuickESPNow/examples/advancedespnow/advancedespnow.cpp
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,78 @@ | ||
#include <Arduino.h> | ||
#if defined ESP32 | ||
#include <WiFi.h> | ||
#include <esp_wifi.h> | ||
#elif defined ESP8266 | ||
#include <ESP8266WiFi.h> | ||
#define WIFI_MODE_STA WIFI_STA | ||
#else | ||
#error "Unsupported platform" | ||
#endif //ESP32 | ||
#include <QuickEspNow.h> | ||
|
||
static const String msg = "Hello ESP-NOW!"; | ||
|
||
#define USE_BROADCAST 1 // Set this to 1 to use broadcast communication | ||
|
||
#if USE_BROADCAST != 1 | ||
// set the MAC address of the receiver for unicast | ||
static uint8_t receiver[] = { 0x12, 0x34, 0x56, 0x78, 0x90, 0x12 }; | ||
#define DEST_ADDR receiver | ||
#else //USE_BROADCAST != 1 | ||
#define DEST_ADDR ESPNOW_BROADCAST_ADDRESS | ||
#endif //USE_BROADCAST != 1 | ||
|
||
bool sent = true; | ||
|
||
const unsigned int SEND_MSG_MSEC = 2000; | ||
|
||
void dataSent (uint8_t* address, uint8_t status) { | ||
sent = true; | ||
Serial.printf ("Message sent to " MACSTR ", status: %d\n", MAC2STR (address), status); | ||
} | ||
|
||
void dataReceived (uint8_t* address, uint8_t* data, uint8_t len, signed int rssi, bool broadcast) { | ||
Serial.print ("Received: "); | ||
Serial.printf ("%.*s\n", len, data); | ||
Serial.printf ("RSSI: %d dBm\n", rssi); | ||
Serial.printf ("From: " MACSTR "\n", MAC2STR (address)); | ||
Serial.printf ("%s\n", broadcast ? "Broadcast" : "Unicast"); | ||
} | ||
|
||
void setup () { | ||
Serial.begin (115200); | ||
WiFi.mode (WIFI_MODE_STA); | ||
#if defined ESP32 | ||
WiFi.disconnect (false, true); | ||
#elif defined ESP8266 | ||
WiFi.disconnect (false); | ||
#endif //ESP32 | ||
|
||
Serial.printf ("Connected to %s in channel %d\n", WiFi.SSID ().c_str (), WiFi.channel ()); | ||
Serial.printf ("IP address: %s\n", WiFi.localIP ().toString ().c_str ()); | ||
Serial.printf ("MAC address: %s\n", WiFi.macAddress ().c_str ()); | ||
quickEspNow.begin (1, 0, false); | ||
quickEspNow.onDataSent (dataSent); | ||
quickEspNow.onDataRcvd (dataReceived); | ||
} | ||
|
||
void loop () { | ||
static time_t lastSend = 0; | ||
static unsigned int counter = 0; | ||
|
||
// Sent flag is needed to wait for the message to be actually sent. Avoids messages dropping, maximizing throughput. | ||
// readyToSendData() is used to avoid sending messages too fast, which can lead to messages dropping. | ||
if (quickEspNow.readyToSendData() && sent && ((millis () - lastSend) > SEND_MSG_MSEC)) { | ||
lastSend = millis (); | ||
String message = String (msg) + " " + String (counter++); | ||
sent = false; | ||
if (!quickEspNow.send (DEST_ADDR, (uint8_t*)message.c_str (), message.length ())) { | ||
Serial.printf (">>>>>>>>>> Message sent\n"); | ||
} else { | ||
Serial.printf (">>>>>>>>>> Message not sent\n"); | ||
sent = true; // In case of error we need to set the flag to true to avoid blocking the loop | ||
} | ||
|
||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
lib/lib_div/QuickESPNow/examples/basicespnow/basicespnow.cpp
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,67 @@ | ||
#include <Arduino.h> | ||
#if defined ESP32 | ||
#include <WiFi.h> | ||
#include <esp_wifi.h> | ||
#elif defined ESP8266 | ||
#include <ESP8266WiFi.h> | ||
#define WIFI_MODE_STA WIFI_STA | ||
#else | ||
#error "Unsupported platform" | ||
#endif //ESP32 | ||
#include <QuickEspNow.h> | ||
|
||
static const String msg = "Hello ESP-NOW!"; | ||
|
||
#define USE_BROADCAST 1 // Set this to 1 to use broadcast communication | ||
|
||
#if USE_BROADCAST != 1 | ||
// set the MAC address of the receiver for unicast | ||
static uint8_t receiver[] = { 0x12, 0x34, 0x56, 0x78, 0x90, 0x12 }; | ||
#define DEST_ADDR receiver | ||
#else //USE_BROADCAST != 1 | ||
#define DEST_ADDR ESPNOW_BROADCAST_ADDRESS | ||
#endif //USE_BROADCAST != 1 | ||
|
||
// Send message every 2 seconds | ||
const unsigned int SEND_MSG_MSEC = 2000; | ||
|
||
void dataReceived (uint8_t* address, uint8_t* data, uint8_t len, signed int rssi, bool broadcast) { | ||
Serial.print ("Received: "); | ||
Serial.printf ("%.*s\n", len, data); | ||
Serial.printf ("RSSI: %d dBm\n", rssi); | ||
Serial.printf ("From: " MACSTR "\n", MAC2STR (address)); | ||
Serial.printf ("%s\n", broadcast ? "Broadcast" : "Unicast"); | ||
} | ||
|
||
void setup () { | ||
Serial.begin (115200); | ||
WiFi.mode (WIFI_MODE_STA); | ||
#if defined ESP32 | ||
WiFi.disconnect (false, true); | ||
#elif defined ESP8266 | ||
WiFi.disconnect (false); | ||
#endif //ESP32 | ||
Serial.printf ("Connected to %s in channel %d\n", WiFi.SSID ().c_str (), WiFi.channel ()); | ||
Serial.printf ("IP address: %s\n", WiFi.localIP ().toString ().c_str ()); | ||
Serial.printf ("MAC address: %s\n", WiFi.macAddress ().c_str ()); | ||
quickEspNow.onDataRcvd (dataReceived); | ||
#ifdef ESP32 | ||
quickEspNow.setWiFiBandwidth (WIFI_IF_STA, WIFI_BW_HT20); // Only needed for ESP32 in case you need coexistence with ESP8266 in the same network | ||
#endif //ESP32 | ||
quickEspNow.begin (1); // If you use no connected WiFi channel needs to be specified | ||
} | ||
|
||
void loop () { | ||
static unsigned int counter = 0; | ||
|
||
String message = String (msg) + " " + String (counter++); | ||
if (!quickEspNow.send (DEST_ADDR, (uint8_t*)message.c_str (), message.length ())) { | ||
Serial.println (">>>>>>>>>> Message sent"); | ||
} else { | ||
Serial.println (">>>>>>>>>> Message not sent"); | ||
} | ||
|
||
delay (SEND_MSG_MSEC); | ||
|
||
} | ||
|
70 changes: 70 additions & 0 deletions
70
lib/lib_div/QuickESPNow/examples/wifi_ap_and_espnow/wifi_ap_and_espnow.cpp
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,70 @@ | ||
#include <Arduino.h> | ||
#if defined ESP32 | ||
#include <WiFi.h> | ||
#include <esp_wifi.h> | ||
#elif defined ESP8266 | ||
#include <ESP8266WiFi.h> | ||
#define WIFI_MODE_STA WIFI_STA | ||
#define WIFI_MODE_AP WIFI_AP | ||
#else | ||
#error "Unsupported platform" | ||
#endif //ESP32 | ||
#include <QuickEspNow.h> | ||
|
||
static const String msg = "Hello esp-now from TTGO"; | ||
|
||
#define USE_BROADCAST 1 // Set this to 1 to use broadcast communication | ||
|
||
#if USE_BROADCAST != 1 | ||
// set the MAC address of the receiver for unicast | ||
static uint8_t receiver[] = { 0x12, 0x34, 0x56, 0x78, 0x90, 0x12 }; | ||
#define DEST_ADDR receiver | ||
#else //USE_BROADCAST != 1 | ||
#define DEST_ADDR ESPNOW_BROADCAST_ADDRESS | ||
#endif //USE_BROADCAST != 1 | ||
|
||
static const uint8_t CHANNEL = 1; | ||
|
||
void dataReceived (uint8_t* address, uint8_t* data, uint8_t len, signed int rssi, bool broadcast) { | ||
Serial.print ("Received: "); | ||
Serial.printf ("%.*s\n", len, data); | ||
Serial.printf ("RSSI: %d dBm\n", rssi); | ||
Serial.printf ("From: " MACSTR "\n", MAC2STR (address)); | ||
Serial.printf ("%s\n", broadcast ? "Broadcast" : "Unicast"); | ||
} | ||
|
||
void setup () { | ||
Serial.begin (115200); | ||
if (!WiFi.mode (WIFI_MODE_AP)) { | ||
Serial.println ("WiFi mode not supported"); | ||
} | ||
if (!WiFi.softAP ("espnowAP", "1234567890", CHANNEL)) { | ||
Serial.println ("WiFi access point not started"); | ||
} | ||
|
||
Serial.printf ("Started AP %s in channel %d\n", WiFi.softAPSSID ().c_str (), WiFi.channel ()); | ||
Serial.printf ("IP address: %s\n", WiFi.softAPIP ().toString ().c_str ()); | ||
Serial.printf ("MAC address: %s\n", WiFi.softAPmacAddress ().c_str ()); | ||
#ifdef ESP32 | ||
quickEspNow.setWiFiBandwidth (WIFI_IF_AP, WIFI_BW_HT20); // Only needed for ESP32 in case you need coexistence with ESP8266 in the same network | ||
#endif //ESP32 | ||
quickEspNow.onDataRcvd (dataReceived); | ||
quickEspNow.begin (CURRENT_WIFI_CHANNEL, WIFI_IF_AP); // Same channel must be used for both AP and ESP-NOW | ||
} | ||
|
||
void loop () { | ||
static time_t lastSend = 60000; | ||
static unsigned int counter = 0; | ||
|
||
if (millis () - lastSend >= 1000) { | ||
lastSend = millis (); | ||
String message = String (msg) + " " + String (counter++); | ||
if (!quickEspNow.send (DEST_ADDR, (uint8_t*)message.c_str (), message.length ())) { | ||
Serial.printf (">>>>>>>>>> Message sent\n"); | ||
} else { | ||
Serial.printf (">>>>>>>>>> Message not sent\n"); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.