Commit Graph

304 Commits

Author SHA1 Message Date
Gregg 72ddee9061 Add weakly-define Arduino loop() function (defined as NO OP)
Allows you to compile a sketch without defining the Arduino loop() function.  Useful in cases where homeSpan.autoPoll() is used instead.
2022-05-21 17:26:27 -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 d326ae1abf Added logic to delete PushButtons when Service is deleted
This completes all code for the ~SpanService() destructor.

To do: create tutorial example demonstrating a Dynamic Bridge
2022-05-09 21:27:18 -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 bddfb4658a Added 'm' CLI command to print free 8-bit heap memory 2022-05-06 22:19:37 -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 212900f624 Initial re-factoring of "i" command
Instead of creating a static configLog for display upon start-up, an info log will be generated based on real-time data whenever the 'i' CLI command is requested.  This provides for more streamlined error-checking as well.
2022-04-30 07:57:01 -05:00
Gregg 82035df0a7 Removed enabling of IPv6
Not having an IPv6 address is NOT the cause of the Arduino 2.0 OTA network port problem.
2022-04-29 18:16:43 -05:00
Gregg 4659e6f660 Enabled IPV6 Address Broadcast
Added to see if this addresses the mdns-discovery issue in Arduino IDE 2.0.0 interface.
2022-04-27 20:42:38 -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 92ece5413f Removed requirement to include HAP Protocol in Accessory Information Service
HAP Protocol does not appear to be needed anymore (as of iOS 15?)
2022-04-08 17:54:50 -05:00
Gregg d20df43a58 Eliminated HAP Protocol Service and updated Examples 1-8
Experimentation reveals that the HAP Protocol Information Service no longer seems to be required by HomeKit.  Examples work fine without it.
2022-04-08 17:46:33 -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 ffdf0296c6 Dramatically simplified OTA enable check in safemode
Rather than auto-enable OTA if not already enabled in safemode, changed the logic to simply rollback to previous app if OTA was used to download a sketch that does not itself have OTA enabled, unless OTA was previously enabled without safemode.

To do:  Delete all complicated SpanOTA logic that (unsuccessfully) tried to track OTA status and check SHA246 partition codes to determine if reboot was OTA or Serial.  None of this is need, but some of the code may be useful for other things in the future.
2022-03-14 21:46:37 -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 7ddbfd55cc Slight OTA cleanup plus confirmed that you cannot enable ROLLBACK in Arduino-ESP32
Since much of the Arduino-ESP32 library is precompiled, you cannot use -DCONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE to define this during compile time (it gets defined but is not used by the precompiled libraries).

TO DO:  create an NVS entry that flags whether last update was via OTA.  If so, automatically enable OTA regardless of enableOTA setting.  This would ensure that OTA cannot be disabled accidentally by uploading a non-enabledOTA sketch to  remote device.
2022-03-07 22:02:23 -06:00
Gregg 3336ac7fbe Small clean-up of OTA
Researching potential use of rollback of OTA.
2022-03-06 18:39:05 -06:00
Gregg db3bea3b5c Completed Example 19 - Web Logs
Also updated SpanWebLog::addLog() so that the log message is also output to the Serial Monitor if the HomeSpan Log Level is set to 1 or greater.

To do: DOCUMENT ALL THIS!
2022-03-06 09:25:17 -06:00
Gregg 33042f191e Added logURL to MDNS broadcast
Broadcast as "logURL" only if Web Logging is enabled.
2022-03-05 22:34:30 -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 b6c019d1a8 Finished Time Stamping - Started Web Log Structure 2022-03-03 21:37:20 -06:00
Gregg 20ce79ef34 Added check to ensure time server is available
If not, homeSpan.timeServer is reset to NULL
2022-03-02 21:41:06 -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 c40c744702 Small modification to status message 2022-02-11 09:24:51 -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 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 4588669cd2 Added ARDUINO_VARIANT (type of board) to MDNS 2022-01-23 16:40:46 -06:00
Gregg 46820c66a2 Add Arduino-ESP32 version number to MDNS output 2022-01-23 15:00:12 -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 3cc14c3a8d Addressed automation issue by extending true/false parsing
Added true/false parsing to all integer-based Characteristics.  Previously true/false was only parsed for BOOL Characteristics.  For integer-based on/off Characteristics, the Home App would send a 0 for off, and a 1 for on, consistent with HAP-R2.  BUT...when using Home App AUTOMATIONS, the Home App would send true/false for integer-based Characteristics, which is inconsistent with HAP-R2.  This meant automations worked with lights (that use the boolean ON Characteristic) but not with fans (that use the uint8 ACTIVE Characteristic).

With this "fix", true/false will be recognized all the time (except for float- and string-based Characteristics.  Confirmed that fans now work with Home App Automations.
2021-12-23 15:37:26 -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
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 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 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 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 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 b95ebcb4fa Added ARDUINO_ESP_VERSION Macro
Will be "1.0.6", "2.0.0", etc.  Can be used as anywhere as a c-string
2021-10-05 20:08:34 -05:00
Gregg 0fd9424d79 Added Arduino-ESP32 Version Number to initial output 2021-10-04 21:14:16 -05:00
Gregg d82566158a Disabled watchdog timeout messages when running on ESP32-C3 2021-10-04 20:39:32 -05:00
Gregg 50bdfd7d37 Added better display of IDF Version 2021-09-25 14:41:20 -05:00
Gregg 5496503afd Added version info for sodium and mbedtls
Also, fixed "bug" in SRP route (did not impact function - just a generated less random numbers than expected).
2021-09-19 22:07:34 -05:00
Gregg 6c9bf39f54 Added PWM diagnostic messages and chip-specific maximum duty resolution 2021-09-14 21:09:58 -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
Raal Goff 86f99f696b allow 'value' property in characteristics updates to have whitespace 2021-08-08 09:27:25 +08:00
Gregg 36499f35ab Added ESP32 chip type, revision, memory, etc. to initial output 2021-06-26 18:35:28 -05: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 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 d2a7030640 Reclaimed memory from REQ and OPT vectors after they are no longer needed.
Lots more memory optimization to perform!
2021-03-09 21:47:52 -06:00
Gregg 8121146c6b Changed ERROR to WARNING when a required Characteristic is missing
Only throw a non-fatal warning instead of a fatal error if a Service is missing a required Characteristic.  This allows for user flexibility in leaving out required Characteristics for Services that don't seem to need them (contrary to the HAP docs).

Also, changed PositionState Characteristic back to Required (instead of Optional) in WindowCovering Service (as specified by HAP).  If PositionState is not included this will only throw an error instead of a warning as a result of the above change.

To Do: Update Example 13 to properly incorporate PositionState Characteristic.
2021-03-09 20:33:54 -06:00
Gregg ff0dfefc47 Added check to ensure initial value of Characteristic is in allowable Range
Check is not applied to STRING Characteristics.  Check is performed at end of each Accessory definition so will account for any changes to min/max as a result of calls to setRange().  If initial value is outside allowable range, a WARNING (not an ERROR) is thrown.
2021-03-06 09:08:57 -06:00
Gregg 7e3d982ee5 Added min/max Range defaults for all Characteristics
Also added new flag "staticRange" for all Characteristics that indicates whether the min/max range can be changed.  An ERROR will be thrown if setRange is attempted for a Characteristic having staticRange=true.
2021-03-05 22:34:55 -06:00
Gregg 26a38b68cc Completed full implementation of setRange() and deprecation of SpanRange()
Next TO DO:  Complete entry of default min/max into all Characteristics (except BOOL and STRING) defined Span.h so that setRange() error checking works for all Characteristics.
2021-03-04 07:18:13 -06:00
Gregg 5c5361be7b Moved UVal back into SpanCharacteristics 2021-03-03 19:53:13 -06:00
Gregg 7930e3a0d9 Re-Factored SpanCharacteristic Constructor and Services.h
Added Characteristics.h file that defines all static data for HAP Characteristics.  Changed macros in Services.h to use this new HapChar structure.

Code is now more streamlined and ready for mix/max range-checking to be added.
2021-02-28 10:49:17 -06:00
Gregg f591735deb Refactored setVal() to use a template
Ensures robustness and is fully backwards compatible.  User does NOT have to specify a template parameter, as the compiler determines this from the setVal() argument itself.  Allows for any numeric type to be properly mapped to correct HAP format for the Characteristic.

This change is also needed to prepare for the refactoring of SpanRange, the addition of UVals to store HAP min/max, and new error-checking of min/max limits within setVal.
2021-02-27 12:36:50 -06:00
Gregg 433e1cd59a Updated setVal() logic
Updated setVal() logic to ensure that every possible combination of parameter type and Characteristic type is handled properly, and without generating a compile-time error related to ambiguous parameters.
2021-02-26 07:53:33 -06:00
Gregg 96d3877ef6 Added check to ensure HostName is valid
Must be 255 or less alphanumeric characters or a hyphen, except hyphen can't be first or last character.
2021-02-18 21:02:41 -06:00
Gregg 66cd30fa80 Small tweak to diagnostic message when OTA is started 2021-02-17 08:54:29 -06:00
Gregg 24cc2486e2 Added Linked Services logic
New SpanService method addLink(SpanService *svc), where svc is a pointer to the SpanService that is being specified as a Linked Service for the current Service.

addLink() returns a pointer to "this" so may be chained
2021-02-14 18:32:54 -06:00
Gregg 35c8f5b48c Added option to disable OTA password
homeSpan.enableOTA() is now homeSpan.enableOTA(boolean auth=true).  Set auth=false to disable password authentication.  Set to true, or leave blank, to enable password authentication.
2021-02-13 21:24:46 -06:00
Gregg f1c3684e1c Updated maxConnections logic and added Socket numbers to output
homeSpan.begin() automatically resizes maxConnections to ensure it is at or below maxLimit, where maxLimit=CONFIG_LWIP_MAX_SOCKETS-2-otaEnabled.

maxConnections still defaults to 8 if unspecified, which means it is reduced to 7 if OTA is enabled.  Users should set maxConnections to a lower number is they have implemented other socket-based services in their sketch
2021-02-13 14:28:10 -06:00
Gregg 7400383b0a Increased number of sockets in WiFiServer to maxConnection+1
This should account for the extra connection opened when all slots are already filled.
2021-02-12 13:23:02 -06:00
Gregg 7e03998865 Added WiFi callback functionality
HomeSpan will call a user-defined function upon establishing WiFi connectivity.
Set function with homeSpan.setWifiCallback(f), where f must be of form void f().
2021-02-11 07:27:29 -06:00
Gregg 3a519bdc54 Added logic to check for OTA partitions
Warning will be thrown If OTA is enabled but partition table is not configured for OTA.  OTA will not be started.
2021-02-09 21:23:37 -06:00
Gregg 98cfde8aa9 Modified 'O' command so that a blank entry cancels the request to update the OTA password 2021-02-08 18:31:51 -06:00
Gregg db3e1c4bb8 Added ability to specify optional sketch version number.
Specify with homeSpan.setSketchVersion(char *).
Read back with homeSpan.getSketchVersion().

Also, MDNS now broadcasts three new fields:

hspn = HomeSpan Version
sketch = Sketch Version
ota = "yes" if OTA enabled, else "no"

These are all optional to HAP but useful if trying to keep track of version updates when using OTA and Serial Monitor is not available.
2021-02-07 11:49:55 -06:00
Gregg 78b7900f19 Added ARDUINO_VARIANT to initial info output 2021-02-07 10:07:37 -06:00
Gregg 29470e4dd9 Completed OTA logic
OTA pasword now stored in NVS.  Use 'O' command to change from default.  Note password is stored as MD5 hash, and is therefore unrecoverable.  Changes to password DO NOT take effect until next reboot.  Password CAN be changed even if OTA has not been enabled for sketch.  Blank passwords are not allowed.

Stored password can only be erased with 'E' command.
2021-02-07 09:58:52 -06:00
Gregg 208905419c Added OTA logic - enable with homeSpan.enableOTA();
TO DO:  Add password for OTA (and require it)
2021-02-06 18:10:48 -06:00
Gregg 03e43e0bbb Added 'Q' command to change default Setup ID and store in NVS
Setup ID can now be stored in NVS and set dynamically with the 'Q' command.  However, homeSpan.setQRID(char *id) will override if present, but will not change the default stored in the NVS.  This default wil be used once again if homeSpan.setQRID() is removed from the sektch.

If the NVS is empty, the default is set to "HSPN" as in version 1.1.4.
2021-01-31 18:58:45 -06:00
Gregg a39b1ede0b Created QR Code Image 2021-01-28 21:14:19 -06:00
Gregg b6b835ad42 Created HapQR class in standalone HapQR.h file
Class used for the creation and storage of a pairing QR Code (just the text, not the actual graphic) from a HAP Setup Code, HAP Category, and HAP Setup ID.  The resulting QR Code text is output to Serial Monitor whenever the SetUp Code is generated or changed.  The user can type this text into any QR Generator to create a QR Code graphic for pairing the device to HomeKit (in lieu of creating a printed tag of the Setup Code formatted using the Scancardium font).

Though not needed for HomeSpan, this class implements all the settings and parameters (such as Version and Reserved) used to generate any Apple HomeKit QR Code.

This class is used internally by HomeSpan and is not intended for the end-user.
2021-01-26 19:13:07 -06:00
Gregg 9b71d6928a Added QR Code logic
HomeSpan now broadcasts a Hashed Setup ID as MDNS "sh", which is used when pairing with a QR Code instead of a Setup Code.  A text version of the resulting QR code is output to the Serial Monitor whenever the 9-digit Setup Code is generated or changed.  The text version of the QR code can then be input into any QR Code Generator to create a pairable QR Code.

The default Setup ID used to create the Hashed Setup ID is "HSPN".  This can be changed with homeSpan.setQRCode(const char *id), where id is exactly 4 alphanumeric characters.  If not, the request to change the Setup ID is silently ignored and remains "HSPN."
2021-01-24 18:46:55 -06:00
Gregg 78cbd926f1 Updated licenses and version number
Change copyright years to 2020-2021, and updated version number to 1.1.4 in preparation for next patch.
2021-01-24 12:02:24 -06:00
Gregg d41b335aee Cleaned up various compiler warnings when compiled with max warning level
Also added a missing check on hapServer existing before it is used (bug introduced in last update where hapServer became dynamically initialized).
2021-01-22 21:37:29 -06:00
Gregg 750a658241 Added new method homeSpan.setPortNum(port)
HomeSpan defaults to running the HAP Server on port 80 (the standard HTTP port).  This method allows the user to over-ride the default and have HomeSpan run the HAP Server on any other port.

ALSO:  In updating this portion of the code, identified an additional parameter to the ESP32 version of WiFiServer that allows one to specify the number of simultaneous Server connections.  The ESP32 default is 4, which suggests that the ESP32 was internally juggling connections that HomeSpan was keeping open (since the HomeSpan default is 8 connections).

This WiFiServer call has been updated to now specify both the port number AND the number of maximum simultaneous connections (to match whatever has been set by HomeSpan).  This may or may not result in improving performance when more than 4 clients are connected.
2021-01-22 09:45:50 -06:00
Gregg b87a3d1dc3 Added new method homeSpan.setHostNameSuffix()
Allows user to replace the 6-byte AccessoryID "suffix" in the hostName with a custom suffix, included a blank string.  To do: Add to documentation.
2021-01-21 08:07:57 -06:00
Gregg b8d4940772 Removed use of LED_BUILTIN in library and all examples
LED_BUILTIN is NOT defined for all ESP32 boards - some do not have a built-in LED!  Instead, Status LED now defaults to Pin 13, as opposed to LED_BUILTIN.  Also, added a new method, homeSpan.getStatusPin(), to return the pin number used for the Status LED, whether or not it remains the default (13) or is changed by user with homeSpan.setStatusPin(pin).  This method is now used in the DEV_Identify.h file for each example, instead of using LED_BUILTIN (which otherwise won't compile for boards without a built-in LED)
2021-01-09 12:51:35 -06:00
Gregg 0939bc5ade Revamped WiFi connection logic
WiFi connection now occurs asynchronously so that if WiFi is lost, or cannot be connected at start-up, the device still operates intead of blocking while it tries to connect.  The new logic should allow for a wider range of chips to connect.
2021-01-03 17:26:17 -06:00
Gregg 27b6bb7eba Added MAX_ACCESSORIES limit=41
Program now halts if more than 41 Accessories are defined.  This allows for a bridge to have 40 Accessories.  HAP limit is 150, but there is not enough memory in ESP32 to robustly handle more (testing up to 50 LightBulb Services worked, but was sluggish).
2021-01-02 21:45:12 -06:00
Gregg a1035bd911 Added validation check to ensure AccessoryInformation is always the first Service to be defined in an Accessory
Required by HAP (overlooked in original error-checking logic)
2020-12-27 12:47:03 -06:00
Gregg b50db3f078 Cleaned up almost all compiler warning messages and cleaned up wifi connect message
1) Used `const char *` instead of `char *` where appropriate, including the need to create a dummy blank string for us in certain places.
2) Set initialization of WiFiClient to 0 instead of NULL, since WiFiClient is not a pointer (probably don't need to set it to anything since WiFiClient overrides the boolean operator anyway).
3) Cleaned up some of the messaging and logic when WiFi tries to connect so that users know to wait a bit.
4) Only remaining warning messages are for casting SpanService to (void *), which I think i unavailable (and is not forbidden).

To Do: Go through examples and check for warnings (will likely need to convert `char *` to `const char *` in many places.
2020-12-27 09:11:18 -06:00
Gregg 3af65a5774 Updated notification logic so that newValue as well as value gets updated by setVal() 2020-12-24 16:40:41 -06:00
Gregg a9bc186a90 Fixed problem with timeVal() function
had forgotten to initialize updateTime to zero at startup (how did this ever work?)
2020-12-12 18:34:39 -06:00
Gregg d849595bfe More updates to Accessory ID
* if Accessory ID is NOT specified, the default is aid=1+aid of last Accessory, with aid of very first Accessory always set to 1.
* aid of first Accessory must ALWAYS be set to 1 - if user over-rides with another value, error will be thrown
* validation now includes checking for duplicate aids, as well as ensuring the first Accessory is always aid=1
2020-12-05 13:50:24 -06:00
Gregg 1847478252 Added ability to specify "aid" for Accessories
If not specified, "aid" defaults to an index number representing the order in which the Accessories were created.   Values are stored as uint32_t  (which is more limited than HAP requirements of uint64_t, but makes the code easier).

TO DO:  Must add validation to ensure duplicate aid values are not used.
2020-12-05 12:41:33 -06:00
Gregg 8b7a48e0ce Update HomeSpan.cpp
Re-ordered CLI menu
2020-11-22 20:44:09 -06:00
Gregg b6c5a6b68d Added License Info to all files 2020-11-02 20:09:09 -06:00
Gregg e2f11630fa Updated SpanButtton to recognize new Double Press event
button(int pin, boolean isLong) changed to button(int pin, int pressType), where pressType can be SpanButton::LONG, SpanButton::SINGLE, or SpanButton::DOUBLE.  Updated Example 16 and confirmed everything works as expected.

To do: Review all prior examples and update SpanButton when needed.  Also need to update Zephyr Vent Hood code!
2020-11-01 12:21:34 -06:00
Gregg f0f761c143 Extended Exmaple 16 to use two Stateless Programmable Switches
Added ServiceLabelIndex Characteristic, which seems to be required as noted in HAP specifications.  However, linking to a ServiceLabel Service does not appear to be required, so there is no need to build any Service-Linking logic into homeSpan - will wait for use-case to be identified.

To do:  Add support for double-click to SpanButton, then include in Example 16.
2020-10-31 15:53:06 -05:00
Gregg 3979498b3c Created Example 16 - Programmable Pushbutton
Modified SpanCharacteristic::sprintfAttributes to streamline logic and add special handling for the ProgrammableSwitchEvent Characteristic as required by HAP:  the value returned for the database or any read request must be set to null (i.e. "value":null).  The only time the real value should be returned is when the device sends a EV/Notify message (when the button is pressed).  Verified that the example works as expected!

TO DO:  Add functionality to allow for Service Namespace and Index label so that you can have multiple programmable pushbuttons in one service - this requires logic for HAP LINKED SERVICE functionality.
2020-10-31 09:35:42 -05:00
Gregg c7f762da5f Completed error-checking/validation
Added validation to ensure all Accessories have a AccessoryInformation Service and all Accessories have a HAPProtocolInformation Service, unless the device is configured as a bridge, in which case only the first Accessory requires a HAPProtocolInformation Service.
2020-10-28 19:48:53 -05:00
Gregg 254406c802 Added more error-checking to SpanCharacteristic
Checks to ensure that: (A) Characteristic is allowable (i.e. either required or optional) for the defined Service, and (B) Characteristic has not already been instantiated for the defined Service.
2020-10-28 07:31:58 -05:00
Gregg 5838768f38 Completed adding all characteristic types to HAPCharList 2020-10-25 21:29:47 -05:00
Gregg f3b1de2f6b Changed apConfig() to use fixed SSID of "HomeSpan-Configuration" 2020-10-12 07:55:07 -05:00
Gregg 8cfd9afa63 Minor tweaks to some LED patterns 2020-10-11 19:18:22 -05:00
Gregg e658d6d4eb Tweaks to blinker() to make sure delayTime ADDs to offTime 2020-10-10 16:40:53 -05:00
Gregg a6d9fa86e2 Update HomeSpan.cpp 2020-10-10 16:19:58 -05:00
Gregg 3872d693a5 Updated Command Mode to include timeout and for apConfigure() to have more cancel options 2020-10-10 08:22:02 -05:00
Gregg 7e4df498db Completed integration of apConfigure()
The 'A' command now resets any existing WiFi functionality so that it can start an Access Point without needing to first reboot.

To Do:  Add a method to cancel out of apConfigure() and reboot by pressing control button.

To Do:  Create time-out for commandMode()
2020-10-09 07:57:30 -05:00
Gregg 5cb09b6ad8 Updated Access Point code 2020-10-08 21:06:05 -05:00
Gregg 206d194cc1 Created commandMode()
Universal command mode for control button operation.
2020-10-07 22:20:44 -05:00
Gregg a4b86f4618 Re-worked network.serialConfigure() and initWifi()
To do:  Re-work apConfigure() and update factory reset so that it only deletes HAP and WIFI data, NOT setup code.
2020-10-07 08:20:37 -05:00
Gregg cf0627e8c9 Updating WiFi Configuration Logic
Changing code so that it is possible to run HomeSpan without configuring WiFi.  HomeSpan can already run without being paired, but requires WiFi at start-up.  No reason to force WiFi to be used if device has buttons to operate the appliance withouth the need for WiFi or a connection to HomeKit.  Work in progress...
2020-10-06 09:09:43 -05:00
Gregg 22962ebfe3 Moved Zephyr into a standalone repository; Re-organized tutorials
Zephyr3, the latest version, was moved into its own repo and renamed ZephyrVentHood.

Deleted Zephyr1, Zephyr2, and Zephyr3, which are no longer needed.

Flattened folder structure for Examples and placed them all in top-level directory
2020-10-04 11:00:08 -05:00
Gregg 82215e8d90 Modified SpanService to accept list of required and optional SpanCharacteristics
Started adding lists to the first few Services in Service.h.  This is a longer-term project to enable HomeSpan to validate a configuration and check that all Services have all required Characteristics and that any optional Characteristics defined are indeed permitted.
2020-10-04 09:58:40 -05:00
Gregg 855d5e9735 Added Error messages and Warnings for SpanRange and SpanButton 2020-10-04 09:26:21 -05:00
Gregg db620e497e Added code to output configuration log and error messages
Config Log is output if logLevel>1 OR there is a fatal error in configuration
2020-10-03 22:21:38 -05:00
Gregg 1d6f07a400 Added HAP Names to all Services and Characteristics in Services.h 2020-10-03 21:39:20 -05:00
Gregg 60c2d5645d Update HomeSpan.cpp
Tweaks to WiFi reset code so that instead of re-starting, HomeSpan simply disconnects WiFi, which triggers initWifi() upon the next call to poll(().
2020-10-03 20:18:58 -05:00
Gregg 546c5048db Fixed bug in initialization logic at beginning of poll()
Full initialization now depends on "isInitialized" flag instead of monitoring Wifi connection, to protect against a loss of WiFi causing a re-initialization, instead of just a wifi reconnect with initWifi() alone.
2020-10-03 15:08:44 -05:00