Compare commits
195 Commits
release-1.
...
master
| Author | SHA1 | Date |
|---|---|---|
|
|
d6fcc50a0b | |
|
|
c6e032b5af | |
|
|
144559f6d6 | |
|
|
f3066ea9c6 | |
|
|
875c53f8fd | |
|
|
7494e0bb22 | |
|
|
e23247c39f | |
|
|
212370f57c | |
|
|
767a125a70 | |
|
|
40e8dcbec2 | |
|
|
beee92f6ee | |
|
|
aad5d26c5b | |
|
|
e522e709c9 | |
|
|
b6ed73aed1 | |
|
|
8f133585f9 | |
|
|
e6b57b6723 | |
|
|
2a91ed645a | |
|
|
a3891cd983 | |
|
|
d9af8032a4 | |
|
|
dbe07dad7e | |
|
|
3ed18b3f79 | |
|
|
a223d3046a | |
|
|
b8338cad71 | |
|
|
1b93c7e75b | |
|
|
d7dbb5fee5 | |
|
|
970f4d7ce8 | |
|
|
9b791e2ac3 | |
|
|
f73c779913 | |
|
|
2d25c044ae | |
|
|
7a13b99942 | |
|
|
c3c32dbc07 | |
|
|
2279c30510 | |
|
|
7de8f1abb4 | |
|
|
463bdd4cda | |
|
|
8e2304bacb | |
|
|
9653224aca | |
|
|
c1b2d49da1 | |
|
|
b4a32e82bb | |
|
|
c0d1a93c52 | |
|
|
901807e47a | |
|
|
f09499359b | |
|
|
e10025bd54 | |
|
|
7ab8354ed7 | |
|
|
892c2247a3 | |
|
|
983e159adf | |
|
|
153ab451fd | |
|
|
9d29b73dac | |
|
|
cce2dc59b4 | |
|
|
dbfad7d222 | |
|
|
3643506d89 | |
|
|
e0ec162938 | |
|
|
747b8c3244 | |
|
|
be4825dacb | |
|
|
214286f4de | |
|
|
80a8935828 | |
|
|
8775a2df85 | |
|
|
1863cc4309 | |
|
|
d523a27124 | |
|
|
638285f48f | |
|
|
a52a2ad432 | |
|
|
4af2bdbbe3 | |
|
|
0c22bfb752 | |
|
|
2bdafb534e | |
|
|
7843ce49a5 | |
|
|
bdf25cbaf9 | |
|
|
96a08ea84b | |
|
|
1267603e71 | |
|
|
a8883c911d | |
|
|
db80dab963 | |
|
|
74d27485d5 | |
|
|
ee2e850505 | |
|
|
7a796bac2f | |
|
|
012c778f15 | |
|
|
0eec3920f4 | |
|
|
d2d1b79c4d | |
|
|
a92f73666a | |
|
|
3273f7f24d | |
|
|
a785c1f937 | |
|
|
3db4676b7d | |
|
|
20f74aa968 | |
|
|
c7f67225d6 | |
|
|
0be3b0cd1b | |
|
|
050a30f72c | |
|
|
4e5d03f63f | |
|
|
04cb07a0fc | |
|
|
059c58ca46 | |
|
|
4334789d50 | |
|
|
fa25369ebb | |
|
|
ccda8f04d9 | |
|
|
b995a75907 | |
|
|
998bd873bc | |
|
|
bfdf114ed3 | |
|
|
d51b74e1c1 | |
|
|
aa9d64cb58 | |
|
|
e83df601b2 | |
|
|
e0f593bc2e | |
|
|
d9e9783dc1 | |
|
|
e6c7637825 | |
|
|
b4bfac54e7 | |
|
|
173ba036f0 | |
|
|
15a0396897 | |
|
|
cd3b525dbb | |
|
|
f96721b948 | |
|
|
520a4f3df0 | |
|
|
9b0555d256 | |
|
|
b05be87a29 | |
|
|
dfec533212 | |
|
|
04443d70dd | |
|
|
2ecbed9f26 | |
|
|
6794a804f9 | |
|
|
64f67fbb8a | |
|
|
bb531184d7 | |
|
|
d1dd565478 | |
|
|
723c343277 | |
|
|
b9efa873dc | |
|
|
fe3269e9ef | |
|
|
73561328e6 | |
|
|
a7d57699a0 | |
|
|
e4df56293a | |
|
|
48cab1f82b | |
|
|
28990d6ed6 | |
|
|
7a50479bac | |
|
|
5ded77d6d9 | |
|
|
d40d709643 | |
|
|
acebaf6caa | |
|
|
7e2625034c | |
|
|
75cbf9715f | |
|
|
3d4b02e492 | |
|
|
1892a0a5a2 | |
|
|
f137b0bee5 | |
|
|
eb821f002f | |
|
|
cbe26c7c41 | |
|
|
11bd605a03 | |
|
|
f6d4d37ff7 | |
|
|
e8f9ca8ac1 | |
|
|
69fd86f2ef | |
|
|
1b74564baf | |
|
|
a11eab4b37 | |
|
|
9b0b18310e | |
|
|
7c5b01e967 | |
|
|
6bc45cf884 | |
|
|
41f755039f | |
|
|
faa99e0fbb | |
|
|
8ce80157b3 | |
|
|
181c5e99b2 | |
|
|
cf2a98d1c2 | |
|
|
2d1b567388 | |
|
|
7a58a20de1 | |
|
|
04a10309c2 | |
|
|
aa6f3690a4 | |
|
|
52e7bfef2b | |
|
|
16f3e9d146 | |
|
|
0f10d9354d | |
|
|
1510718e65 | |
|
|
d441f81548 | |
|
|
be893b0968 | |
|
|
38e0b1efea | |
|
|
e3e0b11717 | |
|
|
24f36bbccb | |
|
|
3bb9df4818 | |
|
|
6011d09e8d | |
|
|
0d404ccf1b | |
|
|
c17fabe326 | |
|
|
959e3cbcde | |
|
|
b6c479eafc | |
|
|
8aec89c0fd | |
|
|
e708d1d148 | |
|
|
c16e0612be | |
|
|
a0bf2c8c8a | |
|
|
0cf12f3331 | |
|
|
218e1f6611 | |
|
|
42e174e3cd | |
|
|
c6183ff20f | |
|
|
b0fa52858f | |
|
|
51385874e4 | |
|
|
13657d45b4 | |
|
|
6bc1483dcb | |
|
|
694723b959 | |
|
|
d10f73e3c7 | |
|
|
3563dc109a | |
|
|
84b3d29954 | |
|
|
e118061cff | |
|
|
7e9e432991 | |
|
|
831d3640cc | |
|
|
30163c1214 | |
|
|
2e1c4cf7a0 | |
|
|
8baf70994d | |
|
|
42156b1622 | |
|
|
a10f00c721 | |
|
|
3cb2e16418 | |
|
|
6ff9de03c9 | |
|
|
b0dbf02227 | |
|
|
15149eb8d7 | |
|
|
bde6b6b5a8 | |
|
|
03400653da |
129
README.md
129
README.md
|
|
@ -4,7 +4,12 @@ Welcome to HomeSpan - a robust and extremely easy-to-use Arduino library for cre
|
|||
|
||||
HomeSpan provides a microcontroller-focused implementation of Apple's HomeKit Accessory Protocol Specification Release R2 (HAP-R2) designed specifically for the Espressif ESP32 microcontroller running within the Arduino IDE. HomeSpan pairs directly to HomeKit via your home WiFi network without the need for any external bridges or components. With HomeSpan you can use the full power of the ESP32's I/O functionality to create custom control software and/or hardware to automatically operate external devices from the Home App on your iPhone, iPad, or Mac, or with Siri.
|
||||
|
||||
HomeSpan requires version 2.0.0 or later of the [Arduino-ESP32 Board Manager](https://github.com/espressif/arduino-esp32), and has been tested up through version 2.0.7 (recommended). HomeSpan can be run on the original ESP32 as well as Espressif's ESP32-S2, ESP32-C3, and ESP32-S3 chips.
|
||||
HomeSpan requires version 2 of the [Arduino-ESP32 Board Manager](https://github.com/espressif/arduino-esp32). HomeSpan can be run on the original ESP32 as well as Espressif's ESP32-S2, ESP32-C3, and ESP32-S3 chips.
|
||||
|
||||
HomeSpan is currently NOT compatible with version 3.X of the Arduino-ESP32 Board Manager, since version 3 contains many breaking changes and is not backwards-compatible with version 2.X of the Arduino-ESP32 Board Manager. At present, HomeSpan can only be compiled under version 2.X of the Board Manager.
|
||||
|
||||
> [!NOTE]
|
||||
> Apple's new HomeKit architecture [requires the use of a Home Hub](https://support.apple.com/en-us/HT207057) (either a HomePod or Apple TV) for full and proper operation of any HomeKit device, including those based on HomeSpan. Without a Home Hub, HomeSpan cannot send notifications to the Home App - things like pushbuttons and temperature sensors will not be able to transmit updates to the Home App. Use of HomeSpan without a Home Hub is NOT recommended.
|
||||
|
||||
### HomeSpan Highlights
|
||||
|
||||
|
|
@ -12,7 +17,7 @@ HomeSpan requires version 2.0.0 or later of the [Arduino-ESP32 Board Manager](ht
|
|||
* Utilizes a unique *Service-Centric* approach to creating HomeKit devices
|
||||
* Takes full advantage of the widely-popular Arduino IDE
|
||||
* 100% HAP-R2 compliance
|
||||
* 41 integrated HomeKit Services
|
||||
* Dozens of integrated HomeKit Services
|
||||
* Operates in either Accessory or Bridge mode
|
||||
* Supports pairing with Setup Codes or QR Codes
|
||||
|
||||
|
|
@ -32,7 +37,7 @@ HomeSpan requires version 2.0.0 or later of the [Arduino-ESP32 Board Manager](ht
|
|||
* Integrated access to the ESP32's on-chip Remote Control peripheral for easy generation of IR and RF signals
|
||||
* Dedicated classes to control one- and two-wire addressable RGB and RGBW LEDs and LED strips
|
||||
* Dedicated classes to control stepper motors that can run smoothly in the background without interfering with HomeSpan
|
||||
* Dedicated class that faciliates seemless point-to-point communication between ESP32 devices using ESP-NOW
|
||||
* Dedicated class that faciliates seamless point-to-point communication between ESP32 devices using ESP-NOW
|
||||
* Integrated Web Log for user-defined log messages
|
||||
* Extensively-commented Tutorial Sketches taking you from the very basics of HomeSpan through advanced HomeKit topics
|
||||
* Additional examples and projects showcasing real-world implementations of HomeSpan
|
||||
|
|
@ -49,40 +54,97 @@ HomeSpan requires version 2.0.0 or later of the [Arduino-ESP32 Board Manager](ht
|
|||
* Launch the WiFi Access Point
|
||||
* A standalone, detailed End-User Guide
|
||||
|
||||
## ❗Latest Update - HomeSpan 1.8.0 (7/8/2023)
|
||||
## ❗Latest Update - HomeSpan 1.9.1 (07/03/2024)
|
||||
|
||||
* **New Stepper Motor Control!**
|
||||
* **HomeSpan now supports *Tag-Length-Value ("TLV8")* Characteristics!**
|
||||
|
||||
* adds new **StepperControl** class that allows for smooth, uninterrupted operation of one or more stepper motors running in the background while HomeSpan continues to run simultaneously in the foreground
|
||||
* supports driver boards with or without PWM, including microstepping modes
|
||||
* supports automatic acceleration and deceleration for smooth starts and stops
|
||||
* motors can be set to an absolute position or instructucted to move a specified number of steps
|
||||
* provides options to automatically enter into a "brake" state after motor stops to conserve power
|
||||
* includes a fully worked example of a motorized window shade
|
||||
* see [Stepper Motor Control](docs/Stepper.md) for details
|
||||
|
||||
* **Upgrades to HomeSpan Web Log output**
|
||||
|
||||
* adds new method `void homeSpan.setWebLogCSS(const char *css)` that allows you to define *Custom Style Sheets (CSS)* for the Web Log text, tables, and background
|
||||
* adds version numbers for the Sodium and MbedTLS libraries, HomeKit pairing status, and a text description of Reset Reason code
|
||||
* see [Message Logging](docs/Logging.md) for details
|
||||
|
||||
* **Upgrades to Web Log Time Server initialization**
|
||||
|
||||
* the process for retrieving the time and date from an NTP server upon booting now runs in the background as a separate task
|
||||
* HomeSpan is no longer blocked from running during the NTP query
|
||||
|
||||
* **Adds new methods to disable HomeSpan's use of the USB Serial port**
|
||||
* adds new, fully-integrated `TLV8()` class library for the creation and management of TLV8 objects
|
||||
* includes methods to handle standard byte-stream VALUES as well as strings, numerical values, zero-length tags, and sub-TLVs
|
||||
* utilizes standard C++ iterators for easy access to reading and writing TLV8 records
|
||||
* adds new `Characteristic` methods `getTLV()`, `getNewTLV()`, and `setTLV()`
|
||||
* adds new `CUSTOM_CHAR_TLV8()` that allows for easy creation of custom TLV8 Characteristics
|
||||
* includes new [Tutorial Example 22 - TLV8 Characteristics](examples/22-TLV8_Characteristics) demonstrating use of the `TLV8()` class and TLV8 Characteristics
|
||||
* see the new [TLV8 Characteristics](docs/TLV8.md) page for complete details and documentation
|
||||
|
||||
* **New *DisplayOrder* TLV8 Characteristic**
|
||||
|
||||
* new Log Level, -1, causes HomeSpan to suppress all OUTPUT messages
|
||||
* new homeSpan method `setSerialInputDisable(boolean val)` disables/re-enables HomeSpan's reading of CLI commands INPUT into the Arduino Serial Monitor
|
||||
* utlizes HomeSpan's new `TLV8()` library
|
||||
* allows you to specify the exact order in which the Input Sources for a Television Service are displayed in the Home App
|
||||
* see [Tutorial Example 22 - TLV8 Characteristics](examples/22-TLV8_Characteristics) for details
|
||||
|
||||
* **New *AccessoryIdentifier* Tutorial**
|
||||
|
||||
* **Adds ability to use a non-standard LED as the HomeSpan Status LED**
|
||||
* demonstrates how to trigger an Accessory's Identifier Characteristic, optionally used to help identify a device during initial pairing
|
||||
* see [Tutorial Example 21 - AccessoryIdentifier](examples/21-AccessoryIdentifier)
|
||||
|
||||
* new homeSpan method `setStatusDevice(Blinkable *sDev)` sets the Status LED to the Blinkable object *sDev*
|
||||
* allows an LED connected to a pin expander, or any other non-standard LED controller (such as an inverted LED that lights when a pin is LOW instead of HIGH) to be used as the HomeSpan Status LED
|
||||
* see [Blinkable.md](docs/Blinkable.md) for details (including an example) on how to create Blinkable objects
|
||||
* **Added support for customizing Pixel chips**
|
||||
|
||||
* new constructor `Pixel(uint8_t pin, [pixelType_t pixelType])` allows your to set the order in which colors are transmitted to the pixel chip, where *pixelType* is one of the following:
|
||||
* PixelType::RGB, PixelType::RBG, PixelType::BRG, PixelType::BGR, PixelType::GBR, PixelType::GRB
|
||||
* PixelType::RGBW, PixelType::RBGW, PixelType::BRGW, PixelType::BGRW, PixelType::GBRW, PixelType::GRBW*
|
||||
* deprecated previous constructor `Pixel(uint8_t pin, boolean isRGBW)`
|
||||
* this constructor will continue to work, but you will receive a warning during compilation that it has been deprecated
|
||||
* users should switch to the new constructor to avoid potential compatibility issues with future versions of HomeSpan
|
||||
* added new method `boolean isRGBW()`
|
||||
* returns *true* if Pixel was constructed as RGBW, else *false* if constructed as RGB only (i.e. no white LED)
|
||||
* added new [PixelTester](examples/Other%20Examples/PixelTester) sketch (found under *Other Examples*) to aid in determining the *pixelType* for any LED Strip
|
||||
* see the [Adressable RGB LEDs](docs/Pixels.md) page for details
|
||||
|
||||
* **New ability to read and set the IIDs of Services and Characteristics**
|
||||
|
||||
* adds new `SpanService` method `getIID()` that returns the IID of a Service
|
||||
* adds new `SpanCharacteristic` method `getIID()` that returns the IID of a Characteristic
|
||||
* adds new `homeSpan` method `resetIID(int newIID)` that resets the IID count for the current Accessory
|
||||
* see the [API Reference](docs/Reference.md) for details
|
||||
|
||||
* **New ability to read Controller pairing data (for advanced use-cases only)**
|
||||
|
||||
* adds new `homeSpan` methods `controllerListBegin()` and `controllerListEnd()` that returns iterators to HomeSpan's internal linked-list of Controller data records
|
||||
* adds new methods to read each Controller's pairing data:
|
||||
* `getID()` - returns a pointer to the 36-byte Device ID of the controller
|
||||
* `getLTPK()` - a pointer to the 32-byte Long-Term Public Key of the controller
|
||||
* `isAdmin()` - returns true if the controller has admin permission, else returns false
|
||||
* adds new `homeSpan` method `setControllerCallback()` to set optional callback function that HomeSpan calls whenever a controller is added, removed, or updated
|
||||
* see the [API Reference](docs/Reference.md) for details
|
||||
|
||||
* **HomeSpan now supports the *write-response ("WR")* protocol**
|
||||
* added automated handling of the HomeKits's *write-response ("WR")* protocol*
|
||||
* not needed for any Characteristics that are currently supported by HomeSpan, but useful for experimentation and work with Custom Characteristics
|
||||
* added extra checks when using `setVal()`
|
||||
* a warning message is output on the Serial Monitor if `setVal()` is called to change the value of a Characteristic from within the `update()` method at the same time the Home App is sending an update request for that value
|
||||
* does not apply if `setVal()` is called from within `update()` to change the value of a Characteristic in response to a *write-response* request from the Home App
|
||||
|
||||
* **Converted the `getLinks()` SpanService method to a template function**
|
||||
* allows user to automatically cast the elements of the returned vector into any specific Service type
|
||||
* also adds an optional parameter to restrict the elements of the returned vector to match a specified HomeSpan Service
|
||||
* see the [API Reference](docs/Reference.md) for details
|
||||
|
||||
* **New ability to halt the pulse generation for a ServoPin**
|
||||
* calling `set(NAN)` for a ServoPin halts the pulse generation, which (for most analog servos) allows the motor to be freely rotated
|
||||
* calling `set(position)`, where *position* equal the desired number of degrees, restarts the pulse generation and sets the servo position accordingly
|
||||
|
||||
* **Refactored client/slot management to save memory and prepare for future integration of Ethernet support**
|
||||
* fixed-array of Client/Socket connections replaced by dynamic linked-list
|
||||
* serial interface now only shows active client connections (rather than a fixed list of client slots)
|
||||
* **deprecated** `homeSpan.reserveSocketConnections()` since it is no longer needed
|
||||
|
||||
* **Fixed bug introduced in 1.9.0 that prevented `homeSpan.setPairingCode()` from saving (and subsequently using) the request Setup Pairing Code**
|
||||
* this method now operates silently, unless an invalid pairing code is provided, in which case an error is reported to the Serial Monitor and *the sketch is halted*
|
||||
* the process for setting the Pairing Code using the CLI 'S' command or via the Access Point are unchanged - confirmation messages are still output to the Serial Monitor and errors do *not* cause the sketch to halt
|
||||
|
||||
* **Fixed memory leak introduced in 1.9.0 that would fail to free a small temporary memory block created when verifying a new connection**
|
||||
* had no practical impact when using a Home Hub since Home Kit only creates a few permanent connections
|
||||
* had significant impact when not using a Home Hub in cases where the Home App repeatedly drops and re-establishes connections, resulting in slow erosion of heap memory and then out-of-memory failure of the device after a few days (note use of HomeSpan without a Home Hub is not formally supported)
|
||||
|
||||
* **Fixed latent bug in SpanPoint**
|
||||
* HomeSpan would crash when printing **SpanPoint** configuration information to the Serial Monitor (the 'i' CLI command) if any of the instances of SpanPoint had *receiveSize=0*
|
||||
* this bug never surfaced before since all the **SpanPoint examples** were based on receiving data and therefore had a non-zero *receiveSize*
|
||||
|
||||
* **Deleted `homeSpan.setMaxConnections()`, which had been *deprecated* many versions ago**
|
||||
|
||||
* **Deleted stand-alone `SpanRange` structure, which had been *deprecated* many versions ago**
|
||||
* this has no impact on standard use of the Characteristic method `setRange()`
|
||||
|
||||
See [Releases](https://github.com/HomeSpan/HomeSpan/releases) for details on all changes and bug fixes included in this update.
|
||||
|
||||
# HomeSpan Resources
|
||||
|
|
@ -106,6 +168,7 @@ HomeSpan includes the following documentation:
|
|||
* [HomeSpan SpanPoint](docs/NOW.md) - facilitates point-to-point, bi-directional communication between ESP32 Devices using ESP-NOW
|
||||
* [HomeSpan Television Services](docs/TVServices.md) - how to use HomeKit's undocumented Television Services and Characteristics
|
||||
* [HomeSpan Message Logging](docs/Logging.md) - how to generate log messages for display on the Arduino Serial Monitor as well as optionally posted to an integrated Web Log page
|
||||
* [HomeSpan TLV8 Characteristics](docs/TLV8.md) - classes and methods for creating TLV8 objects to use with TLV8-based Characteristics
|
||||
* [HomeSpan Device Cloning](docs/Cloning.md) - seamlessly swap a broken device for a new one without needing to re-pair and lose HomeKit automations
|
||||
* [HomeSpan Projects](https://github.com/topics/homespan) - real-world applications of the HomeSpan Library
|
||||
* [HomeSpan FAQ](docs/FAQ.md) - answers to frequently-asked questions
|
||||
|
|
@ -116,9 +179,7 @@ Note that all documentation is version-controlled and tied to each branch. The
|
|||
|
||||
# External Resources
|
||||
|
||||
In addition to HomeSpan resources, developers who are new to HomeKit programming should download Apple's HomeKit Accessory Protocol Specification, Non-Commercial Version, Release R2 (HAP-R2). This document is unfortunately no longer available from Apple (perhaps because it was last updated July, 2019, and is now somewhat out-of-date). However, you may be able find copies of this document elsewhere on the web. Note Apple has not replaced the HAP-R2 document with any other versions for non-commercial use, and Apple's open-source [HomeKit ADK](https://github.com/apple/HomeKitADK) only reflects the original HAP-R2 specs (rather than all the latest Services and Characteristics available in HomeKit for commercial devices).
|
||||
|
||||
You ***do not*** need to read the entire HAP-R2 document. The whole point of HomeSpan is that it implements all the required HAP operations under the hood so you can focus on just programming whatever logic is needed to control your real-world appliances (lights, fans, RF remote controls, etc.) with the device. However, you will find Chapters 8 and 9 of the HAP guide to be an invaluable reference as it lists and describes all of the Services and Characteristics implemented in HomeSpan, many of which you will routinely utilize in your own HomeSpan sketches.
|
||||
In addition to HomeSpan resources, developers who are new to HomeKit programming may find useful Chapters 8 and 9 of Apple's HomeKit Accessory Protocol Specification, Non-Commercial Version, Release R2 (HAP-R2). This document is unfortunately no longer available from Apple (perhaps because it was last updated July, 2019, and is now somewhat out-of-date). However, you may be able find copies of this document elsewhere on the web. Note Apple has not replaced the HAP-R2 document with any other versions for non-commercial use, and Apple's open-source [HomeKit ADK](https://github.com/apple/HomeKitADK) only reflects the original HAP-R2 specs (rather than all the latest Services and Characteristics available in HomeKit for commercial devices).
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
29
docs/FAQ.md
29
docs/FAQ.md
|
|
@ -20,7 +20,11 @@
|
|||
|
||||
#### Can you use more than one HomeSpan device on the same HomeKit network?
|
||||
|
||||
* Yes, multiple ESP32's, each running a separate copy of HomeSpan, can be used on the same HomeKit network, provided that each device has a unique *Device ID*, a unique *Host Name*, and a unique *Display Name*. Normally, the *Device ID* is randomly-generated by HomeSpan at start-up and will therefore automatically be unique across multiple devices. Also, unless you override the suffix of the default *Host Name*, it will also be unique across multiple devices since HomeSpan uses the *Device ID* as the suffix of the *Host Name*. The only thing you need to ensure is that you assign a different *Display Name* to each of your devices. See the [HomeSpan API Reference](https://github.com/HomeSpan/HomeSpan/blob/master/docs/Reference.md) for details on how to do this.
|
||||
* Yes, multiple ESP32's, each running a separate copy of HomeSpan, can be used on the same HomeKit network, provided that each device has a unique *Device ID*, a unique *Host Name*, and a unique *Display Name*. Normally, the *Device ID* is randomly-generated by HomeSpan at start-up and will therefore automatically be unique across multiple devices. Also, unless you override the suffix of the default *Host Name*, it will also be unique across multiple devices since HomeSpan uses the *Device ID* as the suffix of the *Host Name*. The only thing you need to ensure is that you assign a different *Display Name* to each of your devices. See the [HomeSpan API Reference](Reference.md) for details on how to do this.
|
||||
|
||||
#### Does HomeSpan require the use of a HomeKit Hub, such as a HomePod or Apple TV?
|
||||
|
||||
* Yes, if you want HomeSpan to be able to send notifications, such as status updates if a contact sensor is opened, or updates from a temperature sensor. If your device can only be operated from the Home App (i.e. it has no local control buttons) and does not generate any status messages, than a HomeKit Hub would not be necessary. Note you will also need a HomeKit Hub if you wish to control your device via the Internet when away from your local WiFi network. These requirements and conditions are not specific to HomeSpan, but apply to all commercial HomeKit devices as a result of Apple updating its HomeKit Architecture (as of iOS 16.4).
|
||||
|
||||
#### Does HomeSpan support video and audio streams?
|
||||
|
||||
|
|
@ -32,7 +36,7 @@
|
|||
|
||||
#### Will HomeSpan work on an ESP8266 device?
|
||||
|
||||
* No, HomeSpan is coded specifically for the ESP32 and will not operate on an ESP8266 device.
|
||||
* No, HomeSpan is coded specifically for the ESP32 and will not operate on an ESP8266 device, though an ESP8266 can be used as a remote [SpanPoint ESP-NOW](NOW.md) Device.
|
||||
|
||||
#### How can I read HomeSpan's MDNS broadcast mentioned in the [OTA](OTA.md) documentation?
|
||||
|
||||
|
|
@ -44,7 +48,7 @@
|
|||
|
||||
#### Does HomeSpan support Television Services?
|
||||
|
||||
* Yes. Though undocumented by Apple and not officially part of HAP-R2, HomeSpan supports HomeKit Television controls. See [Television Services](../docs/TVServices.md) for details.
|
||||
* Yes. Though undocumented by Apple and not officially part of HAP-R2, HomeSpan supports HomeKit Television controls. See [Television Services](TVServices.md) for details.
|
||||
|
||||
#### Can you use HomeSpan via Bluetooth?
|
||||
|
||||
|
|
@ -64,7 +68,7 @@
|
|||
|
||||
#### Can you add *custom* Services and Characteristics to HomeSpan?
|
||||
|
||||
* Yes, HomeSpan includes two easy-to-use macros to define your own custom Services and custom Characteristics beyond those specified in HAP-R2. See the [HomeSpan API Reference](https://github.com/HomeSpan/HomeSpan/blob/master/docs/Reference.md) for details and examples demonstrating how to do this. Note that any new Characteristics you create will be *completely ignored* by the Home App. Similarly, any new Services you create will be shown in the Home App on a tile labeled "Not Supported". Apple ***does not*** provide any mechanism to extend the functionality of the Home App itself. However, the place where custom Services and Characteristics can be used is in third-party applications designed for these extra features. For example, the *Eve for HomeKit* App properly handles all the Services and Characteristics defined in HAP-R2, *plus* a variety of additional Services and Characteristics designed explictly for use with Eve products. If you know the UUID codes for these extra Services and Characteristics you can add them to HomeKit and use them within the Eve App just as if they were HAP-R2 Services and Characteristics.
|
||||
* Yes, HomeSpan includes two easy-to-use macros to define your own custom Services and custom Characteristics beyond those specified in HAP-R2. See the [HomeSpan API Reference](Reference.md#custom-characteristics-and-custom-services-macros) for details and examples demonstrating how to do this. Note that any new Characteristics you create will be *completely ignored* by the Home App. Similarly, any new Services you create will be shown in the Home App on a tile labeled "Not Supported". Apple ***does not*** provide any mechanism to extend the functionality of the Home App itself. However, the place where custom Services and Characteristics can be used is in third-party applications designed for these extra features. For example, the *Eve for HomeKit* App properly handles all the Services and Characteristics defined in HAP-R2, *plus* a variety of additional Services and Characteristics designed explictly for use with Eve products. If you know the UUID codes for these extra Services and Characteristics you can add them to HomeKit and use them within the Eve App just as if they were HAP-R2 Services and Characteristics.
|
||||
|
||||
#### Can HomeSpan be used for commercial devices?
|
||||
|
||||
|
|
@ -72,7 +76,22 @@
|
|||
|
||||
#### Why does the Home App indicate the Doorbell Service is unsupported?
|
||||
|
||||
* Though not documented in HAP-R2, it appears that the Doorbell Service is designed to be used in conjunction with another service, such as the Lock Mechanism. If you add in a second service, the Home App will show the appropriate Tile (such as a Lock) with the Doorbell being the second service. However, you can still use the Doorbell Service on a stanadlone basis --- even though the Home App says it is unsupported, a button press on the device will properly trigger a chime on your Home Pods as expected.
|
||||
* Though not documented in HAP-R2, it appears that the Doorbell Service is designed to be used in conjunction with another service, such as the Lock Mechanism. If you add in a second service, the Home App will show the appropriate Tile (such as a Lock) with the Doorbell being the second service. However, you can still use the Doorbell Service on a standalone basis --- even though the Home App says it is unsupported, a button press on the device will properly trigger a chime on your Home Pods as expected.
|
||||
|
||||
#### How can I read the current date and time from within my sketch?
|
||||
|
||||
* HomeSpan can automatically acquire the current date and time for your local timezone when you enable the HomeSpan Web Log using `homeSpan.enableWebLog()`. Note this command can be used to set the date and time even without enabling the Web Log itself (see the [HomeSpan API Reference](Reference.md) for details on how to do this). Once the date and time has been acquired, you can use the built-in Arduino-ESP32 `getLocalTime(struct tm *info)` command whenever needed to populate *info* with the current date and time. Note *info* is in [standard Unix](https://man7.org/linux/man-pages/man0/time.h.0p.html) `struct tm` format which is easily parsed as follows:
|
||||
|
||||
```C++
|
||||
struct tm myTime; // create a tm structure
|
||||
getLocalTime(&myTime); // populate the tm structure with current date and time
|
||||
|
||||
// print the individual elements of the tm structure (see standard Unix tm structure for details)
|
||||
|
||||
Serial.printf("Current Date = %02d/%02d/%04d\n", myTime.tm_mon+1, myTime.tm_mday, myTime.tm_year+1900);
|
||||
Serial.printf("Current Time = %02d:%02d:%02d\n", myTime.tm_hour, myTime.tm_min, myTime.tm_sec);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
[↩️](../README.md) Back to the Welcome page
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ Since HomeSpan is a library designed for Arduino's Integrated Development Enviro
|
|||
|
||||
#### Step 2: Install the Arduino-ESP32 Core
|
||||
|
||||
The Arduino IDE comes with built-in compilers and support for a variety of Arduino boards, such as the Arduino Uno and Arduino Nano. However, the IDE does not natively support programming for the ESP32. Fortunately, the IDE allows you to download and install *cores* for other micro-controllers, including the ESP32, so they can be programming from within the Arduino environment. See the [Espressif Arduino-ESP32 GitHub page](https://github.com/espressif/arduino-esp32#arduino-core-for-esp32-wifi-chip) for complete instructions on how to install the Arduino-ESP32 core into the Arduino IDE using the [Arduino IDE Board Manager](https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md).
|
||||
The Arduino IDE comes with built-in compilers and support for a variety of Arduino boards, such as the Arduino Uno and Arduino Nano. However, the IDE does not natively support programming for the ESP32. Fortunately, the IDE allows you to download and install *cores* for other micro-controllers, including the ESP32, so they can be programming from within the Arduino environment. See the [Espressif Arduino-ESP32 GitHub page](https://github.com/espressif/arduino-esp32) for details on the Arduino-ESP32 Core, as well as for instructions on how to install easily this core (and keep it updated) from within the Arduino IDE using the [Arduino IDE Board Manager](https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html#installing-using-arduino-ide).
|
||||
|
||||
#### Step 3: Install HomeSpan
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ HomeSpan is packaged as a standard Arduino library and can be installed either a
|
|||
|
||||
#### Step 4: Acquire an ESP32 Board
|
||||
|
||||
ESP32 development boards are widely available in different configurations from most electronics hobby sites, such as [Adafruit](https://www.adafruit.com) and [Sparkfun](https://www.sparkfun.com). HomeSpan was developed using a dual-core ESP32-WROOM-32 (the [Huzzah32 from Adafruit](https://www.adafruit.com/product/3619)) but should work equally well on dual-core ESP32-WROVER chips. HomeSpan has *not* been tested on any single-core ESP32 chips, such as the ESP32-S2.
|
||||
ESP32 development boards are widely available in different configurations from most electronics hobby sites, such as [Adafruit](https://www.adafruit.com) and [Sparkfun](https://www.sparkfun.com). HomeSpan works with any ESP32 supported by the [Arduino-ESP32 Core](https://docs.espressif.com/projects/arduino-esp32/en/latest/getting_started.html#supported-soc-s), including the original ESP32, the ESP32-S2 and ESP32‑S3, and the ESP32-C3.
|
||||
|
||||
#### Step 5: Install any required USB Drivers
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ To enable Web Logging (it's turned off by default), call the method `homeSpan.en
|
|||
* the total number of WEBLOG() messages to be stored - older messages are discarded in favor of newer ones once the limit you set is reached
|
||||
* the URL of an NTP time server - this is optional and only needed if you want to set the clock of the device at start-up
|
||||
* the time zone for the device - this is only needed if an NTP time server has been specified
|
||||
* the URL of the Web Log page - if unspecified, HomeSpan will serve the Web Log at a page named "status"
|
||||
* the URL of the Web Log page - if unspecified, HomeSpan will serve the Web Log at a page named "status". If set to NULL, HomeSpan will process Web Log data but will *not* serve any Web Log pages to any HTTP requests. However, Web Log data in the form of a finished HTML page can still be accessed by the user by calling `homeSpan.getWebLog()` as described further below
|
||||
|
||||
Additional notes:
|
||||
|
||||
|
|
@ -81,7 +81,63 @@ For example, the following CSS changes the background color of the Web Log page
|
|||
```
|
||||
|
||||
Note that HomeSpan outputs the full content of the Web Log HTML, including whatever CSS you may have specified above, to the Serial Monitor whenever the Log Level is set to 1 or greater. Reviewing this output can be helpful when creating your own CSS.
|
||||
|
||||
|
||||
### Adding User-Defined Data and/or Custom HTML
|
||||
|
||||
Homespan provides a hook into the text used to generate the Web Log that you can extend to add your own data to the initial table as well as more generally add any custom HTML.
|
||||
|
||||
To access this text, set a Web Log callback using `homeSpan.setWebLogCallback(void (*func)(String &htmlText))` where
|
||||
|
||||
* *func* is a function of type *void* that takes a single argument of type *String*, and
|
||||
* *htmlText* will be set by HomeSpan to a String reference containing all the HTML text that the Web Log has already generated to produce the initial table.
|
||||
|
||||
To add your own data to the table, simply extend the String *htmlText* by adding as many `<tr>` and `<td>` HTML tags as needed. If you wish to end the table and add any other HTML, simple include the `</table>` tag in *htmlText*, and then add any other custom HTML. For example, the following function could be used to extend the initial Web Log table to show free DRAM, end the table, and provide a hot link to the HomeSpan Repo:
|
||||
|
||||
```C++
|
||||
void extraData(String &r){
|
||||
r+="<tr><td>Free DRAM:</td><td>" + String(esp_get_free_internal_heap_size()) + " bytes</td></tr>\n";
|
||||
r+="</table><p><a href=\"https://github.com/HomeSpan/HomeSpan\">Click Here to Access HomeSpan Repo</a></p>";
|
||||
}
|
||||
```
|
||||
|
||||
To embed this custom HTML text in the Web Log, call `homeSpan.setWebLogCallback(extraData)` in your sketch.
|
||||
|
||||
### Accessing Web Log HTML from within your sketch
|
||||
|
||||
In addition to (or as an alternative to) having HomeSpan serve HTML Web Log pages in response to HTTP requests, users can directly access the HTML text for a Web Log page from within their sketch for customized processing and handling. Since the HTML for a Web Log page can be very large, HomeSpan only generates the HTML for a Web Log page when the page has been requested, and streams the HTML in sequential chunks of 1024 bytes in response to a Web Log HTTP request. It is therefore not possible for HomeSpan to simply provide the user with a `char *` pointer to the HTML text for a complete Web Log. Instead, HomeSpan provides the user with the following *homeSpan* method to trigger the production of a Web Log page and access the resulting HTML text whenever needed:
|
||||
|
||||
`getWebLog(void (*f)(const char *htmlText, void *data), void *userData)`
|
||||
|
||||
* *f()* - a user-defined function that returns `void` and takes two arguments:
|
||||
* *htmlText* - a null-terminated `const char *` pointer to a chunk of HTML text (max 1024 bytes) provided by HomeSpan
|
||||
* *data* - a `void *` pointer to any user-provided data, *userData*
|
||||
* *userData* - a `void *` pointer to any optional user-provided data that is passed to *f()* as its second argument, *data*
|
||||
|
||||
When the above method is called from a sketch, HomeSpan will repeatedly call the user-defined function *f()* and provide sequential chunks of HTML text for the Web Log page as the first argument, *htmlText*. Once all HTML chunks have been sent to the function *f()*, HomeSpan calls *f()* one final time with *htmlText* set to NULL to indicate there are no more HTML chunks to be sent.
|
||||
|
||||
The primary purpose of this function is for the user to provide their own method of serving an HTML Web Log page, such as through a secure HTTPS channel. Note this channel can be in addition to, or instead of, HomeSpan's normal serving of Web Log pages through HTTP requests depending on whether or not the URL argument used in the `homeSpan.enableWebLog()` method was set to NULL (disabling HomeSpan from serving Web Log pages in response to HTTP requests).
|
||||
|
||||
The following psuedo-code snippet shows how `getWebLog()` can be used:
|
||||
|
||||
```C++
|
||||
...
|
||||
homeSpan.enableWebLog(50,"pool.ntp.org","UTC",NULL); // this enables the Web Log for 50 entries and sets the clock, but prevents HomeSpan from responding to any HTTP requests for a Web Log page
|
||||
...
|
||||
IF WEBLOG NEEDED THEN{
|
||||
homeSpan.getWebLog(myWebLogHandler,NULL); // this triggers HomeSpan to produce the HTML text for a Web Log page and stream the data to myWebLogHandler without any extra user data
|
||||
}
|
||||
...
|
||||
void myWebLogHandler(const char *htmlText, void *args){ // this is the user-defined Web Log handler (note the optional *arg parameter is not used in this example)
|
||||
if(htmlText!=NULL){
|
||||
DO SOMETHING WITH htmlText (e.g. transmit it to the user via an HTTPS connection)
|
||||
}
|
||||
else
|
||||
PERFORM ANY CLEAN-UP PROCESSING (e.g. close the HTTPS connection)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
15
docs/NOW.md
15
docs/NOW.md
|
|
@ -1,6 +1,6 @@
|
|||
# SpanPoint: Point-to-Point Communication between ESP32 Devices
|
||||
|
||||
SpanPoint is HomeSpan's easy-to-use implementation of the Espressif ESP-NOW protocol. SpanPoint provides bi-directional, point-to-point communication of small, fixed-size messages directly between ESP32 devices based on their MAC Addresses without the need for a central WiFi network.
|
||||
SpanPoint is HomeSpan's easy-to-use implementation of the Espressif ESP-NOW protocol. SpanPoint provides bi-directional, point-to-point communication of small, fixed-size messages directly between ESP32 devices based on their MAC Addresses without the need for a central WiFi network. SpanPoint can also be used on an ESP-8266 when configured as a remote device.
|
||||
|
||||
To establish connectivity between any two devices simply instantiate a SpanPoint object on each device that references the MAC Address of the other device, as well as specifies the (potentially different) sizes of the messages that each device is expected to send to, and receive from, the other.
|
||||
|
||||
|
|
@ -61,6 +61,16 @@ Also note that regardless of whether or not the queue if full, if the size of a
|
|||
* if used, this method must be called *before* the instantiation of any SpanPoint objects. Example: `SpanPoint::setPassword("MyPassword");`
|
||||
* the same passphrase must be used among all devices that are communicating via SpanPoint, else the receiving device will not be able to decrypt messages it receives
|
||||
|
||||
* `static void setEncryption(boolean encrypt)`
|
||||
|
||||
* this *optional* **class-level** method provides the ability to enable or disable encryption according to whether *encrypt* is set to *true* or *false*
|
||||
* by default, encryption is normally enabled (using the password above)
|
||||
* if used, this method must be called *before* the instantiation of any SpanPoint objects. Example: `SpanPoint::setEncryption(false);` disables encryption for all SpanPoint connections
|
||||
* note that this is a global setting - if SpanPoint encryption is disabled on the main device, it must also be disabled on every remote device, else communication between devices will fail
|
||||
* enabling/disabling encryption impacts that total number of SpanPoint connections that can be supported by the ESP32's ESP-NOW functionality:
|
||||
* with encryption enabled, the ESP32 can support a maximum of 7 ESP-NOW links (i.e. 7 instances of SpanPoint)
|
||||
* with encryption disabled, the ESP32 can support a maximum of 20 ESP-NOW links (i.e. 20 instances of SpanPoint)
|
||||
|
||||
* `static void setChannelMask(uint16_t mask)`
|
||||
|
||||
* this *optional* **class-level** method changes the default channel bitmask from 0x3FFE (i.e. 0011 1111 1111 1110) to *mask*
|
||||
|
|
@ -81,6 +91,9 @@ Examples showing such a configuration can be found in the Arduino IDE under [*Fi
|
|||
* *RemoteDevice.ino* - a lightweight sketch that simulates taking periodic temperature measurements, which are then transmitted to the Main Device via SpanPoint
|
||||
* *RemoteTempSensor.ino* - a lightweight sketch that is similar to *RemoteDevice.ino*, except that instead of simulating a temperature sensor, it implements an actual Adafruit ADT7410 I2C-based temperature sensor. This sketch also uses some power-management techniques to extend battery life, such as lowering the CPU frequency and entering into deep-sleep after each measurement is taken
|
||||
* *RemoteDevice8266.ino* - similar in function to *RemoteDevice.ino*, but implemented to run on an ESP8266 device using native ESP-NOW commands (since neither HomeSpan nor SpanPoint support the ESP8266). Note that the "complementary" SpanPoint object on the ESP32 that receives data from the ESP8266 must be configured to use the ESP32's *AP MAC Address* (instead of the *STA MAC Address*) by setting *useAPaddress* to *true* in the SpanPoint constructor
|
||||
|
||||
Please also see the [SpanPointLightSwitch Repository](https://github.com/HomeSpan/SpanPointLightSwitch/tree/main) for a detailed example that shows how to use SpanPoint for *bi-directional communication* between an ESP32 "Central Hub" device implementing two HomeKit Lighbulb Accessories, an remote ESP32 device controlling an LED, and a separate ESP8266 device controlling another LED.
|
||||
|
||||
---
|
||||
|
||||
[↩️](../README.md) Back to the Welcome page
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
# Pulse Width Modulation (PWM)
|
||||
|
||||
The ESP32 has up to 16 PWM channels that can be used to drive a variety of devices. HomeSpan includes an integrated PWM library with dedicated classes designed for controlling **Dimmable LEDs** as well as **Servo Motors**. Both classes are provided in a standalone header file that is accessed by placing the following near the top of your sketch:
|
||||
|
||||
`#include "extras/PwmPin.h"`
|
||||
The ESP32 has up to 16 PWM channels that can be used to drive a variety of devices. HomeSpan includes an integrated PWM library with dedicated classes designed for controlling **Dimmable LEDs** as well as **Servo Motors**.
|
||||
|
||||
## *LedPin(uint8_t pin [,float level [,uint16_t frequency [,boolean invert]]])*
|
||||
|
||||
|
|
@ -73,7 +71,8 @@ The *minMicros* parameter must be less than the *maxMicros* parameter, but setti
|
|||
|
||||
* `void set(double position)`
|
||||
|
||||
* sets the position of the Servo Motor to *position* (in degrees). In order to protect the Servo Motor, values of *position* less than *minDegrees* are automatically reset to *minDegrees*, and values greater than *maxDegrees* are automatically reset to *maxDegrees*.
|
||||
* sets the position of the Servo Motor to *position* (in degrees). In order to protect the Servo Motor, values of *position* less than *minDegrees* are automatically reset to *minDegrees*, and values greater than *maxDegrees* are automatically reset to *maxDegrees*
|
||||
* if *position* is specified as *NAN* (i.e. the C++ "not-a-number" constant), the duty-cycle is set to zero, which effectively stops the pulse generation --- for most analog servos this means the motor can be freely rotated. Calling `set()` once again with *position* equal to an actual number of degrees restarts the pulse train and sets the servo position accordingly
|
||||
|
||||
* `int getPin()`
|
||||
|
||||
|
|
|
|||
|
|
@ -6,16 +6,22 @@ Both classes allow you to individually set each of the "pixels" in a multi-pixel
|
|||
|
||||
The methods for both classes are nearly identical, which allows you to readily interchange code written for single-wire devices to use with two-wire devices (and vice-versa) with only minor modifications.
|
||||
|
||||
Both classes are provided in a standalone header file that is accessed by placing the following near the top of your sketch:
|
||||
|
||||
`#include "extras/Pixel.h"`
|
||||
|
||||
## *Pixel(uint8_t pin, [boolean isRGBW])*
|
||||
## *Pixel(uint8_t pin, [pixelType_t pixelType])*
|
||||
|
||||
Creating an instance of this **class** configures the specified *pin* to output a waveform signal suitable for controlling a single-wire, addressable RGB or RGBW LED device with an arbitrary number of pixels. Such devices typically contain SK6812 or WS2812 LEDs. Arguments, along with their defaults if left unspecified, are as follows:
|
||||
|
||||
* *pin* - the pin on which the RGB control signal will be output; normally connected to the "data" input of the addressable LED device
|
||||
* *isRGBW* - set to *true* for RGBW devices that contain 4-color (red/green/blue/white) LEDs; set to *false* for the more typical 3-color RGB devices. Defaults to *false* if unspecified. Note you must set the *isRGBW* flag to *true* if you are using an RGBW device, even if you do not intend on utilizing the white LED
|
||||
* *pixelType* - controls the order in which color data is transmitted, as well as whether the device contains 3-color (red/green/blue) or 4‑color (red/green/blue/white) LEDs. Pre-defined values for *pixelType* are provided in the **PixelType** namespace. Choose from one of the following twelve formats:
|
||||
|
||||
* *PixelType::RGB, PixelType::RBG, PixelType::BRG, PixelType::BGR, PixelType::GBR, PixelType::GRB*
|
||||
* *PixelType::RGBW, PixelType::RBGW, PixelType::BRGW, PixelType::BGRW, PixelType::GBRW, PixelType::GRBW*
|
||||
|
||||
* Example: `Pixel myDevice(26, PixelType::BRGW);` creates a 4-color RGBW device attached to pin 26 where the colors are transmitted in the order blue, red, green, and then white
|
||||
|
||||
Note that *pixelType* is optional. If left unspecified, the default value is *PixelType::GRB*.
|
||||
|
||||
> [!TIP]
|
||||
> Since it is often not obvious which type of LED your specific device may have, HomeSpan includes a sketch designed to help you determine the correct value of *pixelType*. See [*File → Examples → HomeSpan → Other Examples → PixelTester*](../examples/Other%20Examples/PixelTester) under the Arduino IDE for detailed instructions. Please use this tester sketch if you find the colors of your Pixel device are not matching what appears in the Home App.
|
||||
|
||||
The two main methods to set pixel colors are:
|
||||
|
||||
|
|
@ -51,19 +57,26 @@ The **Pixel** class also supports the following class-level methods as a conveni
|
|||
* equivalent to `return(Color().HSV(h,s,v,w));`
|
||||
* example: `Pixel::Color c[]={Pixel::HSV(120,100,100),Pixel::HSV(60,100,100),Pixel::HSV(0,100,100)};` to create a red-yellow-green traffic light pattern
|
||||
|
||||
Finally, the **Pixel** class supports these two additional, but rarely-needed, methods:
|
||||
Finally, the **Pixel** class supports these additional methods:
|
||||
|
||||
* `int getPin()`
|
||||
|
||||
* returns the pin number, or -1 if the instantiation failed due to lack of resources
|
||||
|
||||
* `boolean isRGBW()`
|
||||
|
||||
* returns *true* if *pixelType* specified an RGBW LED, else *false* if just an RGB LED
|
||||
|
||||
* `void setTiming(float high0, float low0, float high1, float low1, uint32_t lowReset)`
|
||||
|
||||
* the default timing parameters used by the **Pixel** class to generate the "data" signal needed to set the colors of an RGB LED device should work with most commercial products based on SK6812 or WS2812 driver chips. Use this method **ONLY** if you need to override the class defaults and replace them with your own timing parameters, where
|
||||
* *high0* and *low0* specify the duration (in microseconds) of the high phase and low phase for a pulse encoding a zero-bit;
|
||||
* *high1* and *low1* specify the duration (in microseconds) of the high phase and low phase for a pulse encoding a one-bit; and
|
||||
* *lowReset* specifies the delay (in microseconds) representing the end of a pulse stream
|
||||
* for reference, the **Pixel** class uses the following defaults: *high0=0.32𝛍s, low0=0.88𝛍s, high1=0.64𝛍s, low1=0.56𝛍s, lowReset=80.0𝛍s*
|
||||
* for reference, the **Pixel** class uses the following defaults: *high0=0.32𝛍s, low0=0.88𝛍s, high1=0.64𝛍s, low1=0.56𝛍s, lowReset=80.0𝛍s*
|
||||
|
||||
> [!TIP]
|
||||
> If your LED colors are flickering, this is likely due to a mismatch in timing parameters. To solve, please search the web for a specifications document for the exact **chip** used by your specific device. These documents generally provide a table listing the durations of the HIGH and LOW periods required to transmit a binary 1 or binary 0. You can then use the `setTiming` method above to set the timing parameters accordingly.
|
||||
|
||||
### Resource Usage and Resource Conflicts
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
# Remote Control Radio Frequency / Infrared Signal Generation
|
||||
|
||||
The ESP32 has an on-chip signal-generator peripheral designed to drive an RF or IR transmitter. HomeSpan includes an easy-to-use library that interfaces with this peripheral so that with a few additional electronic components you can create a HomeSpan device that controls an RF or IR appliance directly from the Home App on your iPhone, or via Siri. The library is accessed by placing the following near the top of your sketch:
|
||||
|
||||
`#include "extras/RFControl.h"`
|
||||
The ESP32 has an on-chip Remote Control (RMT) signal-generator designed to drive an RF or IR transmitter. HomeSpan includes a dedicated, easy-to-use class, **RFControl()**, that interfaces with the ESP32 RMT peripheral so that with a few additional electronic components you can create a HomeSpan device that controls an RF or IR appliance directly from the Home App on your iPhone, or via Siri.
|
||||
|
||||
## *RFControl(int pin, boolean refClock=true)*
|
||||
|
||||
|
|
@ -93,7 +91,6 @@ Below is a complete sketch that produces two different pulse trains with the sig
|
|||
/* HomeSpan Remote Control Example */
|
||||
|
||||
#include "HomeSpan.h" // include the HomeSpan library
|
||||
#include "extras/RFControl.h" // include RF Control Library
|
||||
|
||||
void setup() {
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ The HomeSpan Library is invoked by including *HomeSpan.h* in your Arduino sketch
|
|||
|
||||
## *homeSpan*
|
||||
|
||||
At runtime HomeSpan will create a global **object** named `homeSpan` that supports the following methods:
|
||||
At runtime HomeSpan will create a global **object** named `homeSpan` (of type *class Span*) that supports the following methods:
|
||||
|
||||
* `void begin(Category catID, const char *displayName, const char *hostNameBase, const char *modelName)`
|
||||
* initializes HomeSpan
|
||||
|
|
@ -26,21 +26,31 @@ At runtime HomeSpan will create a global **object** named `homeSpan` that suppor
|
|||
|
||||
---
|
||||
|
||||
The following **optional** `homeSpan` methods override various HomeSpan initialization parameters used in `begin()`, and therefore **should** be called before `begin()` to take effect. If a method is *not* called, HomeSpan uses the default parameter indicated below:
|
||||
The following **optional** `homeSpan` methods override various HomeSpan initialization parameters used in `begin()`, and therefore **should** be called before `begin()` to take effect.
|
||||
Methods with a return type of `Span&` return a reference to `homeSpan` itself and can thus be chained together (e.g. `homeSpan.setControlPin(21).setStatusPin(13);`). If a method is *not* called, HomeSpan uses the default parameter indicated below:
|
||||
|
||||
* `void setControlPin(uint8_t pin)`
|
||||
* sets the ESP32 pin to use for the HomeSpan Control Button. If not specified, HomeSpan will assume there is no Control Button
|
||||
* `Span& setControlPin(uint8_t pin, triggerType=PushButton::TRIGGER_ON_LOW)`
|
||||
* sets the ESP32 *pin* to use for the HomeSpan Control Button
|
||||
* if this method is not called, HomeSpan will assume there is no Control Button
|
||||
* the optional second argument, *triggerType*, configures the Control Button as follows:
|
||||
* `PushButton::TRIGGER_ON_LOW` - triggers when *pin* is driven LOW
|
||||
* suitable for buttons that connect *pin* to GROUND (this is the default when *triggerType* is not specified)
|
||||
* `PushButton::TRIGGER_ON_HIGH` - triggers when *pin* is driven HIGH
|
||||
* suitable for buttons that connect *pin* to VCC (typically 3.3V)
|
||||
* `PushButton::TRIGGER_ON_TOUCH` - uses the device's touch-sensor peripheral to trigger when *pin* has been touched
|
||||
* not available on ESP32-C3
|
||||
* as an alternative, you can set *triggerType* to any user-defined function of the form `boolean(int arg)` to utilize any device as a Control Button. See **SpanButton** below for details
|
||||
|
||||
* `int getControlPin()`
|
||||
* returns the pin number of the HomeSpan Control Button as set by `setControlPin(pin)`, or -1 if no pin has been set
|
||||
|
||||
* `void setStatusPin(uint8_t pin)`
|
||||
* sets the ESP32 pin to use for the HomeSpan Status LED
|
||||
* `Span& setStatusPin(uint8_t pin)`
|
||||
* sets the ESP32 *pin* to use for the HomeSpan Status LED
|
||||
* assumes a standard LED will be connected to *pin*
|
||||
* if neither this method nor any equivalent method is called, HomeSpan will assume there is no Status LED
|
||||
|
||||
* `void setStatusPixel(uint8_t pin, float h=0, float s=100, float v=100)`
|
||||
* sets the ESP32 pin to use for the HomeSpan Status LED
|
||||
* `Span& setStatusPixel(uint8_t pin, float h=0, float s=100, float v=100)`
|
||||
* sets the ESP32 *pin* to use for the HomeSpan Status LED
|
||||
* this method is an *alternative* to using `setStatusPin()` above
|
||||
* assumes an RGB NeoPixel (or equivalent) will be connected to *pin*
|
||||
* works well with ESP32 boards that have a built-in NeoPixel LED, though adding an external NeoPixel is fine
|
||||
|
|
@ -52,14 +62,14 @@ The following **optional** `homeSpan` methods override various HomeSpan initiali
|
|||
* example: `homeSpan.setStatusPixel(8,120,100,20)` sets the Status LED to light green using a NeoPixel attached to pin 8
|
||||
* if neither this method nor any equivalent method is called, HomeSpan will assume there is no Status LED
|
||||
|
||||
* `void setStatusDevice(Blinkable *sDev)`
|
||||
* `Span& setStatusDevice(Blinkable *sDev)`
|
||||
* sets the Status LED to a user-specified Blinkable device, *sDev*
|
||||
* this method is an *alternative* to using either `setStatusPin()` or `setStatusPixel()` above
|
||||
* see [Blinkable](Blinkable.md) for details on how to create generic Blinkable devices
|
||||
* useful when using an LED connected to a pin expander, or other specialized driver, as the Status LED
|
||||
* if neither this method nor any equivalent method is called, HomeSpan will assume there is no Status LED
|
||||
|
||||
* `void setStatusAutoOff(uint16_t duration)`
|
||||
* `Span& setStatusAutoOff(uint16_t duration)`
|
||||
* sets Status LED to automatically turn off after *duration* seconds
|
||||
* Status LED will automatically turn on, and duration timer will be reset, whenever HomeSpan activates a new blinking pattern
|
||||
* if *duration* is set to zero, auto-off is disabled (Status LED will remain on indefinitely)
|
||||
|
|
@ -67,19 +77,19 @@ The following **optional** `homeSpan` methods override various HomeSpan initiali
|
|||
* `int getStatusPin()`
|
||||
* returns the pin number of the Status LED as set by `setStatusPin(pin)`, or -1 if no pin has been set
|
||||
|
||||
* `void setApSSID(const char *ssid)`
|
||||
* `Span& setApSSID(const char *ssid)`
|
||||
* sets the SSID (network name) of the HomeSpan Setup Access Point (default="HomeSpan-Setup")
|
||||
|
||||
* `void setApPassword(const char *pwd)`
|
||||
* `Span& setApPassword(const char *pwd)`
|
||||
* sets the password of the HomeSpan Setup Access Point (default="homespan")
|
||||
|
||||
* `void setApTimeout(uint16_t nSec)`
|
||||
* `Span& setApTimeout(uint16_t nSec)`
|
||||
* sets the duration (in seconds) that the HomeSpan Setup Access Point, once activated, stays alive before timing out (default=300 seconds)
|
||||
|
||||
* `void setCommandTimeout(uint16_t nSec)`
|
||||
* `Span& setCommandTimeout(uint16_t nSec)`
|
||||
* sets the duration (in seconds) that the HomeSpan End-User Command Mode, once activated, stays alive before timing out (default=120 seconds)
|
||||
|
||||
* `void setLogLevel(int level)`
|
||||
* `Span& setLogLevel(int level)`
|
||||
* sets the logging level for diagnostic messages, where:
|
||||
* 0 = top-level HomeSpan status messages, and any `LOG0()` messages specified in the sketch by the user (default)
|
||||
* 1 = all HomeSpan status messages, and any `LOG1()` messages specified in the sketch by the user
|
||||
|
|
@ -93,25 +103,16 @@ The following **optional** `homeSpan` methods override various HomeSpan initiali
|
|||
* `int getLogLevel()`
|
||||
* returns the current Log Level as set by `setLogLevel(level)`
|
||||
|
||||
* `void reserveSocketConnections(uint8_t nSockets)`
|
||||
* reserves *nSockets* network sockets for uses **other than** by the HomeSpan HAP Server for HomeKit Controller Connections
|
||||
* for sketches compiled under Arduino-ESP32 v2.0.1 or later, HomeSpan reserves 14 sockets for HAP Controller Connections
|
||||
* each call to `reserveSocketConnections(nSockets)` reduces this number by *nSockets*
|
||||
* use this method if you add code to a sketch that requires its own socket connections (e.g. a separate web service, an MQTT server, etc.)
|
||||
* multiple calls to this method are allowed - the number of sockets reserved will be the sum of *nSockets* across all calls
|
||||
* note you do not need to separately reserve sockets for built-in HomeSpan functionality
|
||||
* for example, `enableOTA()` already contains an embedded call to `reserveSocketConnections(1)` since HomeSpan knows one socket must be reserved to support OTA
|
||||
|
||||
* `void setPortNum(uint16_t port)`
|
||||
* `Span& setPortNum(uint16_t port)`
|
||||
* sets the TCP port number used for communication between HomeKit and HomeSpan (default=80)
|
||||
|
||||
* `void setHostNameSuffix(const char *suffix)`
|
||||
* `Span& setHostNameSuffix(const char *suffix)`
|
||||
* sets the suffix HomeSpan appends to *hostNameBase* to create the full hostName
|
||||
* if not specified, the default is for HomeSpan to append a dash "-" followed the 6-byte Accessory ID of the HomeSpan device
|
||||
* setting *suffix* to a null string "" is permitted
|
||||
* example: `homeSpan.begin(Category::Fans, "Living Room Ceiling Fan", "LivingRoomFan");` will yield a default *hostName* of the form *LivingRoomFan-A1B2C3D4E5F6.local*. Calling `homeSpan.setHostNameSuffix("v2")` prior to `homeSpan.begin()` will instead yield a *hostName* of *LivingRoomFanv2.local*
|
||||
|
||||
* `void setQRID(const char *id)`
|
||||
* `Span& setQRID(const char *id)`
|
||||
* changes the Setup ID, which is used for pairing a device with a [QR Code](QRCodes.md), from the HomeSpan default to *id*
|
||||
* the HomeSpan default is "HSPN" unless permanently changed for the device via the [HomeSpan CLI](CLI.md) using the 'Q' command
|
||||
* *id* must be exactly 4 alphanumeric characters (0-9, A-Z, and a-z). If not, the request to change the Setup ID is silently ignored and the default is used instead
|
||||
|
|
@ -135,11 +136,11 @@ The following **optional** `homeSpan` methods enable additional features and pro
|
|||
* this command causes HomeSpan to ignore, but does not otherwise alter, any password stored using the 'O' command
|
||||
* returns 0 if enabling OTA was successful, or -1 and reports an error to the Serial Monitor if not
|
||||
|
||||
* `void enableAutoStartAP()`
|
||||
* `Span& enableAutoStartAP()`
|
||||
* enables automatic start-up of WiFi Access Point if WiFi Credentials are **not** found at boot time
|
||||
* methods to alter the behavior of HomeSpan's Access Point, such as `setApTimeout()`, must be called prior to `enableAutoStartAP()` to have an effect
|
||||
|
||||
* `void setApFunction(void (*func)())`
|
||||
* `Span& setApFunction(void (*func)())`
|
||||
* replaces HomeSpan's built-in WiFi Access Point with user-defined function *func*
|
||||
* *func* must be of type *void* and have no arguments
|
||||
* *func* will be called instead of HomeSpan's built-in WiFi Access Point whenever the Access Point is launched:
|
||||
|
|
@ -149,22 +150,36 @@ The following **optional** `homeSpan` methods enable additional features and pro
|
|||
* after identifying the SSID and password of the desired network, *func* must call `setWifiCredentials()` to save and use these values
|
||||
* it is recommended that *func* terminates by restarting the device using `ESP.restart()`. Upon restart HomeSpan will use the SSID and password just saved
|
||||
|
||||
* `void setWifiCredentials(const char *ssid, const char *pwd)`
|
||||
* `Span& setWifiCredentials(const char *ssid, const char *pwd)`
|
||||
* sets the SSID (*ssid*) and password (*pwd*) of the WiFi network to which HomeSpan will connect
|
||||
* *ssid* and *pwd* are automatically saved in HomeSpan's non-volatile storage (NVS) for retrieval when the device restarts
|
||||
* note that the saved values are truncated if they exceed the maximum allowable characters (ssid=32; pwd=64)
|
||||
* :warning: SECURITY WARNING: The purpose of this function is to allow advanced users to *dynamically* set the device's WiFi Credentials using a customized Access Point function specified by `setApFunction(func)`. It it NOT recommended to use this function to hardcode your WiFi SSID and password directly into your sketch. Instead, use one of the more secure methods provided by HomeSpan, such as typing 'W' from the CLI, or launching HomeSpan's Access Point, to set your WiFi credentials without hardcoding them into your sketch
|
||||
|
||||
* `Span& setVerboseWifiReconnect(bool verbose)`
|
||||
* when trying connecting to WiFi, HomeSpan normally logs "Trying to connect to..." messages to the Serial Monitor and the Web Log
|
||||
* calling this method with *verbose* set to *false* supresses these messages
|
||||
* calling this method a second time with *verbose* set to *true* re-activates these messages (default behavior)
|
||||
|
||||
* `void setWifiCallback(void (*func)())`
|
||||
* sets an optional user-defined callback function, *func*, to be called by HomeSpan upon start-up just after WiFi connectivity has been established. This one-time call to *func* is provided for users that are implementing other network-related services as part of their sketch, but that cannot be started until WiFi connectivity is established. The function *func* must be of type *void* and have no arguments
|
||||
* `Span& setWifiCallback(void (*func)())`
|
||||
* sets an optional user-defined callback function, *func*, to be called by HomeSpan upon start-up just after WiFi connectivity has been initially established. This one-time call to *func* is provided for users that are implementing other network-related services as part of their sketch, but that cannot be started until WiFi connectivity is established. The function *func* must be of type *void* and have no arguments
|
||||
|
||||
* `void setPairCallback(void (*func)(boolean status))`
|
||||
* `Span& setWifiCallbackAll(void (*func)(int count))`
|
||||
* similar to `setWiFiCallback()` above, but the user-defined callback function, *func*, is called by HomeSpan *every* time WiFi connectivity has been established or re-established after a disconnect. The function *func* must be of type *void* and accept a single *int* argument, *count*, into which HomeSpan passes the number of times WiFi has been established or re-established (i.e. *count*=1 on initial WiFi connection; *count*=2 if re-established after the first disconnect, etc.)
|
||||
|
||||
* `Span& setPairCallback(void (*func)(boolean status))`
|
||||
* sets an optional user-defined callback function, *func*, to be called by HomeSpan upon completion of pairing to a controller (*status=true*) or unpairing from a controller (*status=false*)
|
||||
* this one-time call to *func* is provided for users that would like to trigger additional actions when the device is first paired, or the device is later unpaired
|
||||
* note this *func* is **not** called upon start-up and should not be used to simply check whether a device is paired or unpaired. It is only called when pairing status changes
|
||||
* the function *func* must be of type *void* and accept one *boolean* argument
|
||||
|
||||
* `void setStatusCallback(void (*func)(HS_STATUS status))`
|
||||
|
||||
* `Span& setControllerCallback(void (*func)())`
|
||||
* sets an optional user-defined callback function, *func*, to be called by HomeSpan every time a new controller is added, removed, or updated, even if the pairing status does not change
|
||||
* note this method differs from `setPairCallback()`, which is only called if the device's pairing status changes, such as when the first controller is added during initial pairing, or the last controller is removed when unpairing
|
||||
* the function *func* must be of type *void* and have no arguments
|
||||
* see the `controllerListBegin()` and `controllerListEnd()` methods for details on how to read the pairing data for each paired controller (*only needed to support certain advanced use cases*)
|
||||
|
||||
* `Span& setStatusCallback(void (*func)(HS_STATUS status))`
|
||||
* sets an optional user-defined callback function, *func*, to be called by HomeSpan whenever its running state (e.g. WiFi Connecting, Pairing Needed...) changes in way that would alter the blinking pattern of the (optional) Status LED
|
||||
* if *func* is set, it will be called regardless of whether or not a Status LED has actually been defined
|
||||
* this allows users to reflect changes to the current state of HomeSpan using alternative methods, such as outputting messages to an embedded LCD or E-Ink display
|
||||
|
|
@ -174,14 +189,14 @@ The following **optional** `homeSpan` methods enable additional features and pro
|
|||
* returns a pre-defined character string message representing *s*, which must be of enum type [HS_STATUS](HS_STATUS.md)
|
||||
* typically used in conjunction with `setStatusCallback()` above
|
||||
|
||||
* `void setPairingCode(const char *s)`
|
||||
* `Span& setPairingCode(const char *s)`
|
||||
* sets the Setup Pairing Code to *s*, which **must** be exactly eight numerical digits (no dashes)
|
||||
* example: `homeSpan.setPairingCode("46637726");`
|
||||
* a hashed version of the Pairing Code will be saved to the device's non-volatile storage, overwriting any currently-stored Pairing Code
|
||||
* if *s* contains an invalid code, an error will be reported and the code will *not* be saved. Instead, the currently-stored Pairing Code (or the HomeSpan default Pairing Code if no code has been stored) will be used
|
||||
* this method operated silently unless *s* contains an invalid code, in which case a fatal error will be reported to the Serial Monitor, the code will *not* be saved, and the sketch will be HALTED
|
||||
* :warning: SECURTY WARNING: Hardcoding a device's Pairing Code into your sketch is considered a security risk and is **not** recommended. Instead, use one of the more secure methods provided by HomeSpan, such as typing 'S \<code\>' from the CLI, or launching HomeSpan's Access Point, to set your Pairing Code without hardcoding it into your sketch
|
||||
|
||||
* `void setSketchVersion(const char *sVer)`
|
||||
* `Span& setSketchVersion(const char *sVer)`
|
||||
* sets the version of a HomeSpan sketch to *sVer*, which can be any arbitrary character string
|
||||
* if unspecified, HomeSpan uses "n/a" as the default version text
|
||||
* HomeSpan displays the version of the sketch in the Arduino IDE Serial Monitor upon start-up
|
||||
|
|
@ -191,31 +206,56 @@ The following **optional** `homeSpan` methods enable additional features and pro
|
|||
* returns the version of a HomeSpan sketch, as set using `void setSketchVersion(const char *sVer)`, or "n/a" if not set
|
||||
* can by called from anywhere in a sketch
|
||||
|
||||
* `void enableWebLog(uint16_t maxEntries, const char *timeServerURL, const char *timeZone, const char *logURL)`
|
||||
* `Span& enableWebLog(uint16_t maxEntries, const char *timeServerURL, const char *timeZone, const char *logURL)`
|
||||
* enables a rolling Web Log that displays the most recent *maxEntries* entries created by the user with the `WEBLOG()` macro. Parameters, and their default values if unspecified, are as follows:
|
||||
* *maxEntries* - maximum number of (most recent) entries to save. If unspecified, defaults to 0, in which case the Web Log will only display status without any log entries
|
||||
* *timeServerURL* - the URL of a time server that HomeSpan will use to set its clock upon startup after a WiFi connection has been established. If unspecified, defaults to NULL, in which case HomeSpan skips setting the device clock
|
||||
* *timeZone* - specifies the time zone to use for setting the clock. Uses standard Unix timezone formatting as interpreted by Espressif IDF. Note the IDF uses a somewhat non-intuitive convention such that a timezone of "UTC+5:00" *subtracts* 5 hours from UTC time, and "UTC-5:00" *adds* 5 hours to UTC time. If *serverURL=NULL* this field is ignored; if *serverURL!=NULL* this field is required
|
||||
* *logURL* - the URL of the Web Log page for this device. If unspecified, defaults to "status"
|
||||
* *timeServerURL* - the URL of a time server that HomeSpan will use to set its clock upon startup after a WiFi connection has been established. HomeSpan will reserve one extra socket connection when a time server is specified. If unspecified, defaults to NULL, in which case HomeSpan skips setting the device clock
|
||||
* *timeZone* - specifies the time zone to use for setting the clock. Uses POSIX.1 format only and does not support the *Time Zone Database*, or *tzdata*. As per [GNU libc documentation for TZ](https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html), *the offset specifies the time value you must **add to the local time** to get a Coordinated Universal Time value*. "UTC+5:00" means that local time + 5 hours give UTC time. See the GNU libc documentation for some examples, including how to specify North American Eastern Standard Time (EST) and Eastern Daylight Time (EDT) with start and end dates of EDT. If *serverURL=NULL* this field is ignored; if *serverURL!=NULL* this field is required
|
||||
* *logURL* - the URL of the Web Log page for this device. If unspecified, defaults to "status". If *logURL* is set to NULL HomeSpan will use the *timeServerURL* and *timeZone* parameters to set the clock, but it will *not* serve any Web Log pages in response to any HTTP requests. However, Web Log data is still accumulated internally and the resulting HTML can be accessed anytime by calling the `homeSpan.getWebLog()` method (see below)
|
||||
* example: `homeSpan.enableWebLog(50,"pool.ntp.org","UTC-1:00","myLog");` creates a web log at the URL *http<nolink>://HomeSpan-\[DEVICE-ID\].local:\[TCP-PORT\]/myLog* that will display the 50 most-recent log messages produced with the WEBLOG() macro. Upon start-up (after a WiFi connection has been established) HomeSpan will attempt to set the device clock by calling the server "pool.ntp.org" and adjusting the time to be 1 hour ahead of UTC.
|
||||
* when attemping to connect to *timeServerURL*, HomeSpan waits 120 seconds for a response. This is done in the background and does not block HomeSpan from running as usual while it tries to set the time. If no response is received after the 120-second timeout period, HomeSpan assumes the server is unreachable and skips the clock-setting procedure. Use `setTimeServerTimeout()` to re-configure the 120-second timeout period to another value
|
||||
* see [Message Logging](Logging.md) for complete details
|
||||
|
||||
* `void setTimeServerTimeout(uint32_t tSec)`
|
||||
* `Span& setTimeServerTimeout(uint32_t tSec)`
|
||||
* changes the default 120-second timeout period HomeSpan uses when `enableWebLog()` tries set the device clock from an internet time server to *tSec* seconds
|
||||
|
||||
* `void setWebLogCSS(const char *css)`
|
||||
* `Span& setWebLogCSS(const char *css)`
|
||||
* sets the format of the HomeSpan Web Log to the custom style sheet specified by *css*
|
||||
* see [Message Logging](Logging.md) for details on how to construct *css*
|
||||
|
||||
|
||||
* `Span& setWebLogCallback(void (*func)(String &htmlText))`
|
||||
* sets an optional user-defined callback function, *func*, to be called by HomeSpan whenever the Web Log is produced
|
||||
* allows user to add additional custom data to the initial table of the Web Log by **extending** the String *htmlText*, which is passed as a reference to *func*
|
||||
* the function *func* must be of type *void* and accept one argument of type *String*
|
||||
* see [Message Logging](Logging.md) for details on how to construct *htmlText*
|
||||
|
||||
* `void getWebLog(void (*f)(const char *htmlBuf, void *args), void *userData)`
|
||||
* when called, HomeSpan *streams* the current Web Log HTML text, and any optionally-specified *userData*, directly to the user-defined function, *f()*, which should return a *void* and accept the following two arguments:
|
||||
* *htmlBuf* - pointer to part of the HTML text for the Web Log page
|
||||
* *args* - a pass-through of the *userData* argument
|
||||
* if user-defined data is not needed, set *userData* to NULL
|
||||
* to avoid creating a single large text buffer, HomeSpan splits the HTML for the Web Log into chunks of 1024 bytes and repeatedly calls *f()* until all the HTML has been streamed; HomeSpan then makes a final call to *f()* with *htmlBuf* set to NULL indicating to the user that the end of the HTML text has been reached
|
||||
* this command is primarily used to redirect Web Log pages to a user-defined process for alternative handling, display, or transmission
|
||||
* see [Message Logging](Logging.md) for more details
|
||||
|
||||
* `void processSerialCommand(const char *CLIcommand)`
|
||||
* processes the *CLIcommand* just as if were typed into the Serial Monitor
|
||||
* allows for programmatic access to all CLI commands, included any custom commands defined by the user
|
||||
* will work whether or not device is connected to a computer
|
||||
* example: `homeSpan.processSerialCommand("A");` starts the HomeSpan Setup Access Point
|
||||
* example: `homeSpan.processSerialCommand("Q HUB3");` changes the HomeKit Setup ID for QR Codes to "HUB3"
|
||||
|
||||
* `Span& setRebootCallback(void (*func)(uint8_t count), uint32_t upTime)`
|
||||
* sets an optional user-defined callback function, *func*, that is called (just once) when *upTime* milliseconds after rebooting have elapsed (default *upTime*=5000 ms if not specified)
|
||||
* the function *func* must be of type *void* and accept one argument of type *uint8_t*
|
||||
* the parameter *count*, which HomeSpan passes to *func*, indicates the number of "short" reboots that have occured prior to the current reboot, where a "short" reboot is any that occurs **before** *upTime* milliseconds have elapsed
|
||||
* this allows the user to provide a generic form of input to a sketch by rapidly turning on/off power to the device a specified number of times, typically to provide a method of resetting some aspect of a remote device
|
||||
* example using a lamba function:
|
||||
* `homeSpan.setRebootCallback( [](uint8_t c) {if(c==3) homeSpan.processSerialCommand("X");} );`
|
||||
* causes HomeSpan to run the 'X' Serial Command, which erases WiFi data, if the device is "short" rebooted exactly 3 times, where each reboot is for less than 5 seconds
|
||||
* note that creating 3 short reboots means you actually cycle the power (or press the reset button) a total of 4 times, since the last time you allow the sketch to run without rebooting
|
||||
|
||||
* `void setSerialInputDisable(boolean val)`
|
||||
* `Span& setSerialInputDisable(boolean val)`
|
||||
* if *val* is true, disables HomeSpan from reading input from the Serial port
|
||||
* if *val* is false, re-enables HomeSpan reading input from the Serial port
|
||||
* useful when the main USB Serial port is needed for reading data from an external Serial peripheral, rather than being used to read input from the Arduino Serial Monitor
|
||||
|
|
@ -238,7 +278,7 @@ The following **optional** `homeSpan` methods provide additional run-time functi
|
|||
* allows for dynamically changing the Accessory database during run-time (i.e. changing the configuration *after* the Arduino `setup()` has finished)
|
||||
* deleting an Accessory automatically deletes all Services, Characteristics, and any other resources it contains
|
||||
* outputs Level-1 Log Messages listing all deleted components
|
||||
* note: though deletions take effect immediately, HomeKit Controllers, such as the Home App, will not be aware of these changes until the database configuration number is updated and rebroadcast - see updateDatabase() below
|
||||
* note: though deletions take effect immediately, HomeKit Controllers, such as the Home App, will not be aware of these changes until the database configuration number is updated and rebroadcast - see `updateDatabase()` below
|
||||
|
||||
* `boolean updateDatabase()`
|
||||
* recomputes the database configuration number and, if changed, rebroadcasts the new number via MDNS so all connected HomeKit Controllers, such as the Home App, can request a full refresh to accurately reflect the new configuration
|
||||
|
|
@ -247,6 +287,43 @@ The following **optional** `homeSpan` methods provide additional run-time functi
|
|||
* use anytime after dynamically adding one or more Accessories (with `new SpanAccessory(aid)`) or deleting one or more Accessories (with `homeSpan.deleteAccessory(aid)`)
|
||||
* **important**: once you delete an Accessory, you cannot re-use the same *aid* when adding a new Accessory (on the same device) unless the new Accessory is configured with the exact same Services and Characteristics as the deleted Accessory
|
||||
* note: this method is **not** needed if you have a static Accessory database that is fully defined in the Arduino `setup()` function of a sketch
|
||||
|
||||
* `Span& resetIID(uint32_t newIID)`
|
||||
* resets the IID count for the current Accessory to *newIID*, which must be greater than 0
|
||||
* throws an error and halts program if called before at least one Accessory is created
|
||||
* example: `homeSpan.resetIID(100)` causes HomeSpan to set the IID to 100 for the very next Service or Characteristic defined within the current Accessory, and then increment the IID count going forward so that any Services or Characteristics subsequently defined (within the same Accessory) have IID=101, 102, etc.
|
||||
* note: calling this function only affects the IID generation for the current Accessory (the count will be reset to IID=1 upon instantiation of a new Accessory)
|
||||
|
||||
* `const_iterator controllerListBegin()` and `const_iterator controllerListEnd()`
|
||||
* returns a *constant iterator* pointing to either the *beginning*, or the *end*, of an opaque linked list that stores all controller data
|
||||
* iterators should be defined using the `auto` keyword as follows: `auto myIt=homeSpan.controllerListBegin();`
|
||||
* controller data can be read from a de-referenced iterator using the following methods:
|
||||
* `const uint8_t *getID()` returns pointer to the 36-byte ID of the controller
|
||||
* `const uint8_t *getLTPK()` returns pointer to the 32-byte Long Term Public Key of the controller
|
||||
* `boolean isAdmin()` returns true if controller has admin permissions, else returns false
|
||||
* <details><summary>click here for example code</summary><br>
|
||||
|
||||
```C++
|
||||
// Extract and print the same data about each controller that HomeSpan prints to the Serial Monitor when using the 's' CLI command
|
||||
|
||||
Serial.printf("\nController Data\n");
|
||||
|
||||
for(auto it=homeSpan.controllerListBegin(); it!=homeSpan.controllerListEnd(); ++it){ // loop over each controller
|
||||
|
||||
Serial.printf("Admin=%d",it->isAdmin()); // indicate if controller has admin permissions
|
||||
|
||||
Serial.printf(" ID="); // print the 36-byte Device ID of the controller
|
||||
for(int i=0;i<36;i++)
|
||||
Serial.printf("%02X",it->getID()[i]);
|
||||
|
||||
Serial.printf(" LTPK="); // print the 32-byte Long-Term Public Key of the controller)
|
||||
for(int i=0;i<32;i++)
|
||||
Serial.printf("%02X",it->getLTPK()[i]);
|
||||
|
||||
Serial.printf("\n");
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -258,18 +335,21 @@ The following `homeSpan` methods are considered experimental, since not all use
|
|||
|
||||
* *stackSize* - size of stack, in bytes, used by the polling task. Default=8192 if unspecified
|
||||
* *priority* - priority at which task runs. Minimum is 1. Maximum is typically 24, but it depends on how the ESP32 operating system is configured. If you set it to an arbitrarily high value (e.g. 999), it will be set to the maximum priority allowed. Default=1 if unspecified
|
||||
* *cpu* - specifies the CPU on which the polling task will run. Valid values are 0 and 1. This paramater is ignored on single-cpu boards. Default=0 if unspecified
|
||||
* *cpu* - specifies the CPU on which the polling task will run. Valid values are 0 and 1. This parameter is ignored on single-cpu boards. Default=0 if unspecified
|
||||
* if used, **must** be placed in a sketch as the last line in the Arduino `setup()` method
|
||||
* HomeSpan will throw and error and halt if both `poll()`and `autoPoll()` are used in the same sketch - either place `poll()` in the Arduino `loop()` method **or** place `autoPoll()` at the the end of the Arduino `setup()` method
|
||||
* if this method is used, and you have no need to add your own code to the main Arduino `loop()`, you can safely skip defining a blank `void loop(){}` function in your sketch
|
||||
* warning: if any code you add to the Arduino `loop()` method tries to alter any HomeSpan settings or functions running in the background `poll()` task, race conditions may yield undefined results
|
||||
|
||||
* `TaskHandle_t getAutoPollTask()`
|
||||
* returns the task handle for the Auto Poll Task, or NULL if Auto Polling has not been used
|
||||
|
||||
## *SpanAccessory(uint32_t aid)*
|
||||
|
||||
Creating an instance of this **class** adds a new HAP Accessory to the HomeSpan HAP Database.
|
||||
|
||||
* every HomeSpan sketch requires at least one Accessory
|
||||
* a sketch can contain a maximum of 41 Accessories per sketch (if exceeded, a runtime error will the thrown and the sketch will halt)
|
||||
* a sketch can contain a maximum of 150 Accessories per sketch (if exceeded, a runtime error will the thrown and the sketch will halt)
|
||||
* there are no associated methods
|
||||
* the argument *aid* is optional.
|
||||
|
||||
|
|
@ -306,11 +386,15 @@ The following methods are supported:
|
|||
* note that Linked Services are only applicable for select HAP Services. See Apple's HAP-R2 documentation for full details
|
||||
* example: `(new Service::Faucet)->addLink(new Service::Valve)->addLink(new Service::Valve);` (links two Valves to a Faucet)
|
||||
|
||||
* `vector<SpanService *> getLinks()`
|
||||
* returns a vector of pointers to Services that were added using `addLink()`
|
||||
* useful for creating loops that iterate over all linked Services
|
||||
* note that the returned vector points to generic SpanServices, which should be re-cast as needed
|
||||
* example: `for(auto myValve : faucet->getLinks()) { if((MyValve *)myValve)->active->getVal()) ... }` checks all Valves linked to a Faucet
|
||||
* `vector<T> getLinks<T=SpanService *>(const char *serviceName=NULL)`
|
||||
* template function that returns a vector of pointers to Services that were added using `addLink()`
|
||||
* if template parameter, *T*, is left blank, the elements of the returned vector will be of type *SpanService \**
|
||||
* if template parameter, *T*, is specified, the elements of the returned vector will be cast into type *T*
|
||||
* if *serviceName* is specified, only those services matching *serviceName* will be included in the return vector
|
||||
* *serviceName* must be one of HomeSpan's built-in Services (e.g. "Valve")
|
||||
* if *serviceName* is left blank or set to NULL, all services will be included in the return vector
|
||||
* this function is useful for creating loops that iterate over all linked Services
|
||||
* example: from within a Faucet Service containing linked Valves defined in *MyValveService*, use `for(auto valve : getLinks<MyValveService *>()) { if(valve->active->getVal()) ... }` to check which Valves are active
|
||||
|
||||
* `virtual boolean update()`
|
||||
* HomeSpan calls this method upon receiving a request from a HomeKit Controller to update one or more Characteristics associated with the Service. Users should override this method with code that implements that requested updates using one or more of the SpanCharacteristic methods below. Method **must** return *true* if update succeeds, or *false* if not.
|
||||
|
|
@ -325,6 +409,9 @@ The following methods are supported:
|
|||
* 0=single press (SpanButton::SINGLE)
|
||||
* 1=double press (SpanButton::DOUBLE)
|
||||
* 2=long press (SpanButton::LONG)
|
||||
|
||||
* `uint32_t getIID()`
|
||||
* returns the IID of the Service
|
||||
|
||||
## *SpanCharacteristic(value [,boolean nvsStore])*
|
||||
|
||||
|
|
@ -332,13 +419,18 @@ This is a **base class** from which all HomeSpan Characteristics are derived, an
|
|||
|
||||
* instantiated Characteristics are added to the HomeSpan HAP Database and associated with the last Service instantiated
|
||||
* instantiating a Characteristic without first instantiating a Service throws an error during initialization
|
||||
* the first argument optionally allows you to set the initial *value* of the Characteristic at startup. If *value* is not specified, HomeSpan will supply a reasonable default for the Characteristic
|
||||
* throws a runtime warning if *value* is outside of the min/max range for the Characteristic, where min/max is either the HAP default, or any new values set via a call to `setRange()`
|
||||
* the first argument optionally allows you to set the initial *value* of the Characteristic at startup using the following formats:
|
||||
* for NUMERIC Characteristics, *value* can be any integer or decimal numeric type, such as `boolean`, `int`, `uint64_t`, `double`, etc. HomeSpan will automatically cast *value* into a variable with the correct numerical precision for the Characteristic specified
|
||||
* for STRING Characteristics, *value* must be either of the type `char *`, or a literal quote-enclosed UTF-8 string
|
||||
* for TLV8 Characteristics, *value* must be of the type `TLV8`
|
||||
* for DATA Characteristics, *value* must be a brace-enclosed *pair* of the form `{uint8_t *data, size_t len}`, where *len* specifies the length of the size of the byte-array *data*
|
||||
* if *value* is not specified, HomeSpan will supply a reasonable default for the Characteristic
|
||||
* for numerical Characteristics, throws a runtime warning if *value* is outside of the min/max range for the Characteristic, where min/max is either the HAP default, or any new values set via a call to `setRange()`
|
||||
* the second optional argument, if set to `true`, instructs HomeSpan to save updates to this Characteristic's value in the device's non-volative storage (NVS) for restoration at startup if the device should lose power. If not specified, *nvsStore* will default to `false` (no storage)
|
||||
* examples:
|
||||
* `new Characteristic::Brightness();` Brightness initialized to default value
|
||||
* `new Characteristic::Brightness(50);` Brightness initialized to 50
|
||||
* `new Characteristic::Brightness(50,true);` Brightness initialized to 50; updates saved in NVS
|
||||
* `new Characteristic::Brightness(50,true);` Brightness initialized to 50; updates to the value are saved to, and restored from, NVS
|
||||
|
||||
#### The following methods are supported for numerical-based Characteristics (e.g. *int*, *float*...):
|
||||
|
||||
|
|
@ -349,12 +441,16 @@ This is a **base class** from which all HomeSpan Characteristics are derived, an
|
|||
|
||||
* `type T getNewVal<T>()`
|
||||
* a template method that returns the desired **new** value to which a HomeKit Controller has requested the Characteristic be updated. Same casting rules as for `getVal<>()`
|
||||
* only applicable when called from within the `update()` loop of a **SpanService** (if called outside of the `update()` loop, the return value is that same as calling `getVal<>()`)
|
||||
|
||||
* `void setVal(value [,boolean notify])`
|
||||
* sets the value of a numerical-based Characteristic to *value*, and, if *notify* is set to true, notifies all HomeKit Controllers of the change. The *notify* flag is optional and will be set to true if not specified. Setting the *notify* flag to false allows you to update a Characateristic without notifying any HomeKit Controllers, which is useful for Characteristics that HomeKit automatically adjusts (such as a countdown timer) but will be requested from the Accessory if the Home App closes and is then re-opened
|
||||
* works with any integer, boolean, or floating-based numerical *value*, though HomeSpan will convert *value* into the appropriate type for each Characteristic (e.g. calling `setValue(5.5)` on an integer-based Characteristic results in *value*=5)
|
||||
* throws a runtime warning if *value* is outside of the min/max range for the Characteristic, where min/max is either the HAP default, or any new min/max range set via a prior call to `setRange()`
|
||||
* *value* is **not** restricted to being an increment of the step size; for example it is perfectly valid to call `setVal(43.5)` after calling `setRange(0,100,5)` on a floating-based Characteristic even though 43.5 does does not align with the step size specified. The Home App will properly retain the value as 43.5, though it will round to the nearest step size increment (in this case 45) when used in a slider graphic (such as setting the temperature of a thermostat)
|
||||
* note that *value* is **not** restricted to being an increment of the step size; for example it is perfectly valid to call `setVal(43.5)` after calling `setRange(0,100,5)` on a floating-based Characteristic even though 43.5 does does not align with the step size specified. The Home App will properly retain the value as 43.5, though it will round to the nearest step size increment (in this case 45) when used in a slider graphic (such as setting the temperature of a thermostat)
|
||||
* throws a runtime warning if called from within the `update()` routine of a **SpanService** *and* `isUpdated()` is *true* for the Characteristic (i.e. it is being updated at the same time via the Home App), *unless* you are changing the value of a Characteristic in response to a *write-response* request from HomeKit (typically used only for certain TLV-based Characteristics)
|
||||
* note this method can be used to update the value of a Characteristic even if the Characteristic is not permissioned for event notifications (EV), in which case the value stored by HomeSpan will be updated but the Home App will *not* be notified of the change
|
||||
|
||||
|
||||
* `SpanCharacteristic *setRange(min, max, step)`
|
||||
* overrides the default HAP range for a Characteristic with the *min*, *max*, and *step* parameters specified
|
||||
|
|
@ -381,10 +477,10 @@ This is a **base class** from which all HomeSpan Characteristics are derived, an
|
|||
* `char *getNewString()`
|
||||
* equivalent to `getNewVal()`, but used exclusively for string-characteristics (i.e. a null-terminated array of characters)
|
||||
|
||||
* `void setString(const char *value)`
|
||||
* `void setString(const char *value [,boolean notify])`
|
||||
* equivalent to `setVal(value)`, but used exclusively for string-characteristics (i.e. a null-terminated array of characters)
|
||||
|
||||
#### The following methods are supported for DATA (i.e. byte-array) Characteristics:
|
||||
#### The following methods are supported for DATA (i.e. byte-array) Characteristics:
|
||||
|
||||
* `size_t getData(uint8_t *data, size_t len)`
|
||||
* similar to `getVal()`, but exclusively used for byte-array Characteristics
|
||||
|
|
@ -392,14 +488,38 @@ This is a **base class** from which all HomeSpan Characteristics are derived, an
|
|||
* returns the total number of bytes encoded in the Characteristic
|
||||
* if *len* is less than the total number of bytes encoded, no data is extracted (i.e. *data* is unmodified) and a warning message is thrown indicating that the size of the *data* array is insufficient to extract all the bytes encoded in the Characteristic
|
||||
* setting *data* to NULL returns the total number of bytes encoded without extracting any data. This can be used to help create a *data* array of sufficient size in advance of extracting the data
|
||||
* note: byte-array Characteristics are encoded and transmitted as base-64 strings. HomeSpan automatically peforms all encoding and decoding between this format and the specified byte arrays. But when output to the Serial Monitor using the 'i' CLI command, the value of byte-array Characteristics are displayed in their base-64 string format (only the first 32 characters are shown), since base-64 is the representation that is actually transmitted to and from HomeKit
|
||||
* a warning message is thrown if the value stored in the Characteristic is not in base-64 format
|
||||
|
||||
* `size_t getNewData(uint8_t *data, size_t len)`
|
||||
* similar to `getData()`, but fills byte array *data*, of specified size *len*, with bytes based on the desired **new** value to which a HomeKit Controller has requested the Characteristic be updated
|
||||
|
||||
* `void setData(uint8_t *data, size_t len)`
|
||||
* `void setData(uint8_t *data, size_t len [,boolean notify])`
|
||||
* similar to `setVal()`, but exclusively used for byte-array Characteristics
|
||||
* updates the Characteristic by "filling" it with *len* bytes from bytes array *data*
|
||||
* note: byte-array Characteristics are encoded and transmitted as base-64 strings. HomeSpan automatically peforms all encoding and decoding between this format and the specified byte arrays. But when output to the Serial Monitor, the value of byte-array Characteristics are displayed in their base-64 format (as opposed to being shown as a byte array), since base-64 is the representation that is actually transmitted to and from HomeKit
|
||||
|
||||
#### The following methods are supported for TLV8 (structured-data) Characteristics:
|
||||
|
||||
* `size_t getTLV(TLV8 &tlv)`
|
||||
* similar to `getVal()`, but exclusively used for TLV8 Characteristics
|
||||
* fills TLV8 structure *tlv* with TLV8 records from the current value of the Characteristic
|
||||
* returns the total number of bytes encoded in the Characteristic
|
||||
* if *tlv8* is not empty, TLV8 records from the Characteristic will be appended to any existing records
|
||||
* similar to DATA Characteristics, TLV8 Characteristics are stored and transmitted as base-64 strings
|
||||
* a warning message is thrown if the value stored in the Characteristic is not in base-64 format, or does not appear to contain TLV8 records
|
||||
|
||||
* `size_t getNewTLV(TLV8 &tlv)`
|
||||
* similar to `getTLV()`, but fills TLV8 structure *tlv* with TLV8 records based on the desired **new** value to which a HomeKit Controller has requested the Characteristic be updated
|
||||
|
||||
* `void setTLV(TLV8 &tlv [,boolean notify])`
|
||||
* similar to `setVal()`, but exclusively used for TLV8 Characteristics
|
||||
* updates the Characteristic by packing the TLV8 structure *tlv* into a byte array and then encoding it in base-64 for storage as a string
|
||||
|
||||
* `NULL_TLV`
|
||||
* this is not a method, but rather a static HomeSpan constant defined as an empty TLV8 object. It may used a placeholder wherever an empty TLV8 object is needed, such as when you want to instantiate a TLV8 Characteristic with *nvsStore=true*, but you don't yet want set the TLV8 value
|
||||
* example: `new Characteristic::DisplayOrder(NULL_TLV,true);`
|
||||
|
||||
* see the [TLV8 Characteristics](TLV8.md) page for complete details on how to read/process/create TLV8 Objects using HomeSpan's TLV8 Library.
|
||||
|
||||
#### The following methods are supported for all Characteristics:
|
||||
|
||||
|
|
@ -435,6 +555,9 @@ This is a **base class** from which all HomeSpan Characteristics are derived, an
|
|||
* returns a pointer to the Characteristic itself so that the method can be chained during instantiation
|
||||
* example: `(new Characteristic::RotationSpeed())->setUnit("percentage");`
|
||||
|
||||
* `uint32_t getIID()`
|
||||
* returns the IID of the Characteristic
|
||||
|
||||
### *SpanButton(int pin, uint16_t longTime, uint16_t singleTime, uint16_t doubleTime, boolean (\*triggerType)(int))*
|
||||
|
||||
Creating an instance of this **class** attaches a pushbutton handler to the ESP32 *pin* specified.
|
||||
|
|
@ -496,7 +619,7 @@ Creating an instance of this **class** attaches a toggle-switch handler to the E
|
|||
* 3=switch is closed (`SpanToggle::CLOSED`)
|
||||
* 4=switch is open (`SpanToggle::OPEN`)
|
||||
|
||||
Note there are no *singleTime*, *longTime*, or *doubleTime* paramaters in the constructor since you can't single-press, double-press, or long-press a toggle switch. Instead, the constructor supports the single parameter *toggleTime* (default=5ms if left unspecified) that sets the minimum time at which the switch needs to be moved to the closed position in order to trigger a call to the `button()` method. This effectively "debounces" the toggle switch.
|
||||
Note there are no *singleTime*, *longTime*, or *doubleTime* parameters in the constructor since you can't single-press, double-press, or long-press a toggle switch. Instead, the constructor supports the single parameter *toggleTime* (default=5ms if left unspecified) that sets the minimum time at which the switch needs to be moved to the closed position in order to trigger a call to the `button()` method. This effectively "debounces" the toggle switch.
|
||||
|
||||
SpanToggle also supports the following additional method:
|
||||
|
||||
|
|
@ -545,17 +668,20 @@ To create more than one user-defined command, simply create multiple instances o
|
|||
### *CUSTOM_CHAR(name,uuid,perms,format,defaultValue,minValue,maxValue,staticRange)*
|
||||
### *CUSTOM_CHAR_STRING(name,uuid,perms,defaultValue)*
|
||||
### *CUSTOM_CHAR_DATA(name,uuid,perms)*
|
||||
### *CUSTOM_CHAR_TLV8(name,uuid,perms)*
|
||||
|
||||
Creates a custom Characteristic that can be added to any Service. Custom Characteristics are generally ignored by the Home App but may be used by other third-party applications (such as *Eve for HomeKit*). The first form should be used create numerical Characterstics (e.g., UINT8, BOOL...). The second form is used to STRING-based Characteristics. The third form is used for DATA-based (i.e. byte-array) Characteristics. Parameters are as follows (note that quotes should NOT be used in any of the macro parameters, except for *defaultValue* when applied to a STRING-based Characteristic):
|
||||
Creates a custom Characteristic that can be added to any Service. Custom Characteristics are generally ignored by the Home App but may be used by other third-party applications (such as *Eve for HomeKit*). The first form should be used create numerical Characterstics (e.g., UINT8, BOOL...); the second form is used to STRING-based Characteristics; the third form is used for DATA-based (i.e. byte-array) Characteristics; and the fourth form is used for TLV8-based (i.e. *structured* byte-array) Characteristics Parameters are as follows (note that quotes should NOT be used in any of the macro parameters, except for *defaultValue* when applied to a STRING-based Characteristic):
|
||||
|
||||
* *name* - the name of the custom Characteristic. This will be added to the Characteristic namespace so that it is accessed the same as any HomeSpan Characteristic
|
||||
* *uuid* - the UUID of the Characteristic as defined by the manufacturer. Must be *exactly* 36 characters in the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, where *X* represent a valid hexidecimal digit. Leading zeros are required if needed as described more fully in HAP-R2 Section 6.6.1
|
||||
* *perms* - additive list of permissions as described in HAP-R2 Table 6-4. Valid values are PR, PW, EV, AA, TW, HD, and WR
|
||||
* *format* - specifies the format of the Characteristic value, as described in HAP-R2 Table 6-5. Valid value are BOOL, UINT8, UINT16, UNIT32, UINT64, INT, and FLOAT (note that the HomeSpan does not presently support the TLV8 formats). Not applicable for the STRING or DATA Characteristic macros
|
||||
* *defaultValue* - specifies the default value of the Characteristic if not defined during instantiation. Not applicable for the DATA Characteristic macro.
|
||||
* *minValue* - specifies the default minimum range for a valid value, which may be able to be overriden by a call to `setRange()`. Not applicable for the STRING or DATA Characteristic macros
|
||||
* *minValue* - specifies the default minimum range for a valid value, which may be able to be overriden by a call to `setRange()`. Not applicable for the STRING or DATA Characteristic macros
|
||||
* *staticRange* - set to *true* if *minValue* and *maxValue* are static and cannot be overridden with a call to `setRange()`. Set to *false* if calls to `setRange()` are allowed. Not applicable for the STRING or DATA Characteristic macros
|
||||
* *name* - the name of the custom Characteristic. This will be added to the Characteristic namespace so that it is accessed the same as any HomeSpan Characteristic. Use UTF-8 coded string for non-ASCII characters.
|
||||
* *uuid* - the UUID of the Characteristic as defined by the manufacturer. Must be either:
|
||||
* *exactly* 36 characters of the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, where *X* represent a valid hexidecimal digit, or
|
||||
* a single hexidecimal number of the form XXXXXXXX with *8 digits or less*, and no leading zeros
|
||||
* *perms* - additive list of permissions. Valid values are PR, PW, EV, AA, TW, HD, and WR (e.g. PR+PW+EV)
|
||||
* *format* - for numerical Characteristics, specifies the number format. Valid value are BOOL, UINT8, UINT16, UNIT32, UINT64, INT, and FLOAT. Not applicable for the STRING, DATA, or TLV8 Characteristic macros
|
||||
* *defaultValue* - specifies the default value of the Characteristic when not defined during instantiation. Not applicable for the DATA or TLV7 Characteristic macros.
|
||||
* *minValue* - specifies the default minimum range for a valid value, which may be able to be overriden by a call to `setRange()`. Not applicable for the STRING, DATA or TLV8 Characteristic macros
|
||||
* *minValue* - specifies the default minimum range for a valid value, which may be able to be overriden by a call to `setRange()`. Not applicable for the STRING, DATA or TLV8 Characteristic macros
|
||||
* *staticRange* - set to *true* if *minValue* and *maxValue* are static and cannot be overridden with a call to `setRange()`. Set to *false* if calls to `setRange()` are allowed. Not applicable for the STRING, DATA or TLV8 Characteristic macros
|
||||
|
||||
As an example, the first line below creates a custom Characteristic named "Voltage" with a UUID code that is recognized by the *Eve for HomeKit* app. The parameters show that the Characteristic is read-only (PR) and notifications are enabled (EV). The default range of allowed values is 0-240, with a default of 120. The range *can* be overridden by subsequent calls to `setRange()`. The second line below creates a custom read-only String-based Characteristic:
|
||||
|
||||
|
|
|
|||
|
|
@ -1,203 +1,455 @@
|
|||
# HomeSpan Services and Characteristics
|
||||
|
||||
HomeSpan implements all HAP-R2 Services and Characteristics except for those that involve video or audio streaming, Apple TV, or advanced lock management (i.e. all HAP Services except those that require Characteristics with a TLV8 data type).
|
||||
Below is a list of all Services supported by HomeSpan, along with a brief description of each Service. Click on the arrow next to the description of any Service to see a list of all Characteristics supported by the Service, as well as a description of each Characteristic.[^1]
|
||||
|
||||
A blue diamond (🔹) next to a Characteristic means it is **required** for that Service, otherwise it is optional. Information included for each Characteristic is as follows:
|
||||
|
||||
* **Format** - the native format of the Characteristic's value. Note that *string* means a standard C-string (i.e. char \*)
|
||||
* **Perms**, where
|
||||
* PR = Paired Read. This means HomeKit can read the value from HomeSpan[^2]
|
||||
* PW = Paired Write. This means HomeKit can write the value to HomeSpan, which triggers a call to `update()`
|
||||
* EV = Event Notification. This means HomeSpan can push notifications of value changes to HomeKit using `setVal()`
|
||||
* **Min** / **Max** - the default minimum and maximum values allowed in HomeKit. For applicable numerical Characteristics, you can change the allowed minimum and maximum values using `setRange()`
|
||||
* **Constants/Defaults**
|
||||
* for enumerated Characteristics, a list of all allowed values in the form of pre-defined constant expressions and their equivalent numeric values. A check mark next to a constant indicates that it is the default value. If your Accessory does not support certain states of a Characteristic, you can change the allowed values using `setValidValues()`
|
||||
* for all other Characteristics, the actual default value that is used if you do not specify one when instantiating the Characteristic
|
||||
|
||||
[^1]: The hexidecimal numbers in parentheses next to each Service and Characteristic represent the short-form of the Apple's UUID for that Service or Characteristic. These are provided for informational purposes only (you do not need to use them, or even know about them, to create HomeSpan sketches)
|
||||
|
||||
[^2]: Though rarely needed, you can change the permissions of a Characteristic using `setPerms()`, `addPerms()`, and `removePerms()`
|
||||
|
||||
HomeSpan Services and Characteristics are implemented as C++ Classes with names that exactly match the spelling and capitalization specified by Apple in Sections 8 and 9 of HAP-R2, but without any spaces. HomeSpan Services are defined in HomeSpan's `Service` namespace. HomeSpan Characteristics are defined in HomeSpan's `Characteristic` namespace. For example, HomeSpan defines the *Carbon Dioxide Sensor* Service (HAP Service 8.7) as `Service::CarbonDioxideSensor`, and the *Carbon Dioxide Detected* Characteristic (HAP Characteristic 9.16) as `Characteristic::CarbonDioxideDetected`.
|
||||
|
||||
HomeSpan Services and Characteristics are instantiated with a C++ `new` command. Services do not take any arguments, whereas Characteristics take a single, optional argument that is used to initialize the value of the Characteristic at startup. If this argument is not specified, HomeSpan will apply a reasonable [default value](#characteristic-types-and-defaults) based on the Characteristic's type and allowed range.
|
||||
The pre-defined constant expressions for enumerated Characteristics are in namespaces that match the name of the Characteristic. For example, to set the *Air Quality* Characteristic of an *Air Quality Sensor* Service, you could use `setVal(Characteristic::AirQuality::GOOD)` or, equivalently, `setVal(2)`.[^3]
|
||||
|
||||
A list of all HomeSpan Services is provided in the table below. For each Service the table also indicates which Characteristics are required and which are optional. For example, a dimmable light bulb could be configured in HomeSpan as such:
|
||||
[^3]: Note that a Characteristic's pre-defined constants are inherited by objects that you create from that Characteristic. This means that if you create a pointer to the *AirQuality* Characteristic using `Characteristic::AirQuality *air = new Characteristic::AirQuality;` then later in your code you can either say<br> `air->setVal(Characteristic::AirQuality::GOOD)` or `air->GOOD`. Both will work, but the latter is much easier to type.
|
||||
|
||||
```C++
|
||||
new Service::LightBulb(); // instantiate a Light Bulb Service
|
||||
new Characteristic:On(); // instantiate the required On Characteristic without setting initial value
|
||||
new Characteristic::Brightness(50); // instantiate an optional Brightness Characteristic and set initial value to 50%
|
||||
new Characteristic::Name("Living Room Lamp"); // instantiate an optional Name Characteristic for this Service, and set to "Living Room Lamp"
|
||||
```
|
||||
<!-- AUTOGENERATED_TEXT. DO NOT EDIT THIS LINE OR ANYTHING BELOW -->
|
||||
|
||||
Please see Sections 8 and 9 of HAP-R2 for a complete description of all HAP Services and Characteristics. Note that HomeSpan's Service and Characteristic Classes already contain all the required HAP fields, such as the UUID, Format, and Permissions, so you don't need to specify any of these parameters.
|
||||
|
||||
Additionally, when first starting up, HomeSpan begins by validating the device's configuration to ensure each Service you instantiate includes all required Characteristics, but does not include any Characteristics that are neither required nor optional. If any errors are found, HomeSpan reports them to the Arduino Serial Monitor.
|
||||
## MANDATORY SERVICES
|
||||
### AccessoryInformation (3E)
|
||||
<i> Required Identification Information. For each Accessory in a HomeSpan device this must be included as the first Service.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>Identify (14) :small_blue_diamond:</b><ul><li> triggers an update when HomeKit wants HomeSpan to run its identification routine for an Accessory</li></ul></td><td align="center">bool</td><td align="center">PW</td><td align="center">1</td><td align="center">1</td><td><ul><li><span>RUN_ID (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>Name (23) </b><ul><li> default display name of the Accessory</li></ul></td><td align="center">string</td><td align="center">PR</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
<tr><td><b>FirmwareRevision (52) </b><ul><li> must be in form x[.y[.z]] - informational only</li></ul></td><td align="center">string</td><td align="center">PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"1.0.0"</td></tr>
|
||||
<tr><td><b>Manufacturer (20) </b><ul><li> any string - informational only</li></ul></td><td align="center">string</td><td align="center">PR</td><td align="center">-</td><td align="center">-</td><td align="center">"HomeSpan"</td></tr>
|
||||
<tr><td><b>Model (21) </b><ul><li> any string - informational only</li></ul></td><td align="center">string</td><td align="center">PR</td><td align="center">-</td><td align="center">-</td><td align="center">"HomeSpan-ESP32"</td></tr>
|
||||
<tr><td><b>SerialNumber (30) </b><ul><li> any string - informational only</li></ul></td><td align="center">string</td><td align="center">PR</td><td align="center">-</td><td align="center">-</td><td align="center">"HS-12345"</td></tr>
|
||||
<tr><td><b>HardwareRevision (53) </b><ul><li> must be in form x[.y[.z]] - informational only</li></ul></td><td align="center">string</td><td align="center">PR</td><td align="center">-</td><td align="center">-</td><td align="center">"1.0.0"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### Service List
|
||||
## LIGHTS, POWER, AND SWITCHES
|
||||
### BatteryService (96)
|
||||
<i> Defines a standalone Battery Service.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>BatteryLevel (68) :small_blue_diamond:</b><ul><li> measured as a percentage</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">100</td></tr>
|
||||
<tr><td><b>ChargingState (8F) :small_blue_diamond:</b><ul><li> indicates state of battery charging</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">2</td><td><ul><li><span>NOT_CHARGING (0) </span>:heavy_check_mark:</li><li><span>CHARGING (1) </span></li><li><span>NOT_CHARGEABLE (2) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusLowBattery (79) :small_blue_diamond:</b><ul><li> indicates state of battery</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_LOW_BATTERY (0) </span>:heavy_check_mark:</li><li><span>LOW_BATTERY (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
|Service|Required Characteristics|Optional Characteristics|
|
||||
|-|-|-|
|
||||
|AccessoryInformation|Identify|FirmwareRevision<br>Manufacturer<br>Model<br>Name<br>SerialNumber<br>HardwareRevision<br>AccessoryFlags|
|
||||
|AirPurifier|Active<br>CurrentAirPurifierState<br>TargetAirPurifierState|Name<br>RotationSpeed<br>SwingMode<br>LockPhysicalControls|
|
||||
|AirQualitySensor|AirQuality|Name<br>OzoneDensity<br>NitrogenDioxideDensity<br>SulphurDioxideDensity<br>PM25Density<br>PM10Density<br>VOCDensity<br>StatusActive<br>StatusFault<br>StatusTampered<br>StatusLowBattery|
|
||||
|BatteryService|BatteryLevel<br>ChargingState<br>StatusLowBattery|Name|
|
||||
|CarbonDioxideSensor|CarbonDioxideDetected|Name<br>StatusActive<br>StatusFault<br>StatusTampered<br>StatusLowBattery<br>CarbonDioxideLevel<br>CarbonDioxidePeakLevel|
|
||||
|CarbonMonoxideSensor|CarbonMonoxideDetected|Name<br>StatusActive<br>StatusFault<br>StatusTampered<br>StatusLowBattery<br>CarbonMonoxideLevel<br>CarbonMonoxidePeakLevel|
|
||||
|ContactSensor|ContactSensorState|Name<br>StatusActive<br>StatusFault<br>StatusTampered<br>StatusLowBattery|
|
||||
|Door|CurrentPosition<br>TargetPosition<br>PositionState|Name<br>HoldPosition<br>ObstructionDetected|
|
||||
|Doorbell|ProgrammableSwitchEvent|Name<br>Volume<br>Brightness|
|
||||
|Fan|Active|Name<br>CurrentFanState<br>TargetFanState<br>RotationDirection<br>RotationSpeed<br>SwingMode<br>LockPhysicalControls|
|
||||
|Faucet|Active|StatusFault<br>Name|
|
||||
|FilterMaintenance|FilterChangeIndication|Name<br>FilterLifeLevel<br>ResetFilterIndication|
|
||||
|GarageDoorOpener|CurrentDoorState<br>TargetDoorState<br>ObstructionDetected|LockCurrentState<br>LockTargetState<br>Name|
|
||||
|HAPProtocolInformation|Version||HeaterCooler|Active<br>CurrentTemperature<br>CurrentHeaterCoolerState<br>TargetHeaterCoolerState|Name<br>RotationSpeed<br>TemperatureDisplayUnits<br>SwingMode<br>CoolingThresholdTemperature<br>HeatingThresholdTemperature<br>LockPhysicalControls|
|
||||
|HumidifierDehumidifier|Active<br>CurrentRelativeHumidity<br>CurrentHumidifierDehumidifierState<br>TargetHumidifierDehumidifierState|Name<br>RelativeHumidityDehumidifierThreshold<br>RelativeHumidityHumidifierThreshold<br>RotationSpeed<br>SwingMode<br>WaterLevel<br>LockPhysicalControls|
|
||||
|HumiditySensor|CurrentRelativeHumidity|Name<br>StatusActive<br>StatusFault<br>StatusTampered<br>StatusLowBattery|
|
||||
|InputSource|Identifier|ConfiguredName<br>IsConfigured<br>CurrentVisibilityState<br>TargetVisibilityState|
|
||||
|IrrigationSystem|Active<br>ProgramMode<br>InUse|RemainingDuration<br>StatusFault|
|
||||
|LeakSensor|LeakDetected|Name<br>StatusActive<br>StatusFault<br>StatusTampered<br>StatusLowBattery|
|
||||
|LightBulb|On|Brightness<br>Hue<br>Name<br>Saturation<br>ColorTemperature|
|
||||
|LightSensor|CurrentAmbientLightLevel|Name<br>StatusActive<br>StatusFault<br>StatusTampered<br>StatusLowBattery|
|
||||
|LockMechanism|LockCurrentState<br>LockTargetState|Name|
|
||||
|Microphone|Mute|Name<br>Volume|
|
||||
|MotionSensor|MotionDetected|Name<br>StatusActive<br>StatusFault<br>StatusTampered<br>StatusLowBattery|
|
||||
|OccupancySensor|OccupancyDetected|Name<br>StatusActive<br>StatusFault<br>StatusTampered<br>StatusLowBattery|
|
||||
|Outlet|On<br>OutletInUse|Name|
|
||||
|SecuritySystem|SecuritySystemCurrentState<br>SecuritySystemTargetState|Name<br>SecuritySystemAlarmType<br>StatusFault<br>StatusTampered|
|
||||
|ServiceLabel|ServiceLabelNamespace||Slat|CurrentSlatState<br>SlatType|Name<br>SwingMode<br>CurrentTiltAngle<br>TargetTiltAngle|
|
||||
|SmokeSensor|SmokeDetected|Name<br>StatusActive<br>StatusFault<br>StatusTampered<br>StatusLowBattery|
|
||||
|Speaker|Mute|Name<br>Volume|
|
||||
|StatelessProgrammableSwitch|ProgrammableSwitchEvent|Name<br>ServiceLabelIndex|
|
||||
|Switch|On|Name|
|
||||
|Television|Active|ConfiguredName<br>ActiveIdentifier<br>RemoteKey<br>PowerModeSelection|
|
||||
|TelevisionSpeaker|VolumeControlType<br>VolumeSelector||TemperatureSensor|CurrentTemperature|Name<br>StatusActive<br>StatusFault<br>StatusTampered<br>StatusLowBattery|
|
||||
|Thermostat|CurrentHeatingCoolingState<br>TargetHeatingCoolingState<br>CurrentTemperature<br>TargetTemperature<br>TemperatureDisplayUnits|CoolingThresholdTemperature<br>CurrentRelativeHumidity<br>HeatingThresholdTemperature<br>Name<br>TargetRelativeHumidity|
|
||||
|Valve|Active<br>InUse<br>ValveType|SetDuration<br>RemainingDuration<br>IsConfigured<br>ServiceLabelIndex<br>StatusFault<br>Name|
|
||||
|Window|CurrentPosition<br>TargetPosition<br>PositionState|Name<br>HoldPosition<br>ObstructionDetected|
|
||||
|WindowCovering|TargetPosition<br>CurrentPosition<br>PositionState|Name<br>HoldPosition<br>CurrentHorizontalTiltAngle<br>TargetHorizontalTiltAngle<br>CurrentVerticalTiltAngle<br>TargetVerticalTiltAngle<br>ObstructionDetected|
|
||||
### LightBulb (43)
|
||||
<i> Defines any type of Light.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>On (25) :small_blue_diamond:</b><ul><li> indicates if the Service is active/on</li></ul></td><td align="center">bool</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>OFF (0) </span>:heavy_check_mark:</li><li><span>ON (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>Brightness (8) </b><ul><li> measured as a percentage</li></ul></td><td align="center">int</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>Hue (13) </b><ul><li> color (in degrees) from red (0) to green (120) to blue (240) and back to red (360)</li></ul></td><td align="center">float</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">360</td><td align="center">0</td></tr>
|
||||
<tr><td><b>Saturation (2F) </b><ul><li> color saturation, measured as a percentage</li></ul></td><td align="center">float</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>ColorTemperature (CE) </b><ul><li> measured in inverse megaKelvin (= 1,000,000 / Kelvin)</li></ul></td><td align="center">uint32</td><td align="center">PR+PW+EV</td><td align="center">140</td><td align="center">500</td><td align="center">200</td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### Characteristic Types and Defaults
|
||||
### Outlet (47)
|
||||
<i> Defines a controllable Outlet used to power any light or appliance.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>On (25) :small_blue_diamond:</b><ul><li> indicates if the Service is active/on</li></ul></td><td align="center">bool</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>OFF (0) </span>:heavy_check_mark:</li><li><span>ON (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>OutletInUse (26) :small_blue_diamond:</b><ul><li> indicates if an appliance or light is plugged into the outlet, regardless of whether on or off </li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_IN_USE (0) </span>:heavy_check_mark:</li><li><span>IN_USE (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
|Characteristic|Type|Default|Range|
|
||||
|-|-|-|-|
|
||||
AccessoryFlags|uint32_t|1|[1,1]|
|
||||
Active|uint8_t|0|[0,1]|
|
||||
ActiveIdentifier|uint32_t|0|[0,255]|
|
||||
AirQuality|uint8_t|0|[0,5]|
|
||||
BatteryLevel|uint8_t|0|[0,100]|
|
||||
Brightness|int|0|[0,100]|
|
||||
CarbonMonoxideLevel|double|0|[0,100]|
|
||||
CarbonMonoxidePeakLevel|double|0|[0,100]|
|
||||
CarbonMonoxideDetected|uint8_t|0|[0,1]|
|
||||
CarbonDioxideLevel|double|0|[0,100000]|
|
||||
CarbonDioxidePeakLevel|double|0|[0,100000]|
|
||||
CarbonDioxideDetected|uint8_t|0|[0,1]|
|
||||
ChargingState|uint8_t|0|[0,2]|
|
||||
ClosedCaptions|uint8_t|0|[0,1]|
|
||||
CoolingThresholdTemperature|double|10|[10,35]|
|
||||
ColorTemperature|uint32_t|200|[140,500]|
|
||||
ContactSensorState|uint8_t|1|[0,1]|
|
||||
ConfiguredName|char \*|"unnamed"|||
|
||||
CurrentAmbientLightLevel|double|1|[0.0001,100000]|
|
||||
CurrentHorizontalTiltAngle|int|0|[-90,90]|
|
||||
CurrentAirPurifierState|uint8_t|1|[0,2]|
|
||||
CurrentSlatState|uint8_t|0|[0,2]|
|
||||
CurrentPosition|uint8_t|0|[0,100]|
|
||||
CurrentVerticalTiltAngle|int|0|[-90,90]|
|
||||
CurrentVisibilityState|uint8_t|0|[0,1]|
|
||||
CurrentHumidifierDehumidifierState|uint8_t|1|[0,3]|
|
||||
CurrentDoorState|uint8_t|1|[0,4]|
|
||||
CurrentFanState|uint8_t|1|[0,2]|
|
||||
CurrentHeatingCoolingState|uint8_t|0|[0,2]|
|
||||
CurrentHeaterCoolerState|uint8_t|1|[0,3]|
|
||||
CurrentMediaState|uint8_t|0|[0,5]|
|
||||
CurrentRelativeHumidity|double|0|[0,100]|
|
||||
CurrentTemperature|double|0|[0,100]|
|
||||
CurrentTiltAngle|int|0|[-90,90]|
|
||||
FilterLifeLevel|double|0|[0,100]|
|
||||
FilterChangeIndication|uint8_t|0|[0,1]|
|
||||
FirmwareRevision|char \*|"1.0.0"|||
|
||||
HardwareRevision|char \*|"1.0.0"|||
|
||||
HeatingThresholdTemperature|double|16|[0,25]|
|
||||
HoldPosition|boolean|false|[0,1]|
|
||||
Hue|double|0|[0,360]|
|
||||
Identify|boolean|false|[0,1]|
|
||||
Identifier|uint32_t|0|[0,255]|
|
||||
InputDeviceType|uint8_t|0|[0,6]|
|
||||
InputSourceType|uint8_t|0|[0,10]|
|
||||
InUse|uint8_t|0|[0,1]|
|
||||
IsConfigured|uint8_t|0|[0,1]|
|
||||
LeakDetected|uint8_t|0|[0,1]|
|
||||
LockCurrentState|uint8_t|0|[0,3]|
|
||||
LockPhysicalControls|uint8_t|0|[0,1]|
|
||||
LockTargetState|uint8_t|0|[0,1]|
|
||||
Manufacturer|char \*|"HomeSpan"|||
|
||||
Model|char \*|"HomeSpan-ESP32"|||
|
||||
MotionDetected|boolean|false|[0,1]|
|
||||
Mute|boolean|false|[0,1]|
|
||||
Name|char \*|"unnamed"|||
|
||||
NitrogenDioxideDensity|double|0|[0,1000]|
|
||||
ObstructionDetected|boolean|false|[0,1]|
|
||||
PM25Density|double|0|[0,1000]|
|
||||
OccupancyDetected|uint8_t|0|[0,1]|
|
||||
OutletInUse|boolean|false|[0,1]|
|
||||
On|boolean|false|[0,1]|
|
||||
OzoneDensity|double|0|[0,1000]|
|
||||
PictureMode|uint8_t|0|[0,13]|
|
||||
PM10Density|double|0|[0,1000]|
|
||||
PositionState|uint8_t|2|[0,2]|
|
||||
PowerModeSelection|uint8_t|0|[0,1]|
|
||||
ProgramMode|uint8_t|0|[0,2]|
|
||||
ProgrammableSwitchEvent|uint8_t|0|[0,2]|
|
||||
RelativeHumidityDehumidifierThreshold|double|50|[0,100]|
|
||||
RelativeHumidityHumidifierThreshold|double|50|[0,100]|
|
||||
RemainingDuration|uint32_t|60|[0,3600]|
|
||||
RemoteKey|uint8_t|0|[0,16]|
|
||||
ResetFilterIndication|uint8_t|0|[1,1]|
|
||||
RotationDirection|int|0|[0,1]|
|
||||
RotationSpeed|double|0|[0,100]|
|
||||
Saturation|double|0|[0,100]|
|
||||
SecuritySystemAlarmType|uint8_t|0|[0,1]|
|
||||
SecuritySystemCurrentState|uint8_t|3|[0,4]|
|
||||
SecuritySystemTargetState|uint8_t|3|[0,3]|
|
||||
SerialNumber|char \*|"HS-12345"|||
|
||||
ServiceLabelIndex|uint8_t|1|[1,255]|
|
||||
ServiceLabelNamespace|uint8_t|1|[0,1]|
|
||||
SlatType|uint8_t|0|[0,1]|
|
||||
SleepDiscoveryMode|uint8_t|0|[0,1]|
|
||||
SmokeDetected|uint8_t|0|[0,1]|
|
||||
StatusActive|boolean|true|[0,1]|
|
||||
StatusFault|uint8_t|0|[0,1]|
|
||||
StatusJammed|uint8_t|0|[0,1]|
|
||||
StatusLowBattery|uint8_t|0|[0,1]|
|
||||
StatusTampered|uint8_t|0|[0,1]|
|
||||
SulphurDioxideDensity|double|0|[0,1000]|
|
||||
SwingMode|uint8_t|0|[0,1]|
|
||||
TargetAirPurifierState|uint8_t|1|[0,1]|
|
||||
TargetFanState|uint8_t|1|[0,1]|
|
||||
TargetTiltAngle|int|0|[-90,90]|
|
||||
TargetHeaterCoolerState|uint8_t|0|[0,2]|
|
||||
SetDuration|uint32_t|60|[0,3600]|
|
||||
TargetHorizontalTiltAngle|int|0|[-90,90]|
|
||||
TargetHumidifierDehumidifierState|uint8_t|0|[0,2]|
|
||||
TargetPosition|uint8_t|0|[0,100]|
|
||||
TargetDoorState|uint8_t|1|[0,1]|
|
||||
TargetHeatingCoolingState|uint8_t|0|[0,3]|
|
||||
TargetMediaState|uint8_t|0|[0,2]|
|
||||
TargetRelativeHumidity|double|0|[0,100]|
|
||||
TargetTemperature|double|16|[10,38]|
|
||||
TargetVisibilityState|uint8_t|0|[0,1]|
|
||||
TemperatureDisplayUnits|uint8_t|0|[0,1]|
|
||||
TargetVerticalTiltAngle|int|0|[-90,90]|
|
||||
ValveType|uint8_t|0|[0,3]|
|
||||
Version|char \*|"1.0.0"|||
|
||||
VOCDensity|double|0|[0,1000]|
|
||||
Volume|uint8_t|0|[0,100]|
|
||||
VolumeControlType|uint8_t|0|[0,3]|
|
||||
VolumeSelector|uint8_t|0|[0,1]|
|
||||
WaterLevel|double|0|[0,100]|
|
||||
### StatelessProgrammableSwitch (89)
|
||||
<i> Defines a "Stateless" Programmable Switch that can be used to trigger actions in the Home App.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>ProgrammableSwitchEvent (73) :small_blue_diamond:</b><ul><li> specifies type of button press</li></ul></td><td align="center">uint8</td><td align="center">PR+EV+NV</td><td align="center">0</td><td align="center">2</td><td><ul><li><span>SINGLE_PRESS (0) </span>:heavy_check_mark:</li><li><span>DOUBLE_PRESS (1) </span></li><li><span>LONG_PRESS (2) </span></li></ul></td></tr>
|
||||
<tr><td><b>ServiceLabelIndex (CB) </b><ul><li> numerical index used to distinguish multiple copies of the same Service within an Accessory</li></ul></td><td align="center">uint8</td><td align="center">PR</td><td align="center">1</td><td align="center">255</td><td align="center">1</td></tr>
|
||||
</table><br>
|
||||
|
||||
### HAP Format Codes (HAP-R2 Table 6-5)
|
||||
### Switch (49)
|
||||
<i> Defines a generic Switch.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>On (25) :small_blue_diamond:</b><ul><li> indicates if the Service is active/on</li></ul></td><td align="center">bool</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>OFF (0) </span>:heavy_check_mark:</li><li><span>ON (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
|HAP-R2 Format Code|HomeSpan C++ Type|
|
||||
|------------------|-----------------|
|
||||
|BOOL|boolean|
|
||||
|UINT8|uint8_t|
|
||||
|UINT16|uint16_t|
|
||||
|UINT32|uint32_t|
|
||||
|UINT64|uint64_t|
|
||||
|INT|int|
|
||||
|FLOAT|double|
|
||||
|STRING|char \*|
|
||||
|TLV8|(not implemented)|
|
||||
|DATA|uint8_t *|
|
||||
## HEATING, VENTILATION, AND AIR CONDITIONING (HVAC)
|
||||
### AirPurifier (BB)
|
||||
<i> Defines a basic Air Purifier with an optional fan and swing mode. Optional Linked Services: <b>FilterMaintenance</b>. Combine with an <b>AirSensor</b> Service for automated operations.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>Active (B0) :small_blue_diamond:</b><ul><li> indicates if the Service is active/on</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>INACTIVE (0) </span>:heavy_check_mark:</li><li><span>ACTIVE (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>CurrentAirPurifierState (A9) :small_blue_diamond:</b><ul><li> indicates current state of air purification</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">2</td><td><ul><li><span>INACTIVE (0) </span>:heavy_check_mark:</li><li><span>IDLE (1) </span></li><li><span>PURIFYING (2) </span></li></ul></td></tr>
|
||||
<tr><td><b>TargetAirPurifierState (A8) :small_blue_diamond:</b><ul><li> indicates desired state of air purifier</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>MANUAL (0) </span></li><li><span>AUTO (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>RotationSpeed (29) </b><ul><li> measured as a percentage</li></ul></td><td align="center">float</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>SwingMode (B6) </b><ul><li> indicates whether swing-mode is enabled</li></ul></td><td align="center">uint8</td><td align="center">PR+EV+PW</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>SWING_DISABLED (0) </span>:heavy_check_mark:</li><li><span>SWING_ENABLED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>LockPhysicalControls (A7) </b><ul><li> indicates if local control lock is enabled</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>CONTROL_LOCK_DISABLED (0) </span>:heavy_check_mark:</li><li><span>CONTROL_LOCK_ENABLED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### Fan (B7)
|
||||
<i> Defines a Fan. Combine with a <b>LightBulb</b> Service to create a Lighted Ceiling Fan.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>Active (B0) :small_blue_diamond:</b><ul><li> indicates if the Service is active/on</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>INACTIVE (0) </span>:heavy_check_mark:</li><li><span>ACTIVE (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>CurrentFanState (AF) </b><ul><li> indicates current state of a fan</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">2</td><td><ul><li><span>INACTIVE (0) </span></li><li><span>IDLE (1) </span>:heavy_check_mark:</li><li><span>BLOWING (2) </span></li></ul></td></tr>
|
||||
<tr><td><b>TargetFanState (BF) </b><ul><li> indicates desired state of fan</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>MANUAL (0) </span></li><li><span>AUTO (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>RotationDirection (28) </b><ul><li> indicates the rotation direction of a fan</li></ul></td><td align="center">int</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>CLOCKWISE (0) </span>:heavy_check_mark:</li><li><span>COUNTERCLOCKWISE (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>RotationSpeed (29) </b><ul><li> measured as a percentage</li></ul></td><td align="center">float</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>SwingMode (B6) </b><ul><li> indicates whether swing-mode is enabled</li></ul></td><td align="center">uint8</td><td align="center">PR+EV+PW</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>SWING_DISABLED (0) </span>:heavy_check_mark:</li><li><span>SWING_ENABLED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>LockPhysicalControls (A7) </b><ul><li> indicates if local control lock is enabled</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>CONTROL_LOCK_DISABLED (0) </span>:heavy_check_mark:</li><li><span>CONTROL_LOCK_ENABLED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### FilterMaintenance (BA)
|
||||
<i> Defines a Filter Maintainence check. Use only as a Linked Service for the <b>AirPurifier</b> Service.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>FilterChangeIndication (AC) :small_blue_diamond:</b><ul><li> indicates state of filter</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_CHANGE_NEEDED (0) </span>:heavy_check_mark:</li><li><span>CHANGE_NEEDED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>FilterLifeLevel (AB) </b><ul><li> measured as a percentage of remaining life</li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">100</td></tr>
|
||||
<tr><td><b>ResetFilterIndication (AD) </b><ul><li> triggers an update when the user chooses to reset the <b>FilterChangeIndication</b> (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PW</td><td align="center">1</td><td align="center">1</td><td><ul><li><span>RESET_FILTER (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### HeaterCooler (BC)
|
||||
<i> Defines a standalone Heater, Cooler, or combined Heater/Cooler.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>Active (B0) :small_blue_diamond:</b><ul><li> indicates if the Service is active/on</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>INACTIVE (0) </span>:heavy_check_mark:</li><li><span>ACTIVE (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>CurrentTemperature (11) :small_blue_diamond:</b><ul><li> current temperature measured in Celsius</li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>CurrentHeaterCoolerState (B1) :small_blue_diamond:</b><ul><li> indicates whether appliance is currently heating, cooling, idle, or off</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">3</td><td><ul><li><span>INACTIVE (0) </span></li><li><span>IDLE (1) </span>:heavy_check_mark:</li><li><span>HEATING (2) </span></li><li><span>COOLING (3) </span></li></ul></td></tr>
|
||||
<tr><td><b>TargetHeaterCoolerState (B2) :small_blue_diamond:</b><ul><li> indicates desired state of heater/cooler</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">2</td><td><ul><li><span>AUTO (0) </span>:heavy_check_mark:</li><li><span>HEAT (1) </span></li><li><span>COOL (2) </span></li></ul></td></tr>
|
||||
<tr><td><b>RotationSpeed (29) </b><ul><li> measured as a percentage</li></ul></td><td align="center">float</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>TemperatureDisplayUnits (36) </b><ul><li> indicates the desired units to display the temperature on the device itself (has no effect on Home App)</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>CELSIUS (0) </span>:heavy_check_mark:</li><li><span>FAHRENHEIT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>SwingMode (B6) </b><ul><li> indicates whether swing-mode is enabled</li></ul></td><td align="center">uint8</td><td align="center">PR+EV+PW</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>SWING_DISABLED (0) </span>:heavy_check_mark:</li><li><span>SWING_ENABLED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>CoolingThresholdTemperature (D) </b><ul><li> cooling turns on when temperature (in Celsius) rises above this threshold</li></ul></td><td align="center">float</td><td align="center">PR+PW+EV</td><td align="center">10</td><td align="center">35</td><td align="center">10</td></tr>
|
||||
<tr><td><b>HeatingThresholdTemperature (12) </b><ul><li> heating turns on when temperature (in Celsius) falls below this threshold</li></ul></td><td align="center">float</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">25</td><td align="center">16</td></tr>
|
||||
<tr><td><b>LockPhysicalControls (A7) </b><ul><li> indicates if local control lock is enabled</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>CONTROL_LOCK_DISABLED (0) </span>:heavy_check_mark:</li><li><span>CONTROL_LOCK_ENABLED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### HumidifierDehumidifier (BD)
|
||||
<i> Defines a Humidifer, Dehumidifier, or combined Humidifer/Dehumidifier.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>Active (B0) :small_blue_diamond:</b><ul><li> indicates if the Service is active/on</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>INACTIVE (0) </span>:heavy_check_mark:</li><li><span>ACTIVE (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>CurrentRelativeHumidity (10) :small_blue_diamond:</b><ul><li> current humidity measured as a percentage</li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>CurrentHumidifierDehumidifierState (B3) :small_blue_diamond:</b><ul><li> indicates current state of humidifier/dehumidifer</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">3</td><td><ul><li><span>INACTIVE (0) </span></li><li><span>IDLE (1) </span>:heavy_check_mark:</li><li><span>HUMIDIFYING (2) </span></li><li><span>DEHUMIDIFYING (3) </span></li></ul></td></tr>
|
||||
<tr><td><b>TargetHumidifierDehumidifierState (B4) :small_blue_diamond:</b><ul><li> indicates desired state of humidifier/dehumidifier</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">2</td><td><ul><li><span>AUTO (0) </span>:heavy_check_mark:</li><li><span>HUMIDIFY (1) </span></li><li><span>DEHUMIDIFY (2) </span></li></ul></td></tr>
|
||||
<tr><td><b>RelativeHumidityDehumidifierThreshold (C9) </b><ul><li> dehumidfier turns on when humidity rises above this threshold</li></ul></td><td align="center">float</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">100</td><td align="center">50</td></tr>
|
||||
<tr><td><b>RelativeHumidityHumidifierThreshold (CA) </b><ul><li> humidfier turns on when humidity falls below this threshold</li></ul></td><td align="center">float</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">100</td><td align="center">50</td></tr>
|
||||
<tr><td><b>RotationSpeed (29) </b><ul><li> measured as a percentage</li></ul></td><td align="center">float</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>SwingMode (B6) </b><ul><li> indicates whether swing-mode is enabled</li></ul></td><td align="center">uint8</td><td align="center">PR+EV+PW</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>SWING_DISABLED (0) </span>:heavy_check_mark:</li><li><span>SWING_ENABLED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>WaterLevel (B5) </b><ul><li> measured as a percentage</li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>LockPhysicalControls (A7) </b><ul><li> indicates if local control lock is enabled</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>CONTROL_LOCK_DISABLED (0) </span>:heavy_check_mark:</li><li><span>CONTROL_LOCK_ENABLED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### Slat (B9)
|
||||
<i> Defines a motorized ventilation Slat(s).</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>CurrentSlatState (AA) :small_blue_diamond:</b><ul><li> indicates current state of slats</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">2</td><td><ul><li><span>FIXED (0) </span>:heavy_check_mark:</li><li><span>JAMMED (1) </span></li><li><span>SWINGING (2) </span></li></ul></td></tr>
|
||||
<tr><td><b>SlatType (C0) :small_blue_diamond:</b><ul><li> indicates the direction of a slat or group of slats</li></ul></td><td align="center">uint8</td><td align="center">PR</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>HORIZONTAL (0) </span>:heavy_check_mark:</li><li><span>VERTICAL (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>SwingMode (B6) </b><ul><li> indicates whether swing-mode is enabled</li></ul></td><td align="center">uint8</td><td align="center">PR+EV+PW</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>SWING_DISABLED (0) </span>:heavy_check_mark:</li><li><span>SWING_ENABLED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>CurrentTiltAngle (C1) </b><ul><li> current angle (in degrees) of slats from fully up or left (-90) to fully open (0) to fully down or right (90)</li></ul></td><td align="center">int</td><td align="center">PR+EV</td><td align="center">-90</td><td align="center">90</td><td align="center">0</td></tr>
|
||||
<tr><td><b>TargetTiltAngle (C2) </b><ul><li> indicated desired angle (in degrees) of slats from fully up or left (-90) to fully open (0) to fully down or right (90) </li></ul></td><td align="center">int</td><td align="center">PW+PR+EV</td><td align="center">-90</td><td align="center">90</td><td align="center">0</td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### Thermostat (4A)
|
||||
<i> Defines a Thermostat used to control a furnace, air conditioner, or both.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>CurrentHeatingCoolingState (F) :small_blue_diamond:</b><ul><li> indicates whether appliance is currently heating, cooling, or just idle</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">2</td><td><ul><li><span>IDLE (0) </span>:heavy_check_mark:</li><li><span>HEATING (1) </span></li><li><span>COOLING (2) </span></li></ul></td></tr>
|
||||
<tr><td><b>TargetHeatingCoolingState (33) :small_blue_diamond:</b><ul><li> indicates desired state of appliance</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">3</td><td><ul><li><span>OFF (0) </span>:heavy_check_mark:</li><li><span>HEAT (1) </span></li><li><span>COOL (2) </span></li><li><span>AUTO (3) </span></li></ul></td></tr>
|
||||
<tr><td><b>CurrentTemperature (11) :small_blue_diamond:</b><ul><li> current temperature measured in Celsius</li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>TargetTemperature (35) :small_blue_diamond:</b><ul><li> indicates desired temperature measures in Celsius</li></ul></td><td align="center">float</td><td align="center">PW+PR+EV</td><td align="center">10</td><td align="center">38</td><td align="center">16</td></tr>
|
||||
<tr><td><b>TemperatureDisplayUnits (36) :small_blue_diamond:</b><ul><li> indicates the desired units to display the temperature on the device itself (has no effect on Home App)</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>CELSIUS (0) </span>:heavy_check_mark:</li><li><span>FAHRENHEIT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>CoolingThresholdTemperature (D) </b><ul><li> cooling turns on when temperature (in Celsius) rises above this threshold</li></ul></td><td align="center">float</td><td align="center">PR+PW+EV</td><td align="center">10</td><td align="center">35</td><td align="center">10</td></tr>
|
||||
<tr><td><b>CurrentRelativeHumidity (10) </b><ul><li> current humidity measured as a percentage</li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>HeatingThresholdTemperature (12) </b><ul><li> heating turns on when temperature (in Celsius) falls below this threshold</li></ul></td><td align="center">float</td><td align="center">PR+PW+EV</td><td align="center">0</td><td align="center">25</td><td align="center">16</td></tr>
|
||||
<tr><td><b>TargetRelativeHumidity (34) </b><ul><li> indicates desired humidity measured as a percentage</li></ul></td><td align="center">float</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
## STANDALONE SENSORS
|
||||
### AirQualitySensor (8D)
|
||||
<i> Defines an Air Quality Sensor. </i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>AirQuality (95) :small_blue_diamond:</b><ul><li> a subjective description</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">5</td><td><ul><li><span>UNKNOWN (0) </span>:heavy_check_mark:</li><li><span>EXCELLENT (1) </span></li><li><span>GOOD (2) </span></li><li><span>FAIR (3) </span></li><li><span>INFERIOR (4) </span></li><li><span>POOR (5) </span></li></ul></td></tr>
|
||||
<tr><td><b>OzoneDensity (C3) </b><ul><li> measured in µg/m<sup>3</sup></li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1000</td><td align="center">0</td></tr>
|
||||
<tr><td><b>NitrogenDioxideDensity (C4) </b><ul><li> measured in µg/m<sup>3</sup></li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1000</td><td align="center">0</td></tr>
|
||||
<tr><td><b>SulphurDioxideDensity (C5) </b><ul><li> measured in µg/m<sup>3</sup></li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1000</td><td align="center">0</td></tr>
|
||||
<tr><td><b>PM25Density (C6) </b><ul><li> 2.5-micron particulate density, measured in µg/m<sup>3</sup></li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1000</td><td align="center">0</td></tr>
|
||||
<tr><td><b>PM10Density (C7) </b><ul><li> 10-micron particulate density, measured in µg/m<sup>3</sup></li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1000</td><td align="center">0</td></tr>
|
||||
<tr><td><b>VOCDensity (C8) </b><ul><li> measured in µg/m<sup>3</sup></li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1000</td><td align="center">0</td></tr>
|
||||
<tr><td><b>StatusActive (75) </b><ul><li> indicates whether the Service is properly functioning </li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_FUNCTIONING (0) </span></li><li><span>FUNCTIONING (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusTampered (7A) </b><ul><li> indicates whether the Service has been tampered with</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_TAMPERED (0) </span>:heavy_check_mark:</li><li><span>TAMPERED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusLowBattery (79) </b><ul><li> indicates state of battery</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_LOW_BATTERY (0) </span>:heavy_check_mark:</li><li><span>LOW_BATTERY (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### CarbonDioxideSensor (97)
|
||||
<i> Defines a Carbon Dioxide Sensor.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>CarbonDioxideDetected (92) :small_blue_diamond:</b><ul><li> indicates if abnormal level is detected</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NORMAL (0) </span>:heavy_check_mark:</li><li><span>ABNORMAL (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>CarbonDioxideLevel (93) </b><ul><li> measured on parts per million (ppm)</li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100000</td><td align="center">0</td></tr>
|
||||
<tr><td><b>CarbonDioxidePeakLevel (94) </b><ul><li> measured in parts per million (ppm)</li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100000</td><td align="center">0</td></tr>
|
||||
<tr><td><b>StatusActive (75) </b><ul><li> indicates whether the Service is properly functioning </li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_FUNCTIONING (0) </span></li><li><span>FUNCTIONING (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusTampered (7A) </b><ul><li> indicates whether the Service has been tampered with</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_TAMPERED (0) </span>:heavy_check_mark:</li><li><span>TAMPERED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusLowBattery (79) </b><ul><li> indicates state of battery</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_LOW_BATTERY (0) </span>:heavy_check_mark:</li><li><span>LOW_BATTERY (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### CarbonMonoxideSensor (7F)
|
||||
<i> Defines a Carbon Monoxide Sensor.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>CarbonMonoxideDetected (69) :small_blue_diamond:</b><ul><li> indicates if abnormal level is detected</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NORMAL (0) </span>:heavy_check_mark:</li><li><span>ABNORMAL (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>CarbonMonoxideLevel (90) </b><ul><li> measured in parts per million (ppm)</li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>CarbonMonoxidePeakLevel (91) </b><ul><li> measured in parts per million (ppm)</li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>StatusActive (75) </b><ul><li> indicates whether the Service is properly functioning </li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_FUNCTIONING (0) </span></li><li><span>FUNCTIONING (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusTampered (7A) </b><ul><li> indicates whether the Service has been tampered with</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_TAMPERED (0) </span>:heavy_check_mark:</li><li><span>TAMPERED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusLowBattery (79) </b><ul><li> indicates state of battery</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_LOW_BATTERY (0) </span>:heavy_check_mark:</li><li><span>LOW_BATTERY (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### ContactSensor (80)
|
||||
<i> Defines a Contact Sensor.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>ContactSensorState (6A) :small_blue_diamond:</b><ul><li> indictates if contact is detected (i.e. closed)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>DETECTED (0) </span></li><li><span>NOT_DETECTED (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>StatusActive (75) </b><ul><li> indicates whether the Service is properly functioning </li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_FUNCTIONING (0) </span></li><li><span>FUNCTIONING (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusTampered (7A) </b><ul><li> indicates whether the Service has been tampered with</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_TAMPERED (0) </span>:heavy_check_mark:</li><li><span>TAMPERED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusLowBattery (79) </b><ul><li> indicates state of battery</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_LOW_BATTERY (0) </span>:heavy_check_mark:</li><li><span>LOW_BATTERY (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### HumiditySensor (82)
|
||||
<i> Defines a Humidity Sensor.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>CurrentRelativeHumidity (10) :small_blue_diamond:</b><ul><li> current humidity measured as a percentage</li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>StatusActive (75) </b><ul><li> indicates whether the Service is properly functioning </li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_FUNCTIONING (0) </span></li><li><span>FUNCTIONING (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusTampered (7A) </b><ul><li> indicates whether the Service has been tampered with</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_TAMPERED (0) </span>:heavy_check_mark:</li><li><span>TAMPERED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusLowBattery (79) </b><ul><li> indicates state of battery</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_LOW_BATTERY (0) </span>:heavy_check_mark:</li><li><span>LOW_BATTERY (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### LeakSensor (83)
|
||||
<i> Defines a Leak Sensor.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>LeakDetected (70) :small_blue_diamond:</b><ul><li> indictates if a leak is detected</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_DETECTED (0) </span>:heavy_check_mark:</li><li><span>DETECTED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusActive (75) </b><ul><li> indicates whether the Service is properly functioning </li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_FUNCTIONING (0) </span></li><li><span>FUNCTIONING (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusTampered (7A) </b><ul><li> indicates whether the Service has been tampered with</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_TAMPERED (0) </span>:heavy_check_mark:</li><li><span>TAMPERED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusLowBattery (79) </b><ul><li> indicates state of battery</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_LOW_BATTERY (0) </span>:heavy_check_mark:</li><li><span>LOW_BATTERY (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### LightSensor (84)
|
||||
<i> Defines a Light Sensor.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>CurrentAmbientLightLevel (6B) :small_blue_diamond:</b><ul><li> measured in Lux (lumens/m<sup>2</sup></li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0.0001</td><td align="center">100000</td><td align="center">1</td></tr>
|
||||
<tr><td><b>StatusActive (75) </b><ul><li> indicates whether the Service is properly functioning </li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_FUNCTIONING (0) </span></li><li><span>FUNCTIONING (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusTampered (7A) </b><ul><li> indicates whether the Service has been tampered with</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_TAMPERED (0) </span>:heavy_check_mark:</li><li><span>TAMPERED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusLowBattery (79) </b><ul><li> indicates state of battery</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_LOW_BATTERY (0) </span>:heavy_check_mark:</li><li><span>LOW_BATTERY (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### MotionSensor (85)
|
||||
<i> Defines a Motion Sensor.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>MotionDetected (22) :small_blue_diamond:</b><ul><li> indicates if motion is detected</li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_DETECTED (0) </span>:heavy_check_mark:</li><li><span>DETECTED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusActive (75) </b><ul><li> indicates whether the Service is properly functioning </li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_FUNCTIONING (0) </span></li><li><span>FUNCTIONING (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusTampered (7A) </b><ul><li> indicates whether the Service has been tampered with</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_TAMPERED (0) </span>:heavy_check_mark:</li><li><span>TAMPERED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusLowBattery (79) </b><ul><li> indicates state of battery</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_LOW_BATTERY (0) </span>:heavy_check_mark:</li><li><span>LOW_BATTERY (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### OccupancySensor (86)
|
||||
<i> Defines and Occupancy Sensor.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>OccupancyDetected (71) :small_blue_diamond:</b><ul><li> indicates if occupanccy is detected</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_DETECTED (0) </span>:heavy_check_mark:</li><li><span>DETECTED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusActive (75) </b><ul><li> indicates whether the Service is properly functioning </li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_FUNCTIONING (0) </span></li><li><span>FUNCTIONING (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusTampered (7A) </b><ul><li> indicates whether the Service has been tampered with</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_TAMPERED (0) </span>:heavy_check_mark:</li><li><span>TAMPERED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusLowBattery (79) </b><ul><li> indicates state of battery</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_LOW_BATTERY (0) </span>:heavy_check_mark:</li><li><span>LOW_BATTERY (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### SmokeSensor (87)
|
||||
<i> Defines a Smoke Sensor.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>SmokeDetected (76) :small_blue_diamond:</b><ul><li> indicates if smoke is detected</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_DETECTED (0) </span>:heavy_check_mark:</li><li><span>DETECTED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusActive (75) </b><ul><li> indicates whether the Service is properly functioning </li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_FUNCTIONING (0) </span></li><li><span>FUNCTIONING (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusTampered (7A) </b><ul><li> indicates whether the Service has been tampered with</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_TAMPERED (0) </span>:heavy_check_mark:</li><li><span>TAMPERED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusLowBattery (79) </b><ul><li> indicates state of battery</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_LOW_BATTERY (0) </span>:heavy_check_mark:</li><li><span>LOW_BATTERY (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### TemperatureSensor (8A)
|
||||
<i> Defines a Temperature Sensor.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>CurrentTemperature (11) :small_blue_diamond:</b><ul><li> current temperature measured in Celsius</li></ul></td><td align="center">float</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>StatusActive (75) </b><ul><li> indicates whether the Service is properly functioning </li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_FUNCTIONING (0) </span></li><li><span>FUNCTIONING (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusTampered (7A) </b><ul><li> indicates whether the Service has been tampered with</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_TAMPERED (0) </span>:heavy_check_mark:</li><li><span>TAMPERED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusLowBattery (79) </b><ul><li> indicates state of battery</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_LOW_BATTERY (0) </span>:heavy_check_mark:</li><li><span>LOW_BATTERY (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
## DOORS, LOCKS, AND WINDOWS
|
||||
### Door (81)
|
||||
<i> Defines a motorized Door.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>CurrentPosition (6D) :small_blue_diamond:</b><ul><li> current position (as a percentage) from fully closed (0) to full open (100)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>TargetPosition (7C) :small_blue_diamond:</b><ul><li> indicates target position (as a percentage) from fully closed (0) to full open (100)</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>ObstructionDetected (24) </b><ul><li> indicates if obstruction is detected</li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_DETECTED (0) </span>:heavy_check_mark:</li><li><span>DETECTED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### Doorbell (121)
|
||||
<i> Defines a Doorbell. Can be used on a standalone basis or in conjunction with a <b>LockMechanism</b> Service.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>ProgrammableSwitchEvent (73) :small_blue_diamond:</b><ul><li> specifies type of button press</li></ul></td><td align="center">uint8</td><td align="center">PR+EV+NV</td><td align="center">0</td><td align="center">2</td><td><ul><li><span>SINGLE_PRESS (0) </span>:heavy_check_mark:</li><li><span>DOUBLE_PRESS (1) </span></li><li><span>LONG_PRESS (2) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### GarageDoorOpener (41)
|
||||
<i> Defines a motorized Garage Door Opener.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>CurrentDoorState (E) :small_blue_diamond:</b><ul><li> indicates current state of a door</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">4</td><td><ul><li><span>OPEN (0) </span></li><li><span>CLOSED (1) </span>:heavy_check_mark:</li><li><span>OPENING (2) </span></li><li><span>CLOSING (3) </span></li><li><span>STOPPED (4) </span></li></ul></td></tr>
|
||||
<tr><td><b>TargetDoorState (32) :small_blue_diamond:</b><ul><li> indicates desired state of door</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>OPEN (0) </span></li><li><span>CLOSED (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>ObstructionDetected (24) :small_blue_diamond:</b><ul><li> indicates if obstruction is detected</li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_DETECTED (0) </span>:heavy_check_mark:</li><li><span>DETECTED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>LockCurrentState (1D) </b><ul><li> indicates state of a lock</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">3</td><td><ul><li><span>UNLOCKED (0) </span>:heavy_check_mark:</li><li><span>LOCKED (1) </span></li><li><span>JAMMED (2) </span></li><li><span>UNKNOWN (3) </span></li></ul></td></tr>
|
||||
<tr><td><b>LockTargetState (1E) </b><ul><li> indicates desired state of lock</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>UNLOCK (0) </span>:heavy_check_mark:</li><li><span>LOCK (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### LockMechanism (45)
|
||||
<i> Defines an electronic Lock.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>LockCurrentState (1D) :small_blue_diamond:</b><ul><li> indicates state of a lock</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">3</td><td><ul><li><span>UNLOCKED (0) </span>:heavy_check_mark:</li><li><span>LOCKED (1) </span></li><li><span>JAMMED (2) </span></li><li><span>UNKNOWN (3) </span></li></ul></td></tr>
|
||||
<tr><td><b>LockTargetState (1E) :small_blue_diamond:</b><ul><li> indicates desired state of lock</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>UNLOCK (0) </span>:heavy_check_mark:</li><li><span>LOCK (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### Window (8B)
|
||||
<i> Defines a motorized Window.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>CurrentPosition (6D) :small_blue_diamond:</b><ul><li> current position (as a percentage) from fully closed (0) to full open (100)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>TargetPosition (7C) :small_blue_diamond:</b><ul><li> indicates target position (as a percentage) from fully closed (0) to full open (100)</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>ObstructionDetected (24) </b><ul><li> indicates if obstruction is detected</li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_DETECTED (0) </span>:heavy_check_mark:</li><li><span>DETECTED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### WindowCovering (8C)
|
||||
<i> Defines a motorized Window Shade, Screen, Awning, etc.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>TargetPosition (7C) :small_blue_diamond:</b><ul><li> indicates target position (as a percentage) from fully closed (0) to full open (100)</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>CurrentPosition (6D) :small_blue_diamond:</b><ul><li> current position (as a percentage) from fully closed (0) to full open (100)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">100</td><td align="center">0</td></tr>
|
||||
<tr><td><b>CurrentHorizontalTiltAngle (6C) </b><ul><li> current angle (in degrees) of slats from fully up (-90) to fully open (0) to fully down (90) </li></ul></td><td align="center">int</td><td align="center">PR+EV</td><td align="center">-90</td><td align="center">90</td><td align="center">0</td></tr>
|
||||
<tr><td><b>TargetHorizontalTiltAngle (7B) </b><ul><li> indicates desired angle (in degrees) of slats from fully up (-90) to fully open (0) to fully down (90)</li></ul></td><td align="center">int</td><td align="center">PW+PR+EV</td><td align="center">-90</td><td align="center">90</td><td align="center">0</td></tr>
|
||||
<tr><td><b>CurrentVerticalTiltAngle (6E) </b><ul><li> current angle (in degrees) of slats from fully left (-90) to fully open (0) to fully right (90)</li></ul></td><td align="center">int</td><td align="center">PR+EV</td><td align="center">-90</td><td align="center">90</td><td align="center">0</td></tr>
|
||||
<tr><td><b>TargetVerticalTiltAngle (7D) </b><ul><li> indicates desired angle (in degrees) of slats from fully left (-90) to fully open (0) to fully right (90)</li></ul></td><td align="center">int</td><td align="center">PW+PR+EV</td><td align="center">-90</td><td align="center">90</td><td align="center">0</td></tr>
|
||||
<tr><td><b>ObstructionDetected (24) </b><ul><li> indicates if obstruction is detected</li></ul></td><td align="center">bool</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_DETECTED (0) </span>:heavy_check_mark:</li><li><span>DETECTED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
## WATER SYSTEMS
|
||||
### Faucet (D7)
|
||||
<i> Defines the master control for a multi-Valve appliance. Linked Services: <b>Valve</b> (at least one required), and <b>HeaterCooler</b> (optional).</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>Active (B0) :small_blue_diamond:</b><ul><li> indicates if the Service is active/on</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>INACTIVE (0) </span>:heavy_check_mark:</li><li><span>ACTIVE (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### IrrigationSystem (CF)
|
||||
<i> Defines an Irrigation System. Linked Services: <b>Valve</b> Service (at least one required).</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>Active (B0) :small_blue_diamond:</b><ul><li> indicates if the Service is active/on</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>INACTIVE (0) </span>:heavy_check_mark:</li><li><span>ACTIVE (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ProgramMode (D1) :small_blue_diamond:</b><ul><li> indicates if pre-scheduled program is running</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">2</td><td><ul><li><span>NONE (0) </span>:heavy_check_mark:</li><li><span>SCHEDULED (1) </span></li><li><span>SCHEDULE_OVERRIDEN (2) </span></li></ul></td></tr>
|
||||
<tr><td><b>InUse (D2) :small_blue_diamond:</b><ul><li> if Service is set to active, this indictes whether it is currently in use</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_IN_USE (0) </span>:heavy_check_mark:</li><li><span>IN_USE (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>RemainingDuration (D4) </b><ul><li> duration (in seconds) remaining for Service to be active/on</li></ul></td><td align="center">uint32</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">3600</td><td align="center">60</td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### Valve (D0)
|
||||
<i> Defines an electronic Valve. Can be used standalone or as a Linked Service for either a <b>Faucet</b> or <b>IrrigationSystem</b> Service.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>Active (B0) :small_blue_diamond:</b><ul><li> indicates if the Service is active/on</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>INACTIVE (0) </span>:heavy_check_mark:</li><li><span>ACTIVE (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>InUse (D2) :small_blue_diamond:</b><ul><li> if Service is set to active, this indictes whether it is currently in use</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_IN_USE (0) </span>:heavy_check_mark:</li><li><span>IN_USE (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ValveType (D5) :small_blue_diamond:</b><ul><li> indicates the type of valve</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">3</td><td><ul><li><span>GENERIC (0) </span>:heavy_check_mark:</li><li><span>IRRIGATION (1) </span></li><li><span>SHOWER_HEAD (2) </span></li><li><span>FAUCET (3) </span></li></ul></td></tr>
|
||||
<tr><td><b>SetDuration (D3) </b><ul><li> specifies the duration (in seconds) for a Service to remain on once activated</li></ul></td><td align="center">uint32</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">3600</td><td align="center">60</td></tr>
|
||||
<tr><td><b>RemainingDuration (D4) </b><ul><li> duration (in seconds) remaining for Service to be active/on</li></ul></td><td align="center">uint32</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">3600</td><td align="center">60</td></tr>
|
||||
<tr><td><b>IsConfigured (D6) </b><ul><li> indicates if a predefined Service has been configured</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_CONFIGURED (0) </span>:heavy_check_mark:</li><li><span>CONFIGURED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ServiceLabelIndex (CB) </b><ul><li> numerical index used to distinguish multiple copies of the same Service within an Accessory</li></ul></td><td align="center">uint8</td><td align="center">PR</td><td align="center">1</td><td align="center">255</td><td align="center">1</td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
## SECURITY SYSTEMS
|
||||
### SecuritySystem (7E)
|
||||
<i> Defines a Security System. Often used in combination with <b>MotionSensor</b> and <b>ContactSensor</b> Services.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>SecuritySystemCurrentState (66) :small_blue_diamond:</b><ul><li> indicates current state of the security system </li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">4</td><td><ul><li><span>ARMED_STAY (0) </span></li><li><span>ARMED_AWAY (1) </span></li><li><span>ARMED_NIGHT (2) </span></li><li><span>DISARMED (3) </span>:heavy_check_mark:</li><li><span>ALARM_TRIGGERED (4) </span></li></ul></td></tr>
|
||||
<tr><td><b>SecuritySystemTargetState (67) :small_blue_diamond:</b><ul><li> indicates desired state of the security system</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">3</td><td><ul><li><span>ARM_STAY (0) </span></li><li><span>ARM_AWAY (1) </span></li><li><span>ARM_NIGHT (2) </span></li><li><span>DISARM (3) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>SecuritySystemAlarmType (8E) </b><ul><li> indicates whether alarm was triggered for known reason</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>KNOWN (0) </span>:heavy_check_mark:</li><li><span>UNKNOWN (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusFault (77) </b><ul><li> indicates whether the Service has a fault (only appears in Eve App, not Home App)</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NO_FAULT (0) </span>:heavy_check_mark:</li><li><span>FAULT (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>StatusTampered (7A) </b><ul><li> indicates whether the Service has been tampered with</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_TAMPERED (0) </span>:heavy_check_mark:</li><li><span>TAMPERED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
## TELEVISIONS
|
||||
### InputSource (D9)
|
||||
<i> Defines an Input Source for a TV. Use only as a Linked Service for the <b>Television</b> Service.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>Identifier (E6) :small_blue_diamond:</b><ul><li> numerical Identifer of the <b>InputSource</b>.</li></ul></td><td align="center">uint32</td><td align="center">PR</td><td align="center">0</td><td align="center">255</td><td align="center">0</td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
<tr><td><b>IsConfigured (D6) </b><ul><li> indicates if a predefined Service has been configured</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>NOT_CONFIGURED (0) </span>:heavy_check_mark:</li><li><span>CONFIGURED (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>CurrentVisibilityState (135) </b><ul><li> current visibility of the Service, as selectable on the Settings Page of the Home App</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>VISIBLE (0) </span>:heavy_check_mark:</li><li><span>NOT_VISIBLE (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>TargetVisibilityState (134) </b><ul><li> indicates desired visibility of the Service, as selectable on the Settings Page of the Home App</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>VISIBLE (0) </span>:heavy_check_mark:</li><li><span>NOT_VISIBLE (1) </span></li></ul></td></tr>
|
||||
</table><br>
|
||||
|
||||
### Television (D8)
|
||||
<i> Defines a TV. Optional Linked Services: <b>InputSource</b> and <b>TelevisionSpeaker</b>.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>Active (B0) :small_blue_diamond:</b><ul><li> indicates if the Service is active/on</li></ul></td><td align="center">uint8</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>INACTIVE (0) </span>:heavy_check_mark:</li><li><span>ACTIVE (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ActiveIdentifier (E7) </b><ul><li> numerical Identifier of the <b>InputSource</b> selected in the Home App.</li></ul></td><td align="center">uint32</td><td align="center">PW+PR+EV</td><td align="center">0</td><td align="center">255</td><td align="center">0</td></tr>
|
||||
<tr><td><b>DisplayOrder (136) </b><ul><li> specifies the order in which the TV inputs are displayed for selection in the Home App</li></ul></td><td align="center">tlv8</td><td align="center">PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">NULL_TLV</td></tr>
|
||||
<tr><td><b>RemoteKey (E1) </b><ul><li> triggers an update when the corresponding key is pressed in the Remote Control widget on an iPhone </li></ul></td><td align="center">uint8</td><td align="center">PW</td><td align="center">4</td><td align="center">15</td><td><ul><li><span>UP (4) </span></li><li><span>DOWN (5) </span></li><li><span>LEFT (6) </span></li><li><span>RIGHT (7) </span></li><li><span>CENTER (8) </span></li><li><span>BACK (9) </span></li><li><span>PLAY_PAUSE (11) </span></li><li><span>INFO (15) </span></li></ul></td></tr>
|
||||
<tr><td><b>PowerModeSelection (DF) </b><ul><li> when defined, creates a "View TV Settings" button in the Home App that triggers an update to this Characteristic when pressed </li></ul></td><td align="center">uint8</td><td align="center">PW</td><td align="center">0</td><td align="center">0</td><td><ul><li><span>VIEW_SETTINGS (0) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
### TelevisionSpeaker (113)
|
||||
<i> Defines a Television Speaker that can be controlled via the Remote Control widget on an iPhone. Use only as a Linked Service for the <b>Television</b> Service.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>VolumeControlType (E9) :small_blue_diamond:</b><ul><li> indicates the type of volume control</li></ul></td><td align="center">uint8</td><td align="center">PR+EV</td><td align="center">0</td><td align="center">3</td><td><ul><li><span>NONE (0) </span></li><li><span>RELATIVE (1) </span></li><li><span>RELATIVE_CURRENT (2) </span></li><li><span>ABSOLUTE (3) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
<tr><td><b>VolumeSelector (EA) :small_blue_diamond:</b><ul><li> triggered by presses to the iPhone's volume up/down buttons when TV is selected in the Remote Control widget</li></ul></td><td align="center">uint8</td><td align="center">PW</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>VOLUME_UP (0) </span></li><li><span>VOLUME_DOWN (1) </span></li></ul></td></tr>
|
||||
<tr><td><b>ConfiguredName (E3) </b><ul><li> default display name of this Service</li></ul></td><td align="center">string</td><td align="center">PW+PR+EV</td><td align="center">-</td><td align="center">-</td><td align="center">"unnamed"</td></tr>
|
||||
</table><br>
|
||||
|
||||
## MISCELLANEOUS
|
||||
### ServiceLabel (CC)
|
||||
<i> Defines a naming scheme for un-nameable Services, such as a <b>StatelessProgrammableSwitch</b>, by Linking them to this Service. When used, those other Services must each include a <b>ServiceLabelIndex</b> Characteristic with a unique value.</i><br><table>
|
||||
<tr><th>Characteristic</th><th>Format</th><th>Perms</th><th>Min</th><th>Max</th><th>Constants/Defaults</th></tr>
|
||||
<tr><td><b>ServiceLabelNamespace (CD) :small_blue_diamond:</b><ul><li> indicates how un-named Services linked together with a <b>ServiceLabel</b> Service should be displayed in the Home App </li></ul></td><td align="center">uint8</td><td align="center">PR</td><td align="center">0</td><td align="center">1</td><td><ul><li><span>DOTS (0) </span></li><li><span>NUMERALS (1) </span>:heavy_check_mark:</li></ul></td></tr>
|
||||
</table><br>
|
||||
|
||||
---
|
||||
|
||||
[↩️](../README.md) Back to the Welcome page
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,18 @@
|
|||
# Common Problems and Potential Solutions
|
||||
|
||||
#### *HomeSpan works correctly when my ESP32 is plugged into a computer or separately powered through the USB port, but it fails to work when powered directly through the ESP32 5V pin without any USB connection*
|
||||
### *My HomeSpan device does not appear in the Home App when I try to pair it*
|
||||
|
||||
* There are a few reasons this may occur:
|
||||
|
||||
* **You have not yet entered your WiFi credentials**. HomeSpan can't connect to your WiFi network until you provide it with your WiFi SSID and password. If HomeSpan can't find these Credentials it outputs a warning message to the Serial Monitor during start-up. You can enter your WiFi Credentials into HomeSpan either directly from the Serial Monitor by using the 'W' CLI command, or via the HomeSpan Access Point Setup Page, or by hardcoding it into your sketch with the `homeSpan.setWifiCredentials()` function, though this last method is not recommended for security reasons.
|
||||
|
||||
* **You are out of range of your WiFi network, or entered the wrong WiFi Credentials**. When HomeSpan first boots, if you've previously entered your WiFi Credentials (see above) it will use them to connect to your WiFi network. Check the Serial Monitor for status on whether a connection has been successfully made. If not, make sure your device is in the range of your WiFi network, and re-enter your WiFi Credentials in case you entered them incorrectly the first time. To double-check that your HomeSpan device is indeed connected to your network after HomeSpan reports a successful connection, open up a terminal window on your computer and use the `ping` command to confirm you can reach the device.
|
||||
|
||||
* **Your iPhone and ESP32 device are not connected to the same WiFi network**. Make sure your HomeSpan device is connected to the same SSID as your iPhone and any HomeKit Hubs (e.g. HomePods or Apple TV). Some routers provide a separate SSID to use for IoT ("Internet of Things") devices. If you decide to use a separate SSID, make sure to configure your router so that message traffic flows unimpeded between your main SSID and your dedicated IoT SSID with absolutely no filtering of any messages. Also note that like most commercial HomeKit devices, ESP32 devices operate only on the 2.4 GHz WiFi band. Most iPhones can operate on either the 2.4 GHz or the 5.0 GHz WiFi bands, so if your router provides multi-band access, you need to make sure it is configured to allow unimpeded cross-traffic between the bands.
|
||||
|
||||
* **Your device thinks it is already paired (this is the most common reason)**. Check the Serial Monitor when HomeSpan first boots - it will let you know if the device is currently *paired* or *unpaired*. If its already *paired* you must unpair it before it can be paired again with the Home App. Normally you would unpair the device from the Home App itself, but if for whatever reason you can't (perhaps the device is no longer showing up in the Home App) you can force HomeSpan to forget all its pairing data and reset its state to *unpaired* by typing either the 'U' or 'H' CLI command into the Serial Monitor. The 'U' command instructs HomeSpan to simply erase all its *Controller* pairing data and reset its state to *unpaired*. The 'H' command instructs HomeSpan to erase all its *Controller* pairing data **and** its *HomeKit Device ID*, after which it reboots into the *unpaired* state and generates a new *HomeKit Device ID*. Typing 'H' is recommended to get the cleanest refresh. Note that your WiFi Credentials and Pairing Setup Code are not changed by either of these commands.
|
||||
|
||||
### *HomeSpan works correctly when my ESP32 is plugged into a computer or separately powered through the USB port, but it fails to work when powered directly through the ESP32 5V pin without any USB connection*
|
||||
|
||||
* On some ESP32 boards, the USB-UART chip only receives power if power is applied through the USB port, and thus remains unpowered if the ESP32 is powered solely through the ESP32 5V pin. As a result, the Serial RX pin associated with UART0 on the ESP32, which is normally driven by the USB-UART chip, is free to float at any voltage. If this pin floats low, the ESP32 thinks there is data to be read from the Serial Monitor, and HomeSpan falls into an infinite loop trying to read this non-existent data.
|
||||
|
||||
|
|
@ -12,15 +24,33 @@
|
|||
|
||||
* Note that adding this pull-up resistor should **not** interefere with normal serial operation of the board, such as using the Serial Monitor or uploading sketches.
|
||||
|
||||
* *As an alternative*, instead of adding a pull-up resistor, you can simply exclude (or comment out) the `Serial.begin()` line in your sketch. This prevents the problem of HomeSpan hanging when you power it through the 5V pin, but it unfortunately means the Serial Monitor will not function when you connect the board to your computer, and you will need to add back `Serial.begin()` whenever you want to use the Serial Monitor.
|
||||
* *As an alternative*, instead of adding a pull-up resistor, you can simply exclude (or comment out) the `Serial.begin()` line in your sketch, or call `homeSpan.setSerialInputDisable(false)` to disable HomeSpan reading from the Serial port. This should prevent the problem of HomeSpan hanging when you power it through the 5V pin, but it unfortunately means the Serial Monitor will not function when you connect the board to your computer, and you will need to add back `Serial.begin()`, or remove `homeSpan.setSerialInputDisable(false)` whenever you want to use the Serial Monitor.
|
||||
|
||||
#### *Compiler Error - `core_version.h` file not found*
|
||||
### *HomeSpan crashes when I enable PSRAM, but works fine if I disable PSRAM*
|
||||
|
||||
* HomeSpan requires the file `core_version.h`. This file is part of each Arduino-ESP32 release package and is properly installed if you use the Arduino Board Manager. If you install the Arduino-ESP32 package manually by downloading the official release zip file (listed under the "Assets" section for each release), you will also find the `core_version.h` is included.
|
||||
* If your ESP32 comes with Quad or Octal PSRAM, the chip will likely need to use one or more additional I/O pins so that it can access the PSRAM using an extended SPI bus, as required for these types of PSRAM. If you happen to use one of those pins for something else (e.g an input button, an LED, etc.) the ESP32 will likely crash whenever PSRAM is enabled.
|
||||
|
||||
* **Resolution:** Check the documentation for your board to see what pins are reserved for use when PSRAM is enabled, and *don't use those pins for anything else.*
|
||||
|
||||
* If you receive the above error when you try to compile a HomeSpan sketch, that means the Arduino-ESP32 package was not properly installed. This can occur if instead of using one of the two methods above, you've tried to manually install the Arduino-ESP32 package by downloading a zip file created live from a specific branch of the Arduino-ESP32 code (typically via the `<> Code` button on GitHub when browsing a particular branch). The `core_version.h` file is usually not included in any of the branches, and thus will not be part of any zip files you request directly from a specific branch.
|
||||
### *The Serial Monitor is reporting* "gpio: gpio_set_level(226): GPIO output gpio_num error"
|
||||
|
||||
* **Resolution:** Use the Arduino Board manager to install the Arduino-ESP32 package (recommended), or install manually using an *official release zip* file found under the "Assets" section of each release version shown on the Arduino-ESP32 GitHub site.
|
||||
* This is an ESP32-generated error message and it occurs if you try to set the output of a pin that either does not exist on your chip, or does exist but it is input-only (i.e. it cannot be used as a output). This typically occurs when you try to compile code for one chip (such as an ESP32-S2) on another chip (such as an ESP32-C3). The code will compile fine, but may produce the above error during run-time.
|
||||
|
||||
* **Resolution:** Check the documentation for your board and *use only pins that exist for your chip, and are not reserved for internal functions, and are not input-only.*
|
||||
|
||||
### *My sketch is too large to be uploaded (error when trying to upload)*
|
||||
|
||||
* Though all ESP32 chips have a minimum of 4MB of flash memory, the amount that can be used to store a program depends on the *partition scheme* selected. By default, the ESP32 uses a parition scheme that reserves 1408 KB for a SPIFFS partition (SPI Flash File Storage) and splits the majority of the remaining flash into two equal OTA partitions of 1280 KB each for program storage. Most HomeSpan sketches come close to filling up an entire OTA partition, and if you add a lot of other libraries you will likely exceed 1280 KB.
|
||||
|
||||
* **Resolution:** Select a different partition table that does not reserve so much flash memory for a SPIFFS partition since SPIFFS is not used at all by HomeSpan and *this partition is just wasting space.*
|
||||
|
||||
* From within the Arduino IDE, the easiest way to reduce the SPIFFS partition is to select the *Minimal SPIFFS* partition scheme from under the Tools menu, and then simply recompile and upload your sketch. This scheme reserves only 128 KB for the SPIFFS partition, which leaves a full 1920 KB of program storage for each OTA partition. This represents a 50% increase in program size, which should suffice for most applications.
|
||||
|
||||
* If for some reason you still need more space, and you only have 4MB of flash, you can try selecting the *Huge App* partition scheme, which reserves 896 KB for SPIFFS and leaves a *single* partition of 3072 KB for program storage. OTA will unfortunately *not* be available in this scheme.
|
||||
|
||||
* Note: if you are not using the Arduino IDE to compile and upload HomeSpan sketches, please consult the documentation for your IDE to learn how to change the partition scheme.
|
||||
|
||||
* Note: if none of the built-in partition schemes contain the right balance of partition sizes for your sketch, you can always create a custom partition scheme as demonstrated in HomeSpan's [CustomNVSParititon Example](../examples/Other%20Examples/CustomNVSPartition). This technique should work even if not using the Arduino IDE.
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -2,28 +2,28 @@
|
|||
|
||||
HomeSpan includes dedicated classes that provide for easy control of a stepper motor connected to an ESP32 via a stepper motor driver board. These classes allow one or more stepper motors to operate smoothly and asynchronously in the background while HomeSpan continues to run in the foreground. On devices with dual processors, stepper-motor control can be run either on the same or a different processor from HomeSpan.
|
||||
|
||||
The HomeSpan class that contains all the methods to control a stepper motor is called **StepperControl**. However, this is an abstract class and cannot be instantiated directly. Instead you instantiate stepper motor objects using driver-specific child-classes (derived from **StepperControl**) that contain all the logic to configure and operate a particular driver board. Each child class supports one or more constructors allowing you to specify which output pins on your ESP32 device will be connected to the required pins on your driver board:
|
||||
The HomeSpan class that contains all the methods to control a stepper motor is called **StepperControl**. However, this is an abstract class and cannot be instantiated directly. Instead you instantiate stepper motor objects using driver-specific child-classes (derived from **StepperControl**) that contain all the logic to configure and operate a particular driver board. Each child class supports one or more constructors allowing you to specify which output pins on your ESP32 device will be connected to the required pins on your driver board.
|
||||
|
||||
The following drivers are currently included in HomeSpan:
|
||||
|
||||
* **[Stepper_TB6612](StepperDrivers/Stepper_TB6612.md)**
|
||||
* This class is used to operate stepper motors driven by a [Toshiba TB6612](https://cdn-shop.adafruit.com/datasheets/TB6612FNG_datasheet_en_20121101.pdf) chip, either with or without the use of ESP32 PWM pins
|
||||
* This class is used to operate stepper motors driven by a [Toshiba TB6612](https://cdn-shop.adafruit.com/datasheets/TB6612FNG_datasheet_en_20121101.pdf) (or equivalent) chip
|
||||
* Can be used either with or without ESP32 PWM pins
|
||||
* See, for example, the [Adafruit TB6612 1.2A DC/Stepper Motor Driver Breakout Board](https://www.adafruit.com/product/2448)
|
||||
* To use, add the following to the top of your sketch: `#include "extras/Stepper_TB6612.h"`
|
||||
* Constructor 1: `Stepper_TB6612(int AIN1, int AIN2, int BIN1, int BIN2)`
|
||||
* controls the driver board using only 4 digital pins from the ESP32
|
||||
* does not provide ability to microstep the motor
|
||||
* Constructor 2: `Stepper_TB6612(int AIN1, int AIN2, int BIN1, int BIN2, int PWMA, int PWMB)`
|
||||
* controls the driver board using 4 digital pins and 2 PWM pins from the ESP32
|
||||
* the addition of the PWM pins provides the ability to microstep the motor
|
||||
|
||||
* **[Stepper_A3967](StepperDrivers/Stepper_A3967.md)**
|
||||
* This class is used to operate stepper motors driven by an [Allegro A3967](https://cdn.sparkfun.com/datasheets/Robotics/A3967-Datasheet.pdf) chip
|
||||
* This class is used to operate stepper motors driven by an [Allegro A3967](https://cdn.sparkfun.com/datasheets/Robotics/A3967-Datasheet.pdf) (or equivalent) chip
|
||||
* See, for example, the [Sparkfun EasyDriver Stepper Motor Board](https://www.sparkfun.com/products/12779)
|
||||
* To use, add the following to the top of your sketch: `#include "extras/Stepper_A3967.h"`
|
||||
* Contructor: `Stepper_A3967(int M1, int M2, int STEP, int DIR, int ENABLE)`
|
||||
* controls the driver board using 5 digital pins from the ESP32
|
||||
* microstepping is built into the driver board (separate ESP32 PWM pins are not needed)
|
||||
|
||||
Click on either of the driver-specific classes above for complete details on how to wire and configure a particular driver board.
|
||||
* **[Stepper_ULN2003A](StepperDrivers/Stepper_ULN2003A.md)**
|
||||
* This class is used to operate stepper motors driven by a [Texas Instruments ULN2003A](https://www.ti.com/lit/ds/symlink/uln2003a.pdf) (or equivalent) chip
|
||||
* See, for example, the [Opencircuit ULN2003 Stepper Motor Driver Board](https://opencircuit.shop/product/uln2003-stepper-motor-driver-module)
|
||||
|
||||
* **[Stepper_UNIPOLAR](StepperDrivers/Stepper_UNIPOLAR.md)**
|
||||
* This class provides a generic driver for use with any center-tapped unipolar stepper motor
|
||||
* Use requires a driver board that can convert the low-voltage/low-current digital signals from 4 pins on the ESP32 to higher-voltage/higher-current signals suitable for operating the stepper motor
|
||||
|
||||
Click on any of the driver-specific classes above for complete details on how to wire and configure a particular driver board.
|
||||
|
||||
## StepperControl Methods
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ Below is a simple sketch demonstrating the above methods:
|
|||
```C++
|
||||
// StepperControl Example using TB6612-based Driver Board with HALF STEP PWM MODE
|
||||
|
||||
#include "Stepper_TB6612.h" // include the driver for a TB6612 chip
|
||||
#include "HomeSpan.h" // HomeSpan includes all the StepperControl classes
|
||||
|
||||
StepperControl *motor; // create a global pointer to StepperControl so it can be accessed in both setup() and loop()
|
||||
|
||||
|
|
@ -186,7 +186,7 @@ A fully worked example showing how to use the *StepperControl* class within a co
|
|||
|
||||
## Creating your own **StepperControl** Driver
|
||||
|
||||
If neither of the above motor driver classes works for your specific chip or driver board, it is relatively straightfoward to create a new driver to use in your sketch. This is because all the logic to operate a stepper motor in the background is already embedded in the abstract **StepperControl** class. To create your own driver, start by creating a child class derived from **StepperControl**. Next, add a constructor that defines the pins and performs any initializations if needed. Finally, define the following methods that **StepperControl** calls to operate the motor:
|
||||
If none of the above motor driver classes works for your specific chip or driver board, it is relatively straightfoward to create a new driver to use in your sketch. This is because all the logic to operate a stepper motor in the background is already embedded in the abstract **StepperControl** class. To create your own driver, start by creating a child class derived from **StepperControl**. Next, add a constructor that defines the pins and performs any initializations if needed. Finally, define the following methods that **StepperControl** calls to operate the motor:
|
||||
|
||||
* `void onStep(boolean direction)` - contains the logic to advance the motor by a single step based on the *direction* parameter
|
||||
* `void onEnable()` - contains the logic that enables the motor driver
|
||||
|
|
@ -199,7 +199,7 @@ Only the first method, `onStep()`, is required to be defined. You can leave any
|
|||
As an example, below is the complete code for the **Stepper_A3967** class:
|
||||
|
||||
```C++
|
||||
#include "StepperControl.h"
|
||||
#include "HomeSpan.h"
|
||||
|
||||
//////////////////////////
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Stepper_A3967
|
||||
|
||||
This is a derived class of **StepperControl** designed to operate stepper motors driven by an [Allegro A3967](https://cdn.sparkfun.com/datasheets/Robotics/A3967-Datasheet.pdf) chip. To use, add `#include "extras/Stepper_A3967.h"` to the top of your sketch.
|
||||
This is a derived class of **StepperControl** designed to operate stepper motors driven by an [Allegro A3967](https://cdn.sparkfun.com/datasheets/Robotics/A3967-Datasheet.pdf) (or equivalent) chip.
|
||||
|
||||
The Allegro A3967 is a specialized driver designed for stepper motors. It contains a built-in PWM generator and pre-programmed stepping modes. Wiring for the [Sparkfun EasyDriver Stepper Motor Board](https://learn.sparkfun.com/tutorials/easy-driver-hook-up-guide?_ga=2.152816825.1841726212.1688220137-156607829.1686369274) that uses this chip is as follows:
|
||||
|
||||
|
|
@ -11,14 +11,14 @@ The Allegro A3967 is a specialized driver designed for stepper motors. It contai
|
|||
* *Motor A* - connect to the "A" coil of the stepper motor
|
||||
* *Motor B* - connect to the "B" coil of the stepper motor
|
||||
#### **Control Connections**
|
||||
* *ENABLE* - connect to a digital pin on the ESP32 - used to enable/disable to motor driver
|
||||
* *STEP, DIR* - connect to two digital pins on the ESP32 - used to step the motor and set the direction
|
||||
* *MS1, MS2* - connect to two digital pins on the ESP32 - used to set the step type mode
|
||||
* *STEP, DIR* - connect to two digital pins on the ESP32 - used to step the motor and set the direction
|
||||
* *ENABLE* - connect to a digital pin on the ESP32 - used to enable/disable to motor driver
|
||||
* *SLEEP, RESET* - already pulled high on the EasyDriver board, so no connection neeed. If using a different driver board, ensure these pins are pulled high, else connect to VCC
|
||||
* *PFD* - not used
|
||||
|
||||
The **Stepper_A3967** class includes the following constructor:
|
||||
* `Stepper_A3967(int M1, int M2, int STEP, int DIR, int ENABLE)`
|
||||
* `Stepper_A3967(int MS1, int MS2, int STEP, int DIR, int ENABLE)`
|
||||
* controls the driver board using 5 digital pins from the ESP32, where the parameters specify the pin numbers. Supports the following step type modes:
|
||||
|
||||
* FULL_STEP_TWO_PHASE
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Stepper_TB6612
|
||||
|
||||
This is a derived class of **StepperControl** designed to operate stepper motors driven by a [Toshiba TB6612](https://cdn-shop.adafruit.com/datasheets/TB6612FNG_datasheet_en_20121101.pdf) chip, either with or without the use of ESP32 PWM pins. To use, add `#include "extras/Stepper_TB6612.h"` to the top of your sketch.
|
||||
This is a derived class of **StepperControl** designed to operate stepper motors driven by a [Toshiba TB6612](https://cdn-shop.adafruit.com/datasheets/TB6612FNG_datasheet_en_20121101.pdf) (or equivalent) chip, either with or without the use of ESP32 PWM pins.
|
||||
|
||||
The Toshiba TB6612 is a generic motor driver providing direct control of two full H-bridges. Wiring for the [Adafruit TB6612 1.2A DC/Stepper Motor Driver Breakout Board](https://learn.adafruit.com/adafruit-tb6612-h-bridge-dc-stepper-motor-driver-breakout) that uses this chip is as follows:
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
# Stepper_ULN2003A
|
||||
|
||||
This is a derived class of **StepperControl** designed to operate stepper motors driven by a [Texas Instruments ULN2003A](https://www.ti.com/lit/ds/symlink/uln2003a.pdf) (or equivalent) chip.
|
||||
|
||||
The Texas Instruments ULN2003A chip containins an array of seven Darlington transistor pairs each capable of converting low-voltage/low-current digital signals into higher-voltage/higher-current outputs suitable for driving a stepper motor.[^1]
|
||||
|
||||
[^1]: Only four of the seven Darlington transistor pairs in the ULN2003A are needed to drive a typical unipolar stepper motor.
|
||||
|
||||
Various manufacturers have incorporated this chip into a dedicated stepper motor board designed to drive unipolar motors such the [28BYJ‑48 5‑Volt Stepper](https://opencircuit.shop/product/28byj-48-5v-stepper-motor-4-phase-5-wire) and [28BYJ‑48 12‑Volt Stepper](https://opencircuit.shop/product/28byj-48-12v-stepper-motor-4-phase-5-wire). Wiring for the [Opencircuit ULN2003 Stepper Motor Driver Board](https://opencircuit.shop/product/uln2003-stepper-motor-driver-module) that uses this chip is as follows:
|
||||
|
||||
#### **Power Connections**[^2]
|
||||
* ➕ - connect to an external DC power supply that will drive stepper motor (5-12V)
|
||||
* ➖ - connect to GND on the ESP32, and to ground of external DC power supply
|
||||
#### **Motor Connections**
|
||||
* plug the motor directly into the board's 5-pin connector
|
||||
#### **Control Connections**
|
||||
* *IN1, IN2, IN3, IN4* - connect to four digital pins on the ESP32 - used to step the motor in either direction
|
||||
|
||||
The **Stepper_ULN2003A** class includes the following constructors:
|
||||
* `Stepper_ULN2003A(int IN1, int IN2, int IN3, int IN4)`
|
||||
* controls the driver board using only 4 digital pins from the ESP32, where the parameters specify the pin numbers. Supports the following step type modes:
|
||||
|
||||
* FULL_STEP_ONE_PHASE
|
||||
* FULL_STEP_TWO_PHASE
|
||||
* HALF_STEP
|
||||
|
||||
❗Note: The ULN2003A chip does not support a short brake state. Calls to the `brake()` method, as well as setting the *endAction* parameter in the `move()` and `moveTo()` methods to **StepperControl::BRAKE** have no effect on the motor driver.<br><br>
|
||||
|
||||
> [!TIP]
|
||||
> If you set the motor to move very slowly (e.g. 500ms per step) you will be able to track how the current is turned on and off for each phase of the motor coils depending on the *step mode* selected by observing the four LEDs (labeled *A, B, C, D*) built into the driver board. See also this [Last Minute Engineers Tutorial](https://lastminuteengineers.com/28byj48-stepper-motor-arduino-tutorial) for a detailed presentation of the ULN2003A and its use to drive a 28BYJ‑48 5‑Volt Stepper Motor.
|
||||
|
||||
|
||||
[^2]: the ULN2003A is a passive chip - there is no VCC power connection between the driver board and the ESP32
|
||||
|
||||
---
|
||||
|
||||
[↩️](../Stepper.md) Back to the Stepper Motor Control page
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
# Stepper_UNIPOLAR
|
||||
|
||||
This class provides a generic driver for use with any center-tapped unipolar stepper motor. Requires the use of a driver board that can convert the low-voltage/low-current digital signals from 4 pins on the ESP32 to higher-voltage/higher-current outputs suitable for direct connection to the two phases (*A* and *B*) of each coil (*1* and *2*) in the stepper motor.
|
||||
|
||||
The **Stepper_UNIPOLAR** class includes the following constructor:
|
||||
* `Stepper_UNIPOLAR(int coil1A, int coil1B, int coil2A, int coil2B)`
|
||||
* controls the driver board using 4 digital pins from the ESP32, where the parameters specify the pin numbers
|
||||
* the driver circuit should be connected and configured such that when any of ESP32 pins specified above are set to are HIGH, current flows through the corresponding coil/phase. Similarly, when a pin is set LOW, the driver circuit should stop the flow of current through the corresponding coil/phase.
|
||||
* supported modes are as follows:
|
||||
|
||||
* FULL_STEP_ONE_PHASE
|
||||
* FULL_STEP_TWO_PHASE
|
||||
* HALF_STEP
|
||||
|
||||
❗Note: This class does not support a short brake state. Calls to the `brake()` method, as well as setting the *endAction* parameter in the `move()` and `moveTo()` methods to **StepperControl::BRAKE** have no effect on the motor driver.<br><br>
|
||||
|
||||
> [!WARNING]
|
||||
> **Note the order of the constructor parameters!** The first two parameters specify the ESP32 pins that control the current flowing through phases *A* and *B* of ***Coil 1***; the second two parameters are for phases *A* and *B* of ***Coil 2***.
|
||||
|
||||
It does *not* matter which coil is defined as *1* or *2*, nor which side is called *A* or *B*, as long as the first two parameters are for one of the coils and the second two are for the other coil. You'll know if you mis-specified the order of the pins because the motor will vibrate back and forth instead of turning clockwise or counterclockwise.
|
||||
|
||||
## Technical Details
|
||||
|
||||
The patterns by which this class sets the specified pins HIGH and LOW depend on the *step mode* chosen as follows:
|
||||
|
||||
#### FULL_STEP_ONE_PHASE
|
||||
|
||||
* 4-step cycles where in each step current flows only through **one** phase of **one** of the coils
|
||||
|
||||
<table>
|
||||
<tr><th></th><th colspan="2">Phase A</th><th colspan="2">Phase B</th></tr>
|
||||
<tr><th></th><th>Coil 1</th><th>Coil 2</th><th>Coil 1</th><th>Coil 2</th></th></tr>
|
||||
<tr><th>Step 1</th><td align="center">HIGH</td><td align="center">-</td><td align="center">-</td><td align="center">-</td></td></tr>
|
||||
<tr><th>Step 2</th><td align="center">-</td><td align="center">HIGH</td><td align="center">-</td><td align="center">-</td></td></tr>
|
||||
<tr><th>Step 3</th><td align="center">-</td><td align="center">-</td><td align="center">HIGH</td><td align="center">-</td></td></tr>
|
||||
<tr><th>Step 4</th><td align="center">-</td><td align="center">-</td><td align="center">-</td><td align="center">HIGH</td></td></tr>
|
||||
</table>
|
||||
<br>
|
||||
|
||||
#### FULL_STEP_TWO_PHASE
|
||||
|
||||
* 4-step cycles where in each step current flows through **one** phase of **each** of the coils
|
||||
|
||||
<table>
|
||||
<tr><th></th><th colspan="2">Phase A</th><th colspan="2">Phase B</th></tr>
|
||||
<tr><th></th><th>Coil 1</th><th>Coil 2</th><th>Coil 1</th><th>Coil 2</th></th></tr>
|
||||
<tr><th>Step 1</th><td align="center">HIGH</td><td align="center">HIGH</td><td align="center">-</td><td align="center">-</td></td></tr>
|
||||
<tr><th>Step 2</th><td align="center">-</td><td align="center">HIGH</td><td align="center">HIGH</td><td align="center">-</td></td></tr>
|
||||
<tr><th>Step 3</th><td align="center">-</td><td align="center">-</td><td align="center">HIGH</td><td align="center">HIGH</td></td></tr>
|
||||
<tr><th>Step 4</th><td align="center">HIGH</td><td align="center">-</td><td align="center">-</td><td align="center">HIGH</td></td></tr>
|
||||
</table>
|
||||
<br>
|
||||
|
||||
#### HALF_STEP
|
||||
|
||||
* 8-step cycles formed by interleaving the 4 steps of the FULL_STEP_ONE_PHASE mode with the 4 steps of the FULL_STEP_TWO_PHASE mode
|
||||
|
||||
<table>
|
||||
<tr><th></th><th colspan="2">Phase A</th><th colspan="2">Phase B</th></tr>
|
||||
<tr><th></th><th>Coil 1</th><th>Coil 2</th><th>Coil 1</th><th>Coil 2</th></th></tr>
|
||||
<tr><th>Step 1</th><td align="center">HIGH</td><td align="center">-</td><td align="center">-</td><td align="center">-</td></td></tr>
|
||||
<tr><th>Step 2</th><td align="center">HIGH</td><td align="center">HIGH</td><td align="center">-</td><td align="center">-</td></td></tr>
|
||||
<tr><th>Step 3</th><td align="center">-</td><td align="center">HIGH</td><td align="center">-</td><td align="center">-</td></td></tr>
|
||||
<tr><th>Step 4</th><td align="center">-</td><td align="center">HIGH</td><td align="center">HIGH</td><td align="center">-</td></td></tr>
|
||||
<tr><th>Step 5</th><td align="center">-</td><td align="center">-</td><td align="center">HIGH</td><td align="center">-</td></td></tr>
|
||||
<tr><th>Step 6</th><td align="center">-</td><td align="center">-</td><td align="center">HIGH</td><td align="center">HIGH</td></td></tr>
|
||||
<tr><th>Step 7</th><td align="center">-</td><td align="center">-</td><td align="center">-</td><td align="center">HIGH</td></td></tr>
|
||||
<tr><th>Step 8</th><td align="center">HIGH</td><td align="center">-</td><td align="center">-</td><td align="center">HIGH</td></td></tr>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
[↩️](../Stepper.md) Back to the Stepper Motor Control page
|
||||
|
|
@ -0,0 +1,313 @@
|
|||
# TLV8 Characteristics
|
||||
|
||||
Most HomeKit Characteristics store a single numerical value or simple string. However, HomeKit supports two additional storage formats - a simple list of bytes (the **DATA** format) and a structured list of tags and values (the **TLV8** format). The DATA format is not used by any Apple-defined Characterstics but it is included in HomeSpan for use when creating Custom Characteristics for non-Apple applications.
|
||||
|
||||
In contrast, the TLV8 format is used extensively by HomeKit during the initial pairing process as well as whenever a new secure (verified) connection is established between HomeKit and a HomeSpan device. There are also a variety of Apple-defined Characteristics that use the TLV8 format to store and transmit multiple sets of values, each represented as byte-arrays of arbitrary length.
|
||||
|
||||
## Overview of TLV8 Format
|
||||
|
||||
The TLV8 format itself is quite simple. A TLV8 object comprises one or more TLV8 *records*, where the first byte in a record represents an identifying TAG (from 0-255), the second byte represents the LENGTH of the value, and the remaining LENGTH-bytes represent the VALUE itself, which is always in the form of a *byte-array* (i.e. an array of 0 or more *uint8_t* elements). Notable points about the TLV8 format are as follows:
|
||||
|
||||
* since the LENGTH is stored only as a single byte, VALUES requiring more than 255 bytes must be represented as sequential TLV8 records *with the same TAG*
|
||||
* it is fine (and in fact common) for a TLV8 object to include multiple records with the same TAG, except that they must be *separated by a record with a different TAG*, otherwise the parser reading the data will concatenate the VALUES from sequential records having the same TAG into a single record (as per above)
|
||||
* records representing a zero-LENGTH VALUE are allowed, and consist of only two bytes: a TAG and a zero (indicating a zero-length VALUE). TAGS with a zero-LENGTH VALUE are often used to separate multiple records having the same TAG
|
||||
* if the VALUE's byte-array is supposed to represent an single, unsigned integer, it should be arranged in little endian format (i.e. least-significant byte first) and padded with trailing zeros as needed to bring the total LENGTH of the VALUE to either 1, 2, 4, or 8 bytes (representing uint8_t, uint16_t, uint32_t, and uint64_t values)
|
||||
* if the VALUE's byte-array is supposed to represent a string, it should not include the terminating null since the LENGTH tells you have many characters are in the string
|
||||
* the bytes that make up a VALUE can themselves represent a separate, complete TLV8 object. There is no limit on the number of "sub-TLVs" that can be recursively nested in a "parent" TLV8 object
|
||||
* a parser reading TLV8 records should silently ignore any TAG it is not expecting. It may be an error to omit a TAG that the parser requires, but it will be not an error to include a TAG it does not recognize
|
||||
* it is **not** possible to unambigously determine whether the VALUE byte-array in a TLV8 record is supposed to represent an unsigned integer, a string, an arbitrary series of bytes, a sub-TLV object, or something else entirely. The only identifying information for any given TLV8 record is its TAG number, which ranges from 0-255. There is no general schema or TLV8 protocol that maps TAG types to VALUE types. Rather, the TAG numbers are arbitrary and users must consult the documentation for each Characteristic to learn what TAG numbers are expected, and what their VALUEs are supposed to represent for that specific Characteristic
|
||||
* since HomeKit data transmissions are often represented in JSON, and JSON is a text-only format, HomeKit requires that TLV8 records are first encoded in base-64 when transmitting JSON to and from Controllers to Accessories.
|
||||
|
||||
Fortunately, HomeSpan includes a dedicated TLV8 library (see below) that automatically takes care of many of the above points, which enables you to read, create, and process TLV8 data without worrying about parsing TLV8 records with more than 255 bytes, converting numerical values to little-endian, or encoding/decoding records into base-64.
|
||||
|
||||
## *TLV8()*
|
||||
|
||||
Creating an instance of HomeSpan's TLV8 **class** using the above constructor builds an empty TLV8 object into which you can add and process TLV8 records. TLV8 objects are instantiated as standard C++ linked-list containers derived from `std::list<tlv8_t>`, where *tlv8_t* is an opaque structure used to store individual TLV8 records.[^opaque]
|
||||
|
||||
Also, as shown below, many of the TLV8 methods utilize linked-list *constant* iterators. These are represented by the typedef *TLV8_itc*.[^iterators]
|
||||
|
||||
[^opaque]:The *tlv8_t* structure is opaque because in general you will not have to create or interact directly with the structure or its data. Note that in addition to the above TLV8-specific methods, you can use any `std::list` method with a TLV8 object if desired.
|
||||
|
||||
[^iterators]:You do not need expert knowledge of C++ containers and iterators in order to use the TLV8 library, but a basic understanding of containers and iterators will make the library much easier to learn and enjoyable to use.
|
||||
|
||||
The method for adding a generic TLV8 record to a TLV8 object is as follows:
|
||||
|
||||
* `TLV8_itc add(uint8_t tag, size_t len, const uint8_t *val)`
|
||||
|
||||
* where *tag* is the TAG identifier for the record to add and *val* is a pointer to a byte-array containing *len* elements
|
||||
* example: `TLV8 myTLV; uint8_t v[]={0x01, 0x05, 0xE3, 0x4C}; tlv.add(1, sizeof(v), v);
|
||||
* setting *val* to NULL reserves *len* bytes of space for the TLV8 record within the TLV8 object, but does not copy any data
|
||||
* this method returns a TLV8 constant iterator to the resulting TLV8 record so you can reference the record at a later time if needed
|
||||
|
||||
In addition to the above generic method suitable for any type of data, the following methods make it easier to add TLV8 records with specific, frequently-used types of data:
|
||||
|
||||
* `TLV8_itc add(uint8_t tag, uintXX_t val)`
|
||||
* adds a TLV8 record containing a single, unsigned numeric value, *val* (i.e. uint8_t, uint16_t, uint32_t, or uint64_t)
|
||||
|
||||
* `TLV8_itc add(uint8_t tag, const char *val)`
|
||||
* adds a TLV8 record containing all the non-null bytes of a null-terminated character string, *val*
|
||||
|
||||
* `TLV8_itc add(uint8_t tag, TLV8 &subTLV)`
|
||||
* adds a TLV8 record containing all the bytes of an entire TLV8 object, *subTLV*
|
||||
|
||||
* `TLV8_itc add(uint8_t tag)`
|
||||
* adds a zero-length TLV8 record containing nothing but a TAG identifer
|
||||
|
||||
Note that if you *add* consecutive records with the same TAG identifier, the TLV8 library will concatenate their data and combine into a single record. For example, `myTLV.add(1,13); myTLV.add(1,300)` will be combined to produce a single 3-byte recording containing the data 0x0D2C01, where the first byte represents from the number 13 and the second two bytes represent the number 300. This may have been your desired outcome, but likely not what you wanted to happen.
|
||||
|
||||
Instead, to create two distinct records with the same tag value, simply interpose a zero-length record with a different TAG identifier between the two as a "separator" like this: `myTLV.add(1,13); myTLV.add(255); myTLV.add(1,300);` Here we used a TAG identifer of 255 to represent the separator, but that choice is arbitrary, unless that TAG happens to be used by the Characteristic for something else (TAG identifiers of 0 or 255 are commonly used as separators).
|
||||
|
||||
The method for finding a TLV8 record within a TLV8 object that contains a specific TAG identifer is as follows:
|
||||
|
||||
* `TLV8_itc find(uint8_t tag)`
|
||||
|
||||
* where *tag* is the TAG identifier you are seeking
|
||||
* returns a TLV8 constant iterator to *first* record that matches; returns *end()* if no records match
|
||||
|
||||
To restrict the search range to a limited set of records, add optional starting and ending iterators *it1* and *it2*:
|
||||
|
||||
* `TLV8_itc find(uint8_t tag [, TLV8_itc it1 [, TLV8_itc it2]])`
|
||||
|
||||
* returns a TLV8 constant iterator to the *first* record within the range of constant iterators from *it1* to *it2* that matches the specified *tag*
|
||||
* search range is inclusive of *it1* but exclusive of *it2*
|
||||
* returns *it2* if no records match
|
||||
* if *it2* is unspecified, default is *end()*; if *it1* is unspecified, default is *begin()*
|
||||
* note `myTLV.find(tag)` is equivalent to `myTLV.find(tag, myTLV.begin(), myTLV.end())`
|
||||
|
||||
Use of the C++ `auto` keyword is generally the best way to save the TVL8_itc iterator that is returned from the `find()` and `add()` methods. For example, `auto myIT = myTLV.find(6)` sets *myIT* to a constant iterator pointing to the first TLV8 record in *myTLV* that has a TAG identifer of 6.
|
||||
|
||||
The method for finding the LENGTH of the data VALUE stored in a particular TLV8 record is as follows:
|
||||
|
||||
* `int len(TLV8_itc it)`
|
||||
* where *it* is an constant iterator pointing to a specific TLV8 record
|
||||
* returns the length of the data VALUE stored in the associated record, which may be zero for a zero-LENGTH record
|
||||
* returns -1 if *it* points to the *end()* of the TLV8 object
|
||||
|
||||
A typical use of the `len()` method is to simultaneously check whether a TLV8 object contains a particular TAG identifier, and that the LENGTH of the TAG matches an expected value. For example, if a certain Characteristic requires a TLV8 record with a TAG identifer of 6 to contain a 32-byte registration number, you can perform the following check:
|
||||
|
||||
```C++
|
||||
auto myIT = myTLV.find(6);
|
||||
if(myTLV.len(myIT)!=32)
|
||||
Serial.printf("Error: TAG 6 is either missing or of improper length\n");
|
||||
else
|
||||
Serial.printf("TAG 6 containing 32 bytes of data has been found\n");
|
||||
```
|
||||
|
||||
The method for printing all of the records in a TLV8 object to the Serial Monitor is as follows:
|
||||
|
||||
* `void print()`
|
||||
|
||||
* prints all TLV8 records, one per line, to the Serial Monitor
|
||||
* format of the output is: TAG(LENGTH) VALUE [NUMERIC], where
|
||||
* TAG = the TAG identifer (0-255)
|
||||
* LENGTH = length of the VALUE byte-array (may be zero)
|
||||
* VALUE = a sequential list, in hexadecimal, of all the bytes in the VALUE byte-array (only displayed if LENGTH>0)
|
||||
* NUMERIC = an unsigned-integer interpretation of the bytes in VALUE, assuming little-endian ordering
|
||||
* this decimal value is only displayed if LENGTH<=8
|
||||
* if LENGTH=0, the word "null" is displayed instead
|
||||
|
||||
To restrict the the printing range to a limited set of records, add optional starting and ending constant iterators *it1* and *it2*:
|
||||
|
||||
* `void print(TLV8_itc it1 [, TLV8_itc it2])`
|
||||
|
||||
* prints all TLV8 records between constant iterators *it1* and *it2*
|
||||
* print range is inclusive of *it1* but exclusive of *it2*
|
||||
* if *it2* is unspecified, prints only the record pointed to by *it1*
|
||||
* note `myTLV.print()` is equivalent to `myTLV.print(myTLV.begin(), myTLV.end())`
|
||||
|
||||
The output generated by `print()` can contain some very long lines, especially if the VALUE of some of the TLV8 records represents other complete TLV8 objects (known as sub-TLVs or "nested" TLVs). To recursively print all sub-TLV objects, use the following method:
|
||||
|
||||
* `void printAll()`
|
||||
|
||||
* recursively prints all TLV8 records, one per line, to the Serial Monitor
|
||||
* inspects each TLV8 record and tries to parse as if the record represented a sub-TLV object
|
||||
* if parsing is successful, prints the record and then calls `printAll()` on the sub-TLV
|
||||
* if not, prints the record and ends this branch of the recursion
|
||||
* the format of each line is the same as that of `print()` except that TAG displays the full path of all TAGs through the branch
|
||||
* note that the output can be very voluminous if your TLV8 object contains many levels of nested sub-TLVs
|
||||
* warning: some care is required when interpretating the output[^subTLVs]
|
||||
|
||||
[^subTLVs]:The `printAll()` method assumes that any VALUE that is consistent with the format of a sub-TLV must be a sub-TLV, even if its just a simple numeric value. For example, `add(10,65536)` yields a record with a TAG identifer of 10 and a 4-byte VALUE of 0x00000100. The `printAll()` method will display this record along with NUMERIC=65536, but it will also then interpret (and thus display) this VALUE as a sub-TLV containing one zero-length record with TAG identifier=0 and another zero-length record with TAG identifer=1, since the VALUE can be successfully parsed as such.
|
||||
|
||||
TLV8 objects manage all of their internal memory requirements, and free up all resources and memory when they go out of scope or are otherwise deleted. However, if you need to "erase" all the contents of a TLV8 object but stil retain the object so you can re-fill with new data, use the following method:
|
||||
|
||||
* `void wipe()`
|
||||
* erases all TLV8 records and frees all associated memory
|
||||
* leaves an empty TLV8 object ready for re-use
|
||||
|
||||
## *TLV8_itc()*
|
||||
|
||||
Objects of type *TLV8_itc* are constant iterators that point to specific *tlv8_t* records in a TLV8 object (or to *end()*). TLV8 iterators are used to access, read from, and write to, the data elements in any given TLV8 record, and are thus a critical part of the TLV8 library. However, if you are using the TLV8 library correctly you should rarely, if ever, need to directly instantiate a *TLV8_itc* using its constructor. Instead, simply use the C++ `auto` keyword as noted above.
|
||||
|
||||
TLV8_itc iterators can be dereferenced to work with data in an individual TLV8 record using the follow methods:
|
||||
|
||||
* `uint8_t getTag()`
|
||||
|
||||
* returns the TAG identifier (0-255) of the TLV8 record
|
||||
* example: `uint8_t tag = myIT->getTag()` or, equivalently, `uint8_t tag = (*myIT).getTag()`
|
||||
|
||||
* `size_t getLen()`
|
||||
|
||||
* returns the LENGTH of the VALUE byte-array of the TLV8 record
|
||||
* example: `size_t len = myIT->getLen()` or, equivalently, `size_t len = (*myIT).getLen()`
|
||||
|
||||
* `uint8_t *get()`
|
||||
|
||||
* returns `uint8_t *` pointing to the first element of the VALUE byte-array of the TLV8 record
|
||||
* for zero-LENGTH TLV8 records, the return value is NULL
|
||||
* example: `uint8_t *v = myIT->get();` or, equivalently, `uint8_t *v = (*myIT).get();`
|
||||
* the `(uint8_t *)` casting operator has been overloaded so you can also obtain this same `uint8_t *` pointer by simply dereferencing the iterator
|
||||
* example: `auto myIT = myTLV.find(6); uint8_t *v = *myIT;`
|
||||
* note this only works if the compiler can determine the need to auto-cast into a `uint8_t *` pointer based on the context of the code
|
||||
|
||||
* `uint8_t get()[i]`
|
||||
* returns the *i<sup>th</sup>* element of the VALUE byte-array
|
||||
* example: `uint8_t n = myIT->get()[i]` or, equivalently, `uint8_t n = (*myIT).get()[i]`
|
||||
* the subscript operator has also been overloaded so you can obtain the *i<sup>th</sup>* element by simply dereferencing the iterator
|
||||
* example: `uint8_t n = (*myIT)[i]`
|
||||
* note there is no range-checking so make sure *i* does not try to reference an element beyond the end of the VALUE byte-array
|
||||
|
||||
* `T getVal<class T>()`
|
||||
* this template function returns a single numeric value of type *T* on the assumption that the VALUE byte-array is storing an unsigned integer in little endian format
|
||||
* *T* can be *uint8_t*, *uint16_t*, *uint32_t*, or *uint64_t* (if unspecified *T* defaults to *uint32_t*)
|
||||
* example: `auto myIT = myTLV.add(50,60000); uint16_t n = myIT->getVal<uint16_t>();`
|
||||
* this method returns the correct numeric value as long as sizeof(*T*) >= LENGTH of the byte-array. For example:
|
||||
* setting *T=uint64_t* with a VALUE byte-array containing 2 bytes returns the *correct* numeric value
|
||||
* setting *T=uint16_t* with a VALUE byte-array containing 4 bytes return an *incorrect* numeric value
|
||||
* this function returns zero for all zero-LENGTH TLV8 records
|
||||
|
||||
### A detailed example using the above methods
|
||||
|
||||
The following code:
|
||||
|
||||
```C++
|
||||
TLV8 myTLV; // instantiates an empty TLV8 object
|
||||
|
||||
myTLV.add(1,8700); // add a TLV8 record with TAG=1 and VALUE=8700
|
||||
auto it_A = myTLV.add(2,180); // add a TLV8 record with TAG=2 and VALUE=180, and save the iterator that is returned
|
||||
|
||||
uint8_t v[32]; // create a 32-byte array, v, and fill it with some data
|
||||
for(int i=0;i<32;i++)
|
||||
v[i]=i;
|
||||
|
||||
myTLV.add(200,32,v); // add a TLV8 record with TAG=200 and copy all 32 bytes of array v into its VALUE
|
||||
|
||||
myTLV.add(50,60000); // add a TLV8 record with TAG=50 and VALUE=60000
|
||||
myTLV.add(255); // add a zero-length TLV8 record with TAG=255 to act as separator
|
||||
myTLV.add(50,120000); // add a TLV8 record with TAG=50 and VALUE=120000
|
||||
myTLV.add(255); // add a zero-length TLV8 record with TAG=255 to act as separator
|
||||
myTLV.add(50,180000); // add a TLV8 record with TAG=50 and VALUE=180000
|
||||
myTLV.add(255); // add a zero-length TLV8 record with TAG=255 to act as separator
|
||||
auto it_B = myTLV.add(50,240000); // add a TLV8 record with TAG=50 and VALUE=240000, and save the iterator that is returned
|
||||
|
||||
auto it_C = myTLV.find(50); // find an iterator to the first TLV8 record with TAG=50;
|
||||
auto it_D = myTLV.find(50,std::next(it_C)); // find an iterator to the first TLV8 record with TAG=50 that occurs AFTER it_C;
|
||||
|
||||
auto it_E = myTLV.find(200); // find an iterator to first TLV8 record with TAG=200;
|
||||
|
||||
Serial.printf("results of myTLV.print():\n\n");
|
||||
|
||||
myTLV.print(); // print the contents of myTLV to the Serial Monitor
|
||||
|
||||
Serial.printf("\n");
|
||||
|
||||
// print content of it_A:
|
||||
|
||||
Serial.printf("it_A: TAG=%d, LENGTH=%d, Value=%d\n", it_A->getTag(), it_A->getLen(), it_A->getVal());
|
||||
|
||||
// print content of it_B using alternative syntax:
|
||||
|
||||
Serial.printf("it_B: TAG=%d, LENGTH=%d, Value=%d\n", (*it_B).getTag(), (*it_B).getLen(), (*it_B).getVal());
|
||||
|
||||
// print contents of it_C and it_D, based on previous find() above:
|
||||
|
||||
Serial.printf("it_C TAG=%d, LENGTH=%d, Value=%d\n", (*it_C).getTag(), (*it_C).getLen(), (*it_C).getVal());
|
||||
Serial.printf("it_D TAG=%d, LENGTH=%d, Value=%d\n", (*it_D).getTag(), (*it_D).getLen(), (*it_D).getVal());
|
||||
|
||||
// you can also use the results of find() directly without saving as a separate iterator, though this is computationally inefficient:
|
||||
|
||||
if(myTLV.find(1)!=myTLV.end()) // check for match
|
||||
Serial.printf("Found: TAG=%d, LENGTH=%d, Value=%d\n", myTLV.find(1)->getTag(), myTLV.find(1)->getLen(), myTLV.find(1)->getVal());
|
||||
|
||||
// sum up all the bytes in it_E:
|
||||
|
||||
int sum=0;
|
||||
for(int i=0; i < it_E->getLen(); i++)
|
||||
sum+= (*it_E)[i];
|
||||
|
||||
Serial.printf("it_E TAG=%d, LENGTH=%d, Sum of all bytes = %d\n", (*it_E).getTag(), (*it_E).getLen(), sum);
|
||||
|
||||
// create a "blank" TLV8 record with TAG=90 and space for 16 bytes:
|
||||
|
||||
auto it_F = myTLV.add(90,16,NULL);
|
||||
|
||||
// copy the first 16 bytes of it_E into it_F and print the record:
|
||||
|
||||
memcpy(*it_F,*it_E,16);
|
||||
myTLV.print(it_F);
|
||||
```
|
||||
|
||||
produces the following output:
|
||||
|
||||
```C++
|
||||
results of myTLV.print():
|
||||
|
||||
1(2) FC21 [8700]
|
||||
2(1) B4 [180]
|
||||
200(32) 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F
|
||||
50(2) 60EA [60000]
|
||||
255(0) [null]
|
||||
50(4) C0D40100 [120000]
|
||||
255(0) [null]
|
||||
50(4) 20BF0200 [180000]
|
||||
255(0) [null]
|
||||
50(4) 80A90300 [240000]
|
||||
|
||||
it_A: TAG=2, LENGTH=1, Value=180
|
||||
it_B: TAG=50, LENGTH=4, Value=240000
|
||||
it_C TAG=50, LENGTH=2, Value=60000
|
||||
it_D TAG=50, LENGTH=4, Value=120000
|
||||
Found: TAG=1, LENGTH=2, Value=8700
|
||||
it_E TAG=200, LENGTH=32, Sum of all bytes = 496
|
||||
90(16) 000102030405060708090A0B0C0D0E0F
|
||||
```
|
||||
|
||||
## Reading and Writing TLV8 Characteristics
|
||||
|
||||
As fully documented in the [API Reference](Reference.md), the following *SpanCharacteristic* methods are used to read and write TLV8 objects to TLV8 Characteristics:
|
||||
|
||||
* `getTLV(TLV8 &tlv)`
|
||||
* `getNewTLV(TLV8 &tlv)`
|
||||
* `setTLV(TLV8 &tlv)`
|
||||
|
||||
These are analagous to the `getVal()`, `getNewVal()` and `setVal()` methods used for numerical-based Characteristics.
|
||||
|
||||
Note that using the above methods *do not* require you to create a separate byte-array that splits records into chunks of 255 bytes, nor does it require you to encode or decode anything into base-64. Rather, you directly read and write to and from the Characteristic into a TLV8 object.[^getString]
|
||||
|
||||
For a detailed example of how TLV8 Characteristics are used in practice, see [Tutorial Example 22 - TLV8_Characteristics](../examples/22-TLV8_Characteristics) demonstrating how the **DisplayOrder** TLV8 Charactersitic can be used to set the order in which Input Sources for a TV Service are displayed in the Home App.
|
||||
|
||||
[^getString]:Since TLV8 Characteristics are stored as base-64 encoded strings, you can always use `getString()` to read the base-64 text, or `getData()` to decode the string into the full byte-array that represents the entire TLV8 object, if you desire. Also, if you really don't want to use HomeSpan's TLV8 library to produce TLV8 objects, but instead prefer to use your own methods to create a TLV8-compliant byte-array, you can do so and then use `setData()` to save the byte-array you produced to the TLV8 Characteristic, which will perform the base-64 encoding for you. Or, if you want to additionally perform your own base-64 encoding (why?), you can do so and then simply use `setString()` to save the resulting encoded text to the TLV8 Characteristic.
|
||||
|
||||
### Write-Response Requests
|
||||
|
||||
For most Characteristics, when the Home App sends HomeSpan a request to update a value, it is instructing HomeSpan to perform some sort of action, such as "change the brightness of a lightbulb to 30%" or "change the target state of the door to open." The only feedback the Home App expects to receive in response to such requests is basically an "OK" or "NOT OKAY" message, which is the purpose of the boolean return value in the `update()` method for every Service.
|
||||
|
||||
However, sometimes the Home App sends HomeSpan a request for information, rather than a direct instruction to perform a task. In such instances, rather than sending back just an OK/NOT-OKAY message, the Home App expects the Accessory device to update the value of the Characteristic *not* with the new value that the Home App sent, but rather with the information it requested. It then expects this information to be transmitted back to the Home App at the conclusion of the update.
|
||||
|
||||
This procedure is known as a "Write-Response Request", and it is the primary purpose for having TLV8 Characteristics, since TLV8 objects are ideal for storing structured information.
|
||||
|
||||
Though the procedure is complex, HomeSpan handles all of the protocol details. You only need to focus on reading the TLV8 Characteristic and updating it with the required TLV8 response as follows:
|
||||
|
||||
* first, from within the `update()` loop of the applicable Service, check to see if the Home App has requested an update to the TLV8 Characteristic;
|
||||
* if so, create a new TLV8 object and use `getNewTLV()` to load the contents of the updated Characteristic into that TLV8 object;
|
||||
* then, use the TLV8 library methods described above to read through the TAGS and VALUES in the TLV8 object to determine what data the Home App is conveying and what information it wants returned (based on the specs for the Characteristic);
|
||||
* next, create a *second* TLV8 object and use the TLV8 library methods above to create the appropriate TAGS and VALUES needed to respond to the information request (again, based on the on the specs for the Characteristic);
|
||||
* finally, use `setVal()` to update the TLV8 Characteristic with the second TLV8 object
|
||||
|
||||
HomeSpan will automatically send the new TLV8 data you placed in the TLV8 Characterstic back to the Home App in its response at the conclusion of the `update()` loop.
|
||||
|
||||
---
|
||||
|
||||
[↩️](../README.md) Back to the Welcome page
|
||||
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ new Service::Television();
|
|||
new Characteristic::Active(0); // set power to OFF at start-up
|
||||
new Characteristic::ConfiguredName("Sony TV"); // optional Characteristic to set name of TV
|
||||
```
|
||||
More advanced control of a TV can enabled with two other optional Characteristics:
|
||||
More advanced control of a TV can enabled with these *optional* Characteristics:
|
||||
|
||||
* `Characteristic::RemoteKey()` - this write-only numerical Characteristic enables HomeSpan to read button presses from the Remote Control widget on an iPhone that can be found under the Control Center. This widget is normally used to control Apple TVs, but it seems any Television Accessory created per above can also be operated from the Remote Control widget. The layout of the widget (which cannot be modified) includes 4 arrows, a central select button, a play/pause button, a large "back" button, and an "info" button. When a "key" is pressed, the Home App sends an update to `Characteristic::RemoteKey()` that can be read by HomeSpan using the usual `update()` method. Values are as follows:
|
||||
|
||||
|
|
@ -38,6 +38,23 @@ More advanced control of a TV can enabled with two other optional Characteristic
|
|||
|
||||
* `Characteristic::ActiveIdentifier()` - this numerical Characteristic is used to control the input source for the TV (e.g. HDMI-1, HDMI-2, Netflix, etc.). It is only used when input sources are defined and linked using `Service::InputSource()` (see below), in which case it is a *required* Characteristic
|
||||
|
||||
* `Characteristic::DisplayOrder()` - this TLV8 Characteristic is used to control the order in which linked Input Sources are displayed in the Home App
|
||||
* absent specifying the order with this Characteristic, the Home App will display the Input Sources in a random order within the selection section (under the power button), and in numerical order on the settings page of the Accessory based on the numeric Identifier for each Input Source
|
||||
* the format of the TLV8 object used by this Characteristic is a series of TLV8 "Identifier" records with TAG=1 and a VALUE set to the Identifer of a particular Input Source; the "Identifier" records should each be separated by an empty TLV8 record with TAG=0
|
||||
* example, the following code snippet sets the display order for three input sources with Identifiers 10, 20, and 30 to be 20, 30, and then 10:
|
||||
|
||||
```C++
|
||||
TLV8 orderTLV; // create an empty TLV8 object named "orderTLV"
|
||||
|
||||
orderTLV.add(1,20); // TAG=1, VALUE=20 (the Identifier of the first Input Source to be displayed)
|
||||
orderTLV.add(0); // TAG=0 (empty record used as a separator)
|
||||
orderTLV.add(1,30); // TAG=1, VALUE=30 (the Identifier of the second Input Source to be displayed)
|
||||
orderTLV.add(0); // TAG=0 (empty record used as a separator)
|
||||
orderTLV.add(1,10); // TAG=1, VALUE=10 (the Identifier of the third Input Source to be displayed)
|
||||
|
||||
new Characteristic::DisplayOrder(orderTLV); // instantiate the DisplayOrder Characteristic and set its value to the orderTLV object
|
||||
```
|
||||
|
||||
### `Service::InputSource()`
|
||||
|
||||
Use `Service::InputSource()` to create a new input source selection for the TV, such as HDMI-1, HDMI-2, Netflix, etc. The use of `Service::InputSource()` is optional - it is perfectly okay to create a Television Service without the ability to select different Input Sources. However, if used, each Input Source Service added should be defined in the *same* Accessory as the Television Service to which it applies, and ***must*** be linked to that Television Service using `addLink()`. The Home App behaves unexpectedly if it finds any Input Source Services that are not linked to a Television Service.
|
||||
|
|
@ -50,7 +67,7 @@ All of this is accomplished by using a combination of some, or all, of the follo
|
|||
|
||||
* `Characteristic::ConfiguredName()` - similar to how its used when applied to `Service::Television()`, this Characteristic allows you set the default name for an Input Source. Note that if you change the name of an Input Source in the Home App, an update will be sent to HomeSpan with the new name for you to use in your sketch if needed. This is very different from the usual `Characteristic::Name()` used for many other Services, and for which name changes performed in the Home App are never communicated back to the Accessory
|
||||
|
||||
* `Characteristic::Identifier()` - this numerical Characteristic sets an ID for each Input Source. Any unsigned 32-bit number can be used as an ID, provided it is *unique* and not used by any other Input Source in the same TV Service. When you use the Input Source Selector in the Home App to choose a particular Input Soure, the `Characteristic::ActiveIdentifier()` from the Television Service (see above) will be updated with a value that matches the ID corresponding to the chosen Input Source. Within HomeSpan you simply use the `update()` method to determine when `Characteristic::ActiveIdentifer()` is updated, and, based on its value, which Input Source was chosen. HomeKit does not seem to require `Characteristic::Identifier()` be defined for an Input Source. However, if it not set, the Home App will not allow it to be displayed as a choice in the Input Source Selector, which defeats the purpose of creating an Input Source!
|
||||
* `Characteristic::Identifier()` - this numerical Characteristic sets an ID for each Input Source. Any unsigned 32-bit number can be used as an ID, provided it is *unique* and not used by any other Input Source in the same TV Service. When you use the Input Source Selector in the Home App to choose a particular Input Source, the `Characteristic::ActiveIdentifier()` from the Television Service (see above) will be updated with a value that matches the ID corresponding to the chosen Input Source. Within HomeSpan you simply use the `update()` method to determine when `Characteristic::ActiveIdentifer()` is updated, and, based on its value, which Input Source was chosen. HomeKit does not seem to require `Characteristic::Identifier()` be defined for an Input Source. However, if it not set, the Home App will not allow it to be displayed as a choice in the Input Source Selector, which defeats the purpose of creating an Input Source!
|
||||
|
||||
* `Characteristic::IsConfigured()` - this Characteristic determines whether an Input Source is allowed to appear as a choice in the Input Source Selector of the Home App. If IsConfigured() is defined and set to 0, the Input Source will appear in the Settings page, but it will be excluded as a choice from the Input Source Selector. If IsConfigured() is defined and set to 1, the Input Source will appear in the Settings page, and will also be included as a choice in the Input Source Selector. If `Characteristic::IsConfigured()` is not defined for an Input Source, that source will still appear as a choice in the Input Source Selector, but it will *not* appear in the list of Input Sources found on the Settings page. This means you will not be able to rename the Input Source from the Home App, nor toggle it as an allowable choice in the Input Selector (see below)
|
||||
|
||||
|
|
@ -66,8 +83,10 @@ This Service allows you to change the volume of a television using the iPhone's
|
|||
|
||||
### Examples
|
||||
|
||||
Please see [*File → Examples → HomeSpan → Other Examples → Television*](../Other%20Examples/Television) for a complete worked example demonstrating the effects of using different combinations of the above Characteristics. Also, don't forget to check out the [HomeSpan Projects](https://github.com/topics/homespan) page for some real-world examples of TV sketches and controllers.
|
||||
|
||||
* Please see [*File → Examples → HomeSpan → Other Examples → Television*](../examples/Other%20Examples/Television) for a complete worked example demonstrating the effects of using different combinations of the above Characteristics
|
||||
* For details on how to use TLV8 records with the DisplayOrder Characteristic, see [Tutorial Example 22 - TLV8 Characteristics](../examples/22-TLV8_Characteristics)
|
||||
* For more advanced use case, see the Television Example on the [HomeSpan Reference Sketches](https://github.com/HomeSpan/HomeSpanReferenceSketches) page
|
||||
* Also, don't forget to check out the [HomeSpan Projects](https://github.com/topics/homespan) page for some real-world examples of TV sketches and controllers.
|
||||
|
||||
### Credits
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
# HomeSpan Tutorials
|
||||
|
||||
The HomeSpan library includes 16 tutorial sketches of increasing complexity that take you through all the functions and features of HomeSpan. The sketches are extensively annotated, and you'll even learn a lot about HomeKit itself by working through all the examples. If you've already loaded HomeSpan into your Arduino IDE, the tutorials will be found under *File → Examples → HomeSpan*. Each sketch is ready to be compiled and uploaded to your ESP32 device so you can see them in action. Alternatively, you can explore just the code within GitHub by clicking on any of titles below. Note: you may want to first read through the [HomeSpan API Overview](Overview.md) before exploring the tutorials. They will probably make a lot more sense if you do!
|
||||
The HomeSpan library includes many tutorial sketches of increasing complexity that take you through all the functions and features of HomeSpan. The sketches are extensively annotated, and you'll even learn a lot about HomeKit itself by working through all the examples. If you've already loaded HomeSpan into your Arduino IDE, the tutorials will be found under *File → Examples → HomeSpan*. Each sketch is ready to be compiled and uploaded to your ESP32 device so you can see them in action. Alternatively, you can explore just the code within GitHub by clicking on any of titles below. Note: you may want to first read through the [HomeSpan API Overview](Overview.md) before exploring the tutorials. They will probably make a lot more sense if you do!
|
||||
|
||||
> :heavy_check_mark: Each example is designed to be operated after pairing your ESP32 to HomeKit so you can control HomeSpan from the Home App on your iPhone, iPad, or Mac. In principle, once you configure and pair your device to HomeKit, your Home App should automatically reflect all changes in your configuration whenever you upload a different tutorial. However, in practice this is not always the case as it seems HomeKit sometimes caches information about devices, which means what you see in your Home App may not be fully in sync with your sketch. If this occurs, unpairing and then re-pairing the ESP32 device usually fixes the issue. If not, you may have to reset the ID on the ESP32 device so that HomeKit thinks it is a new device and will not use any cached data. This is very easy to do - see the [HomeSpan Command-Line Interface (CLI)](CLI.md) page for details.
|
||||
>[!TIP]
|
||||
>Each example is designed to be operated after pairing your ESP32 to HomeKit so you can control HomeSpan from the Home App on your iPhone, iPad, or Mac. In principle, once you configure and pair your device to HomeKit, your Home App should automatically reflect all changes in your configuration whenever you upload a different tutorial. However, in practice this is not always the case as it seems HomeKit sometimes caches information about devices, which means what you see in your Home App may not be fully in sync with your sketch. If this occurs, unpairing and then re-pairing the ESP32 device usually fixes the issue. If not, you may have to reset the HomeKit Device ID on the ESP32 device so that HomeKit thinks it is a new device and will not use any cached data. This is very easy to do - see the [HomeSpan Command-Line Interface (CLI)](CLI.md) page for details.
|
||||
|
||||
### [Example 1 - SimpleLightBulb](../examples/01-SimpleLightBulb)
|
||||
This first example introduces the HomeSpan library and demonstrates how to implement a simple on/off light control using a combination of HomeSpan Accessory, Service, and Characteristic objects. Once this sketch has been uploaded to your HomeSpan device and the device is paired to your home, a new "lightbulb" tile will appear in the Home App of your iPhone, iPad, or Mac. Though the tile will be fully operational (i.e. you can change the status of the lightbulb from "on" or "off"), we won't yet connect an actual light or LED to the HomeSpan device, so nothing real will light up. Instead, in this and the next few examples, we'll focus on learning about the different ways HomeKit controls can be configured. Starting in Example 5, we'll connect an LED to the device and introduce the methods that actually turn the LED on and off from your Home App. HomeSpan API topics covered in this example include:
|
||||
|
|
@ -68,7 +69,9 @@ Example 12 introduces HomeKit *Event Notifications* to implement two new accesso
|
|||
* setting the value of a Characteristic and triggering an Event Notification with the `setVal()` method
|
||||
|
||||
### [Example 13 - TargetStates](../examples/13-TargetStates)
|
||||
Example 13 we demonstrate the simultaneous use of both the `update()` and `loop()` methods by implementing two new Services: a Garage Door Opener and a motorized Window Shade. Both examples showcase HomeKit's Target-State/Current-State framework.
|
||||
Example 13 demonstrates the simultaneous use of both the `update()` and `loop()` methods by implementing two new Services: a Garage Door Opener and a motorized Window Shade. Both examples showcase HomeKit's Target-State/Current-State framework. New HomeSpan API topics covered in this example include:
|
||||
|
||||
* using Enumerated Constants to set the values of Characteristics that represent discrete states (e.g. "raising", "closing")
|
||||
|
||||
### [Example 14 - EmulatedPushButtons](../examples/14-EmulatedPushButtons)
|
||||
Example 14 demonstrates how you can use the `setVal()` and `timeVal()` methods inside a Service's `loop()` method to create a tile in the Home App that emulates a pushbutton switch. In this example pressing the tile in the Home App will cause it to turn on, blink an LED 3 times, and then turn off (just like a real pushbutton might do).
|
||||
|
|
@ -106,6 +109,16 @@ Example 20 illustrates a number of advanced techniques through the implementatio
|
|||
* dynamically deleting Accessories with `homeSpan.deleteAccessory()`
|
||||
* refreshing the Accessory database (which automatically updates the Home App) using `homeSpan.updateDatabase()`
|
||||
* using `homeSpan.autoPoll()` to implement HomeSpan Polling in the background (and on the second core, if available)
|
||||
|
||||
### [Example 21 - AccessoryIdentifier](../examples/21-AccessoryIdentifier)
|
||||
Example 21 shows how the Identifier Characteristic that is always present in each Accessory's required AccessoryInformation Service can be used to create a custom "identification routine" that can be triggered from within the Home App when pairing a device. This example does not use any new HomeSpan methods.
|
||||
|
||||
### [Example 22 - TLV8 Characteristics](../examples/22-TLV8_Characteristics)
|
||||
Example 22 demonstrates how to create and utilize TLV8-based Characteristics through the implementation of the DisplayOrder Characteristic used to set the order in which input sources for a Television Service are presented in the Home App. New HomeSpan API topics covered in this example include:
|
||||
|
||||
* creating TLV8 objects using HomeSpan's TLV8 class
|
||||
* updating TLV8 Characteristics using `setTLV()`
|
||||
|
||||
|
||||
## Other Examples
|
||||
|
||||
|
|
@ -126,6 +139,9 @@ An example of HomeKit's *undocumented* Television Service showing how different
|
|||
### [Pixel](../examples/Other%20Examples/Pixel)
|
||||
Demonstrates how to use HomeSpan's *Pixel* and *Dot* classes to control one- and two-wire Addressable RGB and RGBW LEDs. See the [Addressable RGB LEDs](Pixels.md) page for full details
|
||||
|
||||
### [PixelTester](../examples/Other%20Examples/PixelTester)
|
||||
A sketch to aid in determining the *pixelType* for any RGB(W) LED Strip. See the [Addressable RGB LEDs](Pixels.md) page for full details
|
||||
|
||||
### [CustomService](../examples/Other%20Examples/CustomService)
|
||||
Demonstrates how to create Custom Services and Custom Characteristics in HomeSpan to implement an Atmospheric Pressure Sensor recognized by the *Eve for HomeKit* app. See [Custom Characteristics and Custom Services Macros](Reference.md#custom-characteristics-and-custom-services-macros) for full details
|
||||
|
||||
|
|
@ -133,7 +149,7 @@ Demonstrates how to create Custom Services and Custom Characteristics in HomeSpa
|
|||
Demonstrates how to implement a fully programmable Light Accessory Hub that allows the user to *dynamically* add/delete up to 12 Light Accessories directly through a device-hosted *web interface* or via HomeSpan's *command-line inteface*. Each light can be configured as dimmable/non-dimmable with either no color control, full RGB color control, or color-temperature control. Builds upon many of the techniques used in [Example 20](../examples/20-AdvancedTechniques)
|
||||
|
||||
### [RemoteSensors](../examples/Other%20Examples/RemoteSensors)
|
||||
Demonstrates how *SpanPoint* can be used to transmit messages from battery-powered Remote Devices running light-weight sketches that measure the local temperature, to a wall-powered Main Device running a full HomeSpan sketch implementing Temperature Sensor Accessories. See [SpanPoint: Point-to-Point Communication between ESP32 Devices](NOW.md) for full details regarding the *SpanPoint* class and all of its methods.
|
||||
Demonstrates how *SpanPoint* can be used to transmit messages from battery-powered Remote Devices running light-weight sketches that measure the local temperature, to a wall-powered Main Device running a full HomeSpan sketch implementing Temperature Sensor Accessories. See [SpanPoint: Point-to-Point Communication between ESP32 Devices](NOW.md) for full details regarding the *SpanPoint* class and all of its methods
|
||||
|
||||
### [FadingLED](../examples/Other%20Examples/FadingLED)
|
||||
Demonstrates how the *LedPin* class can use the ESP32's built-in fading control to automatically fade an LED from from one level of brightness to another over a specified period of time. See the [LedPin](PWM.md#pulse-width-modulation-pwm) page for full details
|
||||
|
|
@ -141,6 +157,12 @@ Demonstrates how the *LedPin* class can use the ESP32's built-in fading control
|
|||
### [MotorizedWindowShade](../examples/Other%20Examples/MotorizedWindowShade)
|
||||
Demonstrates how to use the *StepperControl* class to operate a stepper motor. Implements a motorized window shade based on [Example 13](../examples/13-TargetStates) above. See the [Stepper Motor Control](Stepper.md) page for full details
|
||||
|
||||
### [CustomNVSPartition](../examples/Other%20Examples/CustomNVSPartition)
|
||||
Demonstrates how to create a Custom Partition Scheme for your sketch by adding a *partitions.csv* file to your sketch folder. Can be used to expand the size of the non-volatile-storage (NVS) partition, which may be needed when creating a HomeSpan device with many Accessories whose Characteristics you want to save in NVS
|
||||
|
||||
### [ExternalReference](../examples/Other%20Examples/ExternalReference)
|
||||
Demonstrates how to access Characteristics of Services from outside those Services, such as from within the main Arduino `loop()`. In this sketch we re-create the two LEDs in Example 5 with an added function in the main Arduino `loop()` that checks if both LEDs are on at the same time, and if so, they are automatically turned off
|
||||
|
||||
---
|
||||
|
||||
[↩️](../README.md) Back to the Welcome page
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -51,9 +51,6 @@
|
|||
// NOTE: All HomeSpan examples are best understood when reviewed in conjunction with the documentation provided on the HomeSpan GitHub page.
|
||||
// See https://github.com/HomeSpan/HomeSpan for details and references. In particular, you may want to review the HomeSpan API Overview
|
||||
// page before proceeding.
|
||||
|
||||
// These examples also make frequent reference to Apple's HomeKit Accessory Protocol Specification, known as HAP. You can download this
|
||||
// directly from Apple at https://developer.apple.com/support/homekit-accessory-protocol.
|
||||
|
||||
// LET'S GET STARTED...
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -30,12 +30,11 @@
|
|||
// HomeSpan: A HomeKit implementation for the ESP32 //
|
||||
// ------------------------------------------------ //
|
||||
// //
|
||||
// Example 5: Two working on/off LEDs based on the //
|
||||
// Example 5: Two working on/off LEDs based on the //
|
||||
// LightBulb Service //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include "HomeSpan.h"
|
||||
#include "DEV_LED.h" // NEW! Include this new file, DEV_LED.h, which will be fully explained below
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -50,12 +50,11 @@ void setup() {
|
|||
// As usual, all previous comments have been deleted and only new changes from the previous example are shown.
|
||||
|
||||
// NOTE: The Arduino/ESP32 code base does not include the function analogWrite() which is typically used to create a PWM
|
||||
// output to drive the brightness of an LED. The ESP32 code base itself includes a set of functions to create PWM output
|
||||
// and the ESP32 chip has built-in PWM functionality specifically for this purpose. There are numerous libraries
|
||||
// you can download that mimics or reproduces analogWrite() in some form or another. HomeSpan conveniently comes with
|
||||
// its own version of a wrapper around the ESP32 PWM classes that make it very easy to define LED pins, and set the
|
||||
// PWM level (or duty cycle) from 0-100%. These functions are encapsualted in the LedPin class, as defined in
|
||||
// extras/PwmPin.h. We will include this file in our updated DEV_LED.h for use with DEV_DimmableLED.
|
||||
// output to drive the brightness of an LED. Instead, the ESP32 code base itself includes a set of functions to create PWM output
|
||||
// and the ESP32 chip has built-in PWM functionality specifically for this purpose.
|
||||
|
||||
// HomeSpan wraps all of this PWM functionality into a single integrated class called LedPin, making it very easy to define
|
||||
// dimmable LED pins and set the PWM level (i.e. duty cycle) from 0-100%. Use of this LedPin class is shown in DEV_DimmableLED.
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
// DEVICE-SPECIFIC LED SERVICES //
|
||||
////////////////////////////////////
|
||||
|
||||
#include "extras/PwmPin.h" // NEW! Include this HomeSpan "extra" to create LED-compatible PWM signals on one or more pins
|
||||
|
||||
struct DEV_LED : Service::LightBulb { // ON/OFF LED
|
||||
|
||||
int ledPin; // pin number defined for this LED
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -54,8 +54,8 @@ void setup() {
|
|||
// Rather, the default name of the first Accessory Tile will always be shown by the Home App as the name specified in
|
||||
// homeSpan.begin() regardless of whether or not the Name Characteristic has been added to the Accessory Information Service.
|
||||
|
||||
// Below is a replay of Example 6 showing how the Name Characteristic can be used to change the default names of the second,
|
||||
// but not the first, Accessory Tile.
|
||||
// Below is a replay of Example 6 showing how the Name Characteristic can be used to change the default names of the second
|
||||
// and third, but not the first, Accessory Tile.
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
|
|
@ -77,6 +77,14 @@ void setup() {
|
|||
|
||||
new DEV_DimmableLED(17);
|
||||
|
||||
new SpanAccessory();
|
||||
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
new Characteristic::Name(u8"Special chars ÄÖÜß"); // Use UTF-8 coded string for non-ASCII characters
|
||||
|
||||
new DEV_DimmableLED(18);
|
||||
|
||||
} // end of setup()
|
||||
|
||||
//////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
// DEVICE-SPECIFIC LED SERVICES //
|
||||
////////////////////////////////////
|
||||
|
||||
#include "extras/PwmPin.h" // NEW! Include this HomeSpan "extra" to create LED-compatible PWM signals on one or more pins
|
||||
|
||||
struct DEV_LED : Service::LightBulb { // ON/OFF LED
|
||||
|
||||
int ledPin; // pin number defined for this LED
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
// DEVICE-SPECIFIC LED SERVICES //
|
||||
////////////////////////////////////
|
||||
|
||||
#include "extras/PwmPin.h" // allows PWM control of LED brightness
|
||||
|
||||
struct DEV_LED : Service::LightBulb { // ON/OFF LED
|
||||
|
||||
int ledPin; // pin number defined for this LED
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
// DEVICE-SPECIFIC LED SERVICES //
|
||||
////////////////////////////////////
|
||||
|
||||
#include "extras/PwmPin.h" // allows PWM control of LED brightness
|
||||
|
||||
struct DEV_LED : Service::LightBulb { // ON/OFF LED
|
||||
|
||||
int ledPin; // pin number defined for this LED
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -3,10 +3,6 @@
|
|||
// DEVICE-SPECIFIC LED SERVICES //
|
||||
////////////////////////////////////
|
||||
|
||||
#include "extras/PwmPin.h" // library of various PWM functions
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
struct DEV_LED : Service::LightBulb { // ON/OFF LED
|
||||
|
||||
int ledPin; // pin number defined for this LED
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -25,33 +25,47 @@
|
|||
*
|
||||
********************************************************************************/
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// HomeSpan: A HomeKit implementation for the ESP32 //
|
||||
// ------------------------------------------------ //
|
||||
// //
|
||||
// Example 11: Service Names: //
|
||||
// * setting the names of individual Services //
|
||||
// * changing the icons in a bridge Accessory //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// HomeSpan: A HomeKit implementation for the ESP32 //
|
||||
// ------------------------------------------------ //
|
||||
// //
|
||||
// Example 11: Service Names: //
|
||||
// * setting the names of individual Services //
|
||||
// * "changing" the icons in a bridge Accessory //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "HomeSpan.h"
|
||||
|
||||
// INITIAL NOTE: Apple is constantly updating how the Home App Icons are chosen and how/if/where/when the Names for
|
||||
// Accessories and Services are displayed. This example has been tested and verified as of iOS 17.2.1.
|
||||
|
||||
void setup() {
|
||||
|
||||
// As described in previous examples, when pairing a device the Home App will choose default names for each
|
||||
// Accessory Tile, unless you override those default names with your own names by adding a Name Characteristic
|
||||
// to the Accessory Information Service for each Accessory (except the first, which is typically the Bridge Accessory).
|
||||
|
||||
// The same process holds true for the names of the Services in an Accessory with multiple Services, such as a Ceiling Fan with a Light.
|
||||
// When pairing, the Home App will choose default names for each Service (such as Fan, Fan 2, Light, Light 2) depending on the types
|
||||
// of Services included. Similar to the names of Accessory Tiles, you can change the names of individual Services when prompted
|
||||
// during the pairing process, or at any time after pairing from within the appropriate settings pages in the Home App. More importantly,
|
||||
// you can override the default Service names generated by the Home App by simply adding the Name Characteristic to any Service.
|
||||
// The same process holds true for the names of the Services in an Accessory with multiple Services: if a Service is not named,
|
||||
// the Home App will generate one. You can of course change the names of individual Services when prompted
|
||||
// during the pairing process, or at any time after pairing from within the appropriate settings pages in the Home App.
|
||||
|
||||
// But more importantly, you can name Services in your sketch so that those name show up when pairing, saving you the need to
|
||||
// rename them from the settings pages in the Home App.
|
||||
|
||||
// However, note that Service names (whether or not overridden) only appear in the Home App if there is a chance of ambiguity,
|
||||
// such as a Accessory with two Services of the same type. But even if a Service name does not appear in the Home App,
|
||||
// Whereas we previously used the *Name* Characteristic to provide names for Accessory Tiles, we use the *ConfiguredName* Characteristic
|
||||
// to provide names for individual Services within each Accessory.
|
||||
|
||||
// One important distinction between Name and ConfigureName is that Name is only used by the Home App during pairing. After that,
|
||||
// any changes you make to the name of an Accessory Tile from within the Home App are never communicated back to HomeSpan, and any changes
|
||||
// you might make to those names in your sketch will not be reflected in the Home App unless you unpair and re-pair the device. In contrast,
|
||||
// ConfiguredName works like any other Characteristic: changes made to ConfiguredName from within a sketch are proporgated to the Home App,
|
||||
// and any edits you make to a Service's name in the Home App trigger a corresponding call to update() in HomeSpan so HomeSpan and the Home App
|
||||
// are always in sync with regard to the names of any Services that includes the ConfiguredName Characteristic.
|
||||
|
||||
// NOTE: Service names (whether those generated by the Home App or specified via the ConfiguredName Characteristic) are only displayed on the
|
||||
// control screen of an Accessory Tile if there are two more more Services of the same type. But even if a Service name does not appear in the Home App,
|
||||
// it will still be used by Siri to control a specific Service within an Accessory by voice.
|
||||
|
||||
// In the example below we create 5 different functional Accessories, each illustrating how names, as well as icons, are chosen by the Home App
|
||||
|
|
@ -62,103 +76,92 @@ void setup() {
|
|||
|
||||
homeSpan.begin(Category::Bridges,"HomeSpan Bridge");
|
||||
|
||||
// Our first Accessory is the "Bridge" Accessory
|
||||
// Our initial Accessory is therefore the "Bridge" Accessory
|
||||
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
|
||||
// Our second Accessory is a Ceiling Fan with a single Light. There are three things to note:
|
||||
//
|
||||
// * when pairing, the Home App will generate default names of "Light" and "Fan" for the two Services.
|
||||
// However, these names are not displayed on the control screen of the Accessory since there is no
|
||||
// ambiguity between the Light and Fan controls - the Home App displays them differently
|
||||
//
|
||||
// * the icon used by the Home App for the Accessory Tile is a Lightbulb. Why does it choose this instead of a Fan icon?
|
||||
// Recall from Example 3 that for Accessories with multiple Services, if there is any ambiguity of which icon to use,
|
||||
// the Home App chooses based on the Category of the device. But since this device is configured as a Bridge, the
|
||||
// Category provides no helpful information to the Home App. In such cases the Home App picks an icon for the
|
||||
// Accessory Tile that matches the first functional Service in the Accessory, which in this instance in a LightBulb
|
||||
//
|
||||
// * when opening the control screen by clicking the Accessory Tile, the LightBulb control will appear on the left, and
|
||||
// the Fan control will appear on the right
|
||||
// Our first "functional" Accessory is a combination of a LightBulb, Outlet, and Switch. Note that when pairing, the Home App generates
|
||||
// default names of "Light", "Outlet", and "Switch" for these three Services, though these names are NOT displayed on the control screen
|
||||
// of the Accessory since there is only one type of each Service. Also note that the Home App selects a LightBulb icon for the Accessory Tile
|
||||
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
new Characteristic::Name("Light with Fan"); // this sets the name of the Accessory Tile
|
||||
new Service::LightBulb(); // the icon of the Accessory Tile will be a Lightbulb, since this is the first functional Service
|
||||
new Characteristic::Name("Light First"); // this sets the name of the Accessory Tile
|
||||
new Service::LightBulb(); // the icon of the Accessory Tile will be a Lightbulb, since this is the first functional Service
|
||||
new Characteristic::On();
|
||||
new Service::Fan();
|
||||
new Characteristic::Active();
|
||||
|
||||
// Our third Accessory is identical to the second, except we swapped the order of the Lightbulb and Fan Services.
|
||||
// The result is that the Home App now displays the Accessory Tile with a Fan icon intead of a Lightbulb icon.
|
||||
// Also, when opening the control screen by clicking on the Accessory Tile, the Fan control will now appear on the
|
||||
// left, and the LightBulb control on the right.
|
||||
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
new Characteristic::Name("Fan with Light"); // this sets the name of the Accessory Tile
|
||||
new Service::Fan(); // the icon of the Accessory Tile will be a Fan, since this is the first functional Service
|
||||
new Characteristic::Active();
|
||||
new Service::LightBulb();
|
||||
new Service::Outlet();
|
||||
new Characteristic::On();
|
||||
new Characteristic::OutletInUse();
|
||||
new Service::Switch();
|
||||
new Characteristic::On();
|
||||
|
||||
// Our fourth Accessory shows what happens if we implement two identical LightBulb Services (without any Fan Service).
|
||||
// Since both Services are LightBulbs, the Home App sensibly picks a Lightbulb icon for the Accessory Tile. However,
|
||||
// when you click the Accessory Tile and open the control screen, you'll note that the Home App now does display the names
|
||||
// of the Service beneath each control. In this case the Home App uses the default names "Light 1" and "Light 2". The Home App
|
||||
// presumably shows the names of each Service since the two controls are identical and there is otherwise no way of telling which
|
||||
// control operates which light.
|
||||
|
||||
new SpanAccessory();
|
||||
// Our second Accessory is similar to the first, but here we define the Switch Service first. Note that the Home App now selects
|
||||
// a Switch icon for the Accessory Tile
|
||||
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
new Characteristic::Name("Ceiling Lights"); // this sets the name of the Accessory Tile
|
||||
new Service::LightBulb();
|
||||
new Characteristic::Name("Switch First"); // this sets the name of the Accessory Tile
|
||||
new Service::Switch(); // the icon of the Accessory Tile will be a Switch, since this is the first functional Service
|
||||
new Characteristic::On();
|
||||
new Service::LightBulb();
|
||||
new Service::Outlet();
|
||||
new Characteristic::On();
|
||||
new Characteristic::OutletInUse();
|
||||
new Service::LightBulb();
|
||||
new Characteristic::On();
|
||||
|
||||
// Our fifth Accessory combines a single Fan Service with two identical LightBulb Services. Since the first functional Service implemented
|
||||
// is a Fan, the Home App will pick a Fan icon for the Accessory Tile. Also, since we added Name Characteristics to two LightBulb
|
||||
// Services, their default names generated by the Home App ("Light 1" and "Light 2") will be changed to the names specified. Finally,
|
||||
// note that the Home App displays a more compact form of controls on the control screen since there are three Services. The arrangement
|
||||
// and style of the controls will depend on what combination of Characteristics are implemented for each Service.
|
||||
|
||||
new SpanAccessory();
|
||||
// Our third Accessory is similar to the second, but here we define 2 Switches, 2 LightBulbs, but still only 1 Outlet. This time, during pairing
|
||||
// the Home App generates default names of Switch, Switch 2, Light, Light 2, and Outlet. Importantly, note that on the control screen for
|
||||
// this Accessory, the Home App now displays the names of the Switches ("Switch" and "Switch 2") as well as the LightBulbs ("Light" and "Light 2")
|
||||
// under each corresponding control, but it does NOT display the name "Outlet" under the Outlet control since there is only one Outlet Service
|
||||
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
new Characteristic::Name("Fan with Lights"); // this sets the name of the Accessory Tile
|
||||
new Service::Fan();
|
||||
new Characteristic::Active();
|
||||
new Service::LightBulb();
|
||||
new Characteristic::Name("Main Light"); // this changes the default name of this LightBulb Service from "Light 1" to "Main Light"
|
||||
new Characteristic::Name("Two Switches"); // this sets the name of the Accessory Tile
|
||||
new Service::Switch(); // the icon of the Accessory Tile will be a Switch, since this is the first functional Service
|
||||
new Characteristic::On();
|
||||
new Service::Switch();
|
||||
new Characteristic::On();
|
||||
new Service::Outlet();
|
||||
new Characteristic::On();
|
||||
new Service::LightBulb();
|
||||
new Characteristic::Name("Night Light"); // this changes the default name of this LightBulb Service from "Light 2" to "Night Light"
|
||||
new Characteristic::OutletInUse();
|
||||
new Service::LightBulb();
|
||||
new Characteristic::On();
|
||||
new Service::LightBulb();
|
||||
new Characteristic::On();
|
||||
|
||||
// Our sixth Accessory is similar to the fifth, except we added some more features to some of the Services. Note how this changes
|
||||
// the layout of the controls on the control screen.
|
||||
// Our fourth and final Accessory is the same as the third, but this time we use the ConfiguredName Characteristic to define a name for each Service.
|
||||
// When pairing, you should see the Home App now uses the names below instead of generating default names as it did in the other examples. You
|
||||
// should also see these names displayed under each control on the control screen for the Accessory, with the exception of the Outlet Service.
|
||||
// Though we did provide a name for the Outlet, since there is only one Outlet Service in this Accessory, the Home App does not display its name.
|
||||
// Howevever, if from the settings screen for this Accessory you further navigate to the "Accessories" page, you will indeed see the names for each
|
||||
// Service exactly as specified below, including the Outlet name "Aux Power"
|
||||
|
||||
new SpanAccessory();
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
new Characteristic::Name("Multi-Function Fan");
|
||||
new Service::Fan();
|
||||
new Characteristic::Active();
|
||||
new Characteristic::RotationDirection(); // add a control to change the direcion of rotation
|
||||
new Characteristic::RotationSpeed(0); // add a control to set the rotation speed
|
||||
new Service::LightBulb();
|
||||
new Characteristic::Name("Main Light");
|
||||
new Characteristic::Identify();
|
||||
new Characteristic::Name("Central Control"); // this sets the name of the Accessory Tile
|
||||
new Service::Switch(); // the icon of the Accessory Tile will be a Switch, since this is the first functional Service
|
||||
new Characteristic::On();
|
||||
new Characteristic::Brightness(100); // make this light dimmable (with intitial value set to 100%)
|
||||
new Service::LightBulb();
|
||||
new Characteristic::Name("Night Light"); // don't add anything new to this light
|
||||
new Characteristic::ConfiguredName("High Voltage"); // this sets the name of the first Switch Service
|
||||
new Service::Switch();
|
||||
new Characteristic::On();
|
||||
new Characteristic::ConfiguredName("Low Voltage"); // this sets the name of the second Switch Service
|
||||
new Service::Outlet();
|
||||
new Characteristic::On();
|
||||
new Characteristic::OutletInUse();
|
||||
new Characteristic::ConfiguredName("Aux Power"); // this sets the name of the Outlet Service
|
||||
new Service::LightBulb();
|
||||
new Characteristic::On();
|
||||
new Characteristic::ConfiguredName("Main Lights"); // this sets the name of the first LightBulb Service
|
||||
new Service::LightBulb();
|
||||
new Characteristic::On();
|
||||
new Characteristic::ConfiguredName("Accent Lights"); // this sets the name of the second LightBulb Service
|
||||
|
||||
|
||||
} // end of setup()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -60,18 +60,19 @@ void setup() {
|
|||
// guesses the actions a device is taking, and updates it tile's icon accordingly, by comparing the value of the target state
|
||||
// Characteristic it sets, and the current state Characteristic it receives in the form of Event Notifications. When they are the same,
|
||||
// HomeKit assumes the physical device has reached the required position. When they differ, HomeKit assumes something will be opening,
|
||||
// closing, raising, lowering, etc. The details of this process for each Service is outlined in the HAP documentation, but beware
|
||||
// the document is not always up to date with the lastest version of the HomeKit application. Sometimes a little experimenting and a lot
|
||||
// of trial and error is required to fully understand how each Service responds to different combinations of Characteristic values.
|
||||
// closing, raising, lowering, etc. Sometimes a little experimenting and a lot of trial and error is required to fully understand how
|
||||
// each Service responds to different combinations of Characteristic values.
|
||||
|
||||
// As always, we won't be connecting our ESP32 to an actual garage door or window shade but will instead simulate their responses and
|
||||
// actions for illustrative purposes. In some ways the code is more complicated because of the need to simulate values - it might be
|
||||
// easier if we actually were connecting to a garage door or window shade!
|
||||
|
||||
// Fully commented code for both of our derived Services can be found in DEV_DoorsWindows.h. These examples do not introduce any new
|
||||
// HomeSpan functions or features. Rather we are combining everything learned so far into two reasonably complex Services. You may
|
||||
// want to reference the HAP documentation for these two parent Services to fully understand the meaning of the different value settings
|
||||
// for each of the Services' Characteristics.
|
||||
// HomeSpan functions, but you will see how to use HomeSpan's ENUMERATED CONSTANTS, instead of just plain integers, to set the values
|
||||
// of Characteristics where the values represent discrete states (e.g. "lowering", "opening").
|
||||
|
||||
// Please see HomeSpan's Services and Characteristics page for a complete list of the enumerated constants available for Characteristics
|
||||
// where they are applicable.
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,17 +3,33 @@
|
|||
// DEVICE-SPECIFIC LED SERVICES //
|
||||
////////////////////////////////////
|
||||
|
||||
struct DEV_GarageDoor : Service::GarageDoorOpener { // A Garage Door Opener
|
||||
struct DEV_GarageDoor : Service::GarageDoorOpener { // A Garage Door Opener
|
||||
|
||||
SpanCharacteristic *current; // reference to the Current Door State Characteristic (specific to Garage Door Openers)
|
||||
SpanCharacteristic *target; // reference to the Target Door State Characteristic (specific to Garage Door Openers)
|
||||
SpanCharacteristic *obstruction; // reference to the Obstruction Detected Characteristic (specific to Garage Door Openers)
|
||||
Characteristic::CurrentDoorState *current; // reference to the Current Door State Characteristic (specific to Garage Door Openers)
|
||||
Characteristic::TargetDoorState *target; // reference to the Target Door State Characteristic (specific to Garage Door Openers)
|
||||
SpanCharacteristic *obstruction; // reference to the Obstruction Detected Characteristic (specific to Garage Door Openers)
|
||||
|
||||
DEV_GarageDoor() : Service::GarageDoorOpener(){ // constructor() method
|
||||
DEV_GarageDoor() : Service::GarageDoorOpener(){ // constructor() method
|
||||
|
||||
// Below we use enumerated constants rather than integers to set the values of the Characteristics.
|
||||
// Using enumerated constants means not having to remember the integer code for each state. You'll find
|
||||
// a complete list of all available enumerated constants on HomeSpan's Services and Characteristics page.
|
||||
// Note the use of enumerated constants is optional - you can always use the integer code representing
|
||||
// each state instead.
|
||||
|
||||
current=new Characteristic::CurrentDoorState(1); // initial value of 1 means closed
|
||||
target=new Characteristic::TargetDoorState(1); // initial value of 1 means closed
|
||||
obstruction=new Characteristic::ObstructionDetected(false); // initial value of false means NO obstruction is detected
|
||||
current=new Characteristic::CurrentDoorState(Characteristic::CurrentDoorState::CLOSED); // here we use the fully-qualified name of the constant "CLOSED"
|
||||
target=new Characteristic::TargetDoorState(target->CLOSED); // here we use the name of the object instead of the fully-qualified name (much less typing)
|
||||
|
||||
// Below we must use the fully-qualified name of the enumerated constant and cannot use "obstruction->NOT_DETECTED".
|
||||
// Why? Because above we declared "obstruction" to be a pointer to a generic SpanCharacteristic instead of a pointer to
|
||||
// the more specific Characteristic::ObstructionDetected. Either is fine, and it's just a matter of programming preference
|
||||
// (as you can see we use both conventions in this sketch). But the downside of using SpanCharacteristic to declare a
|
||||
// Characteristic that contains enumerated constants is that the object itself does not know about these constants. This is
|
||||
// because all enumerated constants are uniquely defined within their respective specific Characteristic classes, and not in the
|
||||
// generic SpanCharacteristic class from which all specific Characterstics are derived.
|
||||
|
||||
obstruction=new Characteristic::ObstructionDetected(Characteristic::ObstructionDetected::NOT_DETECTED); // this works
|
||||
// obstruction=new Characteristic::ObstructionDetected(obstruction->NOT_DETECTED); // this would produce a compiler error (try it and see)
|
||||
|
||||
Serial.print("Configuring Garage Door Opener"); // initialization message
|
||||
Serial.print("\n");
|
||||
|
|
@ -24,13 +40,13 @@ struct DEV_GarageDoor : Service::GarageDoorOpener { // A Garage Door Opener
|
|||
|
||||
// see HAP Documentation for details on what each value represents
|
||||
|
||||
if(target->getNewVal()==0){ // if the target-state value is set to 0, HomeKit is requesting the door to be in open position
|
||||
if(target->getNewVal()==target->OPEN){ // HomeKit is requesting the door to be in OPEN position
|
||||
LOG1("Opening Garage Door\n");
|
||||
current->setVal(2); // set the current-state value to 2, which means "opening"
|
||||
obstruction->setVal(false); // clear any prior obstruction detection
|
||||
current->setVal(current->OPENING); // set the current-state value to OPENING
|
||||
obstruction->setVal(false); // clear any prior obstruction detection - note we do not bother using an enumerated constant here
|
||||
} else {
|
||||
LOG1("Closing Garage Door\n"); // else the target-state value is set to 1, and HomeKit is requesting the door to be in the closed position
|
||||
current->setVal(3); // set the current-state value to 3, which means "closing"
|
||||
LOG1("Closing Garage Door\n"); // else HomeKit must be requesting the door to be in the CLOSED position
|
||||
current->setVal(current->CLOSING); // set the current-state value to CLOSING
|
||||
obstruction->setVal(false); // clear any prior obstruction detection
|
||||
}
|
||||
|
||||
|
|
@ -43,13 +59,13 @@ struct DEV_GarageDoor : Service::GarageDoorOpener { // A Garage Door Opener
|
|||
if(current->getVal()==target->getVal()) // if current-state matches target-state there is nothing do -- exit loop()
|
||||
return;
|
||||
|
||||
if(current->getVal()==3 && random(100000)==0){ // here we simulate a random obstruction, but only if the door is closing (not opening)
|
||||
current->setVal(4); // if our simulated obstruction is triggered, set the curent-state to 4, which means "stopped"
|
||||
obstruction->setVal(true); // and set obstruction-detected to true
|
||||
if(current->getVal()==current->CLOSING && random(100000)==0){ // here we simulate a random obstruction, but only if the door is closing (not opening)
|
||||
current->setVal(current->STOPPED); // if our simulated obstruction is triggered, set the curent-state to STOPPED
|
||||
obstruction->setVal(true); // and set obstruction-detected to true
|
||||
LOG1("Garage Door Obstruction Detected!\n");
|
||||
}
|
||||
|
||||
if(current->getVal()==4) // if the current-state is stopped, there is nothing more to do - exit loop()
|
||||
if(current->getVal()==current->STOPPED) // if the current-state is stopped, there is nothing more to do - exit loop()
|
||||
return;
|
||||
|
||||
// This last bit of code only gets called if the door is in a state that represents actively opening or actively closing.
|
||||
|
|
@ -83,15 +99,6 @@ struct DEV_WindowShade : Service::WindowCovering { // A motorized Window Sha
|
|||
|
||||
boolean update(){ // update() method
|
||||
|
||||
// The logic below is based on how HomeKit appears to operate in practice, which is NOT consistent with
|
||||
// HAP documentation. In that document HomeKit seems to support fully opening or fully closing a window shade, with
|
||||
// an optional control to HOLD the window shade at a given in-between position while it is moving.
|
||||
|
||||
// In practice, HomeKit does not appear to implement any form of a HOLD control button, even if you instantiate that
|
||||
// Characteristic. Instead, HomeKit provides a full slider control, similar to the brightness control for a lightbulb,
|
||||
// that allows you to set the exact position of the window shade from 0-100%. This obviates the need to any sort of HOLD button.
|
||||
// The resulting logic is also very simple:
|
||||
|
||||
if(target->getNewVal()>current->getVal()){ // if the target-position requested is greater than the current-position, simply log a "raise" message
|
||||
LOG1("Raising Shade\n"); // ** there is nothing more to do - HomeKit keeps track of the current-position so knows raising is required
|
||||
} else
|
||||
|
|
@ -116,11 +123,7 @@ struct DEV_WindowShade : Service::WindowCovering { // A motorized Window Sha
|
|||
// the user in the Home App. If it finds current and target positions are the same, it knows the shade is stopped. Otherwise
|
||||
// it will report the shade is raising or lowering depending on whether the specified target state is greater or less than
|
||||
// the current state.
|
||||
|
||||
// According to HAP, the Characteristic Position State is also required. However, this seems duplicative and is NOT needed
|
||||
// at all given the way HomeKit uses current position. HomeSpan will warn you if Position State is not defined (since it
|
||||
// is technically required) but this works fine without it.
|
||||
|
||||
|
||||
} // loop
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
void setup() {
|
||||
|
||||
// Though HomeKit and the HomeKit Accessory Protocol (HAP) Specification provide a very flexible framework
|
||||
// for creating iOS- and MacOS-controlled devices, they does not contain every possible desired feature.
|
||||
// for creating iOS- and MacOS-controlled devices, they do not contain every possible desired feature.
|
||||
//
|
||||
// One very common Characteristic HomeKit does not seem to contain is a simple pushbutton, like the type you
|
||||
// would find on a remote control. Unlike switches that can be "on" or "off", a pushbutton has no state.
|
||||
|
|
|
|||
|
|
@ -87,10 +87,3 @@ struct DEV_Blinker : Service::LightBulb { // LED Blinker
|
|||
};
|
||||
|
||||
//////////////////////////////////
|
||||
|
||||
// HomeKit Bug Note: There is an apparent bug in HomeKit uncovered during the development of this example.
|
||||
// If you have an Accessory with three or more Services, and the Accessory receives a notification message
|
||||
// from the device, AND the HomeKit interface is open to show the detailed control for this Service tile
|
||||
// in the HomeKit app, then for some reason HomeKit sends an update() request back to the device asking to
|
||||
// set the Characteristic to the value that it just received from an Event Notification. HomeKit is not supposed
|
||||
// to send update requests in response to an Event Notification.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -248,7 +248,7 @@ void loop(){
|
|||
// For example, if you were using an MCP I/O Port Expander with the Adafruit mcp library, you could create a triggerType function for a pin
|
||||
// on the MCP device that is connected to ground through a pushbutton as such:
|
||||
//
|
||||
// boolean MCP_READ(int mcpPin) { return ( !mcp.digitalRead(mcpPin); ) }
|
||||
// boolean MCP_READ(int mcpPin) { return ( !mcp.digitalRead(mcpPin) ); }
|
||||
//
|
||||
// And then simply pass MCP_READ to SpanButton as the triggerType parameter using any of the SpanButton constuctors:
|
||||
//
|
||||
|
|
@ -258,7 +258,7 @@ void loop(){
|
|||
//
|
||||
// Alternatively, you can use a lambda function as the triggerType parameter, thus creating your function on the fly when instantiating a SpanButton:
|
||||
//
|
||||
// new SpanButton(23,[](int mcpPin)->boolean{ return ( !mcp.digitalRead(mcpPin); ) }
|
||||
// new SpanButton(23,[](int mcpPin)->boolean{ return ( !mcp.digitalRead(mcpPin) ); });
|
||||
//
|
||||
// Note: If you create your own triggerType function, don't forget to perform any initialization of the "pin", or setup/configuration of a
|
||||
// pin extender, etc., prior to instantiating a SpanButton that uses your custom function. HomeSpan cannot do this for you.
|
||||
|
|
|
|||
|
|
@ -3,10 +3,6 @@
|
|||
// DEVICE-SPECIFIC LED SERVICES //
|
||||
////////////////////////////////////
|
||||
|
||||
#include "extras/PwmPin.h" // library of various PWM functions
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
struct DEV_DimmableLED : Service::LightBulb { // Dimmable LED
|
||||
|
||||
// This version of the Dimmable LED Service is similar to the one last used in Example 11, but now includes support for 3 physical PushButtons
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -35,12 +35,6 @@
|
|||
// //
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
// WARNING: THIS EXAMPLE STOPPED WORKING CORRECTLY SOMEWHERE AROUND THE IOS 15.2 OR IOS 15.3 UPDATE
|
||||
// AND DOES NOT WORK AS OF IOS 15.4.1
|
||||
//
|
||||
// THE PROBLEM APPEARS TO BE IN THE RENDERING OF INDIVIDUAL VALVES IN THE HOME APP INTERFACE. THEY
|
||||
// APPEAR IN THE EVE HOMEKIT APPLICATION, BUT NOT APPLE'S HOME APP.
|
||||
|
||||
#include "HomeSpan.h"
|
||||
|
||||
// HAP normally treats multiple Services created within the same Accessory as independent of one another. However, certain HAP Services are designed to represent a central point
|
||||
|
|
@ -112,19 +106,19 @@ struct Shower : Service::Faucet { // this is our Shower structur
|
|||
|
||||
SpanCharacteristic *active=new Characteristic::Active(); // our implementation only requires the Active Characteristic
|
||||
|
||||
Shower(int nHeads){ // this is the constructor for Shower. It takes a single argument that specifies the number of spray heads (WaterValves)
|
||||
for(int i=0;i<nHeads;i++) // for each spray head needed ---
|
||||
addLink(new WaterValve(this,i+1)); // --- instantiate a new WaterValve AND link it to the Shower. Also, pass the Shower object's pointer to WaterValve constructor. We'll see why below.
|
||||
Shower(int nHeads){ // this is the constructor for Shower. It takes a single argument that specifies the number of spray heads (WaterValves)
|
||||
for(int i=0;i<nHeads;i++) // for each spray head needed ---
|
||||
addLink(new WaterValve(this)); // --- instantiate a new WaterValve AND link it to the Shower. Also, pass the Shower object's pointer to WaterValve constructor. We'll see why below.
|
||||
}
|
||||
|
||||
struct WaterValve : Service::Valve { // here we define our WaterValve structure as a child class of the HomeSpan Valve Service
|
||||
SpanCharacteristic *active=new Characteristic::Active(1);; // the Active Characteristic is used to specify whether the Valve is Active (open) or Inactive (closed)
|
||||
SpanCharacteristic *inUse=new Characteristic::InUse(); // the InUser Characteristic is used to specify whether water is actually flowing through value
|
||||
SpanCharacteristic *active=new Characteristic::Active(1);; // the Active Characteristic is used to specify whether the Valve is Active (open) or Inactive (closed)
|
||||
SpanCharacteristic *inUse=new Characteristic::InUse(); // the InUse Characteristic is used to specify whether water is actually flowing through value
|
||||
Shower *shower; // storage for the pointer to the "controlling" Shower Service
|
||||
|
||||
WaterValve(Shower *s, int i){ // this is constructor for WaterValve. It takes a single argument that points to the "controlling" Shower Service
|
||||
shower=s; // store the pointer to the Shower Service
|
||||
new Characteristic::ValveType(2); // specify the Value Type (2=Shower Head; see HAP R2 for other choices)
|
||||
WaterValve(Shower *s){ // this is constructor for WaterValve. It takes a single argument that points to the "controlling" Shower Service
|
||||
shower=s; // store the pointer to the Shower Service
|
||||
new Characteristic::ValveType(Characteristic::ValveType::SHOWER_HEAD); // specify the Valve Type as a Shower Head (note use of constant "Characteristic::ValveType::SHOWER_HEAD")
|
||||
}
|
||||
|
||||
boolean update() override { // HomeSpan calls this whenever the Home App requests a change in a Valve's Active Characteristic
|
||||
|
|
@ -134,10 +128,10 @@ struct Shower : Service::Faucet { // this is our Shower structur
|
|||
}
|
||||
|
||||
void loop() override { // Here we check if the Shower is turned on or off, and determine if that means we need to update the Valve
|
||||
if(shower->active->getVal() && active->getVal() && !inUse->getVal()) // If the Shower is Active, and the Valve is Active, but InUse is NOT Active...
|
||||
inUse->setVal(1); // ...set the InUse Characteristic to Active
|
||||
else if(!shower->active->getVal() && inUse->getVal()) // Otherwise, if the Shower is NOT Active but InUse is Active...
|
||||
inUse->setVal(0); // ...set the InUse Characteristic to NOT Active
|
||||
if(shower->active->getVal() && active->getVal() && !inUse->getVal()) // If the Shower is Active, and the Valve is Active but NOT showing InUse...
|
||||
inUse->setVal(1); // ...show Valve as InUse
|
||||
else if(!shower->active->getVal() && inUse->getVal()) // Otherwise, if the Shower is NOT Active but Valve IS showing InUse...
|
||||
inUse->setVal(0); // ...show Valve as NOT InUse
|
||||
}
|
||||
|
||||
}; // WaterValve
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021-2022 Gregg E. Berman
|
||||
* Copyright (c) 2021-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -3,10 +3,6 @@
|
|||
// DEVICE-SPECIFIC LED SERVICES //
|
||||
////////////////////////////////////
|
||||
|
||||
#include "extras/PwmPin.h" // library of various PWM functions
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
struct DEV_DimmableLED : Service::LightBulb { // Dimmable LED
|
||||
|
||||
// This version of the Dimmable LED Service includes a PushButton that can be used to turn on/off the LED. Status of both the
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2022 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2022 Gregg E. Berman
|
||||
* Copyright (c) 2022-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -123,7 +123,7 @@ void addLight(int n){
|
|||
char name[32];
|
||||
sprintf(name,"Light-%d",n); // create the name of the device using the specified "ID"
|
||||
char sNum[32];
|
||||
sprintf(sNum,"%0.10d",n); // create serial number from the ID - this is helpful in case we rename the Light to something else using the Home App
|
||||
sprintf(sNum,"%010d",n); // create serial number from the ID - this is helpful in case we rename the Light to something else using the Home App
|
||||
|
||||
Serial.printf("Adding Accessory: %s\n",name);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,173 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// HomeSpan: A HomeKit implementation for the ESP32 //
|
||||
// ------------------------------------------------ //
|
||||
// //
|
||||
// Example 21: Using the Identify Characteristic //
|
||||
// //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
// This sketch is similar to Example 5, in which we implemented two simple Lightbulb Accessories,
|
||||
// except now we will also add functionality for the Identify Characteristic (we will also configure
|
||||
// the device as a Bridge Accessory, instead of two standalone Accessories).
|
||||
|
||||
// Recall that the Identify Characteristic has been instantiated in every example sketch since it
|
||||
// is a required Characteristic of the AccessoryInformation Service, and that Service is itself
|
||||
// required to be present for every Accessory. Thus, every Accessory (including the Bridge
|
||||
// Accessory if used), has its own instant of the Identify Characteristic.
|
||||
|
||||
// Though not typically used during normal operation of an Accessory, the Identify Characteristic
|
||||
// can be useful when first pairing your device to HomeKit. You may have noticed when pairing your
|
||||
// device using the Home App that there is the word "Identify" at the bottom of each of the screens
|
||||
// that ask you what you want to name each Accessory, what room the Accessory should be assigned to, etc.
|
||||
|
||||
// Clicking "Identify" on any of those screens causes HomeKit to send an update request to the
|
||||
// Identify Characteristic associated with the corresponding Accessory. As with any Characteristic that
|
||||
// is updated via the Home App, this will trigger a call to the update() method for the enclosing Service.
|
||||
|
||||
// The purpose of this is so that your device can run some sort of "identification routine" when requested,
|
||||
// allowing you to visually confirm that you are indeed pairing the correct device. For example, if you
|
||||
// have three separate devices wired to three different lights or appliances, you want to make sure that when
|
||||
// you start pairing each of them to the Home App you are connected to the device you intend.
|
||||
|
||||
// The identification routine can be anything you choose. The only HAP requirement is that it should not take
|
||||
// longer than 5 seconds to run. In the sketch below we have created an identification routine that logs a
|
||||
// message to the Serial Monitor and blinks the LED associated with the Accessory 3 times whenever its
|
||||
// Identify Characteristic is updated.
|
||||
|
||||
#include "HomeSpan.h"
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
// Below is the same DEV_LED Lightbulb Service we've used in many of the previous examples
|
||||
|
||||
struct DEV_LED : Service::LightBulb {
|
||||
|
||||
int ledPin;
|
||||
SpanCharacteristic *power;
|
||||
|
||||
DEV_LED(int ledPin) : Service::LightBulb(){
|
||||
|
||||
power=new Characteristic::On();
|
||||
this->ledPin=ledPin;
|
||||
pinMode(ledPin,OUTPUT);
|
||||
}
|
||||
|
||||
boolean update(){
|
||||
digitalWrite(ledPin,power->getNewVal());
|
||||
LOG0("LED %d: Power %s\n",ledPin,power->getNewVal()?"ON":"OFF");
|
||||
return(true);
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
// NEW: Here we derive a new class, DEV_INFO, from the Accessory Information Service
|
||||
|
||||
// This structure takes a single argument (ledPin), creates a name from it, and assigns
|
||||
// it to the Name Characteristic.
|
||||
|
||||
// It also instantiates the required Identify Characteristic, and implements an update() method
|
||||
// that logs a message to the Serial Monitor and blinks the associated LED three times.
|
||||
|
||||
// Note that in the update() method we do not bother to check which Characteristic has been updated.
|
||||
// This is because the only possibility is the Identify Characteristic.
|
||||
|
||||
// Also, we do not need to use getNewVal() to check the value. The Home App always sends a value of 1,
|
||||
// since it is just trying to trigger the identification routine (the value itself is meaningless).
|
||||
|
||||
struct DEV_INFO : Service::AccessoryInformation {
|
||||
|
||||
int ledPin;
|
||||
|
||||
DEV_INFO(int ledPin) : Service::AccessoryInformation(){
|
||||
|
||||
new Characteristic::Identify();
|
||||
char c[64];
|
||||
sprintf(c,"LED-%d",ledPin);
|
||||
new Characteristic::Name(c);
|
||||
this->ledPin=ledPin;
|
||||
pinMode(ledPin,OUTPUT);
|
||||
}
|
||||
|
||||
boolean update(){
|
||||
LOG0("Running Identification for LED %d\n",ledPin);
|
||||
for(int i=0;i<3;i++){
|
||||
digitalWrite(ledPin,HIGH);
|
||||
delay(500);
|
||||
digitalWrite(ledPin,LOW);
|
||||
delay(500);
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
homeSpan.setLogLevel(1);
|
||||
homeSpan.begin(Category::Lighting,"HomeSpan LEDS");
|
||||
|
||||
// Here we replace the usual construct:
|
||||
|
||||
// new SpanAccessory();
|
||||
// new Service::AccessoryInformation();
|
||||
// new Characteristic::Identify();
|
||||
|
||||
// with this:
|
||||
|
||||
new SpanAccessory();
|
||||
new DEV_INFO(13); // instantiate a new DEV_INFO structure that will run our custom identification routine to blink an LED on pin 13 three times
|
||||
|
||||
new SpanAccessory();
|
||||
new DEV_INFO(16); // Note we instantiate a new DEV_INFO structure for each Accessory in this device
|
||||
new DEV_LED(16); // Here we instantiate the usual DEV_LED structure that controls the LED during normal operation
|
||||
|
||||
new SpanAccessory(); // Here we add a second LED Accessory
|
||||
new DEV_INFO(17);
|
||||
new DEV_LED(17);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void loop(){
|
||||
homeSpan.poll();
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
// NOTE: Once a device has been paired, it is no longer possible to trigger the Identify Characteristic from the Home App.
|
||||
// Apple assumes that the identification routine is no longer needed since you can always identify the device by simply operating it.
|
||||
// However, the Eve for HomeKit app DOES provide an "ID" button in the interface for each Accessory that can be used to trigger
|
||||
// the identification routine for that Accessory at any time after the device has been paired.
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// HomeSpan: A HomeKit implementation for the ESP32 //
|
||||
// ------------------------------------------------ //
|
||||
// //
|
||||
// Example 22: Demonstrates the use of the TLV8 Library //
|
||||
// by implementing DisplayOrder, an optional //
|
||||
// TLV8 Characteristic used with the TV Service //
|
||||
// to set the order in which TV Inputs are //
|
||||
// displayed for selection in the Home App //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "HomeSpan.h"
|
||||
|
||||
// NOTE: Please see the "Other Examples -> Television" sketch for complete details on how to implement a Television Service. The focus
|
||||
// of this sketch is solely to demonstrate how to use the TLV8 Library to create TLV8 data for use with the DisplayOrder Characteristic.
|
||||
|
||||
// First we define a simple Television Input Source Service
|
||||
|
||||
struct TVInput : Service::InputSource {
|
||||
|
||||
SpanCharacteristic *inputID;
|
||||
SpanCharacteristic *inputName;
|
||||
|
||||
TVInput(uint32_t id, const char *name) : Service::InputSource() {
|
||||
|
||||
inputID = new Characteristic::Identifier(id);
|
||||
inputName = new Characteristic::ConfiguredName(name);
|
||||
new Characteristic::IsConfigured(Characteristic::IsConfigured::CONFIGURED);
|
||||
new Characteristic::CurrentVisibilityState(Characteristic::CurrentVisibilityState::VISIBLE);
|
||||
}
|
||||
};
|
||||
|
||||
// Next we define a simple Television Service
|
||||
|
||||
struct HomeSpanTV : Service::Television {
|
||||
|
||||
SpanCharacteristic *active = new Characteristic::Active(0);
|
||||
SpanCharacteristic *activeID = new Characteristic::ActiveIdentifier(10);
|
||||
|
||||
SpanCharacteristic *displayOrder; // Create a pointer to use for the new TLV8 DisplayOrder Characteristic, which will be instantiated below once we build the TLV8 record
|
||||
|
||||
HomeSpanTV() : Service::Television() {
|
||||
|
||||
// Before we instantiate displayOrder, we need to build a TLV8 object with the information required
|
||||
// by the DisplayOrder Characteristic. The (undocumented by Apple!) TLV8 specifications for the
|
||||
// DisplayOrder Characteristic are as follows:
|
||||
|
||||
// TAG NAME FORMAT DESCRIPTION
|
||||
// ---- ------------- ------ --------------------------------------------
|
||||
// 0x01 inputSourceID uint32 ID of the Input Source to be displayed first
|
||||
// 0x00 separator none Empty element to separate the inputSourceIDs
|
||||
// 0x01 inputSourceID uint32 ID of the Input Source to be displayed second
|
||||
// 0x00 separator none Empty element to separate the inputSourceIDs
|
||||
// 0x01 inputSourceID uint32 ID of the Input Source to be displayed third
|
||||
// 0x00 separator none Empty element to separate the inputSourceIDs
|
||||
// etc...
|
||||
|
||||
// To start, instantiate a new TLV8 object
|
||||
|
||||
TLV8 orderTLV; // creates an empty TLV8 object
|
||||
|
||||
// Next, fill it with TAGS and VALUES based on the above specification. The easiest, though
|
||||
// not necessarily most elegant, way to do this is by simply adding each TAG/VALUE as follows:
|
||||
|
||||
orderTLV.add(1,10); // TAG=1, VALUE=ID of first Input Source to be displayed
|
||||
orderTLV.add(0); // TAG=0 (no value)
|
||||
orderTLV.add(1,20); // TAG=1, VALUE=ID of the second Input Source to be displayed
|
||||
orderTLV.add(0); // TAG=0 (no value)
|
||||
orderTLV.add(1,50); // TAG=1, VALUE=ID of the third Input Source to be displayed
|
||||
orderTLV.add(0); // TAG=0 (no value)
|
||||
orderTLV.add(1,30); // TAG=1, VALUE=ID of the fourth Input Source to be displayed
|
||||
orderTLV.add(0); // TAG=0 (no value)
|
||||
orderTLV.add(1,40); // TAG=1, VALUE=ID of the fifth Input Source to be displayed
|
||||
|
||||
// Based on the above structure, we expect the Home App to display our input sources based on their IDs
|
||||
// in the following order: 10, 20, 50, 30, 40. These IDs must of course match the IDs you choose
|
||||
// for your input sources when you create them at the end of this sketch in setup()
|
||||
|
||||
// Now we can instantiate displayOrder using the TLV8 object created above as its initial value
|
||||
|
||||
displayOrder = new Characteristic::DisplayOrder(orderTLV); // set the "value" of DisplayOrder to be the orderTLV object we just created
|
||||
|
||||
// That's it - you've created your first TLV8 Characteristic!
|
||||
}
|
||||
|
||||
// Below we define the usual update() loop. There is nothing "TLV-specific" about this part of the code
|
||||
|
||||
boolean update() override {
|
||||
|
||||
if(active->updated()){
|
||||
LOG0("Set TV Power to: %s\n",active->getNewVal()?"ON":"OFF");
|
||||
}
|
||||
|
||||
if(activeID->updated()){
|
||||
LOG0("Set Input Source to ID=%d\n",activeID->getNewVal());
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
homeSpan.setLogLevel(2);
|
||||
|
||||
homeSpan.begin(Category::Television,"HomeSpan Television");
|
||||
|
||||
SPAN_ACCESSORY();
|
||||
|
||||
(new HomeSpanTV()) // Define a Television Service and link in the InputSources!
|
||||
->addLink(new TVInput(10,"Xfinity"))
|
||||
->addLink(new TVInput(20,"BlueRay Disc"))
|
||||
->addLink(new TVInput(30,"Amazon Prime"))
|
||||
->addLink(new TVInput(40,"Netflix"))
|
||||
->addLink(new TVInput(50,"Hulu"))
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void loop(){
|
||||
homeSpan.poll();
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
* 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 example demonstrates the use of a custom Partition Scheme file: "partitions.csv"
|
||||
|
||||
// During compilation, if a file with this EXACT name is placed in the sketch folder,
|
||||
// the esptool performing the compilation will use the partition scheme found
|
||||
// in "partitions.csv" regardless of what partition scheme you selected in the Arduino IDE.
|
||||
|
||||
// Note if you change the partition scheme it is highly recommended that you fully erase the flash
|
||||
// upon your next compile/upload by enabling the "Erase All Flash" option from the Arduino IDE menu.
|
||||
// NOTE: remember to turn OFF this option after you've successully uploaded a sketch with the new
|
||||
// partition scheme, else you will continue to erase everything saved in the NVS every time you upload
|
||||
// a new sketch (which is likely NOT what you want to occur).
|
||||
|
||||
// The main reason for wanting to create your own partition scheme is to expand the NVS space.
|
||||
// All of the pre-configured partition scheme you can select from the Arduino IDE provide
|
||||
// for 504 records of NVS space. This is usuall sufficient for most HomeSpan projects, but if
|
||||
// you have a LOT of Accessories (as per below) AND you are saving their states in NVS, you can
|
||||
// use up all the NVS space. If this occurs, HomeSpan will warn you of low NVS space upon boot-up.
|
||||
|
||||
// The custom partition scheme included in this sketch folder solves this problem by eliminating
|
||||
// the SPIFFs partition (which is generally not used by HomeSpan) and using this portion of the flash
|
||||
// to provide an NVS space with 3906 records --- more than enough for even the largest projects.
|
||||
|
||||
// For reference, in addition to HomeSpan's internal use of NVS (about 32 records), saving a
|
||||
// numerical Characteristic consumes one additional NVS record, and saving a string Characteristic (of
|
||||
// less than 32 characters) consumes two NVS records. Also, the ESP32 WiFi stack consumes about 130
|
||||
// additional NVS records once initialized. As such, the sketch below requires:
|
||||
|
||||
// 32 records (internal HomeSpan use)
|
||||
// + 320 records (80 Accessories * 4 saved numerical Characterstics)
|
||||
// + 160 records (80 Accessories * 2 records per saved string Characterstic)
|
||||
// + 130 records (with WiFi initialized)
|
||||
// ----------------------------------------
|
||||
// = 642 NVS records needed (which exceeds the normal 504 limit, unless a custom partition scheme is used)
|
||||
|
||||
// Note that once HomeSpan is paired with HomeKit, additional NVS records will be consumed to store the
|
||||
// pairing information for each verified HomeKit Controller.
|
||||
|
||||
// Note also that when compiling under the Arduino IDE, the IDE reports the size of partition based on the
|
||||
// Partition Scheme you selected in the IDE menu, even though that scheme is not actually used if you have your
|
||||
// own "partition.csv" file, as in this example. This may lead the IDE to report an incorrect partition size.
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "HomeSpan.h"
|
||||
|
||||
#define MAX_LIGHTS 80 // configure for 80 Light Accessories
|
||||
|
||||
struct RGB_Light : Service::LightBulb {
|
||||
|
||||
Characteristic::On power{0,true}; // save these 4 numerical Characteristics (4*80 = 320 NVS records)
|
||||
Characteristic::Hue H{0,true};
|
||||
Characteristic::Saturation S{0,true};
|
||||
Characteristic::Brightness V{0,true};
|
||||
|
||||
int lightNumber;
|
||||
|
||||
RGB_Light(int n) : Service::LightBulb(){
|
||||
|
||||
lightNumber=n;
|
||||
LOG0("Configured RGB Light-%0d\n",lightNumber);
|
||||
}
|
||||
|
||||
boolean update(){
|
||||
|
||||
if(power.updated())
|
||||
LOG0("Light-%d: Power=%s",lightNumber,power.getNewVal()?"ON":"OFF");
|
||||
|
||||
if(H.updated())
|
||||
LOG0("Light-%d: Hue=%d",lightNumber,H.getNewVal());
|
||||
|
||||
if(S.updated())
|
||||
LOG0("Light-%d: Saturation=%d",lightNumber,S.getNewVal());
|
||||
|
||||
if(V.updated())
|
||||
LOG0("Light-%d: Brightness=%d",lightNumber,V.getNewVal());
|
||||
|
||||
return(false);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
homeSpan.begin(Category::Lighting,"HomeSpan Max");
|
||||
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
|
||||
for(int i=1;i<=MAX_LIGHTS;i++){
|
||||
char c[60];
|
||||
sprintf(c,"Light-%02d",i);
|
||||
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
new Characteristic::Name(c,true); // save this string Characteristic (2*80 = 160 NVS records)
|
||||
|
||||
new RGB_Light(i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void loop(){
|
||||
|
||||
homeSpan.poll();
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
# --- Custom Partition Table for HomeSpan ---
|
||||
#
|
||||
# Similar to min_spiffs, except that the 128K SPIFF block at the end
|
||||
# is replaced by a 128K NVS block, and the initial 20K NVS block
|
||||
# is no longer used. Note this table is designed for use with 4MB Flash.
|
||||
# To use with 8MB Flash, increase app0 and app1 by 2048K to become 3968K each.
|
||||
# To use with 16MB Flash, increase app0 and app1 by 6144K to become 8064K each
|
||||
#
|
||||
unused_nvs,data,nvs,,20K,
|
||||
otadata,data,ota,,8K,
|
||||
app0,app,ota_0,,1920K,
|
||||
app1,app,ota_1,,1920K,
|
||||
nvs,data,nvs,,128K,
|
||||
coredump,data,coredump,,64K,
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
// Sometimes you need to access Characteristics from outside of the Service structure
|
||||
// in which they were created so you can read and/or modify them in other parts of
|
||||
// a sketch, such as from within the main Arduino loop().
|
||||
|
||||
// This sketch is basically the same as Tutorial Example 5, in which we created
|
||||
// two working LEDs attached to pins 16, and 17. However, in this sketch we will
|
||||
// create global pointers to the LED Services that we can then use in the main loop() to
|
||||
// do something unique.
|
||||
|
||||
#include "HomeSpan.h"
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
// First we define our DEV_LED Service exactly the same as in Tutorial Example 5.
|
||||
// This Service contains a single Characteristic named "power" of type Chacracteristic::On
|
||||
|
||||
struct DEV_LED : Service::LightBulb {
|
||||
|
||||
int ledPin;
|
||||
SpanCharacteristic *power;
|
||||
|
||||
DEV_LED(int ledPin) : Service::LightBulb(){
|
||||
|
||||
power=new Characteristic::On();
|
||||
this->ledPin=ledPin;
|
||||
pinMode(ledPin,OUTPUT);
|
||||
}
|
||||
|
||||
boolean update(){
|
||||
|
||||
digitalWrite(ledPin,power->getNewVal());
|
||||
return(true);
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
// Next we create two pointers to the DEV_LED Service. These are created
|
||||
// outside of any class or function so they are globally-scoped and can be
|
||||
// accessed from anywhere else in this sketch.
|
||||
|
||||
// Note that there are just POINTERS to DEV_LED objects. The objects themselves
|
||||
// are not yet created.
|
||||
|
||||
DEV_LED *led16; // pointer to a DEV_LED structure to be used below to reference a DEV_LED object assigned to pin 16
|
||||
DEV_LED *led17; // pointer to a DEV_LED structure to be used below to reference a DEV_LED object assigned to pin 17
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
homeSpan.begin(Category::Lighting,"HomeSpan LED");
|
||||
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
led16=new DEV_LED(16); // this is the key step - we SAVE the pointer returned by 'new DEV_LED(16)' in the global variable led16 created above
|
||||
|
||||
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
led17=new DEV_LED(17); // also save the pointer to the second LED object using the global variable led17 created above
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void loop(){
|
||||
|
||||
homeSpan.poll();
|
||||
|
||||
// Because the pointers led16 and led17 were created in the global scope, they will still exist even after setup() is completed.
|
||||
// This means we can use them to access the Characteristics within each of those Services.
|
||||
|
||||
// Here we access the power Characteristic of both Services and check to see if they are BOTH on, and if so,
|
||||
// we turn them both off and print a "power overload" message.
|
||||
|
||||
// Note how you can use all the same methods, such as getVal() and setVal(), just as you would do in the Service itself.
|
||||
// Caution: always use getVal(), not getNewVal(), which is only formally defined from within the Service update() method.
|
||||
|
||||
if(led16->power->getVal() && led17->power->getVal()){
|
||||
Serial.printf("Power overload! Can't have both LED's on at the same time. Turn off both LEDs...\n");
|
||||
led16->power->setVal(false);
|
||||
led17->power->setVal(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
|
@ -40,7 +40,6 @@
|
|||
// off.
|
||||
|
||||
#include "HomeSpan.h"
|
||||
#include "extras/PwmPin.h" // library of various PWM functions
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
|
|
|
|||
|
|
@ -40,8 +40,6 @@
|
|||
// as well as for instructions on how you can easily extend StepperControl to create a custom driver for any board.
|
||||
|
||||
#include "HomeSpan.h"
|
||||
#include "extras/Stepper_TB6612.h" // this contains HomeSpan's StepperControl Class for the Adafruit TB6612 driver board
|
||||
#include "extras/Stepper_A3967.h" // this contains HomeSpan's StepperControl Class for the Sparkfun A3967 driver board
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@
|
|||
#endif
|
||||
|
||||
#include "HomeSpan.h"
|
||||
#include "extras/Pixel.h" // include the HomeSpan Pixel class
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
|
|
@ -72,12 +71,12 @@ struct NeoPixel_RGB : Service::LightBulb { // Addressable single-wire RGB L
|
|||
Characteristic::Saturation S{0,true};
|
||||
Characteristic::Brightness V{100,true};
|
||||
Pixel *pixel;
|
||||
uint8_t nPixels;
|
||||
int nPixels;
|
||||
|
||||
NeoPixel_RGB(uint8_t pin, uint8_t nPixels) : Service::LightBulb(){
|
||||
NeoPixel_RGB(uint8_t pin, int nPixels) : Service::LightBulb(){
|
||||
|
||||
V.setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1%
|
||||
pixel=new Pixel(pin); // creates Pixel LED on specified pin
|
||||
pixel=new Pixel(pin); // creates Pixel RGB LED on specified pin
|
||||
this->nPixels=nPixels; // save number of Pixels in this LED Strand
|
||||
update(); // manually call update() to set pixel with restored initial values
|
||||
}
|
||||
|
|
@ -106,12 +105,12 @@ struct NeoPixel_RGBW : Service::LightBulb { // Addressable single-wire RGBW
|
|||
Characteristic::Brightness V{100,true};
|
||||
Characteristic::ColorTemperature T{140,true};
|
||||
Pixel *pixel;
|
||||
uint8_t nPixels;
|
||||
int nPixels;
|
||||
|
||||
NeoPixel_RGBW(uint8_t pin, uint8_t nPixels) : Service::LightBulb(){
|
||||
NeoPixel_RGBW(uint8_t pin, int nPixels) : Service::LightBulb(){
|
||||
|
||||
V.setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1%
|
||||
pixel=new Pixel(pin,true); // creates Pixel RGBW LED (second parameter set to true for RGBW) on specified pin
|
||||
pixel=new Pixel(pin,PixelType::GRBW); // creates Pixel RGBW LED on specified pin (with order of colors chnanged to reflect this specific NeoPixel device)
|
||||
this->nPixels=nPixels; // save number of Pixels in this LED Strand
|
||||
update(); // manually call update() to set pixel with restored initial values
|
||||
}
|
||||
|
|
@ -142,9 +141,9 @@ struct DotStar_RGB : Service::LightBulb { // Addressable two-wire RGB LED S
|
|||
Characteristic::Saturation S{0,true};
|
||||
Characteristic::Brightness V{100,true};
|
||||
Dot *pixel;
|
||||
uint8_t nPixels;
|
||||
int nPixels;
|
||||
|
||||
DotStar_RGB(uint8_t dataPin, uint8_t clockPin, uint8_t nPixels) : Service::LightBulb(){
|
||||
DotStar_RGB(uint8_t dataPin, uint8_t clockPin, int nPixels) : Service::LightBulb(){
|
||||
|
||||
V.setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1%
|
||||
pixel=new Dot(dataPin,clockPin); // creates Dot LED on specified pins
|
||||
|
|
|
|||
|
|
@ -0,0 +1,131 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
/////////////////////// PIXEL TESTER //////////////////////////
|
||||
|
||||
// This sketch is designed to help identify the proper settings to use for a NeoPixel, NeoPixel Strip,
|
||||
// or any device containing one or more single-wire addressable RGB or RGBW LEDs (the "Pixel Device").
|
||||
|
||||
// Before compiling, set PIXEL_PIN to the ESP32 pin that is connected to your Pixel Device, and set NPIXELS to
|
||||
// the numnber of Pixels in the Pixel Device. Note that for some strips a single chip controls more than one LED,
|
||||
// in which case NPIXELS should be set to the number of controlling chips, NOT the number of LEDs.
|
||||
|
||||
// To start, the second argument of the Pixel constructor for the testPixel object below should remain
|
||||
// set to PixelType::RGBW
|
||||
|
||||
// When run, the sketch will repeatedly cycle colors by setting ALL pixels in the device first to RED, then GREEN,
|
||||
// followed by BLUE, and then finally WHITE. After a short pause, the cycle repeats.
|
||||
|
||||
// For each color the brightness will increase from 0 through MAX_BRIGHTNESS, and then back to 0. You can change
|
||||
// MAX_BRIGHTNESS to something lower than 255 if you want to limit how bright the pixels get.
|
||||
|
||||
// For Pixel Devices with more than one pixel, diagnostics are as follows:
|
||||
//
|
||||
// * If all 4 colors repeatedly flash in the order expected, this means the base setting of PixelType::RGBW is correct!
|
||||
//
|
||||
// * If instead of each pixel being set to the same color, the pixels in the strip each light up with a different color
|
||||
// (or no color at all), this means you have an RGB LED, not an RGBW LED. Change the second parameter of the constructor
|
||||
// to PixelType::RGB and re-run the sketch.
|
||||
//
|
||||
// * If all of the pixels are being set to the same color, but the sequence is NOT in the order RED, GREEN, BLUE, change
|
||||
// the second parameter of the constructor so that the order of the PixelType colors match the sequence of the colors
|
||||
// that appear on the Pixel Device. For example, if your RGBW Pixel Device flashes GREEN, RED, BLUE, and than WHITE, use
|
||||
// PixelType::GRBW.
|
||||
|
||||
// For Pixel Devices with only a single pixel, diagnostics are as follows:
|
||||
|
||||
// * If all 4 colors repeatedly flash in the order expected, this means the base setting of PixelType::RGBW is correct!
|
||||
//
|
||||
// * If the pixel does not light at all when set to WHITE this means you have an RGB LED, not an RGBW LED. Change the
|
||||
// second parameter of the constructor to PixelType::RGB and re-run the sketch.
|
||||
//
|
||||
// * If all of the pixels are being set to the same color, but the sequence is NOT in the order RED, GREEN, BLUE, change
|
||||
// the second parameter of the constructor so that the order of the PixelType colors match the sequence of the colors
|
||||
// that appear on the Pixel Device. For example, if your RGB Pixel Device flashes GREEN, RED, and then BLUE, use
|
||||
// PixelType::GRB.
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
#include "HomeSpan.h"
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
#define MAX_BRIGHTNESS 255 // maximum brightness when flashing RGBW [0-255]
|
||||
|
||||
#define PIXEL_PIN 26 // set this to whatever pin you are using - note pin cannot be "input only"
|
||||
#define NPIXELS 8 // set to number of pixels in strip
|
||||
|
||||
Pixel testPixel(PIXEL_PIN, PixelType::RGBW); // change the second argument until device operates with correct colors
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
Serial.printf("\n\nPixel Test on pin %d with %d pixels\n\n",PIXEL_PIN,NPIXELS);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void flashColor(boolean r, boolean g, boolean b, boolean w){
|
||||
|
||||
for(int i=0;i<MAX_BRIGHTNESS;i++){
|
||||
testPixel.set(Pixel::RGB(i*r,i*g,i*b,i*w),NPIXELS);
|
||||
delay(4);
|
||||
}
|
||||
|
||||
for(int i=MAX_BRIGHTNESS;i>=0;i--){
|
||||
testPixel.set(Pixel::RGB(i*r,i*g,i*b,i*w),NPIXELS);
|
||||
delay(4);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void loop(){
|
||||
|
||||
Serial.printf("Red...");
|
||||
flashColor(1,0,0,0);
|
||||
|
||||
Serial.printf("Green...");
|
||||
flashColor(0,1,0,0);
|
||||
|
||||
Serial.printf("Blue...");
|
||||
flashColor(0,0,1,0);
|
||||
|
||||
if(testPixel.isRGBW()){
|
||||
Serial.printf("White...");
|
||||
flashColor(0,0,0,1);
|
||||
}
|
||||
|
||||
Serial.printf("Pausing.\n");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
|
@ -26,7 +26,6 @@
|
|||
********************************************************************************/
|
||||
|
||||
#include "HomeSpan.h" // include the HomeSpan library
|
||||
#include "extras/RFControl.h" // include RF Control Library
|
||||
|
||||
void setup() {
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,8 @@ void setup() {
|
|||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
Serial.printf("Starting\n\n");
|
||||
Serial.printf("\n\nThis is a REMOTE Device with MAC Address = %s\n",WiFi.macAddress().c_str());
|
||||
Serial.printf("NOTE: This MAC Address must be entered into the corresponding SpanPoint() call of the MAIN Device.\n\n");
|
||||
|
||||
// In the line below, replace the MAC Address with that of your MAIN HOMESPAN DEVICE
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,6 @@
|
|||
// DEVICE-SPECIFIC LED SERVICES //
|
||||
////////////////////////////////////
|
||||
|
||||
#include <extras/PwmPin.h>
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
struct DEV_WindowShade : Service::WindowCovering { // A motorized Window Shade with Hold Feature
|
||||
|
||||
SpanCharacteristic *current; // reference to a "generic" Current Position Characteristic (used by a variety of different Service)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
name=HomeSpan
|
||||
version=1.8.0
|
||||
version=1.9.1
|
||||
author=Gregg <homespan@icloud.com>
|
||||
maintainer=Gregg <homespan@icloud.com>
|
||||
sentence=A robust and extremely easy-to-use HomeKit implementation for the Espressif ESP32 running on the Arduino IDE.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -49,22 +49,12 @@ enum FORMAT { // HAP Table 6-5
|
|||
INT=5,
|
||||
FLOAT=6,
|
||||
STRING=7,
|
||||
DATA=8
|
||||
DATA=8,
|
||||
TLV_ENC=9
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
typedef boolean BOOL_t;
|
||||
typedef uint8_t UINT8_t;
|
||||
typedef uint16_t UINT16_t;
|
||||
typedef uint32_t UINT32_t;
|
||||
typedef uint64_t UINT64_t;
|
||||
typedef int32_t INT_t;
|
||||
typedef double FLOAT_t;
|
||||
typedef char * STRING_t;
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
struct HapChar {
|
||||
const char *type;
|
||||
const char *hapName;
|
||||
|
|
@ -113,6 +103,7 @@ struct HapCharacteristics {
|
|||
HAPCHAR( CurrentTemperature, 11, PR+EV, FLOAT, false );
|
||||
HAPCHAR( CurrentTiltAngle, C1, PR+EV, INT, false );
|
||||
HAPCHAR( CurrentVisibilityState, 135, PR+EV, UINT8, true );
|
||||
HAPCHAR( DisplayOrder, 136, PR+EV, TLV_ENC, true );
|
||||
HAPCHAR( FilterLifeLevel, AB, PR+EV, FLOAT, false );
|
||||
HAPCHAR( FilterChangeIndication, AC, PR+EV, UINT8, true );
|
||||
HAPCHAR( FirmwareRevision, 52, PR+EV, STRING, true );
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
|
||||
#elif defined(ARDUINO_ESP32S3_DEV)
|
||||
enum {
|
||||
F13=5,F12=6,F27=7,F15=16,F32=17,F14=18,F16=37,F17=36,F21=35, // Digital Only (9 pins)
|
||||
F13=5,F12=6,F27=7,F15=16,F32=17,F14=18,F16=37,F17=36,F21=38, // Digital Only (9 pins)
|
||||
F26=1,F25=2,F34=20,F39=19,F36=15,F4=4, // A0-A5
|
||||
F22=9,F23=8, // I2C SCL/SDA
|
||||
F5=12,F18=11,F19=13,F33=10, // SPI SCK/SDO/SDI/CS
|
||||
|
|
|
|||
1890
src/HAP.cpp
1890
src/HAP.cpp
File diff suppressed because it is too large
Load Diff
200
src/HAP.h
200
src/HAP.h
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -27,14 +27,31 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include <WiFi.h>
|
||||
|
||||
#include "HomeSpan.h"
|
||||
#include "TLV.h"
|
||||
#include "HAPConstants.h"
|
||||
#include "HKDF.h"
|
||||
#include "SRP.h"
|
||||
|
||||
const TLV8_names HAP_Names[] = {
|
||||
{kTLVType_Separator,"SEPARATOR"},
|
||||
{kTLVType_State,"STATE"},
|
||||
{kTLVType_PublicKey,"PUBKEY"},
|
||||
{kTLVType_Method,"METHOD"},
|
||||
{kTLVType_Salt,"SALT"},
|
||||
{kTLVType_Error,"ERROR"},
|
||||
{kTLVType_Proof,"PROOF"},
|
||||
{kTLVType_EncryptedData,"ENC.DATA"},
|
||||
{kTLVType_Signature,"SIGNATURE"},
|
||||
{kTLVType_Identifier,"IDENTIFIER"},
|
||||
{kTLVType_Permissions,"PERMISSION"}
|
||||
};
|
||||
|
||||
#define hap_controller_IDBYTES 36
|
||||
#define hap_accessory_IDBYTES 17
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// NONCE Structure (HAP used last 64 of 96 bits)
|
||||
|
||||
|
|
@ -46,23 +63,41 @@ struct Nonce {
|
|||
void inc();
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Paired Controller Structure for Permanently-Stored Data
|
||||
|
||||
struct Controller {
|
||||
boolean allocated=false; // slot is allocated with Controller data
|
||||
boolean admin; // Controller has admin privileges
|
||||
uint8_t ID[36]; // Pairing ID
|
||||
uint8_t LTPK[32]; // Long Term Ed2519 Public Key
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Accessory Structure for Permanently-Stored Data
|
||||
|
||||
struct Accessory {
|
||||
uint8_t ID[17]; // Pairing ID in form "XX:XX:XX:XX:XX:XX"
|
||||
uint8_t LTSK[64]; // secret key for Ed25519 signatures
|
||||
uint8_t LTPK[32]; // public key for Ed25519 signatures
|
||||
uint8_t ID[hap_accessory_IDBYTES]; // Pairing ID in form "XX:XX:XX:XX:XX:XX" (no null terminator)
|
||||
uint8_t LTSK[crypto_sign_SECRETKEYBYTES]; // Long Term Ed2519 Secret Key
|
||||
uint8_t LTPK[crypto_sign_PUBLICKEYBYTES]; // Long Term Ed2519 Public Key
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
// Paired Controller Structure for Permanently-Stored Data
|
||||
|
||||
class Controller {
|
||||
friend class HAPClient;
|
||||
|
||||
boolean allocated=false; // DEPRECATED (but needed for backwards compatability with original NVS storage of Controller info)
|
||||
boolean admin; // Controller has admin privileges
|
||||
uint8_t ID[36]; // Pairing ID
|
||||
uint8_t LTPK[32]; // Long Term Ed2519 Public Key
|
||||
|
||||
public:
|
||||
|
||||
Controller(uint8_t *id, uint8_t *ltpk, boolean ad){
|
||||
allocated=true;
|
||||
admin=ad;
|
||||
memcpy(ID,id,36);
|
||||
memcpy(LTPK,ltpk,32);
|
||||
}
|
||||
|
||||
Controller(){}
|
||||
|
||||
const uint8_t *getID() const {return(ID);}
|
||||
const uint8_t *getLTPK() const {return(LTPK);}
|
||||
boolean isAdmin() const {return(admin);}
|
||||
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
|
@ -73,33 +108,29 @@ struct HAPClient {
|
|||
|
||||
// common structures and data shared across all HAP Clients
|
||||
|
||||
static const int MAX_HTTP=8095; // max number of bytes in HTTP message buffer
|
||||
static const int MAX_HTTP=8096; // max number of bytes allowed for HTTP message
|
||||
static const int MAX_CONTROLLERS=16; // maximum number of paired controllers (HAP requires at least 16)
|
||||
static const int MAX_ACCESSORIES=41; // maximum number of allowed Acessories (HAP limit=150, but not enough memory in ESP32 to run that many)
|
||||
static const int MAX_ACCESSORIES=150; // maximum number of allowed Accessories (HAP limit=150)
|
||||
|
||||
static TLV<kTLVType,10> tlv8; // TLV8 structure (HAP Section 14.1) with space for 10 TLV records of type kTLVType (HAP Table 5-6)
|
||||
static nvs_handle hapNVS; // handle for non-volatile-storage of HAP data
|
||||
static nvs_handle srpNVS; // handle for non-volatile-storage of SRP data
|
||||
static uint8_t httpBuf[MAX_HTTP+1]; // buffer to store HTTP messages (+1 to leave room for storing an extra 'overflow' character)
|
||||
static HKDF hkdf; // generates (and stores) HKDF-SHA-512 32-byte keys derived from an inputKey of arbitrary length, a salt string, and an info string
|
||||
static pairState pairStatus; // tracks pair-setup status
|
||||
static SRP6A srp; // stores all SRP-6A keys used for Pair-Setup
|
||||
static Accessory accessory; // Accessory ID and Ed25519 public and secret keys- permanently stored
|
||||
static Controller controllers[MAX_CONTROLLERS]; // Paired Controller IDs and ED25519 long-term public keys - permanently stored
|
||||
static int conNum; // connection number - used to keep track of per-connection EV notifications
|
||||
static pairState pairStatus; // tracks pair-setup status
|
||||
static Accessory accessory; // Accessory ID and Ed25519 public and secret keys - permanently stored
|
||||
static list<Controller, Mallocator<Controller>> controllerList; // linked-list of Paired Controller IDs and ED25519 long-term public keys - permanently stored
|
||||
|
||||
// individual structures and data defined for each Hap Client connection
|
||||
|
||||
WiFiClient client; // handle to client
|
||||
Controller *cPair; // pointer to info on current, session-verified Paired Controller (NULL=un-verified, and therefore un-encrypted, connection)
|
||||
int clientNumber; // client number
|
||||
Controller *cPair=NULL; // pointer to info on current, session-verified Paired Controller (NULL=un-verified, and therefore un-encrypted, connection)
|
||||
|
||||
// These keys are generated in the first call to pair-verify and used in the second call to pair-verify so must persist for a short period
|
||||
|
||||
uint8_t publicCurveKey[32]; // public key for Curve25519 encryption
|
||||
uint8_t sharedCurveKey[32]; // Pair-Verfied Shared Secret key derived from Accessory's epehmeral secretCurveKey and Controller's iosCurveKey
|
||||
uint8_t sessionKey[32]; // shared Session Key (derived with various HKDF calls)
|
||||
uint8_t iosCurveKey[32]; // Curve25519 public key for associated paired controller
|
||||
// These temporary Curve25519 keys are generated in the first call to pair-verify and used in the second call to pair-verify so must persist for a short period
|
||||
|
||||
struct tempKeys_t {
|
||||
uint8_t publicCurveKey[crypto_box_PUBLICKEYBYTES]; // Accessory's Curve25519 Public Key
|
||||
uint8_t sharedCurveKey[crypto_box_PUBLICKEYBYTES]; // Shared-Secret Curve25519 Key derived from Accessory's Secret Key and Controller's Public Key
|
||||
uint8_t sessionKey[crypto_box_PUBLICKEYBYTES]; // Session Key Curve25519 (derived with various HKDF calls)
|
||||
uint8_t iosCurveKey[crypto_box_PUBLICKEYBYTES]; // Controller's Curve25519 Public Key
|
||||
} temp;
|
||||
|
||||
// CurveKey and CurveKey Nonces are created once each new session is verified in /pair-verify. Keys persist for as long as connection is open
|
||||
|
||||
uint8_t a2cKey[32]; // AccessoryToControllerKey derived from HKDF-SHA-512 of sharedCurveKey (HAP Section 6.5.2)
|
||||
|
|
@ -109,19 +140,17 @@ struct HAPClient {
|
|||
|
||||
// define member methods
|
||||
|
||||
void processRequest(); // process HAP request
|
||||
int postPairSetupURL(); // POST /pair-setup (HAP Section 5.6)
|
||||
int postPairVerifyURL(); // POST /pair-verify (HAP Section 5.7)
|
||||
int getAccessoriesURL(); // GET /accessories (HAP Section 6.6)
|
||||
int postPairingsURL(); // POST /pairings (HAP Sections 5.10-5.12)
|
||||
int getCharacteristicsURL(char *urlBuf); // GET /characteristics (HAP Section 6.7.4)
|
||||
int putCharacteristicsURL(char *json); // PUT /characteristics (HAP Section 6.7.2)
|
||||
int putPrepareURL(char *json); // PUT /prepare (HAP Section 6.7.2.4)
|
||||
int getStatusURL(); // GET / status (an optional, non-HAP feature)
|
||||
void processRequest(); // process HAP request
|
||||
int postPairSetupURL(uint8_t *content, size_t len); // POST /pair-setup (HAP Section 5.6)
|
||||
int postPairVerifyURL(uint8_t *content, size_t len); // POST /pair-verify (HAP Section 5.7)
|
||||
int postPairingsURL(uint8_t *content, size_t len); // POST /pairings (HAP Sections 5.10-5.12)
|
||||
int getAccessoriesURL(); // GET /accessories (HAP Section 6.6)
|
||||
int getCharacteristicsURL(char *urlBuf); // GET /characteristics (HAP Section 6.7.4)
|
||||
int putCharacteristicsURL(char *json); // PUT /characteristics (HAP Section 6.7.2)
|
||||
int putPrepareURL(char *json); // PUT /prepare (HAP Section 6.7.2.4)
|
||||
|
||||
void tlvRespond(); // respond to client with HTTP OK header and all defined TLV data records (those with length>0)
|
||||
void sendEncrypted(char *body, uint8_t *dataBuf, int dataLen); // send client complete ChaCha20-Poly1305 encrypted HTTP mesage comprising a null-terminated 'body' and 'dataBuf' with 'dataLen' bytes
|
||||
int receiveEncrypted(); // decrypt HTTP request (HAP Section 6.5)
|
||||
void tlvRespond(TLV8 &tlv8); // respond to client with HTTP OK header and all defined TLV data records
|
||||
int receiveEncrypted(uint8_t *httpBuf, int messageSize); // decrypt HTTP request (HAP Section 6.5)
|
||||
|
||||
int notFoundError(); // return 404 error
|
||||
int badRequestError(); // return 400 error
|
||||
|
|
@ -129,25 +158,82 @@ struct HAPClient {
|
|||
|
||||
// define static methods
|
||||
|
||||
static void init(); // initialize HAP after start-up
|
||||
static void init(); // initialize HAP after start-up
|
||||
|
||||
static void hexPrintColumn(uint8_t *buf, int n, int minLogLevel=0); // prints 'n' bytes of *buf as HEX, one byte per row, subject to specified minimum log level
|
||||
static void hexPrintRow(uint8_t *buf, int n, int minLogLevel=0); // prints 'n' bytes of *buf as HEX, all on one row, subject to specified minimum log level
|
||||
static void charPrintRow(uint8_t *buf, int n, int minLogLevel=0); // prints 'n' bytes of *buf as CHAR, all on one row, subject to specified minimum log level
|
||||
static void hexPrintColumn(const uint8_t *buf, int n, int minLogLevel=0); // prints 'n' bytes of *buf as HEX, one byte per row, subject to specified minimum log level
|
||||
static void hexPrintRow(const uint8_t *buf, int n, int minLogLevel=0); // prints 'n' bytes of *buf as HEX, all on one row, subject to specified minimum log level
|
||||
static void charPrintRow(const uint8_t *buf, int n, int minLogLevel=0); // prints 'n' bytes of *buf as CHAR, all on one row, subject to specified minimum log level
|
||||
|
||||
static Controller *findController(uint8_t *id); // returns pointer to controller with mathching ID (or NULL if no match)
|
||||
static Controller *getFreeController(); // return pointer to next free controller slot (or NULL if no free slots)
|
||||
static Controller *addController(uint8_t *id, uint8_t *ltpk, boolean admin); // stores data for new Controller with specified data. Returns pointer to Controller slot on success, else NULL
|
||||
static int nAdminControllers(); // returns number of admin Controllers stored
|
||||
static void removeControllers(); // removes all Controllers (sets allocated flags to false for all slots)
|
||||
static Controller *findController(uint8_t *id); // returns pointer to controller with matching ID (or NULL if no match)
|
||||
static tagError addController(uint8_t *id, uint8_t *ltpk, boolean admin); // stores data for new Controller with specified data. Returns tagError (if any)
|
||||
static void removeController(uint8_t *id); // removes specific Controller. If no remaining admin Controllers, remove all others (if any) as per HAP requirements.
|
||||
static void printControllers(int minLogLevel=0); // prints IDs of all allocated (paired) Controller, subject to specified minimum log level
|
||||
static void saveControllers(); // saves Controller list in NVS
|
||||
static int nAdminControllers(); // returns number of admin Controller
|
||||
static void tearDown(uint8_t *id); // tears down connections using Controller with ID=id; tears down all connections if id=NULL
|
||||
static void checkNotifications(); // checks for Event Notifications and reports to controllers as needed (HAP Section 6.8)
|
||||
static void checkTimedWrites(); // checks for expired Timed Write PIDs, and clears any found (HAP Section 6.7.2.4)
|
||||
static void eventNotify(SpanBuf *pObj, int nObj, int ignoreClient=-1); // transmits EVENT Notifications for nObj SpanBuf objects, pObj, with optional flag to ignore a specific client
|
||||
static void eventNotify(SpanBuf *pObj, int nObj, HAPClient *ignore=NULL); // transmits EVENT Notifications for nObj SpanBuf objects, pObj, with optional flag to ignore a specific client
|
||||
|
||||
static void getStatusURL(HAPClient *, void (*)(const char *, void *), void *); // GET / status (an optional, non-HAP feature)
|
||||
|
||||
class HAPTLV : public TLV8 { // dedicated class for HAP TLV8 records
|
||||
public:
|
||||
HAPTLV() : TLV8(HAP_Names,11){}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// HapOut Structure
|
||||
|
||||
class HapOut : public std::ostream {
|
||||
|
||||
private:
|
||||
|
||||
struct HapStreamBuffer : public std::streambuf {
|
||||
|
||||
const size_t bufSize=1024; // max allowed for HAP encrypted records
|
||||
char *buffer;
|
||||
uint8_t *encBuf;
|
||||
HAPClient *hapClient=NULL;
|
||||
int logLevel=255; // default is NOT to print anything
|
||||
boolean enablePrettyPrint=false;
|
||||
size_t byteCount=0;
|
||||
size_t indent=0;
|
||||
uint8_t *hash;
|
||||
mbedtls_sha512_context *ctx;
|
||||
void (*callBack)(const char *, void *)=NULL;
|
||||
void *callBackUserData = NULL;
|
||||
|
||||
void flushBuffer();
|
||||
int_type overflow(int_type c) override;
|
||||
int sync() override;
|
||||
size_t getSize(){return(byteCount+pptr()-pbase());}
|
||||
void printFormatted(char *buf, size_t nChars, size_t nsp);
|
||||
|
||||
HapStreamBuffer();
|
||||
~HapStreamBuffer();
|
||||
|
||||
};
|
||||
|
||||
HapStreamBuffer hapBuffer;
|
||||
|
||||
public:
|
||||
|
||||
HapOut() : std::ostream(&hapBuffer){}
|
||||
|
||||
HapOut& setHapClient(HAPClient *hapClient){hapBuffer.hapClient=hapClient;return(*this);}
|
||||
HapOut& setLogLevel(int logLevel){hapBuffer.logLevel=logLevel;return(*this);}
|
||||
HapOut& prettyPrint(){hapBuffer.enablePrettyPrint=true;hapBuffer.logLevel=0;return(*this);}
|
||||
HapOut& setCallback(void(*f)(const char *, void *)){hapBuffer.callBack=f;return(*this);}
|
||||
HapOut& setCallbackUserData(void *userData){hapBuffer.callBackUserData=userData;return(*this);}
|
||||
|
||||
uint8_t *getHash(){return(hapBuffer.hash);}
|
||||
size_t getSize(){return(hapBuffer.getSize());}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Extern Variables
|
||||
|
||||
extern HAPClient **hap;
|
||||
extern HapOut hapOut;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -52,6 +52,7 @@ typedef enum {
|
|||
// HAP Error Codes (HAP Table 5-5)
|
||||
|
||||
typedef enum {
|
||||
tagError_None=0x00,
|
||||
tagError_Unknown=0x01,
|
||||
tagError_Authentication=0x02,
|
||||
tagError_Backoff=0x03,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -38,6 +38,6 @@
|
|||
// incorporated under hkdf.cpp, with a wrapper to always
|
||||
// use SHA-512 with 32 bytes of output as required by HAP.
|
||||
|
||||
struct HKDF {
|
||||
namespace HKDF{
|
||||
int create(uint8_t *outputKey, uint8_t *inputKey, int inputLen, const char *salt, const char *info); // output of HKDF is always a 32-byte key derived from an input key, a salt string, and an info string
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
1262
src/HomeSpan.cpp
1262
src/HomeSpan.cpp
File diff suppressed because it is too large
Load Diff
639
src/HomeSpan.h
639
src/HomeSpan.h
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -27,9 +27,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef ARDUINO_ARCH_ESP32
|
||||
#error ERROR: HOMESPAN IS ONLY AVAILABLE FOR ESP32 MICROCONTROLLERS!
|
||||
#endif
|
||||
#include "version.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wpmf-conversions" // eliminates warning messages from use of pointers to member functions to detect whether update() and loop() are overridden by user
|
||||
#pragma GCC diagnostic ignored "-Wunused-result" // eliminates warning message regarded unused result from call to crypto_scalarmult_curve25519()
|
||||
|
|
@ -37,24 +35,29 @@
|
|||
#include <Arduino.h>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <unordered_set>
|
||||
#include <list>
|
||||
#include <nvs.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <esp_now.h>
|
||||
#include <mbedtls/base64.h>
|
||||
|
||||
#include "extras/Blinker.h"
|
||||
#include "extras/Pixel.h"
|
||||
#include "src/extras/Blinker.h"
|
||||
#include "src/extras/Pixel.h"
|
||||
#include "src/extras/RFControl.h"
|
||||
#include "src/extras/PwmPin.h"
|
||||
#include "src/extras/StepperControl.h"
|
||||
|
||||
#include "Settings.h"
|
||||
#include "Utils.h"
|
||||
#include "Network.h"
|
||||
#include "HAPConstants.h"
|
||||
#include "HapQR.h"
|
||||
#include "Characteristics.h"
|
||||
#include "TLV8.h"
|
||||
|
||||
using std::vector;
|
||||
using std::unordered_map;
|
||||
using std::unordered_set;
|
||||
using std::list;
|
||||
|
||||
enum {
|
||||
GET_AID=1,
|
||||
|
|
@ -64,9 +67,24 @@ enum {
|
|||
GET_EV=16,
|
||||
GET_DESC=32,
|
||||
GET_NV=64,
|
||||
GET_VALUE=128
|
||||
GET_VALUE=128,
|
||||
GET_STATUS=256
|
||||
};
|
||||
|
||||
typedef boolean BOOL_t;
|
||||
typedef uint8_t UINT8_t;
|
||||
typedef uint16_t UINT16_t;
|
||||
typedef uint32_t UINT32_t;
|
||||
typedef uint64_t UINT64_t;
|
||||
typedef int32_t INT_t;
|
||||
typedef double FLOAT_t;
|
||||
typedef const char * STRING_t;
|
||||
typedef const TLV8 & TLV_ENC_t;
|
||||
typedef std::pair<const uint8_t *, size_t> DATA_t;
|
||||
|
||||
static DATA_t NULL_DATA={NULL,0};
|
||||
static TLV8 NULL_TLV{};
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
#define STATUS_UPDATE(LED_UPDATE,MESSAGE_UPDATE) {homeSpan.statusLED->LED_UPDATE;if(homeSpan.statusCallback)homeSpan.statusCallback(MESSAGE_UPDATE);}
|
||||
|
|
@ -103,11 +121,13 @@ struct Span;
|
|||
struct SpanAccessory;
|
||||
struct SpanService;
|
||||
struct SpanCharacteristic;
|
||||
struct SpanRange;
|
||||
struct SpanBuf;
|
||||
struct SpanButton;
|
||||
struct SpanUserCommand;
|
||||
|
||||
struct HAPClient;
|
||||
class Controller;
|
||||
|
||||
extern Span homeSpan;
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
|
@ -130,7 +150,8 @@ struct SpanConfig{
|
|||
|
||||
struct SpanBuf{ // temporary storage buffer for use with putCharacteristicsURL() and checkTimedResets()
|
||||
uint32_t aid=0; // updated aid
|
||||
int iid=0; // updated iid
|
||||
uint32_t iid=0; // updated iid
|
||||
boolean wr=false; // flag to indicate write-response has been requested
|
||||
char *val=NULL; // updated value (optional, though either at least 'val' or 'ev' must be specified)
|
||||
char *ev=NULL; // updated event notification flag (optional, though either at least 'val' or 'ev' must be specified)
|
||||
StatusCode status; // return status (HAP Table 6-11)
|
||||
|
|
@ -143,7 +164,7 @@ struct SpanWebLog{ // optional web status/log data
|
|||
boolean isEnabled=false; // flag to inidicate WebLog has been enabled
|
||||
uint16_t maxEntries=0; // max number of log entries;
|
||||
int nEntries=0; // total cumulative number of log entries
|
||||
const char *timeServer; // optional time server to use for acquiring clock time
|
||||
const char *timeServer=NULL; // optional time server to use for acquiring clock time
|
||||
const char *timeZone; // optional time-zone specification
|
||||
boolean timeInit=false; // flag to indicate time has been initialized
|
||||
char bootTime[33]="Unknown"; // boot time
|
||||
|
|
@ -193,31 +214,35 @@ class Span{
|
|||
friend class SpanCharacteristic;
|
||||
friend class SpanUserCommand;
|
||||
friend class SpanButton;
|
||||
friend class SpanRange;
|
||||
friend class SpanWebLog;
|
||||
friend class SpanOTA;
|
||||
friend class Network;
|
||||
friend class HAPClient;
|
||||
|
||||
const char *displayName; // display name for this device - broadcast as part of Bonjour MDNS
|
||||
const char *hostNameBase; // base of hostName of this device - full host name broadcast by Bonjour MDNS will have 6-byte accessoryID as well as '.local' automatically appended
|
||||
const char *hostNameSuffix=NULL; // optional "suffix" of hostName of this device. If specified, will be used as the hostName suffix instead of the 6-byte accessoryID
|
||||
char *hostName; // full host name of this device - constructed from hostNameBase and 6-byte AccessoryID
|
||||
const char *modelName; // model name of this device - broadcast as Bonjour field "md"
|
||||
char *displayName; // display name for this device - broadcast as part of Bonjour MDNS
|
||||
char *hostNameBase; // base of hostName of this device - full host name broadcast by Bonjour MDNS will have 6-byte accessoryID as well as '.local' automatically appended
|
||||
char *hostNameSuffix=NULL; // optional "suffix" of hostName of this device. If specified, will be used as the hostName suffix instead of the 6-byte accessoryID
|
||||
char *hostName=NULL; // derived full hostname
|
||||
char *modelName; // model name of this device - broadcast as Bonjour field "md"
|
||||
char category[3]=""; // category ID of primary accessory - broadcast as Bonjour field "ci" (HAP Section 13)
|
||||
unsigned long snapTime; // current time (in millis) snapped before entering Service loops() or updates()
|
||||
boolean isInitialized=false; // flag indicating HomeSpan has been initialized
|
||||
boolean isBridge=true; // flag indicating whether device is configured as a bridge (i.e. first Accessory contains nothing but AccessoryInformation and HAPProtocolInformation)
|
||||
HapQR qrCode; // optional QR Code to use for pairing
|
||||
const char *sketchVersion="n/a"; // version of the sketch
|
||||
nvs_handle charNVS; // handle for non-volatile-storage of Characteristics data
|
||||
nvs_handle wifiNVS=0; // handle for non-volatile-storage of WiFi data
|
||||
nvs_handle otaNVS; // handle for non-volatile storaget of OTA data
|
||||
char pairingCodeCommand[12]=""; // user-specified Pairing Code - only needed if Pairing Setup Code is specified in sketch using setPairingCode()
|
||||
String lastClientIP="0.0.0.0"; // IP address of last client accessing device through encrypted channel
|
||||
boolean newCode; // flag indicating new application code has been loaded (based on keeping track of app SHA256)
|
||||
boolean serialInputDisabled=false; // flag indiating that serial input is disabled
|
||||
uint8_t rebootCount=0; // counts number of times device was rebooted (used in optional Reboot callback)
|
||||
uint32_t rebootCallbackTime; // length of time to wait (in milliseconds) before calling optional Reboot callback
|
||||
|
||||
nvs_handle charNVS; // handle for non-volatile-storage of Characteristics data
|
||||
nvs_handle wifiNVS=0; // handle for non-volatile-storage of WiFi data
|
||||
nvs_handle otaNVS; // handle for non-volatile storage of OTA data
|
||||
nvs_handle srpNVS; // handle for non-volatile storage of SRP data
|
||||
nvs_handle hapNVS; // handle for non-volatile-storage of HAP data
|
||||
|
||||
int connected=0; // WiFi connection status (increments upon each connect and disconnect)
|
||||
unsigned long waitTime=60000; // time to wait (in milliseconds) between WiFi connection attempts
|
||||
unsigned long alarmConnect=0; // time after which WiFi connection attempt should be tried again
|
||||
|
|
@ -225,16 +250,18 @@ class Span{
|
|||
const char *defaultSetupCode=DEFAULT_SETUP_CODE; // Setup Code used for pairing
|
||||
uint16_t autoOffLED=0; // automatic turn-off duration (in seconds) for Status LED
|
||||
int logLevel=DEFAULT_LOG_LEVEL; // level for writing out log messages to serial monitor
|
||||
uint8_t maxConnections=CONFIG_LWIP_MAX_SOCKETS-2; // maximum number of allowed simultaneous HAP connections
|
||||
uint8_t requestedMaxCon=CONFIG_LWIP_MAX_SOCKETS-2; // requested maximum number of simultaneous HAP connections
|
||||
unsigned long comModeLife=DEFAULT_COMMAND_TIMEOUT*1000; // length of time (in milliseconds) to keep Command Mode alive before resuming normal operations
|
||||
uint16_t tcpPortNum=DEFAULT_TCP_PORT; // port for TCP communications between HomeKit and HomeSpan
|
||||
char qrID[5]=""; // Setup ID used for pairing with QR Code
|
||||
void (*wifiCallback)()=NULL; // optional callback function to invoke once WiFi connectivity is established
|
||||
void (*wifiCallback)()=NULL; // optional callback function to invoke once WiFi connectivity is initially established
|
||||
void (*wifiCallbackAll)(int)=NULL; // optional callback function to invoke every time WiFi connectivity is established or re-established
|
||||
void (*weblogCallback)(String &)=NULL; // optional callback function to invoke after header table in Web Log is produced
|
||||
void (*pairCallback)(boolean isPaired)=NULL; // optional callback function to invoke when pairing is established (true) or lost (false)
|
||||
boolean autoStartAPEnabled=false; // enables auto start-up of Access Point when WiFi Credentials not found
|
||||
void (*apFunction)()=NULL; // optional function to invoke when starting Access Point
|
||||
void (*statusCallback)(HS_STATUS status)=NULL; // optional callback when HomeSpan status changes
|
||||
void (*rebootCallback)(uint8_t)=NULL; // optional callback when device reboots
|
||||
void (*controllerCallback)()=NULL; // optional callback when Controller is added/removed/changed
|
||||
|
||||
WiFiServer *hapServer; // pointer to the HAP Server connection
|
||||
Blinker *statusLED; // indicates HomeSpan status
|
||||
|
|
@ -243,43 +270,50 @@ class Span{
|
|||
Network network; // configures WiFi and Setup Code via either serial monitor or temporary Access Point
|
||||
SpanWebLog webLog; // optional web status/log
|
||||
TaskHandle_t pollTaskHandle = NULL; // optional task handle to use for poll() function
|
||||
TaskHandle_t loopTaskHandle; // Arduino Loop Task handle
|
||||
boolean verboseWifiReconnect = true; // set to false to not print WiFi reconnect attempts messages
|
||||
|
||||
SpanOTA spanOTA; // manages OTA process
|
||||
SpanConfig hapConfig; // track configuration changes to the HAP Accessory database; used to increment the configuration number (c#) when changes found
|
||||
vector<SpanAccessory *> Accessories; // vector of pointers to all Accessories
|
||||
vector<SpanService *> Loops; // vector of pointer to all Services that have over-ridden loop() methods
|
||||
vector<SpanBuf> Notifications; // vector of SpanBuf objects that store info for Characteristics that are updated with setVal() and require a Notification Event
|
||||
vector<SpanButton *> PushButtons; // vector of pointer to all PushButtons
|
||||
unordered_map<uint64_t, uint32_t> TimedWrites; // map of timed-write PIDs and Alarm Times (based on TTLs)
|
||||
|
||||
unordered_map<char, SpanUserCommand *> UserCommands; // map of pointers to all UserCommands
|
||||
|
||||
list<HAPClient, Mallocator<HAPClient>> hapList; // linked-list of HAPClient structures containing HTTP client connections, parsing routines, and state variables
|
||||
list<HAPClient, Mallocator<HAPClient>>::iterator currentClient; // iterator to current client
|
||||
vector<SpanAccessory *, Mallocator<SpanAccessory *>> Accessories; // vector of pointers to all Accessories
|
||||
vector<SpanService *, Mallocator<SpanService *>> Loops; // vector of pointer to all Services that have over-ridden loop() methods
|
||||
vector<SpanBuf, Mallocator<SpanBuf>> Notifications; // vector of SpanBuf objects that store info for Characteristics that are updated with setVal() and require a Notification Event
|
||||
vector<SpanButton *, Mallocator<SpanButton *>> PushButtons; // vector of pointer to all PushButtons
|
||||
unordered_map<uint64_t, uint32_t> TimedWrites; // map of timed-write PIDs and Alarm Times (based on TTLs)
|
||||
unordered_map<char, SpanUserCommand *> UserCommands; // map of pointers to all UserCommands
|
||||
|
||||
void pollTask(); // poll HAP Clients and process any new HAP requests
|
||||
int getFreeSlot(); // returns free HAPClient slot number. HAPClients slot keep track of each active HAPClient connection
|
||||
void checkConnect(); // check WiFi connection; connect if needed
|
||||
void commandMode(); // allows user to control and reset HomeSpan settings with the control button
|
||||
void resetStatus(); // resets statusLED and calls statusCallback based on current HomeSpan status
|
||||
void reboot(); // reboots device
|
||||
|
||||
int sprintfAttributes(char *cBuf, int flags=GET_VALUE|GET_META|GET_PERMS|GET_TYPE|GET_DESC); // prints Attributes JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator
|
||||
void printfAttributes(int flags=GET_VALUE|GET_META|GET_PERMS|GET_TYPE|GET_DESC); // writes Attributes JSON database to hapOut stream
|
||||
|
||||
void prettyPrint(char *buf, int nsp=2, int minLogLevel=0); // print arbitrary JSON from buf to serial monitor, formatted with indentions of 'nsp' spaces, subject to specified minimum log level
|
||||
SpanCharacteristic *find(uint32_t aid, int iid); // return Characteristic with matching aid and iid (else NULL if not found)
|
||||
SpanCharacteristic *find(uint32_t aid, uint32_t iid); // return Characteristic with matching aid and iid (else NULL if not found)
|
||||
int countCharacteristics(char *buf); // return number of characteristic objects referenced in PUT /characteristics JSON request
|
||||
int updateCharacteristics(char *buf, SpanBuf *pObj); // parses PUT /characteristics JSON request 'buf into 'pObj' and updates referenced characteristics; returns 1 on success, 0 on fail
|
||||
int sprintfAttributes(SpanBuf *pObj, int nObj, char *cBuf); // prints SpanBuf object into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
|
||||
int sprintfAttributes(char **ids, int numIDs, int flags, char *cBuf); // prints accessory.characteristic ids into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
|
||||
void clearNotify(int slotNum); // set ev notification flags for connection 'slotNum' to false across all characteristics
|
||||
int sprintfNotify(SpanBuf *pObj, int nObj, char *cBuf, int conNum); // prints notification JSON into buf based on SpanBuf objects and specified connection number
|
||||
void printfAttributes(SpanBuf *pObj, int nObj); // writes SpanBuf objects to hapOut stream
|
||||
boolean printfAttributes(char **ids, int numIDs, int flags); // writes accessory requested characteristic ids to hapOut stream - returns true if all characteristics are found and readable, else returns false
|
||||
void clearNotify(HAPClient *hc); // clear all notifications related to specific client connection
|
||||
void printfNotify(SpanBuf *pObj, int nObj, HAPClient *hc); // writes notification JSON to hapOut stream based on SpanBuf objects and specified connection
|
||||
|
||||
static boolean invalidUUID(const char *uuid, boolean isCustom){
|
||||
static boolean invalidUUID(const char *uuid){
|
||||
int x=0;
|
||||
sscanf(uuid,"%*8[0-9a-fA-F]%n",&x); // check for short-form of UUID
|
||||
if(strlen(uuid)==x && uuid[0]!='0')
|
||||
return(false);
|
||||
sscanf(uuid,"%*8[0-9a-fA-F]-%*4[0-9a-fA-F]-%*4[0-9a-fA-F]-%*4[0-9a-fA-F]-%*12[0-9a-fA-F]%n",&x);
|
||||
return(isCustom && (strlen(uuid)!=36 || x!=36));
|
||||
return(strlen(uuid)!=36 || x!=36);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Span(); // constructor
|
||||
|
||||
void begin(Category catID=DEFAULT_CATEGORY,
|
||||
const char *displayName=DEFAULT_DISPLAY_NAME,
|
||||
const char *hostNameBase=DEFAULT_HOST_NAME,
|
||||
|
|
@ -291,49 +325,57 @@ class Span{
|
|||
boolean updateDatabase(boolean updateMDNS=true); // updates HAP Configuration Number and Loop vector; if updateMDNS=true and config number has changed, re-broadcasts MDNS 'c#' record; returns true if config number changed
|
||||
boolean deleteAccessory(uint32_t aid); // deletes Accessory with matching aid; returns true if found, else returns false
|
||||
|
||||
void setControlPin(uint8_t pin){controlButton=new PushButton(pin);} // sets Control Pin
|
||||
void setStatusPin(uint8_t pin){statusDevice=new GenericLED(pin);} // sets Status Device to a simple LED on specified pin
|
||||
void setStatusAutoOff(uint16_t duration){autoOffLED=duration;} // sets Status LED auto off (seconds)
|
||||
int getStatusPin(){return(statusLED->getPin());} // get Status Pin (getPin will return -1 if underlying statusDevice is undefined)
|
||||
int getControlPin(){return(controlButton?controlButton->getPin():-1);} // get Control Pin (returns -1 if undefined)
|
||||
|
||||
void setStatusPixel(uint8_t pin,float h=0,float s=100,float v=100){ // sets Status Device to an RGB Pixel on specified pin
|
||||
Span& setControlPin(uint8_t pin, PushButton::triggerType_t triggerType=PushButton::TRIGGER_ON_LOW){ // sets Control Pin, with optional trigger type
|
||||
controlButton=new PushButton(pin, triggerType);
|
||||
return(*this);
|
||||
}
|
||||
|
||||
int getControlPin(){return(controlButton?controlButton->getPin():-1);} // get Control Pin (returns -1 if undefined)
|
||||
|
||||
Span& setStatusPin(uint8_t pin){statusDevice=new GenericLED(pin);return(*this);} // sets Status Device to a simple LED on specified pin
|
||||
Span& setStatusPixel(uint8_t pin,float h=0,float s=100,float v=100){ // sets Status Device to an RGB Pixel on specified pin
|
||||
statusDevice=((new Pixel(pin))->setOnColor(Pixel::HSV(h,s,v)));
|
||||
return(*this);
|
||||
}
|
||||
|
||||
void setStatusDevice(Blinkable *sDev){statusDevice=sDev;}
|
||||
void refreshStatusDevice(){if(statusLED)statusLED->refresh();}
|
||||
|
||||
void setApSSID(const char *ssid){network.apSSID=ssid;} // sets Access Point SSID
|
||||
void setApPassword(const char *pwd){network.apPassword=pwd;} // sets Access Point Password
|
||||
void setApTimeout(uint16_t nSec){network.lifetime=nSec*1000;} // sets Access Point Timeout (seconds)
|
||||
void setCommandTimeout(uint16_t nSec){comModeLife=nSec*1000;} // sets Command Mode Timeout (seconds)
|
||||
void setLogLevel(int level){logLevel=level;} // sets Log Level for log messages (0=baseline, 1=intermediate, 2=all, -1=disable all serial input/output)
|
||||
int getLogLevel(){return(logLevel);} // get Log Level
|
||||
void setSerialInputDisable(boolean val){serialInputDisabled=val;} // sets whether serial input is disabled (true) or enabled (false)
|
||||
boolean getSerialInputDisable(){return(serialInputDisabled);} // returns true if serial input is disabled, or false if serial input in enabled
|
||||
void reserveSocketConnections(uint8_t n){maxConnections-=n;} // reserves n socket connections *not* to be used for HAP
|
||||
void setHostNameSuffix(const char *suffix){hostNameSuffix=suffix;} // sets the hostName suffix to be used instead of the 6-byte AccessoryID
|
||||
void setPortNum(uint16_t port){tcpPortNum=port;} // sets the TCP port number to use for communications between HomeKit and HomeSpan
|
||||
void setQRID(const char *id); // sets the Setup ID for optional pairing with a QR Code
|
||||
void setSketchVersion(const char *sVer){sketchVersion=sVer;} // set optional sketch version number
|
||||
const char *getSketchVersion(){return sketchVersion;} // get sketch version number
|
||||
void setWifiCallback(void (*f)()){wifiCallback=f;} // sets an optional user-defined function to call once WiFi connectivity is established
|
||||
void setPairCallback(void (*f)(boolean isPaired)){pairCallback=f;} // sets an optional user-defined function to call when Pairing is established (true) or lost (false)
|
||||
void setApFunction(void (*f)()){apFunction=f;} // sets an optional user-defined function to call when activating the WiFi Access Point
|
||||
void enableAutoStartAP(){autoStartAPEnabled=true;} // enables auto start-up of Access Point when WiFi Credentials not found
|
||||
void setWifiCredentials(const char *ssid, const char *pwd); // sets WiFi Credentials
|
||||
void setStatusCallback(void (*f)(HS_STATUS status)){statusCallback=f;} // sets an optional user-defined function to call when HomeSpan status changes
|
||||
const char* statusString(HS_STATUS s); // returns char string for HomeSpan status change messages
|
||||
Span& setStatusDevice(Blinkable *sDev){statusDevice=sDev;return(*this);} // sets Status Device to a generic Blinkable object
|
||||
|
||||
void setPairingCode(const char *s){sprintf(pairingCodeCommand,"S %9s",s);} // sets the Pairing Code - use is NOT recommended. Use 'S' from CLI instead
|
||||
void deleteStoredValues(){processSerialCommand("V");} // deletes stored Characteristic values from NVS
|
||||
Span& setStatusAutoOff(uint16_t duration){autoOffLED=duration;return(*this);} // sets Status LED auto off (seconds)
|
||||
int getStatusPin(){return(statusLED->getPin());} // get Status Pin (returns -1 if undefined)
|
||||
void refreshStatusDevice(){if(statusLED)statusLED->refresh();} // refreshes state of Status LED
|
||||
|
||||
Span& setApSSID(const char *ssid){network.apSSID=ssid;return(*this);} // sets Access Point SSID
|
||||
Span& setApPassword(const char *pwd){network.apPassword=pwd;return(*this);} // sets Access Point Password
|
||||
Span& setApTimeout(uint16_t nSec){network.lifetime=nSec*1000;return(*this);} // sets Access Point Timeout (seconds)
|
||||
Span& setCommandTimeout(uint16_t nSec){comModeLife=nSec*1000;return(*this);} // sets Command Mode Timeout (seconds)
|
||||
Span& setLogLevel(int level){logLevel=level;return(*this);} // sets Log Level for log messages (0=baseline, 1=intermediate, 2=all, -1=disable all serial input/output)
|
||||
int getLogLevel(){return(logLevel);} // get Log Level
|
||||
Span& setSerialInputDisable(boolean val){serialInputDisabled=val;return(*this);} // sets whether serial input is disabled (true) or enabled (false)
|
||||
boolean getSerialInputDisable(){return(serialInputDisabled);} // returns true if serial input is disabled, or false if serial input in enabled
|
||||
Span& setPortNum(uint16_t port){tcpPortNum=port;return(*this);} // sets the TCP port number to use for communications between HomeKit and HomeSpan
|
||||
Span& setQRID(const char *id); // sets the Setup ID for optional pairing with a QR Code
|
||||
Span& setSketchVersion(const char *sVer){sketchVersion=sVer;return(*this);} // set optional sketch version number
|
||||
const char *getSketchVersion(){return sketchVersion;} // get sketch version number
|
||||
Span& setWifiCallback(void (*f)()){wifiCallback=f;return(*this);} // sets an optional user-defined function to call once WiFi connectivity is initially established
|
||||
Span& setWifiCallbackAll(void (*f)(int)){wifiCallbackAll=f;return(*this);} // sets an optional user-defined function to call every time WiFi connectivity is established or re-established
|
||||
Span& setPairCallback(void (*f)(boolean isPaired)){pairCallback=f;return(*this);} // sets an optional user-defined function to call when Pairing is established (true) or lost (false)
|
||||
Span& setApFunction(void (*f)()){apFunction=f;return(*this);} // sets an optional user-defined function to call when activating the WiFi Access Point
|
||||
Span& enableAutoStartAP(){autoStartAPEnabled=true;return(*this);} // enables auto start-up of Access Point when WiFi Credentials not found
|
||||
Span& setWifiCredentials(const char *ssid, const char *pwd); // sets WiFi Credentials
|
||||
Span& setStatusCallback(void (*f)(HS_STATUS status)){statusCallback=f;return(*this);} // sets an optional user-defined function to call when HomeSpan status changes
|
||||
const char* statusString(HS_STATUS s); // returns char string for HomeSpan status change messages
|
||||
Span& setPairingCode(const char *s, boolean progCall=true); // sets the Pairing Code - use is NOT recommended. Use 'S' from CLI instead
|
||||
void deleteStoredValues(){processSerialCommand("V");} // deletes stored Characteristic values from NVS
|
||||
Span& resetIID(uint32_t newIID); // resets the IID count for the current Accessory to start at newIID
|
||||
Span& setControllerCallback(void (*f)()){controllerCallback=f;return(*this);} // sets an optional user-defined function to call whenever a Controller is added/removed/changed
|
||||
|
||||
Span& setHostNameSuffix(const char *suffix){asprintf(&hostNameSuffix,"%s",suffix);return(*this);} // sets the hostName suffix to be used instead of the 6-byte AccessoryID
|
||||
|
||||
int enableOTA(boolean auth=true, boolean safeLoad=true){return(spanOTA.init(auth, safeLoad, NULL));} // enables Over-the-Air updates, with (auth=true) or without (auth=false) authorization password
|
||||
int enableOTA(const char *pwd, boolean safeLoad=true){return(spanOTA.init(true, safeLoad, pwd));} // enables Over-the-Air updates, with custom authorization password (overrides any password stored with the 'O' command)
|
||||
|
||||
void enableWebLog(uint16_t maxEntries=0, const char *serv=NULL, const char *tz="UTC", const char *url=DEFAULT_WEBLOG_URL){ // enable Web Logging
|
||||
Span& enableWebLog(uint16_t maxEntries=0, const char *serv=NULL, const char *tz="UTC", const char *url=DEFAULT_WEBLOG_URL){ // enable Web Logging
|
||||
webLog.init(maxEntries, serv, tz, url);
|
||||
return(*this);
|
||||
}
|
||||
|
||||
void addWebLog(boolean sysMsg, const char *fmt, ...){ // add Web Log entry
|
||||
|
|
@ -343,17 +385,35 @@ class Span{
|
|||
va_end(ap);
|
||||
}
|
||||
|
||||
void setWebLogCSS(const char *css){webLog.css="\n" + String(css) + "\n";}
|
||||
Span& setWebLogCSS(const char *css){webLog.css="\n" + String(css) + "\n";return(*this);}
|
||||
Span& setWebLogCallback(void (*f)(String &)){weblogCallback=f;return(*this);}
|
||||
void getWebLog(void (*f)(const char *, void *), void *);
|
||||
|
||||
Span& setVerboseWifiReconnect(bool verbose=true){verboseWifiReconnect=verbose;return(*this);}
|
||||
|
||||
Span& setRebootCallback(void (*f)(uint8_t),uint32_t t=DEFAULT_REBOOT_CALLBACK_TIME){rebootCallback=f;rebootCallbackTime=t;return(*this);}
|
||||
|
||||
void autoPoll(uint32_t stackSize=8192, uint32_t priority=1, uint32_t cpu=0){ // start pollTask()
|
||||
xTaskCreateUniversal([](void *parms){for(;;)homeSpan.pollTask();}, "pollTask", stackSize, NULL, priority, &pollTaskHandle, cpu);
|
||||
xTaskCreateUniversal([](void *parms){
|
||||
for(;;){
|
||||
homeSpan.pollTask();
|
||||
vTaskDelay(5);
|
||||
}
|
||||
},
|
||||
"pollTask", stackSize, NULL, priority, &pollTaskHandle, cpu);
|
||||
LOG0("\n*** AutoPolling Task started with priority=%d\n\n",uxTaskPriorityGet(pollTaskHandle));
|
||||
}
|
||||
|
||||
void setTimeServerTimeout(uint32_t tSec){webLog.waitTime=tSec*1000;} // sets wait time (in seconds) for optional web log time server to connect
|
||||
|
||||
[[deprecated("Please use reserveSocketConnections(n) method instead.")]]
|
||||
void setMaxConnections(uint8_t n){requestedMaxCon=n;} // sets maximum number of simultaneous HAP connections
|
||||
TaskHandle_t getAutoPollTask(){return(pollTaskHandle);}
|
||||
|
||||
Span& setTimeServerTimeout(uint32_t tSec){webLog.waitTime=tSec*1000;return(*this);} // sets wait time (in seconds) for optional web log time server to connect
|
||||
|
||||
list<Controller, Mallocator<Controller>>::const_iterator controllerListBegin();
|
||||
list<Controller, Mallocator<Controller>>::const_iterator controllerListEnd();
|
||||
|
||||
[[deprecated("This function has been deprecated (it is not needed) and no longer does anything. Please remove from sketch to ensure backwards compatilibilty with future versions.")]]
|
||||
Span& reserveSocketConnections(uint8_t n){return(*this);}
|
||||
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
|
|
@ -364,21 +424,21 @@ class SpanAccessory{
|
|||
friend class SpanService;
|
||||
friend class SpanCharacteristic;
|
||||
friend class SpanButton;
|
||||
friend class SpanRange;
|
||||
|
||||
uint32_t aid=0; // Accessory Instance ID (HAP Table 6-1)
|
||||
int iidCount=0; // running count of iid to use for Services and Characteristics associated with this Accessory
|
||||
vector<SpanService *> Services; // vector of pointers to all Services in this Accessory
|
||||
uint32_t aid=0; // Accessory Instance ID (HAP Table 6-1)
|
||||
uint32_t iidCount=0; // running count of iid to use for Services and Characteristics associated with this Accessory
|
||||
vector<SpanService *, Mallocator<SpanService*>> Services; // vector of pointers to all Services in this Accessory
|
||||
|
||||
int sprintfAttributes(char *cBuf, int flags); // prints Accessory JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
|
||||
void printfAttributes(int flags); // writes Accessory JSON to hapOut stream
|
||||
|
||||
protected:
|
||||
|
||||
~SpanAccessory(); // destructor
|
||||
~SpanAccessory(); // destructor
|
||||
|
||||
public:
|
||||
|
||||
SpanAccessory(uint32_t aid=0); // constructor
|
||||
|
||||
void *operator new(size_t size){return(HS_MALLOC(size));} // override new operator to use PSRAM when available
|
||||
SpanAccessory(uint32_t aid=0); // constructor
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
|
|
@ -388,33 +448,43 @@ class SpanService{
|
|||
friend class Span;
|
||||
friend class SpanAccessory;
|
||||
friend class SpanCharacteristic;
|
||||
friend class SpanRange;
|
||||
|
||||
int iid=0; // Instance ID (HAP Table 6-2)
|
||||
const char *type; // Service Type
|
||||
const char *hapName; // HAP Name
|
||||
boolean hidden=false; // optional property indicating service is hidden
|
||||
boolean primary=false; // optional property indicating service is primary
|
||||
vector<SpanCharacteristic *> Characteristics; // vector of pointers to all Characteristics in this Service
|
||||
vector<SpanService *> linkedServices; // vector of pointers to any optional linked Services
|
||||
boolean isCustom; // flag to indicate this is a Custom Service
|
||||
SpanAccessory *accessory=NULL; // pointer to Accessory containing this Service
|
||||
uint32_t iid=0; // Instance ID (HAP Table 6-2)
|
||||
const char *type; // Service Type
|
||||
const char *hapName; // HAP Name
|
||||
boolean hidden=false; // optional property indicating service is hidden
|
||||
boolean primary=false; // optional property indicating service is primary
|
||||
vector<SpanCharacteristic *, Mallocator<SpanCharacteristic*>> Characteristics; // vector of pointers to all Characteristics in this Service
|
||||
vector<SpanService *, Mallocator<SpanService *>> linkedServices; // vector of pointers to any optional linked Services
|
||||
boolean isCustom; // flag to indicate this is a Custom Service
|
||||
SpanAccessory *accessory=NULL; // pointer to Accessory containing this Service
|
||||
|
||||
int sprintfAttributes(char *cBuf, int flags); // prints Service JSON records into buf; return number of characters printed, excluding null terminator
|
||||
void printfAttributes(int flags); // writes Service JSON to hapOut stream
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~SpanService(); // destructor
|
||||
unordered_set<HapChar *> req; // unordered set of pointers to all required HAP Characteristic Types for this Service
|
||||
unordered_set<HapChar *> opt; // unordered set of pointers to all optional HAP Characteristic Types for this Service
|
||||
virtual ~SpanService(); // destructor
|
||||
vector<HapChar *, Mallocator<HapChar*>> req; // vector of pointers to all required HAP Characteristic Types for this Service
|
||||
vector<HapChar *, Mallocator<HapChar*>> opt; // vector of pointers to all optional HAP Characteristic Types for this Service
|
||||
|
||||
public:
|
||||
|
||||
SpanService(const char *type, const char *hapName, boolean isCustom=false); // constructor
|
||||
SpanService *setPrimary(); // sets the Service Type to be primary and returns pointer to self
|
||||
SpanService *setHidden(); // sets the Service Type to be hidden and returns pointer to self
|
||||
SpanService *addLink(SpanService *svc); // adds svc as a Linked Service and returns pointer to self
|
||||
vector<SpanService *> getLinks(){return(linkedServices);} // returns linkedServices vector for use as range in "for-each" loops
|
||||
void *operator new(size_t size){return(HS_MALLOC(size));} // override new operator to use PSRAM when available
|
||||
SpanService(const char *type, const char *hapName, boolean isCustom=false); // constructor
|
||||
SpanService *setPrimary(); // sets the Service Type to be primary and returns pointer to self
|
||||
SpanService *setHidden(); // sets the Service Type to be hidden and returns pointer to self
|
||||
SpanService *addLink(SpanService *svc); // adds svc as a Linked Service and returns pointer to self
|
||||
|
||||
template <typename T=SpanService *> vector<T, Mallocator<T>> getLinks(const char *hapName=NULL){ // returns linkedServices vector, mapped to <T>, for use as range in "for-each" loops
|
||||
vector<T, Mallocator<T>> v;
|
||||
for(auto svc : linkedServices){
|
||||
if(hapName==NULL || !strcmp(hapName,svc->hapName))
|
||||
v.push_back(static_cast<T>(svc));
|
||||
}
|
||||
return(v);
|
||||
}
|
||||
|
||||
uint32_t getIID(){return(iid);} // returns IID of Service
|
||||
|
||||
virtual boolean update() {return(true);} // placeholder for code that is called when a Service is updated via a Controller. Must return true/false depending on success of update
|
||||
virtual void loop(){} // loops for each Service - called every cycle if over-ridden with user-defined code
|
||||
|
|
@ -429,17 +499,24 @@ class SpanCharacteristic{
|
|||
friend class SpanService;
|
||||
|
||||
union UVal {
|
||||
BOOL_t BOOL;
|
||||
UINT8_t UINT8;
|
||||
UINT16_t UINT16;
|
||||
UINT32_t UINT32;
|
||||
UINT64_t UINT64;
|
||||
INT_t INT;
|
||||
FLOAT_t FLOAT;
|
||||
STRING_t STRING = NULL;
|
||||
boolean BOOL;
|
||||
uint8_t UINT8;
|
||||
uint16_t UINT16;
|
||||
uint32_t UINT32;
|
||||
uint64_t UINT64;
|
||||
int32_t INT;
|
||||
double FLOAT;
|
||||
char * STRING = NULL;
|
||||
};
|
||||
|
||||
int iid=0; // Instance ID (HAP Table 6-3)
|
||||
class EVLIST : public vector<HAPClient *, Mallocator<HAPClient *>>{ // vector of current connections that have subscribed to EV notifications for this Characteristic
|
||||
public:
|
||||
boolean has(HAPClient *hc); // returns true if pointer to connection hc is subscribed, else returns false
|
||||
void add(HAPClient *hc); // adds connection hc as new subscriber, IF not already a subscriber
|
||||
void remove(HAPClient *hc); // removes connection hc as a subscriber; okay to remove even if hc was not already a subscriber
|
||||
};
|
||||
|
||||
uint32_t iid=0; // Instance ID (HAP Table 6-3)
|
||||
HapChar *hapChar; // pointer to HAP Characteristic structure
|
||||
const char *type; // Characteristic Type
|
||||
const char *hapName; // HAP Name
|
||||
|
|
@ -454,61 +531,28 @@ class SpanCharacteristic{
|
|||
boolean staticRange; // Flag that indicates whether Range is static and cannot be changed with setRange()
|
||||
boolean customRange=false; // Flag for custom ranges
|
||||
char *validValues=NULL; // Optional JSON array of valid values. Applicable only to uint8 Characteristics
|
||||
boolean *ev; // Characteristic Event Notify Enable (per-connection)
|
||||
char *nvsKey=NULL; // key for NVS storage of Characteristic value
|
||||
boolean isCustom; // flag to indicate this is a Custom Characteristic
|
||||
boolean setRangeError=false; // flag to indicate attempt to set Range on Characteristic that does not support changes to Range
|
||||
boolean setValidValuesError=false; // flag to indicate attempt to set Valid Values on Characteristic that does not support changes to Valid Values
|
||||
|
||||
uint32_t aid=0; // Accessory ID - passed through from Service containing this Characteristic
|
||||
boolean isUpdated=false; // set to true when new value has been requested by PUT /characteristic
|
||||
uint8_t updateFlag=0; // set to either 1 (for normal write) or 2 (for write-response) inside update() when Characteristic is successfully updated via Home App
|
||||
unsigned long updateTime=0; // last time value was updated (in millis) either by PUT /characteristic OR by setVal()
|
||||
UVal newValue; // the updated value requested by PUT /characteristic
|
||||
SpanService *service=NULL; // pointer to Service containing this Characteristic
|
||||
|
||||
int sprintfAttributes(char *cBuf, int flags); // prints Characteristic JSON records into buf, according to flags mask; return number of characters printed, excluding null terminator
|
||||
StatusCode loadUpdate(char *val, char *ev); // load updated val/ev from PUT /characteristic JSON request. Return intitial HAP status code (checks to see if characteristic is found, is writable, etc.)
|
||||
EVLIST evList; // vector of current connections that have subscribed to EV notifications for this Characteristic
|
||||
|
||||
String uvPrint(UVal &u){
|
||||
char c[64];
|
||||
switch(format){
|
||||
case FORMAT::BOOL:
|
||||
return(String(u.BOOL));
|
||||
case FORMAT::INT:
|
||||
return(String(u.INT));
|
||||
case FORMAT::UINT8:
|
||||
return(String(u.UINT8));
|
||||
case FORMAT::UINT16:
|
||||
return(String(u.UINT16));
|
||||
case FORMAT::UINT32:
|
||||
return(String(u.UINT32));
|
||||
case FORMAT::UINT64:
|
||||
sprintf(c,"%llu",u.UINT64);
|
||||
return(String(c));
|
||||
case FORMAT::FLOAT:
|
||||
sprintf(c,"%g",u.FLOAT);
|
||||
return(String(c));
|
||||
case FORMAT::STRING:
|
||||
case FORMAT::DATA:
|
||||
sprintf(c,"\"%s\"",u.STRING);
|
||||
return(String(c));
|
||||
} // switch
|
||||
return(String()); // included to prevent compiler warnings
|
||||
}
|
||||
void printfAttributes(int flags); // writes Characteristic JSON to hapOut stream
|
||||
StatusCode loadUpdate(char *val, char *ev, boolean wr); // load updated val/ev from PUT /characteristic JSON request. Return intitial HAP status code (checks to see if characteristic is found, is writable, etc.)
|
||||
String uvPrint(UVal &u); // returns "printable" String for any type of Characteristic
|
||||
|
||||
void uvSet(UVal &dest, UVal &src); // copies UVal src into UVal dest
|
||||
void uvSet(UVal &u, STRING_t val); // copies string val into UVal u
|
||||
void uvSet(UVal &u, DATA_t data); // copies DATA data into UVal u (after transforming to a char *)
|
||||
void uvSet(UVal &u, TLV_ENC_t tlv); // copies TLV8 tlv into UVal u (after transforming to a char *)
|
||||
|
||||
void uvSet(UVal &dest, UVal &src){
|
||||
if(format==FORMAT::STRING || format==FORMAT::DATA)
|
||||
uvSet(dest,(const char *)src.STRING);
|
||||
else
|
||||
dest=src;
|
||||
}
|
||||
|
||||
void uvSet(UVal &u, const char *val){
|
||||
u.STRING = (char *)realloc(u.STRING, strlen(val) + 1);
|
||||
strcpy(u.STRING, val);
|
||||
}
|
||||
|
||||
template <typename T> void uvSet(UVal &u, T val){
|
||||
template <typename T> void uvSet(UVal &u, T val){ // copies numeric val into UVal u
|
||||
switch(format){
|
||||
case FORMAT::BOOL:
|
||||
u.BOOL=(boolean)val;
|
||||
|
|
@ -531,13 +575,16 @@ class SpanCharacteristic{
|
|||
case FORMAT::FLOAT:
|
||||
u.FLOAT=(double)val;
|
||||
break;
|
||||
case FORMAT::STRING:
|
||||
case FORMAT::DATA:
|
||||
default:
|
||||
break;
|
||||
} // switch
|
||||
}
|
||||
|
||||
template <class T> T uvGet(UVal &u){
|
||||
char *getStringGeneric(UVal &val); // gets the specified UVal for string-based Characteristics
|
||||
size_t getDataGeneric(uint8_t *data, size_t len, UVal &val); // gets the specified UVal for data-based Characteristics
|
||||
size_t getTLVGeneric(TLV8 &tlv, UVal &val); // gets the specified UVal for tlv8-based Characteristics
|
||||
|
||||
template <class T> T uvGet(UVal &u){ // gets the specified UVal for numeric-based Characteristics
|
||||
|
||||
switch(format){
|
||||
case FORMAT::BOOL:
|
||||
|
|
@ -554,44 +601,42 @@ class SpanCharacteristic{
|
|||
return((T) u.UINT64);
|
||||
case FORMAT::FLOAT:
|
||||
return((T) u.FLOAT);
|
||||
case FORMAT::STRING:
|
||||
case FORMAT::DATA:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return(0); // included to prevent compiler warnings
|
||||
return((T)0); // included to prevent compiler warnings
|
||||
}
|
||||
|
||||
|
||||
void setValCheck(); // initial check before setting value of any Characteristic
|
||||
void setValFinish(boolean notify); // final processing after setting value of any Characteristic
|
||||
|
||||
protected:
|
||||
|
||||
~SpanCharacteristic(); // destructor
|
||||
|
||||
template <typename T, typename A=boolean, typename B=boolean> void init(T val, boolean nvsStore, A min=0, B max=1){
|
||||
~SpanCharacteristic(); // destructor
|
||||
|
||||
template <typename T> void init(T val, boolean nvsStore, T min, T max){
|
||||
|
||||
uvSet(value,val);
|
||||
|
||||
if(nvsStore){
|
||||
nvsKey=(char *)malloc(16);
|
||||
nvsKey=(char *)HS_MALLOC(16);
|
||||
uint16_t t;
|
||||
sscanf(type,"%hx",&t);
|
||||
sprintf(nvsKey,"%04X%08X%03X",t,aid,iid&0xFFF);
|
||||
size_t len;
|
||||
|
||||
if(format!=FORMAT::STRING && format!=FORMAT::DATA){
|
||||
if(!nvs_get_blob(homeSpan.charNVS,nvsKey,NULL,&len)){
|
||||
nvs_get_blob(homeSpan.charNVS,nvsKey,&value,&len);
|
||||
}
|
||||
else {
|
||||
nvs_set_blob(homeSpan.charNVS,nvsKey,&value,sizeof(UVal)); // store data
|
||||
nvs_commit(homeSpan.charNVS); // commit to NVS
|
||||
if(format<FORMAT::STRING){
|
||||
if(nvs_get_u64(homeSpan.charNVS,nvsKey,&(value.UINT64))!=ESP_OK) {
|
||||
nvs_set_u64(homeSpan.charNVS,nvsKey,value.UINT64); // store data as uint64_t regardless of actual type (it will be read correctly when access through uvGet())
|
||||
nvs_commit(homeSpan.charNVS); // commit to NVS
|
||||
}
|
||||
} else {
|
||||
if(!nvs_get_str(homeSpan.charNVS,nvsKey,NULL,&len)){
|
||||
char c[len];
|
||||
nvs_get_str(homeSpan.charNVS,nvsKey,c,&len);
|
||||
uvSet(value,(const char *)c);
|
||||
value.STRING = (char *)HS_REALLOC(value.STRING,len);
|
||||
nvs_get_str(homeSpan.charNVS,nvsKey,value.STRING,&len);
|
||||
}
|
||||
else {
|
||||
nvs_set_str(homeSpan.charNVS,nvsKey,value.STRING); // store string data
|
||||
nvs_set_str(homeSpan.charNVS,nvsKey,value.STRING); // store string data
|
||||
nvs_commit(homeSpan.charNVS); // commit to NVS
|
||||
}
|
||||
}
|
||||
|
|
@ -599,130 +644,39 @@ class SpanCharacteristic{
|
|||
|
||||
uvSet(newValue,value);
|
||||
|
||||
if(format!=FORMAT::STRING && format!=FORMAT::DATA) {
|
||||
uvSet(minValue,min);
|
||||
uvSet(maxValue,max);
|
||||
uvSet(stepValue,0);
|
||||
if(format<FORMAT::STRING){
|
||||
uvSet(minValue,min);
|
||||
uvSet(maxValue,max);
|
||||
uvSet(stepValue,0);
|
||||
}
|
||||
|
||||
} // init()
|
||||
|
||||
public:
|
||||
|
||||
SpanCharacteristic(HapChar *hapChar, boolean isCustom=false); // constructor
|
||||
SpanCharacteristic(HapChar *hapChar, boolean isCustom=false); // SpanCharacteristic constructor
|
||||
void *operator new(size_t size){return(HS_MALLOC(size));} // override new operator to use PSRAM when available
|
||||
|
||||
template <class T=int> T getVal(){
|
||||
return(uvGet<T>(value));
|
||||
}
|
||||
template <class T=int> T getVal(){return(uvGet<T>(value));} // gets the value for numeric-based Characteristics
|
||||
char *getString(){return(getStringGeneric(value));} // gets the value for string-based Characteristics
|
||||
size_t getData(uint8_t *data, size_t len){return(getDataGeneric(data,len,value));} // gets the value for data-based Characteristics
|
||||
size_t getTLV(TLV8 &tlv){return(getTLVGeneric(tlv,value));} // gets the value for tlv8-based Characteristics
|
||||
|
||||
template <class T=int> T getNewVal(){
|
||||
return(uvGet<T>(newValue));
|
||||
}
|
||||
template <class T=int> T getNewVal(){return(uvGet<T>(newValue));} // gets the newValue for numeric-based Characteristics
|
||||
char *getNewString(){return(getStringGeneric(newValue));} // gets the newValue for string-based Characteristics
|
||||
size_t getNewData(uint8_t *data, size_t len){return(getDataGeneric(data,len,newValue));} // gets the newValue for data-based Characteristics
|
||||
size_t getNewTLV(TLV8 &tlv){return(getTLVGeneric(tlv,newValue));} // gets the newValue for tlv8-based Characteristics
|
||||
|
||||
void setString(const char *val, boolean notify=true); // sets the value and newValue for string-based Characteristic
|
||||
void setData(const uint8_t *data, size_t len, boolean notify=true); // sets the value and newValue for data-based Characteristic
|
||||
void setTLV(const TLV8 &tlv, boolean notify=true); // sets the value and newValue for tlv8-based Characteristic
|
||||
|
||||
template <typename T> void setVal(T val, boolean notify=true){ // sets the value and newValue for numeric-based Characteristics
|
||||
|
||||
setValCheck();
|
||||
|
||||
char *getString(){
|
||||
if(format == FORMAT::STRING)
|
||||
return value.STRING;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *getNewString(){
|
||||
if(format == FORMAT::STRING)
|
||||
return newValue.STRING;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void setString(const char *val){
|
||||
|
||||
if((perms & EV) == 0){
|
||||
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setString() ignored. No NOTIFICATION permission on this characteristic\n\n",hapName);
|
||||
return;
|
||||
}
|
||||
|
||||
uvSet(value,val);
|
||||
uvSet(newValue,value);
|
||||
|
||||
updateTime=homeSpan.snapTime;
|
||||
|
||||
SpanBuf sb; // create SpanBuf object
|
||||
sb.characteristic=this; // set characteristic
|
||||
sb.status=StatusCode::OK; // set status
|
||||
char dummy[]="";
|
||||
sb.val=dummy; // set dummy "val" so that sprintfNotify knows to consider this "update"
|
||||
homeSpan.Notifications.push_back(sb); // store SpanBuf in Notifications vector
|
||||
|
||||
if(nvsKey){
|
||||
nvs_set_str(homeSpan.charNVS,nvsKey,value.STRING); // store data
|
||||
nvs_commit(homeSpan.charNVS);
|
||||
}
|
||||
|
||||
} // setString()
|
||||
|
||||
size_t getData(uint8_t *data, size_t len){
|
||||
if(format!=FORMAT::DATA)
|
||||
return(0);
|
||||
|
||||
size_t olen;
|
||||
int ret=mbedtls_base64_decode(data,len,&olen,(uint8_t *)value.STRING,strlen(value.STRING));
|
||||
|
||||
if(data==NULL)
|
||||
return(olen);
|
||||
|
||||
if(ret==MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL)
|
||||
LOG0("\n*** WARNING: Can't decode Characteristic::%s with getData(). Destination buffer is too small (%d out of %d bytes needed)\n\n",hapName,len,olen);
|
||||
else if(ret==MBEDTLS_ERR_BASE64_INVALID_CHARACTER)
|
||||
LOG0("\n*** WARNING: Can't decode Characteristic::%s with getData(). Data is not in base-64 format\n\n",hapName);
|
||||
|
||||
return(olen);
|
||||
}
|
||||
|
||||
size_t getNewData(uint8_t *data, size_t len){
|
||||
if(format!=FORMAT::DATA)
|
||||
return(0);
|
||||
|
||||
size_t olen;
|
||||
int ret=mbedtls_base64_decode(data,len,&olen,(uint8_t *)newValue.STRING,strlen(newValue.STRING));
|
||||
|
||||
if(data==NULL)
|
||||
return(olen);
|
||||
|
||||
if(ret==MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL)
|
||||
LOG0("\n*** WARNING: Can't decode Characteristic::%s with getData(). Destination buffer is too small (%d out of %d bytes needed)\n\n",hapName,len,olen);
|
||||
else if(ret==MBEDTLS_ERR_BASE64_INVALID_CHARACTER)
|
||||
LOG0("\n*** WARNING: Can't decode Characteristic::%s with getData(). Data is not in base-64 format\n\n",hapName);
|
||||
|
||||
return(olen);
|
||||
}
|
||||
|
||||
void setData(uint8_t *data, size_t len){
|
||||
|
||||
if((perms & EV) == 0){
|
||||
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setData() ignored. No NOTIFICATION permission on this characteristic\n\n",hapName);
|
||||
return;
|
||||
}
|
||||
|
||||
if(len<1){
|
||||
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setData() ignored. Size of data buffer must be greater than zero\n\n",hapName);
|
||||
return;
|
||||
}
|
||||
|
||||
size_t olen;
|
||||
mbedtls_base64_encode(NULL,0,&olen,data,len); // get length of string buffer needed (mbedtls includes the trailing null in this size)
|
||||
TempBuffer<char> tBuf(olen); // create temporary string buffer, with room for trailing null
|
||||
mbedtls_base64_encode((uint8_t*)tBuf.buf,olen,&olen,data,len ); // encode data into string buf
|
||||
setString(tBuf.buf); // call setString to continue processing as if characteristic was a string
|
||||
}
|
||||
|
||||
template <typename T> void setVal(T val, boolean notify=true){
|
||||
|
||||
if((perms & EV) == 0){
|
||||
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setVal() ignored. No NOTIFICATION permission on this characteristic\n\n",hapName);
|
||||
return;
|
||||
}
|
||||
|
||||
if(val < uvGet<T>(minValue) || val > uvGet<T>(maxValue)){
|
||||
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setVal(%g) is out of range [%g,%g]. This may cause device to become non-reponsive!\n\n",
|
||||
if(!((val >= uvGet<T>(minValue)) && (val <= uvGet<T>(maxValue)))){
|
||||
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setVal(%g) is out of range [%g,%g]. This may cause device to become non-responsive!\n\n",
|
||||
hapName,(double)val,uvGet<double>(minValue),uvGet<double>(maxValue));
|
||||
}
|
||||
|
||||
|
|
@ -732,27 +686,35 @@ class SpanCharacteristic{
|
|||
updateTime=homeSpan.snapTime;
|
||||
|
||||
if(notify){
|
||||
SpanBuf sb; // create SpanBuf object
|
||||
sb.characteristic=this; // set characteristic
|
||||
sb.status=StatusCode::OK; // set status
|
||||
char dummy[]="";
|
||||
sb.val=dummy; // set dummy "val" so that sprintfNotify knows to consider this "update"
|
||||
homeSpan.Notifications.push_back(sb); // store SpanBuf in Notifications vector
|
||||
|
||||
if(updateFlag!=2){ // do not broadcast EV if update is being done in context of write-response
|
||||
SpanBuf sb; // create SpanBuf object
|
||||
sb.characteristic=this; // set characteristic
|
||||
sb.status=StatusCode::OK; // set status
|
||||
char dummy[]="";
|
||||
sb.val=dummy; // set dummy "val" so that printfNotify knows to consider this "update"
|
||||
homeSpan.Notifications.push_back(sb); // store SpanBuf in Notifications vector
|
||||
}
|
||||
|
||||
if(nvsKey){
|
||||
nvs_set_blob(homeSpan.charNVS,nvsKey,&value,sizeof(UVal)); // store data
|
||||
nvs_set_u64(homeSpan.charNVS,nvsKey,value.UINT64); // store data as uint64_t regardless of actual type (it will be read correctly when access through uvGet())
|
||||
nvs_commit(homeSpan.charNVS);
|
||||
}
|
||||
}
|
||||
|
||||
} // setVal()
|
||||
} // setVal()
|
||||
|
||||
boolean updated(); // returns true within update() if Characteristic was updated by Home App
|
||||
unsigned long timeVal(); // returns time elapsed (in millis) since value was last updated, either by Home App or by using setVal()
|
||||
uint32_t getIID(); // returns IID of Characteristic
|
||||
|
||||
boolean updated(){return(isUpdated);} // returns isUpdated
|
||||
unsigned long timeVal(); // returns time elapsed (in millis) since value was last updated
|
||||
|
||||
SpanCharacteristic *setValidValues(int n, ...); // sets a list of 'n' valid values allowed for a Characteristic and returns pointer to self. Only applicable if format=INT, UINT8, UINT16, or UINT32
|
||||
SpanCharacteristic *setPerms(uint8_t perms); // sets permissions of a Characteristic
|
||||
SpanCharacteristic *addPerms(uint8_t dPerms); // add permissions of a Characteristic
|
||||
SpanCharacteristic *removePerms(uint8_t dPerms); // removes permissions of a Characteristic
|
||||
SpanCharacteristic *setDescription(const char *c); // sets description of a Characteristic
|
||||
SpanCharacteristic *setUnit(const char *c); // set unit of a Characteristic
|
||||
SpanCharacteristic *setValidValues(int n, ...); // sets a list of 'n' valid values allowed for a Characteristic - only applicable if format=INT, UINT8, UINT16, or UINT32
|
||||
|
||||
template <typename A, typename B, typename S=int> SpanCharacteristic *setRange(A min, B max, S step=0){
|
||||
template <typename A, typename B, typename S=int> SpanCharacteristic *setRange(A min, B max, S step=0){ // sets the allowed range of a Characteristic
|
||||
|
||||
if(!staticRange){
|
||||
uvSet(minValue,min);
|
||||
|
|
@ -765,40 +727,6 @@ class SpanCharacteristic{
|
|||
return(this);
|
||||
|
||||
} // setRange()
|
||||
|
||||
SpanCharacteristic *setPerms(uint8_t perms){
|
||||
perms&=0x7F;
|
||||
if(perms>0)
|
||||
this->perms=perms;
|
||||
return(this);
|
||||
}
|
||||
|
||||
SpanCharacteristic *addPerms(uint8_t dPerms){
|
||||
return(setPerms(perms|dPerms));
|
||||
}
|
||||
|
||||
SpanCharacteristic *removePerms(uint8_t dPerms){
|
||||
return(setPerms(perms&(~dPerms)));
|
||||
}
|
||||
|
||||
SpanCharacteristic *setDescription(const char *c){
|
||||
desc = (char *)realloc(desc, strlen(c) + 1);
|
||||
strcpy(desc, c);
|
||||
return(this);
|
||||
}
|
||||
|
||||
SpanCharacteristic *setUnit(const char *c){
|
||||
unit = (char *)realloc(unit, strlen(c) + 1);
|
||||
strcpy(unit, c);
|
||||
return(this);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
struct [[deprecated("Please use Characteristic::setRange() method instead.")]] SpanRange{
|
||||
SpanRange(int min, int max, int step);
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
|
|
@ -825,15 +753,6 @@ class SpanButton : public PushButton {
|
|||
buttonType_t buttonType=HS_BUTTON; // type of SpanButton
|
||||
|
||||
public:
|
||||
|
||||
static constexpr triggerType_t TRIGGER_ON_LOW=PushButton::TRIGGER_ON_LOW;
|
||||
static constexpr triggerType_t TRIGGER_ON_HIGH=PushButton::TRIGGER_ON_HIGH;
|
||||
|
||||
#if SOC_TOUCH_SENSOR_NUM > 0
|
||||
static constexpr triggerType_t TRIGGER_ON_TOUCH=PushButton::TRIGGER_ON_TOUCH;
|
||||
static void setTouchCycles(uint16_t measureTime, uint16_t sleepTime){PushButton::setTouchCycles(measureTime,sleepTime);}
|
||||
static void setTouchThreshold(touch_value_t thresh){PushButton::setTouchThreshold(thresh);}
|
||||
#endif
|
||||
|
||||
SpanButton(int pin, uint16_t longTime=2000, uint16_t singleTime=5, uint16_t doubleTime=200, triggerType_t triggerType=TRIGGER_ON_LOW);
|
||||
SpanButton(int pin, triggerType_t triggerType, uint16_t longTime=2000, uint16_t singleTime=5, uint16_t doubleTime=200) : SpanButton(pin,longTime,singleTime,doubleTime,triggerType){};
|
||||
|
|
@ -882,7 +801,8 @@ class SpanPoint {
|
|||
static uint8_t lmk[16];
|
||||
static boolean initialized;
|
||||
static boolean isHub;
|
||||
static vector<SpanPoint *> SpanPoints;
|
||||
static boolean useEncryption;
|
||||
static vector<SpanPoint *, Mallocator<SpanPoint *>> SpanPoints;
|
||||
static uint16_t channelMask; // channel mask (only used for remote devices)
|
||||
static QueueHandle_t statusQueue; // queue for communication between SpanPoint::dataSend and SpanPoint::send
|
||||
static nvs_handle pointNVS; // NVS storage for channel number (only used for remote devices)
|
||||
|
|
@ -899,8 +819,9 @@ class SpanPoint {
|
|||
public:
|
||||
|
||||
SpanPoint(const char *macAddress, int sendSize, int receiveSize, int queueDepth=1, boolean useAPaddress=false);
|
||||
static void setPassword(const char *pwd){init(pwd);};
|
||||
static void setChannelMask(uint16_t mask);
|
||||
static void setPassword(const char *pwd){init(pwd);}
|
||||
static void setChannelMask(uint16_t mask);
|
||||
static void setEncryption(boolean encrypt){useEncryption=encrypt;}
|
||||
boolean get(void *dataBuf);
|
||||
boolean send(const void *data);
|
||||
uint32_t time(){return(millis()-receiveTime);}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -24,6 +24,8 @@
|
|||
* SOFTWARE.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#include <DNSServer.h>
|
||||
|
||||
|
|
@ -40,7 +42,7 @@ void Network::scan(){
|
|||
int n=WiFi.scanNetworks();
|
||||
|
||||
free(ssidList);
|
||||
ssidList=(char **)calloc(n,sizeof(char *));
|
||||
ssidList=(char **)HS_CALLOC(n,sizeof(char *));
|
||||
numSSID=0;
|
||||
|
||||
for(int i=0;i<n;i++){
|
||||
|
|
@ -50,7 +52,7 @@ void Network::scan(){
|
|||
found=true;
|
||||
}
|
||||
if(!found){
|
||||
ssidList[numSSID]=(char *)calloc(WiFi.SSID(i).length()+1,sizeof(char));
|
||||
ssidList[numSSID]=(char *)HS_CALLOC(WiFi.SSID(i).length()+1,sizeof(char));
|
||||
sprintf(ssidList[numSSID],"%s",WiFi.SSID(i).c_str());
|
||||
numSSID++;
|
||||
}
|
||||
|
|
@ -116,10 +118,7 @@ void Network::apConfigure(){
|
|||
|
||||
WiFiServer apServer(80);
|
||||
client=0;
|
||||
|
||||
TempBuffer <uint8_t> tempBuffer(MAX_HTTP+1);
|
||||
uint8_t *httpBuf=tempBuffer.buf;
|
||||
|
||||
|
||||
const byte DNS_PORT = 53;
|
||||
DNSServer dnsServer;
|
||||
IPAddress apIP(192, 168, 4, 1);
|
||||
|
|
@ -178,20 +177,30 @@ void Network::apConfigure(){
|
|||
LOG2("<<<<<<<<< ");
|
||||
LOG2(client.remoteIP());
|
||||
LOG2(" <<<<<<<<<\n");
|
||||
|
||||
int nBytes=client.read(httpBuf,MAX_HTTP+1); // read all available bytes up to maximum allowed+1
|
||||
|
||||
if(nBytes>MAX_HTTP){ // exceeded maximum number of bytes allowed
|
||||
|
||||
int messageSize=client.available();
|
||||
|
||||
if(messageSize>MAX_HTTP){ // exceeded maximum number of bytes allowed
|
||||
badRequestError();
|
||||
LOG0("\n*** ERROR: Exceeded maximum HTTP message length\n\n");
|
||||
LOG0("\n*** ERROR: HTTP message of %d bytes exceeds maximum allowed (%d)\n\n",messageSize,MAX_HTTP);
|
||||
continue;
|
||||
}
|
||||
|
||||
TempBuffer<uint8_t> httpBuf(messageSize+1); // leave room for null character added below
|
||||
|
||||
int nBytes=client.read(httpBuf,messageSize); // read all available bytes up to maximum allowed+1
|
||||
|
||||
if(nBytes!=messageSize || client.available()!=0){
|
||||
badRequestError();
|
||||
LOG0("\n*** ERROR: HTTP message not read correctly. Expected %d bytes, read %d bytes, %d bytes remaining\n\n",messageSize,nBytes,client.available());
|
||||
continue;
|
||||
}
|
||||
|
||||
httpBuf[nBytes]='\0'; // add null character to enable string functions
|
||||
char *body=(char *)httpBuf; // char pointer to start of HTTP Body
|
||||
|
||||
httpBuf[nBytes]='\0'; // add null character to enable string functions
|
||||
char *body=(char *)httpBuf.get(); // char pointer to start of HTTP Body
|
||||
char *p; // char pointer used for searches
|
||||
|
||||
if(!(p=strstr((char *)httpBuf,"\r\n\r\n"))){
|
||||
if(!(p=strstr((char *)httpBuf.get(),"\r\n\r\n"))){
|
||||
badRequestError();
|
||||
LOG0("\n*** ERROR: Malformed HTTP request (can't find blank line indicating end of BODY)\n\n");
|
||||
continue;
|
||||
|
|
@ -230,7 +239,7 @@ void Network::processRequest(char *body, char *formData){
|
|||
|
||||
String responseHead="HTTP/1.1 200 OK\r\nContent-type: text/html\r\n";
|
||||
|
||||
String responseBody="<html><head><style>"
|
||||
String responseBody="<html><meta charset=\"utf-8\"><head><style>"
|
||||
"p{font-size:300%; margin:1em}"
|
||||
"label{font-size:300%; margin:1em}"
|
||||
"input{font-size:250%; margin:1em}"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -28,11 +28,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <unordered_set>
|
||||
#include "Settings.h"
|
||||
|
||||
using std::unordered_set;
|
||||
|
||||
const int MAX_SSID=32; // max number of characters in WiFi SSID
|
||||
const int MAX_PWD=64; // max number of characters in WiFi Password
|
||||
|
||||
|
|
@ -43,7 +40,7 @@ struct Network {
|
|||
const int MAX_HTTP=4095; // max number of bytes in HTTP message
|
||||
|
||||
const char *apSSID=DEFAULT_AP_SSID; // Access Point SSID
|
||||
const char *apPassword=DEFAULT_AP_PASSWORD; // Access Point password (does not need to be secret - only used to ensure excrypted WiFi connection)
|
||||
const char *apPassword=DEFAULT_AP_PASSWORD; // Access Point password (does not need to be secret - only used to ensure encrypted WiFi connection)
|
||||
unsigned long lifetime=DEFAULT_AP_TIMEOUT*1000; // length of time (in milliseconds) to keep Access Point alive before shutting down and restarting
|
||||
|
||||
char **ssidList=NULL;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef HS_MALLOC
|
||||
|
||||
#if defined(BOARD_HAS_PSRAM)
|
||||
#define HS_MALLOC ps_malloc
|
||||
#define HS_CALLOC ps_calloc
|
||||
#define HS_REALLOC ps_realloc
|
||||
#define ps_new(X) new(ps_malloc(sizeof(X)))X
|
||||
#else
|
||||
#define HS_MALLOC malloc
|
||||
#define HS_CALLOC calloc
|
||||
#define HS_REALLOC realloc
|
||||
#define ps_new(X) new X
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
struct Mallocator {
|
||||
typedef T value_type;
|
||||
Mallocator() = default;
|
||||
template <class U> constexpr Mallocator(const Mallocator<U>&) {}
|
||||
[[nodiscard]] T* allocate(std::size_t n) {
|
||||
auto p = static_cast<T*>(HS_MALLOC(n*sizeof(T)));
|
||||
if(p==NULL){
|
||||
Serial.printf("\n\n*** FATAL ERROR: Requested allocation of %d bytes failed. Program Halting.\n\n",n*sizeof(T));
|
||||
while(1);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
void deallocate(T* p, std::size_t) noexcept { std::free(p); }
|
||||
};
|
||||
template <class T, class U>
|
||||
bool operator==(const Mallocator<T>&, const Mallocator<U>&) { return true; }
|
||||
template <class T, class U>
|
||||
bool operator!=(const Mallocator<T>&, const Mallocator<U>&) { return false; }
|
||||
|
||||
#endif
|
||||
278
src/SRP.cpp
278
src/SRP.cpp
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -29,29 +29,12 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
#include "SRP.h"
|
||||
#include "HAP.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SRP6A::SRP6A(){
|
||||
|
||||
uint8_t tBuf[768]; // temporary buffer for staging
|
||||
uint8_t tHash[64]; // temporary buffer for storing SHA-512 results
|
||||
|
||||
char N3072[]="FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74"
|
||||
"020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437"
|
||||
"4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
|
||||
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05"
|
||||
"98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB"
|
||||
"9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"
|
||||
"E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718"
|
||||
"3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33"
|
||||
"A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7"
|
||||
"ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864"
|
||||
"D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E2"
|
||||
"08E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF";
|
||||
|
||||
// initialize MPI structures
|
||||
|
||||
mbedtls_mpi_init(&N);
|
||||
|
|
@ -65,134 +48,156 @@ SRP6A::SRP6A(){
|
|||
mbedtls_mpi_init(&S);
|
||||
mbedtls_mpi_init(&k);
|
||||
mbedtls_mpi_init(&u);
|
||||
mbedtls_mpi_init(&K);
|
||||
mbedtls_mpi_init(&M1);
|
||||
mbedtls_mpi_init(&M1V);
|
||||
mbedtls_mpi_init(&M2);
|
||||
mbedtls_mpi_init(&_rr);
|
||||
mbedtls_mpi_init(&t1);
|
||||
mbedtls_mpi_init(&t2);
|
||||
mbedtls_mpi_init(&t3);
|
||||
|
||||
// load N and g into mpi structures
|
||||
// load N and g into MPI structures
|
||||
|
||||
mbedtls_mpi_read_string(&N,16,N3072);
|
||||
mbedtls_mpi_lset(&g,5);
|
||||
mbedtls_mpi_lset(&g,g3072);
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
SRP6A::~SRP6A(){
|
||||
|
||||
mbedtls_mpi_free(&N);
|
||||
mbedtls_mpi_free(&g);
|
||||
mbedtls_mpi_free(&s);
|
||||
mbedtls_mpi_free(&x);
|
||||
mbedtls_mpi_free(&v);
|
||||
mbedtls_mpi_free(&A);
|
||||
mbedtls_mpi_free(&b);
|
||||
mbedtls_mpi_free(&B);
|
||||
mbedtls_mpi_free(&S);
|
||||
mbedtls_mpi_free(&k);
|
||||
mbedtls_mpi_free(&u);
|
||||
mbedtls_mpi_free(&_rr);
|
||||
mbedtls_mpi_free(&t1);
|
||||
mbedtls_mpi_free(&t2);
|
||||
mbedtls_mpi_free(&t3);
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void SRP6A::createVerifyCode(const char *setupCode, Verification *vData){
|
||||
|
||||
TempBuffer<uint8_t> tBuf(80); // temporary buffer for staging
|
||||
TempBuffer<uint8_t> tHash(64); // temporary buffer for storing SHA-512 results
|
||||
char *icp; // storage for I:P
|
||||
|
||||
// generate random salt, s
|
||||
|
||||
randombytes_buf(vData->salt,16); // generate 16 random bytes for salt
|
||||
|
||||
// create I:P
|
||||
|
||||
asprintf(&icp,"%s:%.3s-%.2s-%.3s",I,setupCode,setupCode+3,setupCode+5);
|
||||
|
||||
// compute x = SHA512( s | SHA512( I | ":" | P ) )
|
||||
|
||||
memcpy(tBuf,vData->salt,16); // write salt into first 16 bytes of staging buffer
|
||||
mbedtls_sha512_ret((uint8_t *)icp,strlen(icp),tBuf+16,0); // create hash of username:password and write into last 64 bytes of staging buffer
|
||||
mbedtls_sha512_ret(tBuf,80,tHash,0); // create second hash of salted, hashed username:password
|
||||
mbedtls_mpi_read_binary(&x,tHash,64); // load hash result into x
|
||||
|
||||
// compute v = g^x %N
|
||||
|
||||
mbedtls_mpi_exp_mod(&v,&g,&x,&N,&_rr); // create verifier, v (_rr is an internal "helper" structure that mbedtls uses to speed up subsequent exponential calculations)
|
||||
mbedtls_mpi_write_binary(&v,vData->verifyCode,384); // write v into verifyCode (padding with initial zeros is less than 384 bytes)
|
||||
|
||||
free(icp);
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void SRP6A::createPublicKey(const Verification *vData, uint8_t *publicKey){
|
||||
|
||||
TempBuffer<uint8_t> tBuf(768); // temporary buffer for staging
|
||||
TempBuffer<uint8_t> tHash(64); // temporary buffer for storing SHA-512 results
|
||||
TempBuffer<uint8_t> privateKey(32); // temporary buffer for generating private key random numbers
|
||||
|
||||
// load stored salt, s, and verification code, v
|
||||
|
||||
mbedtls_mpi_read_binary(&s,vData->salt,16); // load salt into s for use in later steps
|
||||
mbedtls_mpi_read_binary(&v,vData->verifyCode,384); // load verifyCode into v for use below
|
||||
|
||||
// generate random private key, b
|
||||
|
||||
randombytes_buf(privateKey,32); // generate 32 random bytes for private key
|
||||
mbedtls_mpi_read_binary(&b,privateKey,32); // load private key into b
|
||||
|
||||
// compute k = SHA512( N | PAD(g) )
|
||||
|
||||
mbedtls_mpi_write_binary(&N,tBuf,384); // write N into first half of staging buffer
|
||||
mbedtls_mpi_write_binary(&g,tBuf+384,384); // write g into second half of staging buffer (fully padded with leading zeros)
|
||||
mbedtls_sha512_ret(tBuf,768,tHash,0); // create hash of data
|
||||
mbedtls_mpi_read_binary(&k,tHash,64); // load hash result into mpi structure k
|
||||
mbedtls_mpi_read_binary(&k,tHash,64); // load hash result into k
|
||||
|
||||
// compute B = (k*v + g^b) %N
|
||||
|
||||
mbedtls_mpi_mul_mpi(&t1,&k,&v); // t1 = k*v
|
||||
mbedtls_mpi_exp_mod(&t2,&g,&b,&N,&_rr); // t2 = g^b %N
|
||||
mbedtls_mpi_add_mpi(&t3,&t1,&t2); // t3 = t1 + t2
|
||||
mbedtls_mpi_mod_mpi(&B,&t3,&N); // B = t3 %N = ACCESSORY PUBLIC KEY
|
||||
|
||||
mbedtls_mpi_write_binary(&B,publicKey,384); // write B into publicKey (padding with initial zeros is less than 384 bytes)
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void SRP6A::createVerifyCode(const char *setupCode, uint8_t *verifyCode, uint8_t *salt){
|
||||
void SRP6A::createSessionKey(const uint8_t *publicKey, size_t len){
|
||||
|
||||
uint8_t tBuf[80]; // temporary buffer for staging
|
||||
uint8_t tHash[64]; // temporary buffer for storing SHA-512 results
|
||||
char icp[22]; // storage for I:P
|
||||
TempBuffer<uint8_t> tBuf(768); // temporary buffer for staging
|
||||
TempBuffer<uint8_t> tHash(64); // temporary buffer for storing SHA-512 results
|
||||
|
||||
randombytes_buf(salt,16); // generate 16 random bytes using libsodium (which uses the ESP32 hardware-based random number generator)
|
||||
mbedtls_mpi_read_binary(&s,salt,16);
|
||||
|
||||
sprintf(icp,"Pair-Setup:%.3s-%.2s-%.3s",setupCode,setupCode+3,setupCode+5);
|
||||
|
||||
// compute x = SHA512( s | SHA512( I | ":" | P ) )
|
||||
|
||||
mbedtls_mpi_write_binary(&s,tBuf,16); // write s into first 16 bytes of staging buffer
|
||||
mbedtls_sha512_ret((uint8_t *)icp,strlen(icp),tBuf+16,0); // create hash of username:password and write into last 64 bytes of staging buffer
|
||||
mbedtls_sha512_ret(tBuf,80,tHash,0); // create second hash of salted, hashed username:password
|
||||
mbedtls_mpi_read_binary(&x,tHash,64); // load hash result into mpi structure x
|
||||
|
||||
// compute v = g^x % N
|
||||
|
||||
mbedtls_mpi_exp_mod(&v,&g,&x,&N,&_rr); // create verifier, v (_rr is an internal "helper" structure that mbedtls uses to speed up subsequent exponential calculations)
|
||||
mbedtls_mpi_write_binary(&v,verifyCode,384); // write v into verifyCode
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void SRP6A::loadVerifyCode(uint8_t *verifyCode, uint8_t *salt){
|
||||
|
||||
mbedtls_mpi_read_binary(&s,salt,16);
|
||||
mbedtls_mpi_read_binary(&v,verifyCode,384);
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void SRP6A::createPublicKey(){
|
||||
|
||||
getPrivateKey(); // create and load b (random 32 bytes)
|
||||
|
||||
// compute B = kv + g^b %N
|
||||
|
||||
mbedtls_mpi_mul_mpi(&t1,&k,&v); // t1 = k*v
|
||||
mbedtls_mpi_exp_mod(&t2,&g,&b,&N,&_rr); // t2 = g^b %N
|
||||
mbedtls_mpi_add_mpi(&t3,&t1,&t2); // t3 = t1 + t2
|
||||
mbedtls_mpi_mod_mpi(&B,&t3,&N); // B = t3 %N = ACCESSORY PUBLIC KEY
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void SRP6A::getPrivateKey(){
|
||||
|
||||
uint8_t privateKey[32];
|
||||
|
||||
randombytes_buf(privateKey,32); // generate 32 random bytes using libsodium (which uses the ESP32 hardware-based random number generator)
|
||||
mbedtls_mpi_read_binary(&b,privateKey,32);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void SRP6A::createSessionKey(){
|
||||
|
||||
uint8_t tBuf[768]; // temporary buffer for staging
|
||||
uint8_t tHash[64]; // temporary buffer for storing SHA-512 results
|
||||
mbedtls_mpi_read_binary(&A,publicKey,len); // load client PublicKey into A
|
||||
|
||||
// compute u = SHA512( PAD(A) | PAD(B) )
|
||||
|
||||
mbedtls_mpi_write_binary(&A,tBuf,384); // write A into first half of staging buffer
|
||||
mbedtls_mpi_write_binary(&B,tBuf+384,384); // write B into second half of staging buffer
|
||||
mbedtls_mpi_write_binary(&A,tBuf,384); // write A into first half of staging buffer (padding with initial zeros is less than 384 bytes)
|
||||
mbedtls_mpi_write_binary(&B,tBuf+384,384); // write B into second half of staging buffer (padding with initial zeros is less than 384 bytes)
|
||||
mbedtls_sha512_ret(tBuf,768,tHash,0); // create hash of data
|
||||
mbedtls_mpi_read_binary(&u,tHash,64); // load hash result into mpi structure u
|
||||
|
||||
// compute S = (Av^u)^b %N
|
||||
// compute S = (A * v^u)^b %N
|
||||
|
||||
mbedtls_mpi_exp_mod(&t1,&v,&u,&N,&_rr); // t1 = v^u %N
|
||||
mbedtls_mpi_mul_mpi(&t2,&A,&t1); // t2 = A*t1
|
||||
mbedtls_mpi_mod_mpi(&t1,&t2,&N); // t1 = t2 %N (this is needed to reduce size of t2 before next calculation)
|
||||
mbedtls_mpi_exp_mod(&S,&t1,&b,&N,&_rr); // S = t1^b %N
|
||||
|
||||
// compute K = SHA512( S )
|
||||
// compute K = SHA512( PAD(S) )
|
||||
|
||||
mbedtls_mpi_write_binary(&S,tBuf,384); // write S into staging buffer (only first half of buffer will be used)
|
||||
mbedtls_sha512_ret(tBuf,384,tHash,0); // create hash of data
|
||||
mbedtls_mpi_read_binary(&K,tHash,64); // load hash result into mpi structure K. This is the SRP SHARED SECRET KEY
|
||||
|
||||
mbedtls_mpi_write_binary(&K,sharedSecret,64); // store SHARED SECRET in easy-to-use binary (uint8_t) format
|
||||
mbedtls_sha512_ret(tBuf,384,K,0); // create hash of data - this is the SRP SHARED SESSION KEY, K
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
int SRP6A::verifyProof(){
|
||||
|
||||
uint8_t tBuf[976]; // temporary buffer for staging
|
||||
uint8_t tHash[64]; // temporary buffer for storing SHA-512 results
|
||||
int SRP6A::verifyClientProof(const uint8_t *proof){
|
||||
|
||||
size_t count=0; // total number of bytes for final hash
|
||||
TempBuffer<uint8_t> tBuf(976); // temporary buffer for staging
|
||||
TempBuffer<uint8_t> tHash(64); // temporary buffer for storing SHA-512 results
|
||||
|
||||
memcpy(M1,proof,64); // load client Proof into M1
|
||||
|
||||
size_t count=0; // total number of bytes for final hash
|
||||
size_t sLen;
|
||||
|
||||
|
||||
// compute M1V = SHA512( SHA512(N) xor SHA512(g) | SHA512(I) | s | A | B | K )
|
||||
|
||||
mbedtls_mpi_write_binary(&N,tBuf,384); // write N into staging buffer
|
||||
mbedtls_sha512_ret(tBuf,384,tHash,0); // create hash of data
|
||||
mbedtls_sha512_ret((uint8_t *)g3072,1,tBuf,0); // create hash of g, but place output directly into staging buffer
|
||||
mbedtls_sha512_ret(&g3072,1,tBuf,0); // create hash of g, but place output directly into staging buffer
|
||||
|
||||
for(int i=0;i<64;i++) // H(g) -> H(g) XOR H(N), with results in first 64 bytes of staging buffer
|
||||
tBuf[i]^=tHash[i];
|
||||
|
|
@ -209,13 +214,12 @@ int SRP6A::verifyProof(){
|
|||
mbedtls_mpi_write_binary(&B,tBuf+count,sLen); // concatenate B to staging buffer. Note B is NOT padded with leading zeros (so may be less than 384 bytes)
|
||||
count+=sLen; // increment total bytes written to staging buffer
|
||||
|
||||
mbedtls_mpi_write_binary(&K,tBuf+count,64); // concatenate K to staging buffer (should always be 64 bytes since it is a hashed value)
|
||||
memcpy(tBuf+count,K,64); // concatenate K to staging buffer (should always be 64 bytes since it is a hashed value)
|
||||
count+=64; // final total of bytes written to staging buffer
|
||||
|
||||
mbedtls_sha512_ret(tBuf,count,tHash,0); // create hash of data
|
||||
mbedtls_mpi_read_binary(&M1V,tHash,64); // load hash result into mpi structure M1V
|
||||
|
||||
if(!mbedtls_mpi_cmp_mpi(&M1,&M1V)) // cmp_mpi uses same logic as strcmp: returns 0 if EQUAL, otherwise +/- 1
|
||||
mbedtls_sha512_ret(tBuf,count,tHash,0); // create hash of data - this is M1V
|
||||
|
||||
if(!memcmp(M1,tHash,64)) // check that client Proof M1 matches M1V
|
||||
return(1); // success - proof from HAP Client is verified
|
||||
|
||||
return(0);
|
||||
|
|
@ -223,60 +227,34 @@ int SRP6A::verifyProof(){
|
|||
|
||||
//////////////////////////////////////
|
||||
|
||||
void SRP6A::createProof(){
|
||||
void SRP6A::createAccProof(uint8_t *proof){
|
||||
|
||||
uint8_t tBuf[512]; // temporary buffer for staging
|
||||
TempBuffer<uint8_t> tBuf(512); // temporary buffer for staging
|
||||
|
||||
// compute M2 = H( A | M1 | K )
|
||||
// compute M2 = SHA512( A | M1 | K )
|
||||
|
||||
mbedtls_mpi_write_binary(&A,tBuf,384); // write A into staging buffer
|
||||
mbedtls_mpi_write_binary(&M1,tBuf+384,64); // concatenate M1 (now verified) to staging buffer
|
||||
mbedtls_mpi_write_binary(&K,tBuf+448,64); // concatenate K to staging buffer
|
||||
mbedtls_sha512_ret(tBuf,512,tBuf,0); // create hash of data
|
||||
mbedtls_mpi_read_binary(&M2,tBuf,64); // load hash results into mpi structure M2
|
||||
|
||||
memcpy(tBuf+384,M1,64); // concatenate M1 (now verified) to staging buffer
|
||||
memcpy(tBuf+448,K,64); // concatenate K to staging buffer
|
||||
mbedtls_sha512_ret(tBuf,512,proof,0); // create hash of data writing directly to proof - this is M2
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
int SRP6A::loadTLV(kTLVType tag, mbedtls_mpi *mpi, int nBytes){
|
||||
|
||||
uint8_t *buf=HAPClient::tlv8.buf(tag,nBytes);
|
||||
|
||||
if(!buf)
|
||||
return(0);
|
||||
|
||||
mbedtls_mpi_write_binary(mpi,buf,nBytes);
|
||||
return(1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
int SRP6A::writeTLV(kTLVType tag, mbedtls_mpi *mpi){
|
||||
|
||||
int nBytes=HAPClient::tlv8.len(tag);
|
||||
|
||||
if(nBytes>0){
|
||||
mbedtls_mpi_read_binary(mpi,HAPClient::tlv8.buf(tag),nBytes);
|
||||
return(1);
|
||||
};
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void SRP6A::print(mbedtls_mpi *mpi, int minLogLevel){
|
||||
|
||||
if(homeSpan.getLogLevel()<minLogLevel)
|
||||
return;
|
||||
|
||||
char sBuf[2000];
|
||||
void SRP6A::print(mbedtls_mpi *mpi){
|
||||
|
||||
size_t sLen;
|
||||
|
||||
mbedtls_mpi_write_string(mpi,16,sBuf,2000,&sLen);
|
||||
mbedtls_mpi_write_string(mpi,16,NULL,0,&sLen);
|
||||
TempBuffer<char> sBuf(sLen);
|
||||
mbedtls_mpi_write_string(mpi,16,sBuf,sLen,&sLen);
|
||||
|
||||
Serial.printf("%d %s\n",(sLen-1)/2,sBuf); // subtract 1 for null-terminator, and then divide by 2 to get number of bytes (e.g. 4F = 2 characters, but represents just one mpi byte)
|
||||
Serial.printf("%d %s\n",(sLen-1)/2,sBuf.get()); // subtract 1 for null-terminator, and then divide by 2 to get number of bytes (e.g. 4F = 2 characters, but represents just one mpi byte)
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
constexpr char SRP6A::N3072[];
|
||||
constexpr char SRP6A::I[];
|
||||
const uint8_t SRP6A::g3072;
|
||||
|
|
|
|||
74
src/SRP.h
74
src/SRP.h
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -31,11 +31,19 @@
|
|||
#include <mbedtls/bignum.h>
|
||||
#include <mbedtls/base64.h>
|
||||
|
||||
#include "HAPConstants.h"
|
||||
#include "Utils.h"
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Pair-Setup Code Verification Data and Salt
|
||||
|
||||
struct Verification {
|
||||
uint8_t salt[16];
|
||||
uint8_t verifyCode[384];
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// SRP-6A Structure from RFC 5054 (Nov 2007)
|
||||
// ** HAP uses N=3072-bit Group specified in RFC 5054
|
||||
// ** HAP uses N=3072-bit Group specified in RFC 5054 with Generator g=5
|
||||
// ** HAP replaces H=SHA-1 with H=SHA-512 (HAP Section 5.5)
|
||||
//
|
||||
// I = SRP-6A username, defined by HAP to be the word "Pair-Setup"
|
||||
|
|
@ -43,6 +51,22 @@
|
|||
|
||||
struct SRP6A {
|
||||
|
||||
static constexpr char N3072[]="FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74"
|
||||
"020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437"
|
||||
"4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
|
||||
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05"
|
||||
"98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB"
|
||||
"9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"
|
||||
"E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718"
|
||||
"3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33"
|
||||
"A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7"
|
||||
"ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864"
|
||||
"D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E2"
|
||||
"08E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF";
|
||||
|
||||
static const uint8_t g3072=5;
|
||||
static constexpr char I[]="Pair-Setup";
|
||||
|
||||
mbedtls_mpi N; // N - 3072-bit Group pre-defined prime used for all SRP-6A calculations (384 bytes)
|
||||
mbedtls_mpi g; // g - pre-defined generator for the specified 3072-bit Group (g=5)
|
||||
mbedtls_mpi k; // k = H(N | PAD(g)) - SRP-6A multiplier (which is different from versions SRP-6 or SRP-3)
|
||||
|
|
@ -54,39 +78,25 @@ struct SRP6A {
|
|||
mbedtls_mpi A; // A - public key RECEIVED from HAP Client (max 384 bytes)
|
||||
mbedtls_mpi u; // u = H(PAD(A) | PAB(B)) - "u-factor" (64 bytes)
|
||||
mbedtls_mpi S; // S = (A*v^u)^b %N - SRP shared "premaster" key, based on accessory private key and client public key (max 384 bytes)
|
||||
mbedtls_mpi K; // K = H( S ) - SRP SHARED SECRET KEY (64 bytes)
|
||||
mbedtls_mpi M1; // M1 - proof RECEIVED from HAP Client (64 bytes)
|
||||
mbedtls_mpi M1V; // M1V - accessory's independent computation of M1 to verify proof (see code for details of computation)
|
||||
mbedtls_mpi M2; // M2 - accessory's counter-proof to send to HAP Client after M1=M1V has been verified (64 bytes)
|
||||
|
||||
mbedtls_mpi t1; // temporary mpi structures for intermediate results
|
||||
mbedtls_mpi t2;
|
||||
mbedtls_mpi t3;
|
||||
|
||||
uint8_t K[64]; // K = H(S) - SRP SHARED SECRET KEY (64 bytes)
|
||||
uint8_t M1[64]; // M1 - proof RECEIVED from HAP Client (64 bytes)
|
||||
mbedtls_mpi t1; // temp1 - temporary mpi structures for intermediate results
|
||||
mbedtls_mpi t2; // temp2 - temporary mpi structures for intermediate results
|
||||
mbedtls_mpi t3; // temp3 - temporary mpi structures for intermediate results
|
||||
mbedtls_mpi _rr; // _rr - temporary "helper" for large exponential modulus calculations
|
||||
|
||||
char I[11]="Pair-Setup"; // I - userName pre-defined by HAP pairing setup protocol
|
||||
char g3072[2]="\x05"; // g - 3072-bit Group generator
|
||||
|
||||
uint8_t sharedSecret[64]; // permanent storage for binary version of SHARED SECRET KEY for ease of use upstream
|
||||
|
||||
SRP6A(); // initializes N, G, and computes k
|
||||
|
||||
void createVerifyCode(const char *setupCode, uint8_t *verifyCode, uint8_t *salt);
|
||||
void loadVerifyCode(uint8_t *verifyCode, uint8_t *salt);
|
||||
|
||||
void getSalt(); // generates and stores random 16-byte salt, s
|
||||
void getPrivateKey(); // generates and stores random 32-byte private key, b
|
||||
void getSetupCode(char *c); // generates and displays random 8-digit Pair-Setup code, P, in format XXX-XX-XXX
|
||||
void createPublicKey(); // computes x, v, and B from random s, P, and b
|
||||
void createSessionKey(); // computes u from A and B, and then S from A, v, u, and b
|
||||
|
||||
int loadTLV(kTLVType tag, mbedtls_mpi *mpi, int nBytes); // load binary contents of mpi into a TLV record and set its length
|
||||
int writeTLV(kTLVType tag, mbedtls_mpi *mpi); // write binary contents of a TLV record into an mpi
|
||||
|
||||
int verifyProof(); // verify M1 SRP6A Proof received from HAP client (return 1 on success, 0 on failure)
|
||||
void createProof(); // create M2 server-side SRP6A Proof based on M1 as received from HAP Client
|
||||
~SRP6A();
|
||||
|
||||
void print(mbedtls_mpi *mpi, int minLogLevel=0); // prints size of mpi (in bytes), followed by the mpi itself (as a hex charcter string), subject to specified minimum log level
|
||||
void *operator new(size_t size){return(HS_MALLOC(size));} // override new operator to use PSRAM when available
|
||||
|
||||
void createVerifyCode(const char *setupCode, Verification *vData); // generates random s and computes v; writes back resulting Verification Data
|
||||
void createPublicKey(const Verification *vData, uint8_t *publicKey); // generates random b and computes k and B; writes back resulting Accessory Public Key
|
||||
void createSessionKey(const uint8_t *publicKey, size_t len); // computes u, S, and K from Client Public Key, A (of variable length)
|
||||
int verifyClientProof(const uint8_t *proof); // verifies Client Proof, M1, received from HAP client (return 1 on success, 0 on failure)
|
||||
void createAccProof(uint8_t *proof); // computes M2; write back resulting Accessory Proof
|
||||
|
||||
void print(mbedtls_mpi *mpi); // prints size of mpi (in bytes), followed by the mpi itself (as a hex character string)
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -24,41 +24,9 @@
|
|||
* SOFTWARE.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
// USER-DEFINED SETTINGS AND REFERENCE ENUMERATION CLASSES
|
||||
|
||||
#include <core_version.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// HomeSpan Version //
|
||||
|
||||
#define HS_MAJOR 1
|
||||
#define HS_MINOR 8
|
||||
#define HS_PATCH 0
|
||||
|
||||
#define STRINGIFY(x) _STR(x)
|
||||
#define _STR(x) #x
|
||||
|
||||
#define HOMESPAN_VERSION STRINGIFY(HS_MAJOR) "." STRINGIFY(HS_MINOR) "." STRINGIFY(HS_PATCH)
|
||||
|
||||
#define VERSION(major,minor,patch) major*10000+minor*100+patch
|
||||
|
||||
#ifndef REQUIRED
|
||||
#define REQUIRED 0
|
||||
#endif
|
||||
|
||||
#if (REQUIRED>VERSION(HS_MAJOR,HS_MINOR,HS_PATCH))
|
||||
#error THIS SKETCH REQUIRES A LATER VERSION OF THE HOMESPAN LIBRARY
|
||||
#endif
|
||||
|
||||
#define ARDUINO_ESP_VERSION STRINGIFY(ARDUINO_ESP32_GIT_DESC)
|
||||
|
||||
#if ESP_ARDUINO_VERSION_MAJOR<2
|
||||
#error HOMESPAN REQUIRES VERSION 2 OF THE ARDUINO ESP32 LIBRARY
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// DEFAULT SETTINGS //
|
||||
|
||||
|
|
@ -84,6 +52,10 @@
|
|||
|
||||
#define DEFAULT_WEBLOG_URL "status" // change with optional fourth argument in homeSpan.enableWebLog()
|
||||
|
||||
#define DEFAULT_LOW_MEM_THRESHOLD 80000 // default low watermark memory (for internal RAM) threshold that triggers warning
|
||||
|
||||
#define DEFAULT_REBOOT_CALLBACK_TIME 5000 // default time (in milliseconds) to check for reboot callback
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// OTA PARTITION INFO //
|
||||
|
||||
|
|
|
|||
894
src/Span.h
894
src/Span.h
File diff suppressed because it is too large
Load Diff
314
src/TLV.h
314
src/TLV.h
|
|
@ -1,314 +0,0 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
template <class tagType, int maxTags>
|
||||
class TLV {
|
||||
|
||||
int cLen; // total number of bytes in all defined TLV records, including TAG andf LEN (suitable for use as Content-Length in HTTP Body)
|
||||
int numTags; // actual number of tags defined
|
||||
|
||||
struct tlv_t {
|
||||
tagType tag; // TAG
|
||||
int len; // LENGTH
|
||||
uint8_t *val; // VALUE buffer
|
||||
int maxLen; // maximum length of VALUE buffer
|
||||
const char *name; // abbreviated name of this TAG
|
||||
};
|
||||
|
||||
tlv_t tlv[maxTags]; // pointer to array of TLV record structures
|
||||
tlv_t *find(tagType tag); // returns pointer to TLV record with matching TAG (or NULL if no match)
|
||||
|
||||
public:
|
||||
|
||||
TLV();
|
||||
|
||||
int create(tagType tag, int maxLen, const char *name); // creates a new TLV record of type 'tag' with 'maxLen' bytes and display 'name'
|
||||
|
||||
void clear(); // clear all TLV structures
|
||||
int val(tagType tag); // returns VAL for TLV with matching TAG (or -1 if no match)
|
||||
int val(tagType tag, uint8_t val); // sets and returns VAL for TLV with matching TAG (or -1 if no match)
|
||||
uint8_t *buf(tagType tag); // returns VAL Buffer for TLV with matching TAG (or NULL if no match)
|
||||
uint8_t *buf(tagType tag, int len); // set length and returns VAL Buffer for TLV with matching TAG (or NULL if no match or if LEN>MAX)
|
||||
int len(tagType tag); // returns LEN for TLV matching TAG (or 0 if TAG is found but LEN not yet set; -1 if no match at all)
|
||||
void print(int minLogLevel=0); // prints all defined TLVs (those with length>0), subject to specified minimum log level
|
||||
int unpack(uint8_t *tlvBuf, int nBytes); // unpacks nBytes of TLV content from single byte buffer into individual TLV records (return 1 on success, 0 if fail)
|
||||
int pack(uint8_t *tlvBuf); // if tlvBuf!=NULL, packs all defined TLV records (LEN>0) into a single byte buffer, spitting large TLVs into separate 255-byte chunks. Returns number of bytes (that would be) stored in buffer
|
||||
int pack_old(uint8_t *buf); // packs all defined TLV records (LEN>0) into a single byte buffer, spitting large TLVs into separate 255-byte records. Returns number of bytes stored in buffer
|
||||
|
||||
}; // TLV
|
||||
|
||||
//////////////////////////////////////
|
||||
// TLV contructor()
|
||||
|
||||
template<class tagType, int maxTags>
|
||||
TLV<tagType, maxTags>::TLV(){
|
||||
numTags=0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// TLV create(tag, maxLen, name)
|
||||
|
||||
template<class tagType, int maxTags>
|
||||
int TLV<tagType, maxTags>::create(tagType tag, int maxLen, const char *name){
|
||||
|
||||
if(numTags==maxTags){
|
||||
Serial.print("\n*** ERROR: Can't create new TLC tag type with name='");
|
||||
Serial.print(name);
|
||||
Serial.print("' - exceeded number of records reserved\n\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
tlv[numTags].tag=tag;
|
||||
tlv[numTags].maxLen=maxLen;
|
||||
tlv[numTags].name=name;
|
||||
tlv[numTags].len=-1;
|
||||
tlv[numTags].val=(uint8_t *)malloc(maxLen);
|
||||
numTags++;
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// TLV find(tag)
|
||||
|
||||
template<class tagType, int maxTags>
|
||||
typename TLV<tagType, maxTags>::tlv_t *TLV<tagType, maxTags>::find(tagType tag){
|
||||
|
||||
for(int i=0;i<numTags;i++){
|
||||
if(tlv[i].tag==tag)
|
||||
return(tlv+i);
|
||||
}
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// TLV clear()
|
||||
|
||||
template<class tagType, int maxTags>
|
||||
void TLV<tagType, maxTags>::clear(){
|
||||
|
||||
cLen=0;
|
||||
|
||||
for(int i=0;i<numTags;i++)
|
||||
tlv[i].len=-1;
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// TLV val(tag)
|
||||
|
||||
template<class tagType, int maxTags>
|
||||
int TLV<tagType, maxTags>::val(tagType tag){
|
||||
|
||||
tlv_t *tlv=find(tag);
|
||||
|
||||
if(tlv && tlv->len>0)
|
||||
return(tlv->val[0]);
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// TLV val(tag, val)
|
||||
|
||||
template<class tagType, int maxTags>
|
||||
int TLV<tagType, maxTags>::val(tagType tag, uint8_t val){
|
||||
|
||||
tlv_t *tlv=find(tag);
|
||||
|
||||
if(tlv){
|
||||
tlv->val[0]=val;
|
||||
tlv->len=1;
|
||||
cLen+=tlv->len+2;
|
||||
return(val);
|
||||
}
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// TLV buf(tag)
|
||||
|
||||
template<class tagType, int maxTags>
|
||||
uint8_t *TLV<tagType, maxTags>::buf(tagType tag){
|
||||
|
||||
tlv_t *tlv=find(tag);
|
||||
|
||||
if(tlv)
|
||||
return(tlv->val);
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// TLV buf(tag, len)
|
||||
|
||||
template<class tagType, int maxTags>
|
||||
uint8_t *TLV<tagType, maxTags>::buf(tagType tag, int len){
|
||||
|
||||
tlv_t *tlv=find(tag);
|
||||
|
||||
if(tlv && len<=tlv->maxLen){
|
||||
tlv->len=len;
|
||||
cLen+=tlv->len;
|
||||
|
||||
for(int i=0;i<tlv->len;i+=255)
|
||||
cLen+=2;
|
||||
|
||||
return(tlv->val);
|
||||
}
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// TLV print()
|
||||
|
||||
template<class tagType, int maxTags>
|
||||
void TLV<tagType, maxTags>::print(int minLogLevel){
|
||||
|
||||
if(homeSpan.getLogLevel()<minLogLevel)
|
||||
return;
|
||||
|
||||
for(int i=0;i<numTags;i++){
|
||||
|
||||
if(tlv[i].len>0){
|
||||
Serial.printf("%s(%d) ",tlv[i].name,tlv[i].len);
|
||||
|
||||
for(int j=0;j<tlv[i].len;j++)
|
||||
Serial.printf("%02X",tlv[i].val[j]);
|
||||
|
||||
Serial.printf("\n");
|
||||
|
||||
} // len>0
|
||||
} // loop over all TLVs
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// TLV pack(tlvBuf)
|
||||
|
||||
template<class tagType, int maxTags>
|
||||
int TLV<tagType, maxTags>::pack(uint8_t *tlvBuf){
|
||||
|
||||
int n=0;
|
||||
int nBytes;
|
||||
|
||||
for(int i=0;i<numTags;i++){
|
||||
|
||||
if((nBytes=tlv[i].len)>0){
|
||||
for(int j=0;j<tlv[i].len;j+=255,nBytes-=255){
|
||||
if(tlvBuf!=NULL){
|
||||
*tlvBuf++=tlv[i].tag;
|
||||
*tlvBuf++=nBytes>255?255:nBytes;
|
||||
memcpy(tlvBuf,tlv[i].val+j,nBytes>255?255:nBytes);
|
||||
tlvBuf+=nBytes>255?255:nBytes;
|
||||
}
|
||||
n+=(nBytes>255?255:nBytes)+2;
|
||||
} // j-loop
|
||||
} // len>0
|
||||
|
||||
} // loop over all TLVs
|
||||
|
||||
return(n);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// TLV len(tag)
|
||||
|
||||
template<class tagType, int maxTags>
|
||||
int TLV<tagType, maxTags>::len(tagType tag){
|
||||
|
||||
tlv_t *tlv=find(tag);
|
||||
|
||||
if(tlv)
|
||||
return(tlv->len>0?tlv->len:0);
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// TLV unpack(tlvBuf, nBytes)
|
||||
|
||||
template<class tagType, int maxTags>
|
||||
int TLV<tagType, maxTags>::unpack(uint8_t *tlvBuf, int nBytes){
|
||||
|
||||
clear();
|
||||
|
||||
tagType tag;
|
||||
int tagLen;
|
||||
uint8_t *val;
|
||||
int currentLen;
|
||||
int state=0;
|
||||
|
||||
for(int i=0;i<nBytes;i++){
|
||||
|
||||
switch(state){
|
||||
|
||||
case 0: // ready to read next tag
|
||||
if((tag=(tagType)tlvBuf[i])==-1){ // read TAG; return with error if not found
|
||||
clear();
|
||||
return(0);
|
||||
}
|
||||
state=1;
|
||||
break;
|
||||
|
||||
case 1: // ready to read tag length
|
||||
tagLen=tlvBuf[i]; // read LEN
|
||||
currentLen=len(tag); // get current length of existing tag
|
||||
if(!(val=buf(tag,tagLen+currentLen))){ // get VAL Buffer for TAG and set LEN (returns NULL if LEN > maxLen)
|
||||
clear();
|
||||
return(0);
|
||||
}
|
||||
|
||||
val+=currentLen; // move val to end of current length (tag repeats to load more than 255 bytes)
|
||||
|
||||
if(tagLen==0) // no bytes to read
|
||||
state=0;
|
||||
else // move to next state
|
||||
state=2;
|
||||
break;
|
||||
|
||||
case 2: // ready to read another byte into VAL
|
||||
*val=tlvBuf[i]; // copy byte into VAL buffer
|
||||
val++; // increment VAL buffer (already checked for sufficient length above)
|
||||
tagLen--; // decrement number of bytes to continue copying
|
||||
if(tagLen==0) // no more bytes to copy
|
||||
state=0;
|
||||
break;
|
||||
|
||||
} // switch
|
||||
} // for-loop
|
||||
|
||||
if(state==0) // should always end back in state=0
|
||||
return(1); // return success
|
||||
|
||||
clear();
|
||||
return(0); // return fail
|
||||
}
|
||||
|
|
@ -0,0 +1,299 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
#include "TLV8.h"
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
tlv8_t::tlv8_t(uint8_t tag, size_t len, const uint8_t* val) : tag{tag}, len{len} {
|
||||
if(len>0){
|
||||
this->val=std::unique_ptr<uint8_t>((uint8_t *)HS_MALLOC(len));
|
||||
if(val!=NULL)
|
||||
memcpy((this->val).get(),val,len);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void tlv8_t::update(size_t addLen, const uint8_t *addVal){
|
||||
if(addLen>0){
|
||||
uint8_t *p=val.release();
|
||||
p=(uint8_t *)HS_REALLOC(p,len+addLen);
|
||||
val=std::unique_ptr<uint8_t>(p);
|
||||
if(addVal!=NULL)
|
||||
memcpy(p+len,addVal,addLen);
|
||||
len+=addLen;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
void tlv8_t::osprint(std::ostream& os) const {
|
||||
|
||||
uint8_t *p=val.get(); // starting pointer
|
||||
uint8_t *pend=p+len; // ending pointer (may equal starting if len=0)
|
||||
|
||||
do{
|
||||
uint8_t nBytes=(pend-p)>255?255:(pend-p); // max is 255 bytes per TLV record
|
||||
os.write((char *)&tag,1);
|
||||
os.write((char *)&nBytes,1);
|
||||
os.write((char *)p,nBytes);
|
||||
p+=nBytes;
|
||||
} while(p<pend);
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
TLV8_itc TLV8::add(uint8_t tag, size_t len, const uint8_t* val) {
|
||||
|
||||
if(!empty() && back().getTag()==tag)
|
||||
back().update(len,val);
|
||||
else
|
||||
emplace_back(tag,len,val);
|
||||
|
||||
return(--end());
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
TLV8_itc TLV8::add(uint8_t tag, TLV8 &subTLV){
|
||||
|
||||
auto it=add(tag,subTLV.pack_size(),NULL); // create space for inserting sub TLV and store iterator to new element
|
||||
subTLV.pack(*it); // pack subTLV into new element
|
||||
return(--end());
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
TLV8_itc TLV8::add(uint8_t tag, uint64_t val){
|
||||
|
||||
uint8_t *p=reinterpret_cast<uint8_t *>(&val);
|
||||
size_t nBytes=sizeof(uint64_t);
|
||||
while(nBytes>1 && p[nBytes-1]==0) // TLV requires little endian of size 1, 2, 4, or 8 bytes (include trailing zeros as needed)
|
||||
nBytes--;
|
||||
if(nBytes==3) // need to include a trailing zero so that total bytes=4
|
||||
nBytes=4;
|
||||
else if(nBytes>4) // need to include multiple trailing zeros so that total bytes=8
|
||||
nBytes=8;
|
||||
return(add(tag, nBytes, p));
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
TLV8_itc TLV8::find(uint8_t tag, TLV8_itc it1, TLV8_itc it2) const {
|
||||
|
||||
auto it=it1;
|
||||
while(it!=it2 && it->getTag()!=tag)
|
||||
it++;
|
||||
return(it);
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
size_t TLV8::pack_size(TLV8_itc it1, TLV8_itc it2) const {
|
||||
|
||||
size_t nBytes=0;
|
||||
|
||||
while(it1!=it2){
|
||||
nBytes+=2+(*it1).getLen();
|
||||
if((*it1).getLen()>255)
|
||||
nBytes+=2*(((*it1).getLen()-1)/255);
|
||||
it1++;
|
||||
}
|
||||
|
||||
return(nBytes);
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
size_t TLV8::pack(uint8_t *buf, size_t bufSize) const {
|
||||
|
||||
size_t nBytes=0;
|
||||
|
||||
while(nBytes<bufSize && currentPackIt!=endPackIt){
|
||||
switch(currentPackPhase){
|
||||
|
||||
case 0:
|
||||
currentPackBuf=*currentPackIt;
|
||||
endPackBuf=(*currentPackIt)+currentPackIt->getLen();
|
||||
currentPackPhase=1;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
*buf++=currentPackIt->getTag();
|
||||
nBytes++;
|
||||
currentPackPhase=2;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
currentPackLen=endPackBuf-currentPackBuf;
|
||||
if(currentPackLen>255)
|
||||
currentPackLen=255;
|
||||
*buf++=currentPackLen;
|
||||
nBytes++;
|
||||
currentPackPhase=3;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if(currentPackLen==0){
|
||||
if(endPackBuf==currentPackBuf){
|
||||
currentPackIt++;
|
||||
currentPackPhase=0;
|
||||
} else {
|
||||
currentPackPhase=1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
size_t copyBytes=(currentPackLen<(bufSize-nBytes)) ? currentPackLen : (bufSize-nBytes);
|
||||
memcpy(buf,currentPackBuf,copyBytes);
|
||||
buf+=copyBytes;
|
||||
currentPackBuf+=copyBytes;
|
||||
currentPackLen-=copyBytes;
|
||||
nBytes+=copyBytes;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(nBytes);
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
int TLV8::unpack(uint8_t *buf, size_t bufSize){
|
||||
|
||||
if(bufSize==0)
|
||||
return(-1);
|
||||
|
||||
if(empty())
|
||||
unpackPhase=0;
|
||||
|
||||
while(bufSize>0){
|
||||
switch(unpackPhase){
|
||||
|
||||
case 0:
|
||||
unpackTag=*buf++;
|
||||
bufSize--;
|
||||
add(unpackTag);
|
||||
unpackPhase=1;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
unpackBytes=*buf++;
|
||||
bufSize--;
|
||||
if(unpackBytes==0)
|
||||
unpackPhase=0;
|
||||
else
|
||||
unpackPhase=2;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
size_t copyBytes=unpackBytes<bufSize ? unpackBytes : bufSize;
|
||||
add(unpackTag,copyBytes,buf);
|
||||
buf+=copyBytes;
|
||||
unpackBytes-=copyBytes;
|
||||
bufSize-=copyBytes;
|
||||
if(unpackBytes==0)
|
||||
unpackPhase=0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return(unpackPhase);
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
int TLV8::unpack(TLV8_itc it){
|
||||
|
||||
if(it==end())
|
||||
return(0);
|
||||
|
||||
return(unpack(*it,it->getLen()));
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
const char *TLV8::getName(uint8_t tag) const {
|
||||
|
||||
if(names==NULL)
|
||||
return(NULL);
|
||||
|
||||
for(int i=0;i<nNames;i++){
|
||||
if(names[i].tag==tag)
|
||||
return(names[i].name);
|
||||
}
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
void TLV8::print(TLV8_itc it1, TLV8_itc it2) const {
|
||||
|
||||
while(it1!=it2){
|
||||
const char *name=getName(it1->getTag());
|
||||
if(name)
|
||||
Serial.printf("%s",name);
|
||||
else
|
||||
Serial.printf("%d",it1->getTag());
|
||||
Serial.printf("(%d) ",it1->getLen());
|
||||
for(int i=0;i<it1->getLen();i++)
|
||||
Serial.printf("%02X",(*it1)[i]);
|
||||
if(it1->getLen()==0)
|
||||
Serial.printf(" [null]");
|
||||
else if(it1->getLen()<=4)
|
||||
Serial.printf(" [%u]",it1->getVal());
|
||||
else if(it1->getLen()<=8)
|
||||
Serial.printf(" [%llu]",it1->getVal<uint64_t>());
|
||||
Serial.printf("\n");
|
||||
it1++;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void TLV8::printAll_r(String label) const{
|
||||
|
||||
for(auto it=begin();it!=end();it++){
|
||||
Serial.printf("%s",label.c_str());
|
||||
print(it);
|
||||
TLV8 tlv;
|
||||
if(tlv.unpack(*it,(*it).getLen())==0)
|
||||
tlv.printAll_r(label+String((*it).getTag())+"-");
|
||||
}
|
||||
Serial.printf("%sDONE\n",label.c_str());
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void TLV8::osprint(std::ostream& os, TLV8_itc it1, TLV8_itc it2) const {
|
||||
|
||||
for(auto it=it1;it!=it2;it++)
|
||||
(*it).osprint(os);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
|
@ -0,0 +1,147 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <sstream>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
#include "PSRAM.h"
|
||||
|
||||
class tlv8_t {
|
||||
|
||||
private:
|
||||
|
||||
uint8_t tag;
|
||||
size_t len;
|
||||
std::unique_ptr<uint8_t> val;
|
||||
|
||||
public:
|
||||
|
||||
tlv8_t(uint8_t tag, size_t len, const uint8_t* val);
|
||||
void update(size_t addLen, const uint8_t *addVal);
|
||||
void osprint(std::ostream& os) const;
|
||||
|
||||
operator uint8_t*() const {
|
||||
return(val.get());
|
||||
}
|
||||
|
||||
uint8_t & operator[](int index) const {
|
||||
return(val.get()[index]);
|
||||
}
|
||||
|
||||
uint8_t *get() const {
|
||||
return(val.get());
|
||||
}
|
||||
|
||||
size_t getLen() const {
|
||||
return(len);
|
||||
}
|
||||
|
||||
uint8_t getTag() const {
|
||||
return(tag);
|
||||
}
|
||||
|
||||
template<class T=uint32_t> T getVal() const {
|
||||
T iVal=0;
|
||||
for(int i=0;i<len;i++)
|
||||
iVal|=static_cast<T>(val.get()[i])<<(i*8);
|
||||
return(iVal);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
typedef std::list<tlv8_t, Mallocator<tlv8_t>>::const_iterator TLV8_itc;
|
||||
typedef struct { const uint8_t tag; const char *name; } TLV8_names;
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
class TLV8 : public std::list<tlv8_t, Mallocator<tlv8_t>> {
|
||||
|
||||
TLV8_itc mutable currentPackIt;
|
||||
TLV8_itc mutable endPackIt;
|
||||
uint8_t mutable *currentPackBuf;
|
||||
uint8_t mutable *endPackBuf;
|
||||
int mutable currentPackPhase;
|
||||
size_t mutable currentPackLen;
|
||||
|
||||
uint8_t unpackTag;
|
||||
size_t unpackBytes;
|
||||
int unpackPhase;
|
||||
|
||||
const TLV8_names *names=NULL;
|
||||
int nNames=0;
|
||||
|
||||
void printAll_r(String label) const;
|
||||
|
||||
public:
|
||||
|
||||
TLV8(){};
|
||||
TLV8(const TLV8_names *names, int nNames) : names{names}, nNames{nNames} {};
|
||||
|
||||
TLV8_itc add(uint8_t tag, size_t len, const uint8_t *val);
|
||||
TLV8_itc add(uint8_t tag, uint64_t val);
|
||||
TLV8_itc add(uint8_t tag, TLV8 &subTLV);
|
||||
TLV8_itc add(uint8_t tag){return(add(tag, 0, NULL));}
|
||||
TLV8_itc add(uint8_t tag, const char *val){return(add(tag, strlen(val), reinterpret_cast<const uint8_t*>(val)));}
|
||||
|
||||
TLV8_itc find(uint8_t tag, TLV8_itc it1, TLV8_itc it2) const;
|
||||
TLV8_itc find(uint8_t tag, TLV8_itc it1) const {return(find(tag, it1, end()));}
|
||||
TLV8_itc find(uint8_t tag) const {return(find(tag, begin(), end()));}
|
||||
|
||||
int len(TLV8_itc it) const {return(it==end()?-1:(*it).getLen());}
|
||||
|
||||
size_t pack_size(TLV8_itc it1, TLV8_itc it2) const;
|
||||
size_t pack_size() const {return(pack_size(begin(), end()));}
|
||||
|
||||
void pack_init(TLV8_itc it1, TLV8_itc it2) const {currentPackIt=it1; endPackIt=it2; currentPackPhase=0;}
|
||||
void pack_init(TLV8_itc it1) const {pack_init(it1, std::next(it1));}
|
||||
void pack_init() const {pack_init(begin(),end());}
|
||||
|
||||
size_t pack(uint8_t *buf, size_t bufSize) const;
|
||||
size_t pack(uint8_t *buf) const {pack_init(); return(pack(buf,pack_size()));}
|
||||
|
||||
const char *getName(uint8_t tag) const;
|
||||
|
||||
void print(TLV8_itc it1, TLV8_itc it2) const;
|
||||
void print(TLV8_itc it1) const {print(it1, std::next(it1));}
|
||||
void print() const {print(begin(), end());}
|
||||
void printAll() const {printAll_r("");}
|
||||
|
||||
void osprint(std::ostream& os, TLV8_itc it1, TLV8_itc it2) const;
|
||||
void osprint(std::ostream& os, TLV8_itc it1) const {osprint(os, it1, std::next(it1));}
|
||||
void osprint(std::ostream& os) const {osprint(os, begin(), end());}
|
||||
|
||||
int unpack(uint8_t *buf, size_t bufSize);
|
||||
int unpack(TLV8_itc it);
|
||||
|
||||
void wipe() {std::list<tlv8_t, Mallocator<tlv8_t>>().swap(*this);}
|
||||
};
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -73,6 +73,20 @@ char *Utils::readSerial(char *c, int max){
|
|||
|
||||
//////////////////////////////////////
|
||||
|
||||
char *Utils::stripBackslash(char *c){
|
||||
|
||||
size_t n=strlen(c);
|
||||
char *p=c;
|
||||
for(int i=0;i<=n;i++){
|
||||
*p=c[i];
|
||||
if(*p!='\\')
|
||||
p++;
|
||||
}
|
||||
return(c);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
String Utils::mask(char *c, int n){
|
||||
String s="";
|
||||
int len=strlen(c);
|
||||
|
|
@ -278,4 +292,4 @@ void PushButton::reset(){
|
|||
|
||||
//////////////////////////////////////
|
||||
|
||||
touch_value_t PushButton::threshold=0;
|
||||
PushButton::touch_value_t PushButton::threshold=0;
|
||||
|
|
|
|||
78
src/Utils.h
78
src/Utils.h
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -28,13 +28,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <driver/timer.h>
|
||||
|
||||
#include "PSRAM.h"
|
||||
|
||||
namespace Utils {
|
||||
|
||||
char *readSerial(char *c, int max); // read serial port into 'c' until <newline>, but storing only first 'max' characters (the rest are discarded)
|
||||
String mask(char *c, int n); // simply utility that creates a String from 'c' with all except the first and last 'n' characters replaced by '*'
|
||||
|
||||
char *stripBackslash(char *c); // strips backslashes out of c (Apple unecessesarily "escapes" forward slashes in JSON)
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
|
@ -42,27 +43,58 @@ String mask(char *c, int n); // simply utility that creates a String fr
|
|||
// going out of scope
|
||||
|
||||
template <class bufType>
|
||||
struct TempBuffer {
|
||||
bufType *buf;
|
||||
int nBytes;
|
||||
class TempBuffer {
|
||||
|
||||
private:
|
||||
|
||||
TempBuffer(size_t len){
|
||||
nBytes=len*sizeof(bufType);
|
||||
buf=(bufType *)heap_caps_malloc(nBytes,MALLOC_CAP_8BIT);
|
||||
bufType *buf=NULL;
|
||||
size_t nElements;
|
||||
|
||||
public:
|
||||
|
||||
TempBuffer(size_t _nElements=1) : nElements(_nElements) {
|
||||
buf=(bufType *)HS_MALLOC(nElements*sizeof(bufType));
|
||||
if(buf==NULL){
|
||||
Serial.print("\n\n*** FATAL ERROR: Requested allocation of ");
|
||||
Serial.print(nBytes);
|
||||
Serial.print(" bytes failed. Program Halting.\n\n");
|
||||
Serial.printf("\n\n*** FATAL ERROR: Requested allocation of %d bytes failed. Program Halting.\n\n",nElements*sizeof(bufType));
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
|
||||
TempBuffer(bufType *addBuf...) : nElements(0) {
|
||||
va_list args;
|
||||
va_start(args,addBuf);
|
||||
while(addBuf!=NULL){
|
||||
size_t addElements=va_arg(args,size_t);
|
||||
buf=(bufType *)HS_REALLOC(buf,(nElements+addElements)*sizeof(bufType));
|
||||
if(buf==NULL){
|
||||
Serial.printf("\n\n*** FATAL ERROR: Requested allocation of %d bytes failed. Program Halting.\n\n",nElements*sizeof(bufType));
|
||||
while(1);
|
||||
}
|
||||
memcpy(buf+nElements,addBuf,addElements*sizeof(bufType));
|
||||
nElements+=addElements;
|
||||
addBuf=va_arg(args,bufType *);
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
~TempBuffer(){
|
||||
heap_caps_free(buf);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
int len(){
|
||||
return(nBytes);
|
||||
return(nElements*sizeof(bufType));
|
||||
}
|
||||
|
||||
int size(){
|
||||
return(nElements);
|
||||
}
|
||||
|
||||
bufType *get(){
|
||||
return(buf);
|
||||
}
|
||||
|
||||
operator bufType*() const{
|
||||
return(buf);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -71,12 +103,6 @@ struct TempBuffer {
|
|||
// PushButton //
|
||||
////////////////////////////////
|
||||
|
||||
#if SOC_TOUCH_VERSION_2
|
||||
typedef uint32_t touch_value_t;
|
||||
#else
|
||||
typedef uint16_t touch_value_t;
|
||||
#endif
|
||||
|
||||
class PushButton{
|
||||
|
||||
int status;
|
||||
|
|
@ -85,15 +111,23 @@ class PushButton{
|
|||
uint32_t singleAlarm;
|
||||
uint32_t doubleAlarm;
|
||||
uint32_t longAlarm;
|
||||
|
||||
#if SOC_TOUCH_VERSION_2
|
||||
typedef uint32_t touch_value_t;
|
||||
#else
|
||||
typedef uint16_t touch_value_t;
|
||||
#endif
|
||||
|
||||
static touch_value_t threshold;
|
||||
static const int calibCount=20;
|
||||
|
||||
public:
|
||||
|
||||
typedef boolean (*triggerType_t)(int pin);
|
||||
|
||||
protected:
|
||||
|
||||
int pressType;
|
||||
typedef boolean (*triggerType_t)(int pin);
|
||||
|
||||
int pin;
|
||||
triggerType_t triggerType;
|
||||
|
||||
|
|
|
|||
93
src/src.ino
93
src/src.ino
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -27,66 +27,61 @@
|
|||
|
||||
#include "HomeSpan.h"
|
||||
|
||||
struct LED_Service : Service::LightBulb {
|
||||
|
||||
int ledPin;
|
||||
SpanCharacteristic *power;
|
||||
|
||||
LED_Service(int ledPin) : Service::LightBulb(){
|
||||
power=new Characteristic::On();
|
||||
this->ledPin=ledPin;
|
||||
pinMode(ledPin,OUTPUT);
|
||||
}
|
||||
|
||||
boolean update(){
|
||||
digitalWrite(ledPin,power->getNewVal());
|
||||
return(true);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
struct invertedLED : Blinkable { // create a child class derived from Blinkable
|
||||
|
||||
int pin; // variable to store the pin number
|
||||
|
||||
invertedLED(int pin) : pin{pin} { // constructor that initializes the pin parameter
|
||||
pinMode(pin,OUTPUT); // set the pin to OUTPUT
|
||||
digitalWrite(pin,HIGH); // set pin HIGH (which is off for an inverted LED)
|
||||
}
|
||||
|
||||
void on() override { digitalWrite(pin,LOW); } // required function on() - sets pin LOW
|
||||
void off() override { digitalWrite(pin,HIGH); } // required function off() - sets pin HIGH
|
||||
int getPin() override { return(pin); } // required function getPin() - returns pin number
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////
|
||||
CUSTOM_CHAR(TestChar,3F4F,PR+PW,UINT8,20,0,100,false)
|
||||
CUSTOM_CHAR_STRING(TestString,3F45,PR+EV,"Hello");
|
||||
CUSTOM_CHAR_TLV8(TestTLV,45674F457,PW+PR);
|
||||
CUSTOM_CHAR_DATA(TestData,303,PW+PW);
|
||||
|
||||
void setup() {
|
||||
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
homeSpan.setLogLevel(2);
|
||||
homeSpan.enableWebLog();
|
||||
|
||||
// homeSpan.setLogLevel(-1);
|
||||
// homeSpan.setSerialInputDisable(true);
|
||||
homeSpan.enableOTA();
|
||||
homeSpan.begin(Category::Lighting,"HomeSpan LightBulb");
|
||||
|
||||
homeSpan.setStatusDevice(new invertedLED(13)); // set Status LED to be a new Blinkable device attached to pin 13
|
||||
homeSpan.setStatusAutoOff(30);
|
||||
|
||||
homeSpan.begin(Category::Lighting,"HomeSpan LED");
|
||||
new SpanUserCommand('D', " - disconnect WiFi", [](const char *buf){WiFi.disconnect();});
|
||||
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
new LED_Service(13);
|
||||
}
|
||||
new Characteristic::Identify();
|
||||
new Service::LightBulb();
|
||||
new Characteristic::On();
|
||||
new Characteristic::TestChar(30);
|
||||
new Characteristic::TestString();
|
||||
new Characteristic::TestString("MyName");
|
||||
new Characteristic::TestTLV();
|
||||
Characteristic::TestData *testData = new Characteristic::TestData();
|
||||
|
||||
TLV8 myTLV;
|
||||
|
||||
myTLV.add(5,0x20);
|
||||
myTLV.add(5,0x30);
|
||||
myTLV.add(1);
|
||||
myTLV.add(5,255);
|
||||
|
||||
Characteristic::TestTLV *testTLV = new Characteristic::TestTLV(myTLV);
|
||||
|
||||
size_t n=testTLV->getData(NULL,0);
|
||||
uint8_t buf[n];
|
||||
testTLV->getData(buf,n);
|
||||
|
||||
Serial.printf("\n");
|
||||
for(int i=0;i<n;i++)
|
||||
Serial.printf("%d %0X\n",i,buf[i]);
|
||||
Serial.printf("\n");
|
||||
|
||||
testData->setData(buf,8);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void loop(){
|
||||
homeSpan.poll();
|
||||
void loop(){
|
||||
|
||||
homeSpan.poll();
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -35,16 +35,18 @@
|
|||
// Single-Wire RGB/RGBW NeoPixels //
|
||||
////////////////////////////////////////////
|
||||
|
||||
Pixel::Pixel(int pin, boolean isRGBW){
|
||||
Pixel::Pixel(int pin, pixelType_t pixelType){
|
||||
|
||||
rf=new RFControl(pin,false,false); // set clock to 1/80 usec, no default driver
|
||||
if(!*rf)
|
||||
return;
|
||||
|
||||
if(isRGBW)
|
||||
this->lastBit=0;
|
||||
map=pixelType;
|
||||
|
||||
if(map[3])
|
||||
bytesPerPixel=4;
|
||||
else
|
||||
this->lastBit=8;
|
||||
bytesPerPixel=3;
|
||||
|
||||
setTiming(0.32, 0.88, 0.64, 0.56, 80.0); // set default timing parameters (suitable for most SK68 and WS28 RGB pixels)
|
||||
|
||||
|
|
@ -82,10 +84,10 @@ void Pixel::set(Color *c, int nPixels, boolean multiColor){
|
|||
status.nPixels=nPixels;
|
||||
status.color=c;
|
||||
status.iMem=0;
|
||||
status.iBit=32;
|
||||
status.started=true;
|
||||
status.px=this;
|
||||
status.multiColor=multiColor;
|
||||
status.iByte=0;
|
||||
|
||||
loadData(this); // load first two bytes of data to get started
|
||||
loadData(this);
|
||||
|
|
@ -112,12 +114,15 @@ void IRAM_ATTR Pixel::loadData(void *arg){
|
|||
RMTMEM.chan[status.px->rf->getChannel()].data32[status.iMem].val=0;
|
||||
return;
|
||||
}
|
||||
|
||||
int startBit=status.px->map[status.iByte];
|
||||
int endBit=startBit-8;
|
||||
|
||||
for(int i=0;i<8;i++)
|
||||
RMTMEM.chan[status.px->rf->getChannel()].data32[status.iMem++].val=status.px->pattern[(status.color->val>>(--status.iBit))&1];
|
||||
|
||||
if(status.iBit==status.px->lastBit){
|
||||
status.iBit=32;
|
||||
for(int iBit=startBit;iBit>endBit;iBit--)
|
||||
RMTMEM.chan[status.px->rf->getChannel()].data32[status.iMem++].val=status.px->pattern[(status.color->val>>iBit)&1];
|
||||
|
||||
if(++status.iByte==status.px->bytesPerPixel){
|
||||
status.iByte=0;
|
||||
status.color+=status.multiColor;
|
||||
status.nPixels--;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -37,20 +37,38 @@
|
|||
|
||||
[[maybe_unused]] static const char* PIXEL_TAG = "Pixel";
|
||||
|
||||
typedef const uint8_t pixelType_t[];
|
||||
|
||||
namespace PixelType {
|
||||
|
||||
pixelType_t RGB={31,23,15,0};
|
||||
pixelType_t RBG={31,15,23,0};
|
||||
pixelType_t BRG={23,15,31,0};
|
||||
pixelType_t BGR={15,23,31,0};
|
||||
pixelType_t GBR={15,31,23,0};
|
||||
pixelType_t GRB={23,31,15,0};
|
||||
pixelType_t RGBW={31,23,15,7};
|
||||
pixelType_t RBGW={31,15,23,7};
|
||||
pixelType_t BRGW={23,15,31,7};
|
||||
pixelType_t BGRW={15,23,31,7};
|
||||
pixelType_t GBRW={15,31,23,7};
|
||||
pixelType_t GRBW={23,31,15,7};
|
||||
};
|
||||
|
||||
////////////////////////////////////////////
|
||||
// Single-Wire RGB/RGBW NeoPixels //
|
||||
////////////////////////////////////////////
|
||||
|
||||
class Pixel : public Blinkable {
|
||||
|
||||
public:
|
||||
public:
|
||||
struct Color {
|
||||
union{
|
||||
struct {
|
||||
uint8_t white:8;
|
||||
uint8_t blue:8;
|
||||
uint8_t red:8;
|
||||
uint8_t green:8;
|
||||
uint8_t red:8;
|
||||
};
|
||||
uint32_t val;
|
||||
};
|
||||
|
|
@ -121,11 +139,11 @@ class Pixel : public Blinkable {
|
|||
struct pixel_status_t {
|
||||
int nPixels;
|
||||
Color *color;
|
||||
int iBit;
|
||||
int iMem;
|
||||
boolean started;
|
||||
Pixel *px;
|
||||
boolean multiColor;
|
||||
int iByte;
|
||||
};
|
||||
|
||||
RFControl *rf; // Pixel utilizes RFControl
|
||||
|
|
@ -133,7 +151,8 @@ class Pixel : public Blinkable {
|
|||
uint32_t resetTime; // minimum time (in usec) between pulse trains
|
||||
uint32_t txEndMask; // mask for end-of-transmission interrupt
|
||||
uint32_t txThrMask; // mask for threshold interrupt
|
||||
uint32_t lastBit; // 0=RGBW; 8=RGB
|
||||
uint8_t bytesPerPixel; // RGBW=4; RGB=3
|
||||
const uint8_t *map; // color map representing order in which color bytes are transmitted
|
||||
Color onColor; // color used for on() command
|
||||
|
||||
const int memSize=sizeof(RMTMEM.chan[0].data32)/4; // determine size (in pulses) of one channel
|
||||
|
|
@ -142,14 +161,16 @@ class Pixel : public Blinkable {
|
|||
volatile static pixel_status_t status; // storage for volatile information modified in interupt handler
|
||||
|
||||
public:
|
||||
Pixel(int pin, boolean isRGBW=false); // creates addressable single-wire RGB (false) or RGBW (true) LED connected to pin (such as the SK68 or WS28)
|
||||
void set(Color *c, int nPixels, boolean multiColor=true); // sets colors of nPixels based on array of Colors c; setting multiColor to false repeats Color in c[0] for all nPixels
|
||||
void set(Color c, int nPixels=1){set(&c,nPixels,false);} // sets color of nPixels to be equal to specific Color c
|
||||
|
||||
Pixel(int pin, pixelType_t pixelType=PixelType::GRB); // creates addressable single-wire LED of pixelType connected to pin (such as the SK68 or WS28)
|
||||
void set(Color *c, int nPixels, boolean multiColor=true); // sets colors of nPixels based on array of Colors c; setting multiColor to false repeats Color in c[0] for all nPixels
|
||||
void set(Color c, int nPixels=1){set(&c,nPixels,false);} // sets color of nPixels to be equal to specific Color c
|
||||
|
||||
static Color RGB(uint8_t r, uint8_t g, uint8_t b, uint8_t w=0){return(Color().RGB(r,g,b,w));} // an alternative method for returning an RGB Color
|
||||
static Color HSV(float h, float s, float v, double w=0){return(Color().HSV(h,s,v,w));} // an alternative method for returning an HSV Color
|
||||
|
||||
int getPin(){return(rf->getPin());} // returns pixel pin if valid, else returns -1
|
||||
boolean isRGBW(){return(bytesPerPixel==4);} // returns true if RGBW LED, else false if RGB LED
|
||||
void setTiming(float high0, float low0, float high1, float low1, uint32_t lowReset); // changes default timings for bit pulse - note parameters are in MICROSECONDS
|
||||
|
||||
operator bool(){ // override boolean operator to return true/false if creation succeeded/failed
|
||||
|
|
@ -159,6 +180,10 @@ class Pixel : public Blinkable {
|
|||
void on() {set(onColor);}
|
||||
void off() {set(RGB(0,0,0,0));}
|
||||
Pixel *setOnColor(Color c){onColor=c;return(this);}
|
||||
|
||||
[[deprecated("Please use Pixel(int pin, pixelType_t pixelType) constructor instead.")]]
|
||||
Pixel(int pin, boolean isRGBW):Pixel(pin,isRGBW?PixelType::GRBW:PixelType::GRB){};
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -251,16 +251,21 @@ void ServoPin::set(double degrees){
|
|||
if(!channel)
|
||||
return;
|
||||
|
||||
double usec=(degrees-minDegrees)*microsPerDegree+minMicros;
|
||||
if(!isnan(degrees)){
|
||||
double usec=(degrees-minDegrees)*microsPerDegree+minMicros;
|
||||
|
||||
if(usec<minMicros)
|
||||
usec=minMicros;
|
||||
else if(usec>maxMicros)
|
||||
usec=maxMicros;
|
||||
|
||||
usec*=timer->freq_hz/1e6*(pow(2,(int)timer->duty_resolution)-1);
|
||||
|
||||
channel->duty=usec;
|
||||
} else {
|
||||
channel->duty=0;
|
||||
}
|
||||
|
||||
if(usec<minMicros)
|
||||
usec=minMicros;
|
||||
else if(usec>maxMicros)
|
||||
usec=maxMicros;
|
||||
|
||||
usec*=timer->freq_hz/1e6*(pow(2,(int)timer->duty_resolution)-1);
|
||||
|
||||
channel->duty=usec;
|
||||
ledc_channel_config(channel);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Gregg E. Berman
|
||||
* Copyright (c) 2023-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Gregg E. Berman
|
||||
* Copyright (c) 2023-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -28,6 +28,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "PwmPin.h"
|
||||
|
||||
[[maybe_unused]] static const char* STEPPER_TAG = "StepperControl";
|
||||
|
||||
|
|
@ -103,3 +104,12 @@ class StepperControl {
|
|||
};
|
||||
|
||||
//////////////////////////
|
||||
|
||||
#include "Stepper_UNIPOLAR.h"
|
||||
#include "Stepper_TB6612.h" // https://www.adafruit.com/product/2448
|
||||
#include "Stepper_A3967.h" // https://www.sparkfun.com/products/12779
|
||||
|
||||
|
||||
struct Stepper_ULN2003A : Stepper_UNIPOLAR {
|
||||
Stepper_ULN2003A(int IN1, int IN2, int IN3, int IN4, std::pair<uint32_t, uint32_t> taskParams = {1,0}) : Stepper_UNIPOLAR(IN1,IN3,IN2,IN4,taskParams){}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Gregg E. Berman
|
||||
* Copyright (c) 2023-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -25,6 +25,8 @@
|
|||
*
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Implementation of StepperControl for a Sparkfun A3967 EasyDriver Stepper Motor Driver
|
||||
// Breakout Board (https://www.sparkfun.com/products/12779)
|
||||
|
||||
|
|
@ -37,10 +39,6 @@
|
|||
// disabled (no current / high impedence). The EasyDriver board does NOT support
|
||||
// the short brake mode.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "StepperControl.h"
|
||||
|
||||
//////////////////////////
|
||||
|
||||
struct Stepper_A3967 : StepperControl {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Gregg E. Berman
|
||||
* Copyright (c) 2023-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -25,6 +25,8 @@
|
|||
*
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Implementation of StepperControl for an Adafruit TB6612 1.2A DC/Stepper Motor Driver
|
||||
// Breakout Board (https://www.adafruit.com/product/2448)
|
||||
|
||||
|
|
@ -44,11 +46,6 @@
|
|||
// In either configuration the motor outputs can be enabled (current running through the coils)
|
||||
// disabled (no current / high impedence) or set to a short brake.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "StepperControl.h"
|
||||
#include "PwmPin.h"
|
||||
|
||||
//////////////////////////
|
||||
|
||||
struct Stepper_TB6612 : StepperControl {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,169 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Implementation of a basic 4-wire controller for a center-tapped Unipolar Stepper Motor
|
||||
// with two coils (Coil 1 and Coil 2) each having two driving inputs (A and B).
|
||||
//
|
||||
// Requires 4 pins on the ESP32 connected to an appropriate driver circuit, such as a set
|
||||
// of Darlington transitors, that are in turn connected to each of the 4 Stepper Motor wires:
|
||||
//
|
||||
// * Coil 1, Input A (1A)
|
||||
// * Coil 1, Input B (1B)
|
||||
// * Coil 2, Input A (2A)
|
||||
// * Coil 2, Input B (2B)
|
||||
//
|
||||
// When any of the pins are HIGH, the driver circuit should cause current to flow in the corresponding
|
||||
// half of the coil. When the pin is set LOW, the driver circuit should stop the flow of current through
|
||||
// that half of the coil. Supported modes and driving logic are as follows:
|
||||
//
|
||||
// FULL_STEP_ONE_PHASE (4 steps, where current flows only through ONE of the phases of ONE of the coils at each step):
|
||||
//
|
||||
// 1A 2A 1B 2B
|
||||
// Step 1: HI -- -- --
|
||||
// Step 2: -- HI -- --
|
||||
// Step 3: -- -- HI --
|
||||
// Step 4: -- -- -- HI
|
||||
//
|
||||
// FULL_STEP_TWO_PHASE (4 steps, where current flows through ONE of the phases of EACH of the coils at each step):
|
||||
//
|
||||
// 1A 2A 1B 2B
|
||||
// Step 1: HI HI -- --
|
||||
// Step 2: -- HI HI --
|
||||
// Step 3: -- -- HI HI
|
||||
// Step 4: HI -- -- HI
|
||||
//
|
||||
// HALF_STEP (8 steps that alternate between the 4 steps of the FULL_STEP modes above):
|
||||
//
|
||||
// 1A 2A 1B 2B
|
||||
// Step 1: HI -- -- --
|
||||
// Step 2: HI HI -- --
|
||||
// Step 3: -- HI -- --
|
||||
// Step 4: -- HI HI --
|
||||
// Step 5: -- -- HI --
|
||||
// Step 6: -- -- HI HI
|
||||
// Step 7: -- -- -- HI
|
||||
// Step 8: HI -- -- HI
|
||||
|
||||
// NOTE ORDER OF CONSTRUCTOR PARAMETERS: First the two pins that drive the A and B side of Coil 1,
|
||||
// followed by the two pints that drive the A and B side of Coil 2.
|
||||
|
||||
// It does not matter which coil is defined as 1 or 2, nor which side is called A or B, as long as
|
||||
// the first two parameters are for one of the coils and the second two are for the other coil.
|
||||
|
||||
// Note: This driver supports enabling and disabling all current flow, but does NOT support a short brake.
|
||||
|
||||
//////////////////////////
|
||||
|
||||
struct Stepper_UNIPOLAR : StepperControl {
|
||||
|
||||
int c1A, c1B, c2A, c2B;
|
||||
uint8_t phase, nPhases;
|
||||
double offset;
|
||||
|
||||
//////////////////////////
|
||||
|
||||
Stepper_UNIPOLAR(int coil1A, int coil1B, int coil2A, int coil2B, std::pair<uint32_t, uint32_t> taskParams = {1,0}) : StepperControl(taskParams.first,taskParams.second) {
|
||||
|
||||
c1A=coil1A;
|
||||
c1B=coil1B;
|
||||
c2A=coil2A;
|
||||
c2B=coil2B;
|
||||
|
||||
pinMode(c1A,OUTPUT);
|
||||
pinMode(c1B,OUTPUT);
|
||||
pinMode(c2A,OUTPUT);
|
||||
pinMode(c2B,OUTPUT);
|
||||
|
||||
setStepType(FULL_STEP_ONE_PHASE);
|
||||
}
|
||||
|
||||
//////////////////////////
|
||||
|
||||
void onEnable() override {
|
||||
setPins();
|
||||
}
|
||||
|
||||
//////////////////////////
|
||||
|
||||
void onDisable() override {
|
||||
digitalWrite(c1A,0);
|
||||
digitalWrite(c1B,0);
|
||||
digitalWrite(c2A,0);
|
||||
digitalWrite(c2B,0);
|
||||
}
|
||||
|
||||
//////////////////////////
|
||||
|
||||
void onStep(boolean direction) override {
|
||||
if(direction)
|
||||
phase=(phase+1)%nPhases;
|
||||
else
|
||||
phase=(phase+nPhases-1)%nPhases;
|
||||
|
||||
setPins();
|
||||
}
|
||||
|
||||
//////////////////////////
|
||||
|
||||
void setPins(){
|
||||
float levelA=cos(phase*TWO_PI/nPhases+offset)*100.0;
|
||||
float levelB=sin(phase*TWO_PI/nPhases+offset)*100.0;
|
||||
digitalWrite(c1A,levelA>0.01);
|
||||
digitalWrite(c1B,levelA<-0.01);
|
||||
digitalWrite(c2A,levelB>0.01);
|
||||
digitalWrite(c2B,levelB<-0.01);
|
||||
}
|
||||
|
||||
//////////////////////////
|
||||
|
||||
StepperControl *setStepType(int mode) override {
|
||||
|
||||
switch(mode){
|
||||
case FULL_STEP_ONE_PHASE:
|
||||
phase=0;
|
||||
nPhases=4;
|
||||
offset=0;
|
||||
break;
|
||||
case FULL_STEP_TWO_PHASE:
|
||||
phase=0;
|
||||
nPhases=4;
|
||||
offset=TWO_PI/8.0;
|
||||
break;
|
||||
case HALF_STEP:
|
||||
phase=0;
|
||||
nPhases=8;
|
||||
offset=0;
|
||||
break;
|
||||
default:
|
||||
ESP_LOGE(STEPPER_TAG,"Unknown StepType=%d",mode);
|
||||
}
|
||||
return(this);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -25,49 +25,40 @@
|
|||
*
|
||||
********************************************************************************/
|
||||
|
||||
// This is a placeholder .ino file that allows you to easily edit the contents of this files using the Arduino IDE,
|
||||
// as well as compile and test from this point. This file is ignored when the library is included in other sketches.
|
||||
#include "PwmPin.h"
|
||||
|
||||
#include "Stepper_TB6612.h" // include the driver for a TB6612 chip
|
||||
#include "Stepper_A3967.h"
|
||||
|
||||
StepperControl *bigMotor;
|
||||
StepperControl *smallMotor;
|
||||
|
||||
#define BIG_MOTOR_POSITION 1600
|
||||
#define SMALL_MOTOR_POSITION 2064
|
||||
|
||||
///////////////////
|
||||
ServoPin servo(21,0,500,2200,-60,60);
|
||||
|
||||
void setup() {
|
||||
|
||||
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
Serial.printf("\nHomeSpan Stepper Control\n\n");
|
||||
|
||||
bigMotor=(new Stepper_TB6612(23,32,22,14,33,27))->setStepType(StepperControl::HALF_STEP)->setAccel(10,20);
|
||||
smallMotor=new Stepper_A3967(18,21,5,4,19);
|
||||
Serial.print("\n\nReady\n\n");
|
||||
|
||||
// smallMotor->setStepType(StepperControl::EIGHTH_STEP);
|
||||
for(int count=0;count<3;count++){
|
||||
for(int i=-60;i<61;i++){
|
||||
servo.set(i);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
for(int i=60;i>-61;i--){
|
||||
servo.set(i);
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
delay(5000);
|
||||
|
||||
servo.set(NAN);
|
||||
|
||||
delay(10000);
|
||||
|
||||
servo.set(0);
|
||||
|
||||
// bigMotor->setStepType(StepperControl::HALF_STEP);
|
||||
// bigMotor->setAccel(10,20);
|
||||
}
|
||||
|
||||
///////////////////
|
||||
//////////////////////////////////////
|
||||
|
||||
void loop(){
|
||||
|
||||
if(smallMotor->position()==0)
|
||||
smallMotor->moveTo(SMALL_MOTOR_POSITION,2);
|
||||
else if(smallMotor->position()==SMALL_MOTOR_POSITION)
|
||||
smallMotor->moveTo(0,2);
|
||||
|
||||
if(bigMotor->position()==0)
|
||||
bigMotor->moveTo(BIG_MOTOR_POSITION,4);
|
||||
else if(bigMotor->position()==BIG_MOTOR_POSITION)
|
||||
bigMotor->moveTo(0,4);
|
||||
|
||||
delay(1000);
|
||||
Serial.printf("Small Motor: %d Big Motor %d\n",smallMotor->stepsRemaining(),bigMotor->stepsRemaining());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// HomeSpan Version //
|
||||
|
||||
#define HS_MAJOR 1
|
||||
#define HS_MINOR 9
|
||||
#define HS_PATCH 1
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
#ifndef ARDUINO_ARCH_ESP32
|
||||
#error ERROR: HOMESPAN IS ONLY AVAILABLE FOR ESP32 MICROCONTROLLERS!
|
||||
#include <FATAL_ERROR>
|
||||
#endif
|
||||
|
||||
#include <esp_arduino_version.h>
|
||||
|
||||
#if ESP_ARDUINO_VERSION_MAJOR!=2
|
||||
#error ERROR: HOMESPAN REQUIRES VERSION 2 OF THE ARDUINO ESP32 LIBRARY. HOMESPAN IS NOT COMPATIBLE WITH VERSION 1 OR VERSION 3
|
||||
#include <FATAL_ERROR>
|
||||
#endif
|
||||
|
||||
#define STRINGIFY(x) _STR(x)
|
||||
#define _STR(x) #x
|
||||
|
||||
#define HOMESPAN_VERSION STRINGIFY(HS_MAJOR) "." STRINGIFY(HS_MINOR) "." STRINGIFY(HS_PATCH)
|
||||
|
||||
#define VERSION(major,minor,patch) major*10000+minor*100+patch
|
||||
|
||||
#ifndef REQUIRED
|
||||
#define REQUIRED 0
|
||||
#endif
|
||||
|
||||
#if (REQUIRED>VERSION(HS_MAJOR,HS_MINOR,HS_PATCH))
|
||||
#error ERROR: THIS SKETCH REQUIRES A LATER VERSION OF THE HOMESPAN LIBRARY
|
||||
#include <FATAL_ERROR>
|
||||
#endif
|
||||
|
||||
#define ARDUINO_ESP_VERSION STRINGIFY(ESP_ARDUINO_VERSION_MAJOR) "." STRINGIFY(ESP_ARDUINO_VERSION_MINOR) "." STRINGIFY(ESP_ARDUINO_VERSION_PATCH)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/zsh
|
||||
|
||||
grep -B 1000 "AUTOGENERATED_TEXT" ../docs/ServiceList.md > ServiceList.md
|
||||
./makeServices ../src/Characteristics.h ../src/Span.h >> ServiceList.md
|
||||
mv ServiceList.md ../docs/ServiceList.md
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue