Commit Graph

270 Commits

Author SHA1 Message Date
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
Gregg 77c48dcf46 Updated SpanButton to use Utils::PushButton
SpanButton now instantiates PushButton instead of keeping track of its own triggering logic.  This means that SpanButton longPress() is triggered by holding down the button for longTime WITHOUT the need to release.  This is a desired change.

Next:  Must update Example 15 to state that SpanButtons trigger a long press withouth needing to be released.

To do:  Consider adding a "repeating mode" for longPress in which the SpanButton re-triggers every longTime while button continues to be pressed.  Best way to implement is probably by creating a PushButton::extend() method.
2020-10-03 10:45:01 -05:00
Gregg 0bdeb7508d Created #defines in Settings.h for all statusLED.start() commands
Reviewed and simplified the number of different blinking patterns.  All are now labeled in Settings.h
2020-10-03 09:36:01 -05:00
Gregg 0a5cf52569 Modified Service::update() to return boolean instead of StatusCode
Also moved StatusCode definitions from Settings.h to HAPConstants.h.  There was no reason to have the user return a StatusCode of OK or UNABLE from update() since the only other choice was BUSY and HomeKit does not seem to distinguish errors.  Either it's okay or not okay, which can more easily be represented by a simply return of TRUE or FALSE from update().

The user now needs to know nothing about StatusCodes.   All Examples were modified to change StatusCode update() to boolean update() and return(StatusCode:OK) to return (true).

Much simpler.
2020-10-01 21:41:26 -05:00
Gregg fbd33bb29d Created homeSpan::setMaxConnections() to make number of HAP connections dynamic
This completes all changes to Settings.h.  User will not need to ever access this files or change any settings.
2020-09-30 10:00:10 -05:00
Gregg ba66c6f01a Normalized all #includes
Convention is that every *.cpp references, in this order:

1) Any required core librries
2) Its own *.h  (i.e. Foo.cpp -> Foo.h)
3) All other *.h files needed by the cpp, UNLESS those *.h files are already in its own *.h file.  Must include all *.h files that are not in its own *.h file even if it is others that are referenced.
2020-09-29 07:28:27 -05:00
Gregg 606601f447 Add 'L' command to change Log Level 2020-09-28 19:59:03 -05:00
Gregg dee954d5bd Converted VERBOSE macros to LogLevel macros that use real-time if-statements.
This change allows the user to set the log-level with homeSpan.setLogLevel() instead of needing to change in Settings.h.  Next up:  Update Example that introduces VERBOSE to instead use setLogLevel().  Consider adding an interactive 'L' command to change this during run-time.

Also, added "#pragma once" to every *.h file to prevent duplication of definitions.  TO DO:  Review all #include to ensure sanity across all files.
2020-09-28 18:04:59 -05:00
Gregg 2d8f36e735 Created HomeSpan::setApPassword() and setAPTimeout()
Moved default values into Settings.h
2020-09-27 22:31:11 -05:00
Gregg fa8c5934ea Eliminated ServiceType from Library and Example 11
Next up - update Examples 12+ to delete ServiceType
2020-09-27 15:56:48 -05:00
Gregg 814d751e71 Created SpanService::setPrimary() and setHidden()
These optional methods can be "chained" when instantiating a new SpanService to configure the Service as Primary or Hidden (or both).  This alleviates the need to ServiceType to be propogated through the Service constructor.

Next Up:  Eliminate ServiceType construct and update Examples to use setPrimary instead.
2020-09-27 14:51:31 -05:00
Gregg 538a3a9531 Added PushButton::primed()
Allows you to determine if short-press has occured but button not yet released.
2020-09-27 14:33:38 -05:00
Gregg a40447b8f8 Created methods to set Control and Status Pins
Created separate init() methods for PushButton and Blinker.  Created HomeSpan:setControlPin and HomeSpan:setStatusPin that can be called from main setup() to modify the defaults.  All default settings being migrated to Settings.h
2020-09-27 13:41:02 -05:00
Gregg ac25b94b67 Fully implemented Generic PushButton
Generic PushButton now used for all device control functions.
2020-09-26 17:13:17 -05:00
Gregg b7de0cf710 Created Generic PushButton
Wll be used for control button.  Nothing to do with buttons that control Accessories, which are handled by SpanButton.
2020-09-26 16:23:44 -05:00
Gregg 6a2d0741aa Finished 'U' unparing routines
Next Up:  Add method to break out of WiFi connection loop by using push button in case WiFi SSID/PWD has changed but there is no desire to unpair controllers.  To Do:  Move blinking status light setting to named macros.
2020-09-24 09:29:52 -05:00
Gregg 69c7d939b8 Update HomeSpan.cpp
Setup Code now saved after serialConfig() or apConfig().

Next up: Create 'U' command to unpair controller.  Change function of control button so it unpairs (short press) or resets WiFi (long press).

To do:  Revisit statusLED blinking paterns to make sure they are clear and consistent - save them as macros in settings.h
2020-09-23 08:51:13 -05:00
Gregg 7d19df3f69 Added 'S' command to change setup code
Verified all functionality works as expected.  Next Up:  Add this code to both serial and AP network configurations.  To Do: alter 'H' command so it removes controllers (unpairs) but retains HAP ID and other data. - perhaps make this 'U' command?
2020-09-22 08:14:02 -05:00
Gregg c9a661573d Made NVS Handles static variables of HAPClient
Now have nvs_handle hapNVS, wifiNVS, and srpNVS.  All three are opened once in HAPClient::init()
2020-09-22 07:28:02 -05:00
Gregg 446679abab Created SRP6A:createVerifyCode()
This generates an SRP verification code from a setupCode and randomly-generated salt.  Function creates the salt internally and returns both the resulting verification code and salt that was used.  These are stored in NVS permanently.

Next Step: create SRP6A:loadVerifycode()
2020-09-20 22:00:01 -05:00
Gregg b0307c9ab0 Completed WiFi credentials code
WiFi data now set/resest/saved as needed.  Next up: saving/resetting Setup Code.
2020-09-20 08:25:16 -05:00
Gregg d93c45c0bc Updated Network:apConfigure
Improved Robustness - all functionality now completed.
2020-09-19 08:39:27 -05:00
Gregg dd6c8d904a Completed Network::apConfig() 2020-09-15 07:00:31 -05:00
Gregg 123e2924a5 Completed Network::serialConfigure()
Next up: update and complete Network::apConfigure()
2020-09-12 10:06:44 -05:00
Gregg 4a6c737c72 Moving serial wifi update into Network.cpp 2020-09-07 11:02:44 -05:00
Gregg 3da2b9a311 Change Config.cpp to Network.cpp
Move all configuration code into Network.cpp, eliminating any calls or connection to HAP.cpp.  Network.cpp is now standalone for HomeSpan.cpp to call directly to handle ALL apects of WiFI and Setup Code initialization.

Also move TempBuffer from HAP.h to Utils.h so it can be used by Network.h
2020-09-06 08:24:13 -05:00
Gregg af3c093cdc updated configure() 2020-09-04 22:19:14 -05:00
Gregg a5e0b1c0ad cleaning up Configure()
TO DO: Add max length to other form inputs;  try limiting number of connections to exactly 1.  Next:  parse form data and initiate wifi connection.
2020-09-04 07:27:50 -05:00
Gregg 9a80b8fa41 Moved all captive code into Configure.cpp 2020-09-03 21:48:08 -05:00
Gregg efe33fcdb9 Created captiveAccessURL()
Developing captive AP routines inside HAP.cpp
2020-09-01 22:08:51 -05:00
Gregg cd5b3115f5 Further updates to Captive AP Mode 2020-09-01 08:34:59 -05:00
Gregg 705a0922e1 Started work on CaptiveAP
Added span::config(hostName) to provide CaptiveAP at start-up.
2020-08-30 22:07:16 -05:00
Gregg b42dd9dfba Implemented Reset Button
Allows for reset of HAP (press for 5 seconds, but less than 10) or Factory reset (press for 10 second).  Use  setResetPin to change from default of pint 21.
2020-08-23 08:14:31 -05:00
Gregg 2172ac1ce6 Implemented Blinker statusLED
Replaced manual blinking with automated Blinker statusLED
2020-08-22 21:52:25 -05:00
Gregg f056b6ae82 Completed SpanButton()
And finished code for Example 15 to verify SpanButton() works as expected.  To Do: add comments and notes to Example 15.
2020-08-20 21:39:13 -05:00