Commit Graph

233 Commits

Author SHA1 Message Date
Gregg f2e1f5bc70 Updated Blinker Class to allow for NULL Blinkable Device
If NULL, all functions are ignored and getPin() returns -1
2022-09-02 18:15:53 -05:00
Gregg 6fecf2c29f updating main code to incorporate new Blinkable class/interface 2022-08-28 18:32:52 -05:00
Gregg fc76db092d started development of Blinkable Interface to allow generic LED to be used with Blinker 2022-08-27 17:33:08 -05:00
Gregg fbc60a67eb Added setTouchCycles() and setTouchThreshold() to SpanButton as static functions 2022-08-17 06:29:26 -05:00
Gregg 3b2c36f179 Changed PushButton::pressType_t to triggerType_t and refreshed triggerType_t constants
Pre-selects are no defined in both PushButton and SpanButton as: TRIGGER_ON_LOW, TRIGGER_ON_HIGH, and TRIGGER_ON_TOUCH
2022-08-15 21:21:21 -05:00
Gregg dbcd9e267b Added check to ignore PushButton::TOUCH is compiling on ESP32-C3
The C3 does not have touch capability.  Compiler will throw an error is PushButton::TOUCH is referenced when compiling for C3.
2022-08-13 10:06:33 -05:00
Gregg ee55f268bd Finalized new SpanButton and PushButton functionality
Streamlined interface for both functions.  To Do:  Update SpanButton documentation
2022-08-13 07:52:32 -05:00
Gregg 9191b8664e Adding generic SpanButton function 2022-08-12 23:15:02 -05:00
Gregg 7841081fda Added option to set SpanButton type
Types include: GROUNDED, POWERED, and TOUCH.
Also added configureTouch() to customize parameters used for touch sensors.
2022-08-12 21:56:45 -05:00
Gregg 54b8374573 begin update of PushButton to make it more generic
Eliminated constructor that had no pin parameter.  Pin parameter is now always required.  Since PushButton was not part of HomeSpan API, these changes should not impact any users.
2022-08-11 06:12:41 -05:00
Gregg 57d791178c starting update of ControlPin logic to make it more generic 2022-08-10 06:20:50 -05:00
Gregg c891548ffa Updated webLog logic to print system messages as well as user messaages
User messages only printer is logLevel>0.  Also, user messages are prefixed in CLI with the word "WEBLOG: "
2022-07-23 08:19:25 -05:00
Gregg 989b315fc0 Updated WiFi disconnect/re-connect logic
Only initialize MDNS, WebLog, and OTA when first connecting to WiFi.  Do not re-initialize upon re-connections after a disconnect.

Also, add number of disconnects, and reset_reason() to WebLog
2022-07-11 21:23:20 -05:00
Gregg c5ba453a95 Converted Span to class; added homeSpan.getLogLevel() and homeSpan.addWebLog(fmt,...)
These functions are needed to provide public access to API now that Span is a class instead of a struct
2022-05-29 10:27:34 -05:00
Gregg 2b25acf2e1 Converted SpanUserCommand to class from struct
Also cleaned up some code by moving a few HAPClient routines into Span polling function.
2022-05-29 06:42:38 -05:00
Gregg 86a0c1cf75 Changed SpanCharacteristic and SpanButton from struct to class
Also moved SpanButton checking into Span instead of awkward reference to HAPClient function
2022-05-28 14:48:49 -05:00
Gregg bb1d0050e2 Changed SpanAccessory and SpanService to class from struct
Split members into private/protected/public
2022-05-28 11:24:11 -05:00
Gregg f75596f3cd Changed deleteAccessory from int to boolean
Returns true on success, otherwise false
2022-05-22 13:13:34 -05:00
Gregg 6018f37b60 Added optional stackSize argument to homeSpan.autoPoll()
If not specified, default is CONFIG_ARDUINO_LOOP_STACK_SIZE which is typically defined in the Arduino-ESP32 library as 8192.
2022-05-22 11:00:40 -05:00
HomeSpan 6d409e9b89 updated version check
requires version 2.X of the Arduino-ESP32 board manager
2022-05-22 08:57:23 -05:00
Gregg 00ea4c6dd8 Changes homeSpan.getAccessory(aid) to homeSpan.deleteAccessory()
The only reason to have used getAccessory(aid) is to delete it, so the delete command is now invoked automatically.  Function returns 0 on success (matching aid found) or -1 on fail (aid not found)
2022-05-21 12:08:03 -05:00
Gregg 52a977d2f1 Revert "sort Accessories by AID to ensure same order all the time during dynamic changes"
This reverts commit 2e98b163b2.
2022-05-19 10:18:00 -05:00
HomeSpan 2e98b163b2 sort Accessories by AID to ensure same order all the time during dynamic changes 2022-05-18 16:31:15 -05:00
Gregg 615d373850 Added Example 20 - Dynamic Bridge. Also created homeSpan.getAccessory(aid) 2022-05-14 10:00:30 -05:00
Gregg dc11c59a00 Deleted 'C' CLI command - replaced with homeSpan.updateDatabase()
Method homeSpan.updateDatabase(boolean updateMDNS) recomputes database hash and compares with previous hash.  If changed, config number is updated and saved in NVS along with new hash.  If updateMDNS is true, a new "c#" MDNS record is also broadcast with the new config number.  This triggers HomeKit to call for a database refresh.  Method returns true if config number has changed, or false if it has not.
2022-05-09 21:03:23 -05:00
Gregg 058d6b0c96 Completed destructors for SpanAccessory, SpanService, and SpanCharacteristics
Tested to ensure any combination can be deleted.

To do: must add logic to destruct any PushButtons that were added to a Service
2022-05-08 15:27:50 -05:00
Gregg 05f1204b4f Continuing destructor code... 2022-05-08 11:56:26 -05:00
Gregg 554cefd3ce Initial work on adding destructors to Accessories, Services, and Characteristics
Will allow for dynamic changes to database without rebooting.
2022-05-08 07:02:19 -05:00
Gregg 7546350775 Added "C" CLI command and updated/fixed config number logic
The "C" command computes a hash of the current database config and updates the config number if needed.  If config number has changed, the MDNS "c#" record is updated and the new config number is rebroadcast.  This triggers HomeKit to immediately request an update of the HAP database so that the changes can be shortly reflected in the Home App without the need to close any Client connections or reboot the device.

The config number logic has also been updated/fixed.  Previously it would create a hash from the full HAP database, which includes the value of each characteristic.  Thus, initial value changes of Characteristics, as a result of stored values in NVS, would cause an update to the config number upon reboot.
 This is not problematic, but also not intended, as a change in value is not really a change in the database config.  The new logic computes a hash of the database that EXCLUDES all Characteristic values.
2022-05-06 17:04:15 -05:00
Gregg 628c29c6b6 Updating logic that determined HAP Configuration Number (MDNS=c#) 2022-05-06 16:13:25 -05:00
Gregg f48cea8afb Completed refactoring of 'i' CLI command
All error checking and database validation is now done dynamically every time the 'i' command is run.
2022-05-01 17:03:07 -05:00
Gregg 18414d8856 Continuing refactor of 'i' CLI command 2022-05-01 12:47:08 -05:00
Gregg 7b30f971e2 Continued refactoring of 'i' CLI command 2022-05-01 09:24:45 -05:00
Gregg 9f71c67f14 Updated logic for required/optional Characteristics
Logic now embedded in 'i' CLI command.
2022-04-30 22:20:42 -05:00
Gregg 0e6f7d27f9 Continuing with 'i' refactoring
Next up: Re-do optional/required Characteristics logic
2022-04-30 18:18:15 -05:00
Gregg 5f463b013e Continuing to refactor 'i' CLI command 2022-04-30 16:29:31 -05:00
Gregg 88f2373a71 Continued refactoring of 'i' CLI command 2022-04-30 11:04:57 -05:00
Gregg 044fe22b1f Made FirmwareRevision Characteristic PR+EV instead of just PR
Allows for updating FirmwareRevision, which HomeKit seems to poll every 60 seconds.
2022-04-26 21:45:29 -05:00
Gregg 54dbda9484 Changed homeSpan.start() to homeSpan.autoPoll() 2022-04-24 08:42:18 -05:00
Gregg c290c8637e Added homeSpan.start() method as alternative to homeSpan.poll()
Rather than call homeSpan.poll() in the main Arduino loop() function, you can instead call homeSpan.start() at the end of the set-up function.  This keeps the main Arduino loop() function free for user-defined code that will not block, and does not get blocked by, homeSpan.poll().

If using a dual-core processor, polling now occurs on core 0, instead of the core 1 (where all other Arduino stuff normally runs).

HomeSpan will throw a fatal error and halt processing if both homeSpan.poll() and homeSpan.start() are used in the same sketch.
2022-04-23 07:22:45 -05:00
Gregg 6409157180 Completed all SpanOTA safemode logic and cleaned up previous iterations of the logic
Must document in safemode in API as well as discuss in OTA documentation.
2022-03-14 22:01:28 -05:00
Gregg 1b0c4835cb Progress on additional SafeMode logic to Auto-enable OTA 2022-03-13 14:42:19 -05:00
Gregg b6eb5afcbf Started work on auto-enabling OTA to start even if not enabled. 2022-03-13 10:19:11 -05:00
Gregg eac06129fc Moved all OTA logic into SpanOTA and completed "safeLoad" protocol 2022-03-12 16:31:50 -06:00
Gregg f3d5092340 SpanOTA in progress 2022-03-12 14:31:15 -06:00
Gregg 2f1044b013 Adding Custom Magic Cookie to OTA Partition
Will prevent uploading a non-HomeSpan sketch via OTA to an existing HomeSpan device.
2022-03-12 08:24:01 -06:00
Gregg f37889f8da Added ClientIP as permanent part of Web Log ; DELETED homeSpan.getClientIP()
ClientIP will show as "0.0.0.0" if log message is not related to client request
2022-03-05 22:24:23 -06:00
Gregg cf22ff1a92 Added homeSpan.getClientIP()
Gets IP address (as char *) of last client to send a request.  Useful as part of web log messages.  Will return 0.0.0.0 if used outside of any code that is responding to a client request.
2022-03-05 22:06:34 -06:00
Gregg e3b9ed99cb Added homeSpan.setTimeServerTimeout(uint32_t tSec);
Sets timeout when connecting to Time Server (default is 10 seconds if not specified)
2022-03-05 20:35:01 -06:00
Gregg 2787966c48 Converted webLog.addLog() to variadic form
Also created WEBLOG() variadic macro
2022-03-05 18:13:27 -06:00
Gregg d9a9e6f31c Changed webLog in HomeSpan from pointer to instantiated variable
Added isEnabled to SpanWebLog to indicate whether Web Log has been enabled.  This allows the use of homeSpan.webLog.addLog() without ever enabling (in which case the log entries are ignored).
2022-03-05 12:50:20 -06:00
Gregg acc64f863a Added addLog(const char *) to SpanWebLog()
Also included logic so that clockTime is set to "Unknown" is addLog() is called prior to WiFi being established.

Next up: replace addLog(const char *) with a variadic set of parameters with dynamic storage allocation.
2022-03-05 10:40:01 -06:00
Gregg 168be05586 Progress on SpanWebLog() 2022-03-05 10:03:13 -06:00
Gregg 91ab626d6c Update HomeSpan.h 2022-03-04 06:15:48 -06:00
Gregg b6c019d1a8 Finished Time Stamping - Started Web Log Structure 2022-03-03 21:37:20 -06:00
Gregg 571bc55852 Added optional homeSpan.setTimeServer() method
If specified, HomeSpan will try to get internet time after establishing WiFi connection.  Consumes one socket connection.
2022-02-27 18:29:58 -06:00
Gregg 170e0b61b1 Add new macro CUSTOM_SERV() to created custom services
Also, updated error checking so that the UUID for both custom Services and custom Characteristics are checked for syntax.  A fatal error is thrown if an ill-formatted UUID is found, since this will definitely prevent pairing with the HomeApp.

The UUID for HAP Services and Characteristics are NOT error checked, since these are fixed in HomeSpan.

Also, the custom Characteristics are not validated against the optional list for a service.  If the user adds a custom Characteristic to a HAP Service, it is assumed to be valid.  Similarly, none of the Characteristics (HAP of Custom) in a Custom Service are validated at all.
2022-02-27 09:51:27 -06:00
Gregg bf2e1354b1 Added second version of SpanUserCommand() that takes a void *arg
Useful for passing a pointer to a Service that can be used in the CLI command.
2022-02-22 21:53:17 -06:00
Gregg 02d841390c Updated License Dates 2022-02-20 13:05:03 -06:00
Gregg ac88329d34 Deprecated setMaxConnections(); Added reserveSocketConnections()
Use homeSpan.reserveSocketConnections(n) to reserve n sockets *not* to be used for HAP.  Multiple calls can be used to cumulate a total number of reserved sockets.  This makes is easy to add reserveSocketConnections(n) at multiple point in the code whenever a certain number of sockets need to be reserved for use with that portion of the code.  For example enableOTA() calls reserveSocketConnections(1).

If both setMaxConnections(), and one or more reserveSocketConnections(), methods are called HomeSpan will use the more restrictive net value.
2022-02-10 21:55:03 -06:00
Gregg 4973d1aaa1 Revert "Initial coding of protectPinISR(pin) method"
This reverts commit 852a916d61.
2022-02-10 21:09:42 -06:00
Gregg 32b417a1da Added homeSpan method deleteStoredValues()
Provides a programmatic way of deleting all stored Characteristic values from NVS.  Identical to the 'V' CLI Command.
2022-02-10 21:02:10 -06:00
Gregg f955ff689b Added homeSpan.setPairCallback() method
Callback function must be of type void()(boolean isPaired).  Will be called when device is paired and when device is unpaired.  Allows for user-defineable actions upon device pairing/unpairing.
2022-02-06 08:39:47 -06:00
Gregg 852a916d61 Initial coding of protectPinISR(pin) method
Works for all NVS calls in homeSpan.h.  To Do:  Add logic to all other NVS calls.
2022-01-30 22:33:07 -06:00
Gregg d667f5e81d Added homeSpan.setStatusAutoOff(uint16_t duration)
Optional method to automatically turn off Status LED after a *duration* seconds.  LED will resume normal operation any time it is re-triggered with a new pattern.  This also resets the elapsed time used to check for autoOff.
2021-12-26 23:07:37 -06:00
Gregg 8737efea14 Added setUnit(char *) as method to SpanCharacteristic
Optional method to add or override the units for a Characteristic (i.e., "percentage", or "celsius") as per HAP-R2 Table 6-6.
2021-12-23 22:28:26 -06:00
Gregg 715adf44f1 Added setDescription(const char *) method to SpanCharacteristic
This allows you to add an optional "description" to a Characteristic.  This is not the same as the name of a Service and is generally not used by the Home App.  However, it appears to be consumed by the Eve app, which can be helpful in some circumstances when developing custom characteristics.
2021-12-17 06:44:27 -06:00
Gregg 48b21df329 Created method setPairingCode(const char *s)
Allows for programmatic creation of Pairing Setup Code.  Not recommended, but added for a convenience - should use 'S' from CLI instead.
2021-11-12 18:01:27 -06:00
HomeSpan fcf715d874 Added getLinks() method to SpanServices
This returns a vector of linked Services that can be used in a for-each loop as such:

for(auto services : getLinks()){ ... }

Must cast services into specific Service type to access anything not generic to the SpanService   class
2021-11-09 21:18:34 -06:00
HomeSpan 3f833beb74 Added ability to change permissions for Characteristics
New methods for Characteristics:

setPerms(uint8_t perms);
addPerms(uint8_t dPerms);
removePerms(uint8_t dPerms);

where perms and dPerms = PR|PW|EV...
2021-11-09 21:08:52 -06:00
Gregg 6f765e8988 Added non-notify option to setVal()
Second optional argument to setVal() determines whether or not HomeSpan sends notification of new value to HomeKit.  Default if left blank is "true" for backwards compatibility.
2021-11-07 20:45:44 -06:00
Gregg 226548defa Added check to ensure Custom Characteristic has valid UUID
And also converted ERRORS to WARNINGS when a Characteristic that is not in the REQ or OPT list is specified for a Service.   This allows the user to add any Characteristic to any Service without forcing an Error (just a Warning).
2021-10-29 22:54:10 -05:00
Gregg 61a2be533b Moved Range checking to a standalone routine checkRanges()
Ranges are now checked for all Characteristics at the end of the configuration, instead of at the end of each Accessory definition.  This is much cleaner and the output is easier to read.

To do:  Revisit use of REQ and OPT - what should constitute a fatal error and what should be a warning.

To do:  Revisit Character definitions - attempt to normalize using the methods implemented for Custom Characteristics
2021-10-26 22:05:44 -05:00
Gregg 65b15b5628 Added AID info to Set Range log message 2021-10-26 05:39:54 -05:00
Gregg eb9530800e Created typedef for HAP types - used to simplify CUSTOM_CHAR
No need to specify both FORMAT and TYPE.   For example, specifying UINT16 automatically sets type to be uint16_t.

To do:  Explore if this can be used for standard Characteristics - revisit standard Characteristics definitions and structure to see if it can be simplified.
2021-10-25 21:57:29 -05:00
Gregg 4309be8f91 Finalized CUSTOM_CHAR() macro to add a custom Characteristic 2021-10-24 21:19:38 -05:00
Gregg 4eb1ebf806 Update HomeSpan.h 2021-10-23 13:21:21 -05:00
Gregg b90fc5aad5 Updated logic re STRING Characteristics
Added setString() as analog to setVal().  This complements getString and getNewString() which are analogs to getVal() and getNewVal().
2021-10-23 13:16:49 -05:00
Gregg dcbfbc3e15 Correct setVal() logic to properly check for EV permissions, not PW permissions 2021-10-22 09:17:26 -05:00
Gregg 26c15c9ca2 Fixed strncpy() warnings
Changed strncpy() to strcpy() when copying new string values
2021-10-18 22:48:56 -05:00
HomeSpan 353749baea
Merge pull request #121 from unreality/master
add support for Televisions
2021-10-17 16:10:50 -05:00
Gregg 8236b6fb9a Marked old SpanRange() class as [[deprecated]]
This will cause a Warning (not an Error) at compile time indicating the class has been deprecated and that the Characteristic::setRange() method should be used instead.  Sketch will still run and SpanRange will still function correctly if used.  Will delete from code base at some point in the future.
2021-10-05 21:27:41 -05:00
Gregg 6de645216c CHANGED default settings for StatusPin and ControlPin
Re-worked code to allow for NO Status LED Pin and NO Control Pin.  If Control Pin is not set explicitly with homeSpan.setControlPin(), there will be no Control Pin.  There is no longer a default since there are too many board variations with S2 and C3 chips now supported.  Same for Status Pin - it will not be defined unless set explicitly with homeSpan.setStatusPin(), with the exception that if LED_BUILTIN is defined (i.e. there is a built-in LED), then the Status LED Pin will default to LED_BUILTIN if not explicitly defined.  MUST UPDATE DOCUMENTATION - THIS CHANGES DEFAULT BEHAVIOR OF HOMESPAN AND MAY REQUIRE UPDATES TO EXISTING SKETCHES
2021-10-05 21:10:24 -05:00
Gregg 0dd341faa9 Update HomeSpan.h
eliminates -Wpmf-conversion warnings generated by our checks for override of update(), loop(), and button() methods
2021-09-22 05:31:46 -05:00
HomeSpan edf5522ca0 Addresses compiler warnings in Arduino-ESP32 2.0.0 2021-09-05 20:39:37 -05:00
Gregg 946819f3d4 updated setValidValues() to return pointer to self
Allows for chaining methods.
2021-09-05 09:14:21 -05:00
Gregg 6a74ce9283 Add setValidValues(int n, ...) method to Characteristic
Allows user to explicitly set the valid values for a Characteristic of type UINT8.  Throws an error if used with any other Characteristic type.
2021-09-05 08:54:34 -05:00
Raal Goff fc9714ed95 ConfiguredName is writeable, allow writes to string characteristics when they have write perms 2021-08-09 19:41:31 +08:00
Gregg 6d77e2559a Added setApFunction(); simplified enableAutoStartAP()
Simplified enableAutoStartAP() so it no longer takes any arguments.  It now simply enables the auto launch of the WiFi Access Point at start-up if WiFi Credentials are not found.

New method setApFunction() will now be used to set an alternative method for the WiFi Access Point.  This will be called anytime 'A' is typed into the CLI, which also covers the auto-launch of the AP at start-up a well as starting it via the Control Button, since both of these functions call processCommand('A').
2021-06-20 15:20:56 -05:00
HomeSpan fc01e37590 Created setWifiCredentials() method
To be used with user-define Access Point, but CAN be used to programmatically hardcode SSID and PASSWORD (not a good idea to do this!)
2021-06-20 06:37:09 -05:00
Gregg e3d081bb35 updated enableAutoStartAP to accept user-define function as argument 2021-06-19 21:36:18 -05:00
Gregg 6356012fd6 Added 'V' command to CLI
This command erases all values of saved Characteristics
2021-06-13 14:49:36 -05:00
Gregg c7d82f74c6 Logic added to save setVal() status changes in NVS
Also created new Example 18 demonstrating NVS storage for an LED.
To do: Create CLI command to erase stored characteristics.
2021-06-13 10:55:06 -05:00
Gregg f4c9c430ef Replace restore() method with second optional parameter when instantiating Characteristic
To enable save/restore for a Characteristic, set second parameter to TRUE when instantiating.  Since first parameter was optional as well, this requires setting it as well.

Next up:  Must add logic to setVal() to store new value as well.
2021-06-13 09:20:13 -05:00
Gregg 40798b15cf Begin development of NVS Characteristic storage
Used method restore() to restore value.  To do:  Change this to a flag during instantiation of a new Characteristic instead of a separate method.
2021-06-13 08:45:11 -05:00
Gregg 1dfd66bf25 Add homeSpan.enableAutoStartAP()
Enables auto-start of AccessPoint if WiFi Credentials not found.
2021-06-05 10:30:21 -05:00
Gregg bda90c59ca Created SpanUserCommand()
Allows the user to add a command function to the Command Line Interface.  All User Commands are defined with a '@' prefix.

To Do:  Document this new feature.
2021-05-30 13:45:52 -05:00
Gregg 16aff0e855 Updated formatting of Accessory Database output to Serial Monitor
Used unicode arrows and symbols, and included more detailed information about each Service and Characteristic.
2021-03-10 22:44:59 -06:00
Gregg 53268127be Updated Examples to use `setRange()` instead of `new SpanRange()`
setRange() is preferred method.  SpanRange() is legacy only
2021-03-07 17:39:42 -06:00
Gregg 3b40aeec74 Added check to throw error is setRange is called twice on same Characteristic 2021-03-06 08:30:09 -06:00