Skip to content

Commit

Permalink
Add support for Wiz Smart Remote using #define USE_WIZMOTE and comm…
Browse files Browse the repository at this point in the history
…and `SetOption164 1`
  • Loading branch information
arendst committed Feb 12, 2025
1 parent 8621b9a commit c076331
Show file tree
Hide file tree
Showing 27 changed files with 2,255 additions and 13 deletions.
2 changes: 2 additions & 0 deletions BUILDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ Note: the `minimal` variant is not listed as it shouldn't be used outside of the
| USE_IR_RECEIVE | - | x / - | x | x | x | x |
| USE_IR_REMOTE_FULL | - | - / - | - | - | x | - | Enable ALL protocols |
| | | | | | | |
| USE_WIZMOTE | - | - / - | - | - | - | - |
| | | | | | | |
| USE_SR04 | - | - / - | - | x | - | - |
| USE_ME007 | - | - / - | - | - | - | - |
| USE_DYP | - | - / - | - | - | - | - |
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ All notable changes to this project will be documented in this file.
- Support for RC-switch decoding of 64-bit received data
- Berry `tasmota.defer()` (#22976)
- Support for Lithuanian language translations by zzdovydas (#22971)
- `MqttTLS` field in `Status 6` to indicate if the MQTT connection is encrypted
- `MqttTLS` field in `Status 6` to indicate if the MQTT connection is encrypted (#22995)
- Support for Wiz Smart Remote using `#define USE_WIZMOTE` and command `SetOption164 1`

### Breaking Changed

Expand Down
6 changes: 3 additions & 3 deletions CODE_OWNERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ In addition to @arendst the following code is mainly owned by:
| xdrv_71_magic_switch | @barbudor
| xdrv_72_pipsolar | @chefpro
| xdrv_73_lora | @arendst
| xdrv_74 |
| xdrv_74_lorawan | @arendst
| xdrv_75_dali | @eeak, @arendst
| xdrv_76 |
| xdrv_77 |
| xdrv_76_serial_i2c | @s-hadinger
| xdrv_77_wizmote | @arendst
| xdrv_78 |
| xdrv_79_esp32_ble | @staars, @btsimonh
| xdrv_81_esp32_webcam | @gemu, @philrich
Expand Down
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
- Support for ESP32 Two-Wire Automotive Interface (TWAI) or Controller Area Network (CAN) busses
- `#define FIX_JSON_HEXADECIMAL` to change JSON hexadecimal value "FF5F78" into "0xFF5F78" [#22919](https://github.com/arendst/Tasmota/issues/22919)
- Support for RC-switch decoding of 64-bit received data
- Support for Wiz Smart Remote using `#define USE_WIZMOTE` and command `SetOption164 1`
- `MqttTLS` field in `Status 6` to indicate if the MQTT connection is encrypted [#22995](https://github.com/arendst/Tasmota/issues/22995)
- Formatter `%_U` for `ext_snprintf_P()` to print uint64_t variable as decimal equivalent to `%llu`
- GPS driver select baudrate using GPIO GPS_RX1 (9600bps), GPS_RX2 (19200bps) or GPS_RX3 (38400bps) [#22869](https://github.com/arendst/Tasmota/issues/22869)
- I2S AAC support for web radio [#22787](https://github.com/arendst/Tasmota/issues/22787)
Expand Down
19 changes: 19 additions & 0 deletions lib/lib_div/QuickESPNow/LICENSE.md
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.
80 changes: 80 additions & 0 deletions lib/lib_div/QuickESPNow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Quick ESP-NOW

[![PlatformIO Registry](https://badges.registry.platformio.org/packages/gmag11/library/QuickEspNow.svg)](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 added lib/lib_div/QuickESPNow/Throughput.xlsx
Binary file not shown.
78 changes: 78 additions & 0 deletions lib/lib_div/QuickESPNow/examples/advancedespnow/advancedespnow.cpp
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 lib/lib_div/QuickESPNow/examples/basicespnow/basicespnow.cpp
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);

}

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");
}

}

}
Loading

0 comments on commit c076331

Please sign in to comment.