Commit Graph

299 Commits

Author SHA1 Message Date
Gregg e2678f5661 Added position() method to SpanToggle()
Created PushButton::OPEN and PushButton::CLOSED enums.

This completes all SpanToggle() functionality.  Will add a SpanToggle() to UnitTest.
2023-02-03 23:09:08 -06:00
Gregg c3d0c98e04 Created SpanToggle()
Derived from SpanButton()
2023-01-31 22:55:43 -06:00
Gregg 03ba061b9b Added logic to hide AP SSID from broadcasting when WIFI_AP_STA used for SpanPoint
This does NOT effect the HomeSpan Access Point from being broadcast as usual when launched.
2023-01-28 18:05:59 -06:00
Gregg eb53e7f6e7 Moved SpanPoint initialization message to main Info 'i' output
Created SpanPoint table within 'i' output
2023-01-25 22:22:49 -06:00
Gregg 7eca1e776b Add option to SpanPoint to use softAP MAC Address instead of STA
Needed to support ESP-NOW on ESP-8266 chips, which seem to only work if connecting into softAP MAC Address once HomeSpan is connected to WiFi network (prior to connection ESP-8266 will properly connect to normal STA address as well as softAP address).
2023-01-22 18:05:59 -06:00
Gregg 72b4ece64d Added DATA format
Includes 3 new methods: getData(), getNewData(), and setData()
2023-01-01 11:33:50 -06:00
Gregg eecce34848 Added NVS storage for last channel used in SpanPoint
Applicable only for remote devices (i.e. not a Hub device).  Last channel stored is used as initial channel upon reboot, provided that this channel is allowed by the channel mask (if not, the first allowed channel is selected instead).
2022-12-27 09:55:30 -06:00
Gregg 7939624bf7 Added Service::TelevisionSpeaker
Also updated Television Example.  Volume buttons on remote now function as expected, though there does not seems to be a mute button
2022-12-23 16:51:55 -06:00
Gregg 484f1c4f2e Cleaned up compiler warnings
* Changed ~SpanService to virtual function to ensure any user-defined destructor is also called

* Found/corrected bug in error message related to defining a Characteristic without any Service

* Added warning/error ID numbers to warning/error messages

* Other misc changes to clean up compiler warnings
2022-12-02 17:49:54 -06:00
Gregg f775a63b7a Completed and tested all statusCallback and statusString logic 2022-10-30 08:49:53 -05:00
Gregg 05cbc03f12 Added homeSpan.statusString(HS_STATUS statusMessage)
Can be used in statusCallback to convert HS_STATUS to char string
2022-10-29 18:36:30 -05:00
HomeSpan 645c169a5e created STATUS_UPDATE macro
Combines statusLED updates with statusCallback updates
2022-10-29 11:34:48 -05:00
Gregg d55dad1529 Added more events to statusCallback() 2022-10-29 07:37:34 -05:00
HomeSpan bb1b599797 Completed homeSpan.setStatusCallback()
To Do: create documentation
2022-10-24 21:48:37 -04:00
HomeSpan 7ff91ccf02 Changed hsEventCallback to statusCallback 2022-10-24 19:03:15 -04:00
HomeSpan 4e23c5e357 Updating hsEventCallback with more events 2022-10-24 06:46:04 -04:00
HomeSpan 5b38c6a04a Started homeSpan.setEventCallback() 2022-10-23 21:26:41 -04:00
Gregg 74bbde2492 Changed SpanPoint::send(void *data) to SpanPoint::send(const void *data) 2022-10-16 16:53:11 -05:00
Gregg 2d411bab82 Updated SpanPoint so that WiFi_AP_STA is only used if receiveSize>0
Next up: explore power-reducing modes and sleep modes for remote sensors to extend battery life.
2022-10-03 22:04:51 -05:00
Gregg ab21a0c96c Created Other Examples - RemoteSensors
Created MainDevice and RemoteDevice sketches
2022-10-02 10:14:09 -05:00
Gregg 23afdb3711 Completed all SpanPoint code
Allows for bi-directional transmission between main HomeSpan device and one or more remote devices.

To Do:  Create and test with Temperature Sensor Example
2022-10-01 15:33:11 -05:00
Gregg b7317c3b5f Added SpanPoint::send() functionality
Works as expected.

Next Up:  Modify send() logic so that channels are NOT scanned if device is a main HomeSpan hub.
2022-09-30 22:20:32 -05:00
Gregg c819426dec Moving HomePoint.h back into HomeSpan.h
Added SpanPoint::setAsHub(), which is called after homeSpan.begin() to set device as Hub so SpanPoint knows not to change WiFi channel.

Also added check to make sure there are no SpanPoint objects instantiated before a call to homeSpan.begin() (if it is called at all).
2022-09-30 17:27:57 -05:00
Gregg 72294bde8b Move all SpanPoint code into separate HomePoint.cpp and HomePoint.h files
This enables SpanPoint to operate as a standalone library with no reliance on anything in HomeSpan.

To Do: migrate all HomePeer code into SpanPoint.  This will yield a universal standalone HomePoint library that can be used for BOTH the receiver and the sender (which automatically means two-way communication is always possible)
2022-09-28 21:16:29 -05:00
Gregg 58683586bc Added SpanPoint::get()
This completes SpanPoint.  Next: rename HomePeer to be HomePoint.
2022-09-26 22:00:32 -05:00
Gregg 4f983051ce Created SpanPoint
Verified ESP-NOW is communicating correctly with HomeSpan.  Verified encryption works.  Next step - create linkages between incoming data and Services; create queue structure to transfer data.
2022-09-25 13:53:54 -05:00
Gregg 22cfa130b4 Created HomePeer
This is a self-contained library that is used for remote devices set up as HomeSpan Peers via ESP-NOW.
2022-09-24 16:49:32 -05:00
Gregg 4a4a5f8a6b Started development of ESP-NOW
Also, added WiFi.begin("none") to make sure all WiFi data is erased when requested.
2022-09-05 18:42:37 -05:00
Gregg 355a2dfd4d Updated rest of code to reflect latest version of statusLED
Removed all checks to see if statusLED is defined, since it will now ALWAYS be defined, even if the statusDevice is set to NULL.
2022-09-02 18:47:15 -05:00
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 fc76db092d started development of Blinkable Interface to allow generic LED to be used with Blinker 2022-08-27 17:33:08 -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 16b71af6f7 Added button type to SpanButton HomeSpan Info 2022-08-14 18:14:41 -05:00
Gregg e8d40150ed Incorporated logic to auto-calibrate touch sensors
Works with ESP32, ESP32-S2, and ESP32-S3 (ESP32-C3 does not support Touch Sensors).
2022-08-14 18:03:59 -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 57d791178c starting update of ControlPin logic to make it more generic 2022-08-10 06:20:50 -05:00
Gregg 689ea86991 Updating ProgrammableHub2 Example 2022-07-28 17:13:04 -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 f75596f3cd Changed deleteAccessory from int to boolean
Returns true on success, otherwise false
2022-05-22 13:13:34 -05:00
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