Editing Example 4

This commit is contained in:
Gregg 2020-07-18 23:05:02 -05:00
parent e6a3fc7261
commit 17184483ba
4 changed files with 127 additions and 13 deletions

View File

@ -17,9 +17,9 @@ void setup() {
Serial.begin(115200); // Start a serial connection - this is needed for you to type in your WiFi credentials
// Begin a HomeSpan Session. Required parameters are Category and Name.
// These are used by HomeKit to configure the icon and name of the device shown when initially pairing.
// There are no other effects of these settings and they are ignored by HomeKit after pairing is complete.
// You can even specify a Lighting Category for a Faucet. This effects nothing but the initial incon.
// These are used by HomeKit to configure the icon and name of the device shown when initially pairing, as well
// as set the icon (but not the name) of defined Accessories in some cases.
// There are no other effects. You can even specify a "Lighting" Category for a Faucet with no ill effects (except the icons)
// A complete list of Categories can be found in Settings.h, which is based on Section 13 of Apple's
// HomeKit Accessory Protocol (HAP) Specifications Document.

View File

@ -0,0 +1,57 @@
////////////////////////////////////////////////////////////
// //
// HomeSpan: A HomeKit implementation for the ESP32 //
// ------------------------------------------------ //
// //
// Example 3: A simple on/off ceiling fan with an //
// on/off ceiling light //
// //
////////////////////////////////////////////////////////////
#include "HomeSpan.h" // Always start by including the HomeSpan library
void setup() {
// Example 3 shows how adding multiple Services to a single Accessory allows us to create a multi-featured Accessory, such as a ceiling fan wih a ceiling light
Serial.begin(115200); // Start a serial connection - this is needed for you to type in your WiFi credentials
homeSpan.begin(Category::Fans,"HomeSpan Ceiling Fan"); // Begin a HomeSpan Session - note the Category has been set to "Fans"
// We begin by creating a Light Bulb Accessory just as in Examples 1 and 2, but with Name now set to "My Ceiling Fan"
new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments
new Service::AccessoryInformation(); // HAP requires every Accessory to implement an AccessoryInformation Service, which has 6 required Characteristics
new Characteristic::Name("My Ceiling Fan"); // Name of the Accessory, which shows up on the HomeKit "tiles", and should be unique across Accessories
new Characteristic::Manufacturer("HomeSpan"); // Manufacturer of the Accessory (arbitrary text string, and can be the same for every Accessory)
new Characteristic::SerialNumber("123-ABC"); // Serial Number 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::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 Characteristic::On(); // This Service requires the "On" Characterstic to turn the light on and off
// Now we create the a Fan Service within this same Accessory
new Service::Fan(); // Create the Fan Service
new Characteristic::Active(); // This Service requires the "Active" Characterstic to turn the fan on and off
// IMPORTANT: HomeKit Controllers often cache a lot of information. If your Controller does not update to match the above configuration,
// simply select the Accessory in your Controller and under setting, select "Remove Accessory" and then re-pair.
} // end of setup()
//////////////////////////////////////
void loop(){
homeSpan.poll(); // run HomeSpan!
} // end of loop()

View File

@ -0,0 +1,57 @@
////////////////////////////////////////////////////////////
// //
// HomeSpan: A HomeKit implementation for the ESP32 //
// ------------------------------------------------ //
// //
// Example 4: A variable-speed ceiling fan with //
// dimmable ceiling light //
// //
////////////////////////////////////////////////////////////
#include "HomeSpan.h" // Always start by including the HomeSpan library
void setup() {
// Example 4 expands on Example 3 by adding Characteristics to set fan speed, fan direction, and light brightness.
// For ease of reading, all prior comments have been removed and new comments added to show explicit changes from previous example.
Serial.begin(115200);
homeSpan.begin(Category::Fans,"HomeSpan Ceiling Fan");
new SpanAccessory();
new Service::AccessoryInformation();
new Characteristic::Name("My Ceiling Fan");
new Characteristic::Manufacturer("HomeSpan");
new Characteristic::SerialNumber("123-ABC");
new Characteristic::Model("120-Volt Lamp");
new Characteristic::FirmwareRevision("0.9");
new Characteristic::Identify();
new Service::HAPProtocolInformation();
new Characteristic::Version("1.1.0");
new Service::LightBulb();
new Characteristic::On();
new Characteristic::Name("Light Control"); // Adding a Name Characteristic allows us to name this specific Service (see below)
new Service::Fan();
new Characteristic::Active();
new Characteristic::Name("Fan Control"); // Adding a Name Characteristic allows us to name this specific Service (see below)
// A Note about Names: HomeKit generally uses the name of the primary Service (first one defined) as the name to display on a Tile. However, you can
// set HomeKit (from within the Controller) to display each Service as its own tile. In that case the names of the Light and Fan Tiles with both display
// as "My Ceiling Fan." By setting individual names for each Service you can create your own display names when Tiles are shown separately.
} // end of setup()
//////////////////////////////////////
void loop(){
homeSpan.poll(); // run HomeSpan!
} // end of loop()