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.
This commit is contained in:
Gregg 2022-04-08 17:46:33 -05:00
parent 4ada3542cd
commit d20df43a58
13 changed files with 52 additions and 381 deletions

View File

@ -1,7 +1,7 @@
/********************************************************************************* /*********************************************************************************
* MIT License * MIT License
* *
* Copyright (c) 2020 Gregg E. Berman * Copyright (c) 2020-2022 Gregg E. Berman
* *
* https://github.com/HomeSpan/HomeSpan * https://github.com/HomeSpan/HomeSpan
* *
@ -98,14 +98,7 @@ void setup() { // Your HomeSpan code should be placed within the
// new Characteristic::Model("120-Volt Lamp"); // Model of the Accessory (arbitrary text string, and can be the same for every Accessory) // new Characteristic::Model("120-Volt Lamp"); // Model of the Accessory (arbitrary text string, and can be the same for every Accessory)
// new Characteristic::FirmwareRevision("0.9"); // Firmware of the Accessory (arbitrary text string, and can be the same for every Accessory) // new Characteristic::FirmwareRevision("0.9"); // Firmware of the Accessory (arbitrary text string, and can be the same for every Accessory)
// *NOTE* HAP requires that the AccessoryInformation Service always be instantiated BEFORE any other Services, which is why we created it first. // *NOTE* HAP requires that the Accessory Information Service always be instantiated BEFORE any other Services, which is why we created it first.
// HAP also requires every Accessory (with the exception of those in Bridges, as we will see later) to implement the HAP Protocol Information Service.
// This Service supports a single required Characteristic that defines the version number of HAP used by the device.
// HAP Release R2 requires this version to be set to "1.1.0"
new Service::HAPProtocolInformation(); // Create the HAP Protcol Information Service
new Characteristic::Version("1.1.0"); // Set the Version Characteristicto "1.1.0" as required by HAP
// Now that the required "informational" Services have been defined, we can finally create our Light Bulb Service // Now that the required "informational" Services have been defined, we can finally create our Light Bulb Service

View File

@ -1,7 +1,7 @@
/********************************************************************************* /*********************************************************************************
* MIT License * MIT License
* *
* Copyright (c) 2020 Gregg E. Berman * Copyright (c) 2020-2022 Gregg E. Berman
* *
* https://github.com/HomeSpan/HomeSpan * https://github.com/HomeSpan/HomeSpan
* *
@ -52,9 +52,6 @@ void setup() {
new Service::AccessoryInformation(); // HAP requires every Accessory to implement an AccessoryInformation Service, with the required Identify Characteristic new Service::AccessoryInformation(); // HAP requires every Accessory to implement an AccessoryInformation Service, with the required Identify Characteristic
new Characteristic::Identify(); // Create the required Identify new Characteristic::Identify(); // Create the required Identify
new Service::HAPProtocolInformation(); // Create the HAP Protcol Information Service
new Characteristic::Version("1.1.0"); // Set the Version Characteristicto "1.1.0" as required by HAP
new Service::LightBulb(); // Create the Light Bulb Service new Service::LightBulb(); // Create the Light Bulb Service
new Characteristic::On(); // This Service requires the "On" Characterstic to turn the light on and off new Characteristic::On(); // This Service requires the "On" Characterstic to turn the light on and off
@ -65,9 +62,6 @@ void setup() {
new Service::AccessoryInformation(); // HAP requires every Accessory to implement an AccessoryInformation Service, with the required Identify Characteristic new Service::AccessoryInformation(); // HAP requires every Accessory to implement an AccessoryInformation Service, with the required Identify Characteristic
new Characteristic::Identify(); // Create the required Identify new Characteristic::Identify(); // Create the required Identify
new Service::HAPProtocolInformation(); // Create the HAP Protcol Information Service
new Characteristic::Version("1.1.0"); // Set the Version Characteristicto "1.1.0" as required by HAP
new Service::LightBulb(); // Create the Light Bulb Service new Service::LightBulb(); // Create the Light Bulb Service
new Characteristic::On(); // This Service requires the "On" Characterstic to turn the light on and off new Characteristic::On(); // This Service requires the "On" Characterstic to turn the light on and off

View File

@ -1,7 +1,7 @@
/********************************************************************************* /*********************************************************************************
* MIT License * MIT License
* *
* Copyright (c) 2020 Gregg E. Berman * Copyright (c) 2020-2022 Gregg E. Berman
* *
* https://github.com/HomeSpan/HomeSpan * https://github.com/HomeSpan/HomeSpan
* *
@ -50,9 +50,6 @@ void setup() {
new Service::AccessoryInformation(); // HAP requires every Accessory to implement an AccessoryInformation Service, with the required Identify Characteristic new Service::AccessoryInformation(); // HAP requires every Accessory to implement an AccessoryInformation Service, with the required Identify Characteristic
new Characteristic::Identify(); // Create the required Identify new Characteristic::Identify(); // Create the required Identify
new Service::HAPProtocolInformation(); // Create the HAP Protcol Information Service
new Characteristic::Version("1.1.0"); // Set the Version Characteristicto "1.1.0" as required by HAP
new Service::LightBulb(); // Create the Light Bulb Service new Service::LightBulb(); // Create the Light Bulb Service
new Characteristic::On(); // This Service requires the "On" Characterstic to turn the light on and off new Characteristic::On(); // This Service requires the "On" Characterstic to turn the light on and off

View File

@ -1,7 +1,7 @@
/********************************************************************************* /*********************************************************************************
* MIT License * MIT License
* *
* Copyright (c) 2020 Gregg E. Berman * Copyright (c) 2020-2022 Gregg E. Berman
* *
* https://github.com/HomeSpan/HomeSpan * https://github.com/HomeSpan/HomeSpan
* *
@ -50,10 +50,7 @@ void setup() {
new SpanAccessory(); new SpanAccessory();
new Service::AccessoryInformation(); new Service::AccessoryInformation();
new Characteristic::Identify(); new Characteristic::Identify();
new Service::HAPProtocolInformation();
new Characteristic::Version("1.1.0");
new Service::LightBulb(); new Service::LightBulb();
new Characteristic::On(true); // NEW: Providing an argument sets its initial value. In this case it means the LightBulb will be turned on at start-up new Characteristic::On(true); // NEW: Providing an argument sets its initial value. In this case it means the LightBulb will be turned on at start-up

View File

@ -1,7 +1,7 @@
/********************************************************************************* /*********************************************************************************
* MIT License * MIT License
* *
* Copyright (c) 2020 Gregg E. Berman * Copyright (c) 2020-2022 Gregg E. Berman
* *
* https://github.com/HomeSpan/HomeSpan * https://github.com/HomeSpan/HomeSpan
* *
@ -74,10 +74,7 @@ void setup() {
new SpanAccessory(); new SpanAccessory();
new Service::AccessoryInformation(); new Service::AccessoryInformation();
new Characteristic::Identify(); new Characteristic::Identify();
new Service::HAPProtocolInformation();
new Characteristic::Version("1.1.0");
// In Example 2 we instantiated a LightBulb Service and its "On" Characteristic here. We are now going to replace these two lines (by commenting them out)... // In Example 2 we instantiated a LightBulb Service and its "On" Characteristic here. We are now going to replace these two lines (by commenting them out)...
@ -97,10 +94,7 @@ void setup() {
new SpanAccessory(); new SpanAccessory();
new Service::AccessoryInformation(); new Service::AccessoryInformation();
new Characteristic::Identify(); new Characteristic::Identify();
new Service::HAPProtocolInformation();
new Characteristic::Version("1.1.0");
// new Service::LightBulb(); // Same as above, this line is deleted... // new Service::LightBulb(); // Same as above, this line is deleted...
// new Characteristic::On(); // This line is also deleted... // new Characteristic::On(); // This line is also deleted...

View File

@ -1,7 +1,7 @@
/********************************************************************************* /*********************************************************************************
* MIT License * MIT License
* *
* Copyright (c) 2020 Gregg E. Berman * Copyright (c) 2020-2022 Gregg E. Berman
* *
* https://github.com/HomeSpan/HomeSpan * https://github.com/HomeSpan/HomeSpan
* *
@ -64,20 +64,14 @@ void setup() {
new SpanAccessory(); new SpanAccessory();
new Service::AccessoryInformation(); new Service::AccessoryInformation();
new Characteristic::Identify(); new Characteristic::Identify();
new Service::HAPProtocolInformation();
new Characteristic::Version("1.1.0");
new DEV_LED(16); // create an on/off LED attached to pin 16 (same as in Example 5) new DEV_LED(16); // create an on/off LED attached to pin 16 (same as in Example 5)
new SpanAccessory(); new SpanAccessory();
new Service::AccessoryInformation(); new Service::AccessoryInformation();
new Characteristic::Identify(); new Characteristic::Identify();
new Service::HAPProtocolInformation();
new Characteristic::Version("1.1.0");
new DEV_DimmableLED(17); // NEW! create a dimmable (PWM-driven) LED attached to pin 17. See new code at end of DEV_LED.h new DEV_DimmableLED(17); // NEW! create a dimmable (PWM-driven) LED attached to pin 17. See new code at end of DEV_LED.h

View File

@ -1,7 +1,7 @@
/********************************************************************************* /*********************************************************************************
* MIT License * MIT License
* *
* Copyright (c) 2020 Gregg E. Berman * Copyright (c) 2020-2022 Gregg E. Berman
* *
* https://github.com/HomeSpan/HomeSpan * https://github.com/HomeSpan/HomeSpan
* *
@ -65,21 +65,15 @@ void setup() {
new Service::AccessoryInformation(); new Service::AccessoryInformation();
new Characteristic::Identify(); new Characteristic::Identify();
new Characteristic::Name("Simply LED"); // This use of Name() will be ignored by the Home App. The default name for the Accessory will continue to be shown as "HomeSpan LED" new Characteristic::Name("Simple LED"); // This use of Name() will be ignored by the Home App. The default name for the Accessory will continue to be shown as "HomeSpan LED"
new Service::HAPProtocolInformation();
new Characteristic::Version("1.1.0");
new DEV_LED(16); // create an on/off LED attached to pin 16 (same as in Example 5) new DEV_LED(16);
new SpanAccessory(); new SpanAccessory();
new Service::AccessoryInformation(); new Service::AccessoryInformation();
new Characteristic::Identify(); new Characteristic::Identify();
new Characteristic::Name("Dimmable LED"); // This DOES change the default name for the Accessory from "HomeSpan LED 2" to "Dimmable LED" new Characteristic::Name("Dimmable LED"); // This DOES change the default name for the Accessory from "HomeSpan LED 2" to "Dimmable LED"
new Service::HAPProtocolInformation();
new Characteristic::Version("1.1.0");
new DEV_DimmableLED(17); new DEV_DimmableLED(17);

View File

@ -1,115 +0,0 @@
/*********************************************************************************
* MIT License
*
* Copyright (c) 2020 Gregg E. Berman
*
* https://github.com/HomeSpan/HomeSpan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
********************************************************************************/
////////////////////////////////////////////////////////////
// //
// HomeSpan: A HomeKit implementation for the ESP32 //
// ------------------------------------------------ //
// //
// Example 7: Transforming AccessoryInformation into a //
// derived Service that implements the //
// Identify Characteristic //
// //
////////////////////////////////////////////////////////////
#include "HomeSpan.h"
#include "DEV_LED.h"
#include "DEV_Identify.h" // NEW! This is where we store all code for the DEV_Identify Service
void setup() {
// In Example 5 we saw how to create a derived Service to encapsulate all the functionality needed to implement DEV_LED
// in it's own DEV_LED.h file. Then, in Example 6 we extended that further by implementing DEV_DimmableLED. In this
// example we do the same for the AccessoryInformation Service. Note how AccessoryInformation, and all of its
// Characteristics, need to be defined for every Accessory. By deriving a new Service that implements a multi-argument
// constructor we can avoid having to separately create each required Characteristic every time. Creating a derived Service
// also allows us to implement device-specific code for the Identify Characteristic. We will call this derived Service
// DEV_Identify, and store its code in "DEV_Identify.h" which has already been included above.
// As usual, all previous comments have been deleted and only new changes from the previous example are shown.
// NOTE: To see how this works in practice, you'll need to unpair your device and re-pair it once the new code is loaded.
// This will allow oyu to activate the identify routines.
Serial.begin(115200);
homeSpan.begin(Category::Lighting,"HomeSpan LEDs");
new SpanAccessory();
// Rather than instantiate the AccessoryInformation Service and all of it's required Characteristics,
// we'll delete these line (comment them out)...
// new Service::AccessoryInformation();
// new Characteristic::Name("On/Off LED");
// new Characteristic::Manufacturer("HomeSpan");
// new Characteristic::SerialNumber("123-ABC");
// new Characteristic::Model("20mA LED");
// new Characteristic::FirmwareRevision("0.9");
// new Characteristic::Identify();
// ...and replace them with this single line that implements everything above. See DEV_Identify.h for
// details on how this is defined. Note there is an extra argument at the end we set to 3.
// This optional argument will be used to run the identify routine (see code for details)
new DEV_Identify("On/Off LED","HomeSpan","123-ABC","20mA LED","0.9",3); // NEW! This implements all the Characteristics above
new Service::HAPProtocolInformation();
new Characteristic::Version("1.1.0");
new DEV_LED(16); // create an on/off LED attached to pin 16 (same as in Example 5)
new SpanAccessory();
// Same as above, we can replace all of this...
// new Service::AccessoryInformation();
// new Characteristic::Name("Dimmable LED");
// new Characteristic::Manufacturer("HomeSpan");
// new Characteristic::SerialNumber("123-ABC");
// new Characteristic::Model("20mA LED");
// new Characteristic::FirmwareRevision("0.9");
// new Characteristic::Identify();
// ...with this (note we set last argument to 5 this time - see code for what this does)
new DEV_Identify("Dimmable LED","HomeSpan","123-ABC","20mA LED","0.9",5); // NEW! This implements all the Characteristics above
new Service::HAPProtocolInformation();
new Characteristic::Version("1.1.0");
new DEV_DimmableLED(17); // create a dimmable (PWM-driven) LED attached to pin 17
} // end of setup()
//////////////////////////////////////
void loop(){
homeSpan.poll();
} // end of loop()

View File

@ -1,65 +0,0 @@
//////////////////////////////////
// DEVICE-SPECIFIC SERVICES //
//////////////////////////////////
// Here we define the DEV_Identify Service as derived class of AccessoryInformation
struct DEV_Identify : Service::AccessoryInformation {
int nBlinks; // number of times to blink built-in LED in identify routine
SpanCharacteristic *identify; // reference to the Identify Characteristic
// Next we define the constructor using all the arguments needed to implement the required Characteristics
// of AccessoryInformation, plus one extra argument at the end called "nBlinks" we will use to specify how many
// times HomeSpan should blink the built-in LED when HomeKit calls this device's Identify routine during pairing.
DEV_Identify(const char *name, const char *manu, const char *sn, const char *model, const char *version, int nBlinks) : Service::AccessoryInformation(){
new Characteristic::Name(name); // create all the required Characteristics with values set based on above arguments
new Characteristic::Manufacturer(manu);
new Characteristic::SerialNumber(sn);
new Characteristic::Model(model);
new Characteristic::FirmwareRevision(version);
identify=new Characteristic::Identify(); // store a reference to the Identify Characteristic for use below
this->nBlinks=nBlinks; // store the number of times to blink the LED
pinMode(homeSpan.getStatusPin(),OUTPUT); // make sure LED is set for output
}
// How HomeKit Identifies Devices:
//
// When HomeKit first pairs with a new device it "calls" that device's identify routine for every defined Accessory.
// To do so, HomeKit requests the Identify Characteristic for each defined AccessoryInformation Service to be set to "true".
// The Identify Characteristic is write-only, so no value is ever stored, even though HomeKit is requesting its value
// be updated. We can therefore use the same update() method as if the Identify Characteristic was the same as any
// other boolean Characteristic.
// There are many ways to implement some form of identification. For an LED, you could blink it one or more times.
// For a LightBulb, you can flash it on and off. For window shade, you could raise and lower it.
// Most commerical devices don't do anything. Because HomeSpan can be used to control many different types of
// device, below we implement a very generic routine that simply blinks the Status LED the number of times specified above.
// In principle, this code could call a user-defined routine that is different for each physcially-attached device (light, shade, fan, etc),
// but in practice this is overkill.
// Note that the blink routine below starts by turning off the Status LED and then leaves it on once it has blinked
// the specified number of times. This is because when HomeSpan starts up if confirms to user that it has connected
// to the WiFi network by turning on the Status LED. Thus we want to leave it on when blinking is completed.
// Also note we use the homeSpan.getStatusPin() method to find the pin number associated with the Status LED
boolean update(){
for(int i=0;i<nBlinks;i++){
digitalWrite(homeSpan.getStatusPin(),LOW);
delay(250);
digitalWrite(homeSpan.getStatusPin(),HIGH);
delay(250);
}
return(true); // return true
} // update
};

View File

@ -1,58 +0,0 @@
////////////////////////////////////
// DEVICE-SPECIFIC LED SERVICES //
////////////////////////////////////
#include "extras/PwmPin.h" // allows PWM control of LED brightness
struct DEV_LED : Service::LightBulb { // ON/OFF LED
int ledPin; // pin number defined for this LED
SpanCharacteristic *power; // reference to the On Characteristic
DEV_LED(int ledPin) : Service::LightBulb(){ // constructor() method
power=new Characteristic::On();
this->ledPin=ledPin;
pinMode(ledPin,OUTPUT);
} // end constructor
boolean update(){ // update() method
digitalWrite(ledPin,power->getNewVal());
return(true); // return true
} // update
};
//////////////////////////////////
struct DEV_DimmableLED : Service::LightBulb { // Dimmable LED
LedPin *ledPin; // reference to Led Pin
SpanCharacteristic *power; // reference to the On Characteristic
SpanCharacteristic *level; // reference to the Brightness Characteristic
DEV_DimmableLED(int pin) : Service::LightBulb(){ // constructor() method
power=new Characteristic::On();
level=new Characteristic::Brightness(50); // Brightness Characteristic with an initial value of 50%
level->setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1%
this->ledPin=new LedPin(pin); // configures a PWM LED for output to the specified pin
} // end constructor
boolean update(){ // update() method
ledPin->set(power->getNewVal()*level->getNewVal());
return(true); // return true
} // update
};
//////////////////////////////////

View File

@ -1,7 +1,7 @@
/********************************************************************************* /*********************************************************************************
* MIT License * MIT License
* *
* Copyright (c) 2020 Gregg E. Berman * Copyright (c) 2020-2022 Gregg E. Berman
* *
* https://github.com/HomeSpan/HomeSpan * https://github.com/HomeSpan/HomeSpan
* *
@ -31,33 +31,29 @@
// ------------------------------------------------ // // ------------------------------------------------ //
// // // //
// Example 8: HomeKit Bridges and Bridge Accessories // // Example 8: HomeKit Bridges and Bridge Accessories //
// ** the preferred method for HomeSpan ** //
// // // //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include "HomeSpan.h" #include "HomeSpan.h"
#include "DEV_LED.h" #include "DEV_LED.h"
#include "DEV_Identify.h"
void setup() { void setup() {
// Though we've seen in prior examples that one device can support multiple Accessories, HomeKit provides a more // If the only Service defined in the FIRST Accessory of a mult-Accessory device is the required Accessory Information Service,
// general multi-Accessory framework that is somewhat more robust and easier to use: HomeKit Bridges. // the device is said to be configured as a "Bridge". Historically there may have been a number of functional differences between bridge
// A Bridge is a device that includes multiple Accessories, except that the FIRST defined Accessory contains // devices and non-bridge devices, but since iOS 15, it's not obvious there are any differences in functionality, with two exceptions:
// nothing but the AccessoryInformation Service and the HAPProtcolInformation Service. When such a device is paired
// to HomeKit, it is automatically recognized as a Bridge. All of the other Accessories defined in the device are // 1. Recall from Example 7 that the use of Characteristic::Name() to change the default name of an Accessory Tile
// associated with this Bridge. If you unpair the Bridge from HomeKit, all associated Accessories are automatically // does not work for the first Accessory defined. The Home App always displays the default name of the first Accessory Tile
// removed. // as the name of the device specified in homeSpan.begin(). However, this is not an issue when implementing a device
// // as a Bridge, since the first Accessory is nothing but the Bridge itself - having the default name match the name
// Adding, editing, and deleting the other Accessories occurs in the same manner as before, but because the device // of the device in this case makes much more sense. More importantly, you can now use Characteristic::Name() to change the
// is paired as a Bridge, changes to the other Accessories is less likely to require you to un-pair and re-pair // default name of BOTH the LED Accessory Tiles.
// the device. HomeKit seems to be able to better process changes when they are done within a Bridge framework.
// // 2. Devices configured as a Bridge appear in the Home App under the main settings page that displays all Hubs and Bridges.
// One added bonus is that the HAPProtcolInformation Service only needs to be defined for the Bridge Accessory, and
// does not need to be repeated for other Accessories. // The sketch below is functionally identical to Example 7, except that instead of defining two Accessories (one for the Simple On/Off
// // LED and one for the Dimmable LED), we define three Accessories, where the first acts as the Bridge.
// Example 8 is functionally identical to Example 7, except that instead of defining two Accessories (one for the on/off
// LED and one for the dimmable LED), we define three Accessories, where the first acts as the Bridge.
// As usual, all previous comments have been deleted and only new changes from the previous example are shown. // As usual, all previous comments have been deleted and only new changes from the previous example are shown.
@ -65,40 +61,28 @@ void setup() {
Serial.begin(115200); Serial.begin(115200);
homeSpan.begin(Category::Bridges,"HomeSpan Bridge"); // CHANGED! Note that we replaced Category::Lighting with Bridges (this changes the icon when pairing) // Below we replace Category::Lighting with Category::Bridges. This changes the icon of the device shown when pairing
// with the Home App. It does NOT change any of the icons for an Accessory Tile (these are determined by the types of
// Services implemented in each Accessory - see Example 9). Note you can choose any Category you like - for instance,
// we could have continued to use Category::Lighting, even though we are configuring the device as a Bridge.
// We begin by creating a Bridge Accessory, which look just like any other Accessory, homeSpan.begin(Category::Bridges,"HomeSpan Bridge");
// except that is only contains DEV_Identify (which is derived from AccessoryInformation)
// and HAPProtcolInformation (required). Note that HomeKit will still call the identify
// update() routine upon pairing, so we specify the number of blinks to be 3.
new SpanAccessory(); new SpanAccessory(); // This first Accessory is the new "Bridge" Accessory. It contains no functional Services, just the Accessory Information Service
new DEV_Identify("Bridge #1","HomeSpan","123-ABC","HS Bridge","0.9",3); new Service::AccessoryInformation();
new Service::HAPProtocolInformation(); new Characteristic::Identify();
new Characteristic::Version("1.1.0");
new SpanAccessory(); // This second Accessory is the same as the first Accessory in Example 7, with the exception that Characteristic::Name() now does something
new Service::AccessoryInformation();
new Characteristic::Identify();
new Characteristic::Name("Simple LED"); // Note that unlike in Example 7, this use of Name() is properly implented by the Home App since it is not the first Accessory (the Bridge above is the first)
new DEV_LED(16);
// Now we simply repeat the definitions of the previous LED Accessories, as per Example 7, with two exceptions: new SpanAccessory(); // This third Accessory is the same as the second Accessory in Example 7
// 1) We no longer need to include the HAPProtocolInformation Service. new Service::AccessoryInformation();
// 2) We will set the number of blinks to zero, so that only the bridge accessory will cause the Built-In new Characteristic::Identify();
// LED to blink. This becomes especially important if you had 20 Accessories defined and needed to wait a new Characteristic::Name("Dimmable LED");
// minute or more for all the blinking to finish while pairing. new DEV_DimmableLED(17);
new SpanAccessory();
new DEV_Identify("On/Off LED","HomeSpan","123-ABC","20mA LED","0.9",0); // CHANGED! The number of blinks is now set to zero
// new Service::HAPProtocolInformation(); - DELETED - NO LONGER NEEDED
// new Characteristic::Version("1.1.0"); - DELETED - NO LONGER NEEDED
new DEV_LED(16); // create an on/off LED attached to pin 16
new SpanAccessory();
new DEV_Identify("Dimmable LED","HomeSpan","123-ABC","20mA LED","0.9",0); // CHANGED! The number of blinks is now set to zero
// new Service::HAPProtocolInformation(); - DELETED - NO LONGER NEEDED
// new Characteristic::Version("1.1.0"); - DELETED - NO LONGER NEEDED
new DEV_DimmableLED(17); // create a dimmable (PWM-driven) LED attached to pin 17
} // end of setup() } // end of setup()

View File

@ -1,38 +0,0 @@
//////////////////////////////////
// DEVICE-SPECIFIC SERVICES //
//////////////////////////////////
struct DEV_Identify : Service::AccessoryInformation {
int nBlinks; // number of times to blink built-in LED in identify routine
SpanCharacteristic *identify; // reference to the Identify Characteristic
DEV_Identify(const char *name, const char *manu, const char *sn, const char *model, const char *version, int nBlinks) : Service::AccessoryInformation(){
new Characteristic::Name(name); // create all the required Characteristics with values set based on above arguments
new Characteristic::Manufacturer(manu);
new Characteristic::SerialNumber(sn);
new Characteristic::Model(model);
new Characteristic::FirmwareRevision(version);
identify=new Characteristic::Identify(); // store a reference to the Identify Characteristic for use below
this->nBlinks=nBlinks; // store the number of times to blink the LED
pinMode(homeSpan.getStatusPin(),OUTPUT); // make sure LED is set for output
}
boolean update(){
for(int i=0;i<nBlinks;i++){
digitalWrite(homeSpan.getStatusPin(),LOW);
delay(250);
digitalWrite(homeSpan.getStatusPin(),HIGH);
delay(250);
}
return(true); // return true
} // update
};

View File

@ -1468,7 +1468,7 @@ void SpanAccessory::validate(){
if(!foundProtocol && (aid==1 || !homeSpan.isBridge)){ // HAPProtocolInformation must always be present in Accessory if aid=1, and any other Accessory if the device is not a bridge) if(!foundProtocol && (aid==1 || !homeSpan.isBridge)){ // HAPProtocolInformation must always be present in Accessory if aid=1, and any other Accessory if the device is not a bridge)
homeSpan.configLog+=" \u2718 Service HAPProtocolInformation"; homeSpan.configLog+=" \u2718 Service HAPProtocolInformation";
homeSpan.configLog+=" *** ERROR! Required Service for this Accessory not found. ***\n"; homeSpan.configLog+=" *** ERROR! Required Service for this Accessory not found. ***\n";
homeSpan.nFatalErrors++; // homeSpan.nFatalErrors++;
} }
} }