From 883a29252e06d02217359204f0f29bead68a302d Mon Sep 17 00:00:00 2001 From: royfocker19 <39307144+royfocker19@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:39:42 -0300 Subject: [PATCH 1/6] Update Kconfig.projbuild Outlet_in_use GPIO and Outlet GPIO can be specified with menuconfig --- examples/smart_outlet/main/Kconfig.projbuild | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/examples/smart_outlet/main/Kconfig.projbuild b/examples/smart_outlet/main/Kconfig.projbuild index 6f3e3fe..d56ea1f 100644 --- a/examples/smart_outlet/main/Kconfig.projbuild +++ b/examples/smart_outlet/main/Kconfig.projbuild @@ -23,4 +23,27 @@ menu "Example Configuration" help Setup id to be used for HomeKot pairing, if hard-coded setup code is enabled. + config OUTLET_GPIO + int "Outlet GPIO number" + range 0 34 + default 33 + help + GPIO number (IOxx) to control relay pin. + + Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used. + + Default is GPIO 33 (Built in Led on ESP32CAM by AI Thinker) + + GPIOs 35-39 are input-only so cannot be used as outputs. + + config OUTLET_IN_USE_GPIO + int "Outlet in use GPIO number" + range 0 34 + default 0 + help + GPIO number (IOxx) to sense outlet in use. + + Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to blink. + + GPIOs 35-39 are input-only so cannot be used as outputs. endmenu From 2a126df1ea2f401c3933ad22664b283e46c46642 Mon Sep 17 00:00:00 2001 From: royfocker19 <39307144+royfocker19@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:44:38 -0300 Subject: [PATCH 2/6] Update app_main.c --- examples/smart_outlet/main/app_main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/smart_outlet/main/app_main.c b/examples/smart_outlet/main/app_main.c index 782e3fa..4759b35 100644 --- a/examples/smart_outlet/main/app_main.c +++ b/examples/smart_outlet/main/app_main.c @@ -38,6 +38,7 @@ #include #include +#include "outlet.h" static const char *TAG = "HAP outlet"; @@ -45,10 +46,12 @@ static const char *TAG = "HAP outlet"; #define SMART_OUTLET_TASK_STACKSIZE 4 * 1024 #define SMART_OUTLET_TASK_NAME "hap_outlet" -#define OUTLET_IN_USE_GPIO GPIO_NUM_0 +#define OUTLET_IN_USE_GPIO CONFIG_OUTLET_IN_USE_GPIO #define ESP_INTR_FLAG_DEFAULT 0 +#define OUTLET_GPIO CONFIG_OUTLET_GPIO + static xQueueHandle s_esp_evt_queue = NULL; /** * @brief the recover outlet in use gpio interrupt function @@ -117,9 +120,10 @@ static int outlet_write(hap_write_data_t write_data[], int count, write = &write_data[i]; if (!strcmp(hap_char_get_type_uuid(write->hc), HAP_CHAR_UUID_ON)) { ESP_LOGI(TAG, "Received Write. Outlet %s", write->val.b ? "On" : "Off"); - /* TODO: Control Actual Hardware */ + if (outlet_set_on(write->val.b) == 0) { hap_char_update_val(write->hc, &(write->val)); *(write->status) = HAP_STATUS_SUCCESS; + } } else { *(write->status) = HAP_STATUS_RES_ABSENT; } @@ -237,5 +241,8 @@ void app_main() /* Create the application thread */ xTaskCreate(smart_outlet_thread_entry, SMART_OUTLET_TASK_NAME, SMART_OUTLET_TASK_STACKSIZE, NULL, SMART_OUTLET_TASK_PRIORITY, NULL); + gpio_pad_select_gpio(OUTLET_GPIO); + /* Set the GPIO as a push/pull output */ + gpio_set_direction(OUTLET_GPIO, GPIO_MODE_OUTPUT); } From cf02e90c5cd766a940eed1195b727c16deab5296 Mon Sep 17 00:00:00 2001 From: royfocker19 <39307144+royfocker19@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:45:58 -0300 Subject: [PATCH 3/6] Add files via upload --- outlet.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ outlet.h | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 outlet.c create mode 100644 outlet.h diff --git a/outlet.c b/outlet.c new file mode 100644 index 0000000..b958072 --- /dev/null +++ b/outlet.c @@ -0,0 +1,57 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2018 + * + * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, + * it is 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. + * + */ + +/* HomeKit Outlet Example Hardware Implementation +*/ + +#include + +#include "driver/gpio.h" +#include "esp_log.h" + + +static bool s_on = false; + +static const char *TAG = "outlet"; +#define OUTLET_GPIO CONFIG_OUTLET_GPIO + + + +/** + * @brief turn on/off the outlet + */ +int outlet_set_on(bool value) +{ + ESP_LOGI(TAG, "outlet_set_on : %s", value == true ? "true" : "false"); + + if (value == true) { + gpio_set_level(OUTLET_GPIO, 0); + } else { + gpio_set_level(OUTLET_GPIO, 1); + } + + return 0; +} + + diff --git a/outlet.h b/outlet.h new file mode 100644 index 0000000..bced210 --- /dev/null +++ b/outlet.h @@ -0,0 +1,43 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2018 + * + * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, + * it is 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. + * + */ + +/* HomeKit Outlet Example +*/ + +#ifndef _OUTLET_H_ +#define _OUTLET_H_ + + + +/** + * @brief turn on/off the outlet + * + * @param value The "On" value + * + * @return none + */ +int outlet_set_on(bool value); + + +#endif /* _OUTLET_H_ */ From a11cb697b934105b0bcdc5a6dfb8e0d322168f0d Mon Sep 17 00:00:00 2001 From: royfocker19 <39307144+royfocker19@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:46:53 -0300 Subject: [PATCH 4/6] Delete outlet.c --- outlet.c | 57 -------------------------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 outlet.c diff --git a/outlet.c b/outlet.c deleted file mode 100644 index b958072..0000000 --- a/outlet.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * ESPRESSIF MIT License - * - * Copyright (c) 2018 - * - * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, - * it is 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. - * - */ - -/* HomeKit Outlet Example Hardware Implementation -*/ - -#include - -#include "driver/gpio.h" -#include "esp_log.h" - - -static bool s_on = false; - -static const char *TAG = "outlet"; -#define OUTLET_GPIO CONFIG_OUTLET_GPIO - - - -/** - * @brief turn on/off the outlet - */ -int outlet_set_on(bool value) -{ - ESP_LOGI(TAG, "outlet_set_on : %s", value == true ? "true" : "false"); - - if (value == true) { - gpio_set_level(OUTLET_GPIO, 0); - } else { - gpio_set_level(OUTLET_GPIO, 1); - } - - return 0; -} - - From f99b76a6bf3f5dca09ade6777248fabd8d990e43 Mon Sep 17 00:00:00 2001 From: royfocker19 <39307144+royfocker19@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:47:03 -0300 Subject: [PATCH 5/6] Delete outlet.h --- outlet.h | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 outlet.h diff --git a/outlet.h b/outlet.h deleted file mode 100644 index bced210..0000000 --- a/outlet.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ESPRESSIF MIT License - * - * Copyright (c) 2018 - * - * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, - * it is 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. - * - */ - -/* HomeKit Outlet Example -*/ - -#ifndef _OUTLET_H_ -#define _OUTLET_H_ - - - -/** - * @brief turn on/off the outlet - * - * @param value The "On" value - * - * @return none - */ -int outlet_set_on(bool value); - - -#endif /* _OUTLET_H_ */ From 316711ca3e4e18417d262e2a02bca460de7b6ad7 Mon Sep 17 00:00:00 2001 From: royfocker19 <39307144+royfocker19@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:47:33 -0300 Subject: [PATCH 6/6] Add files via upload --- examples/smart_outlet/main/outlet.c | 57 +++++++++++++++++++++++++++++ examples/smart_outlet/main/outlet.h | 43 ++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 examples/smart_outlet/main/outlet.c create mode 100644 examples/smart_outlet/main/outlet.h diff --git a/examples/smart_outlet/main/outlet.c b/examples/smart_outlet/main/outlet.c new file mode 100644 index 0000000..b958072 --- /dev/null +++ b/examples/smart_outlet/main/outlet.c @@ -0,0 +1,57 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2018 + * + * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, + * it is 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. + * + */ + +/* HomeKit Outlet Example Hardware Implementation +*/ + +#include + +#include "driver/gpio.h" +#include "esp_log.h" + + +static bool s_on = false; + +static const char *TAG = "outlet"; +#define OUTLET_GPIO CONFIG_OUTLET_GPIO + + + +/** + * @brief turn on/off the outlet + */ +int outlet_set_on(bool value) +{ + ESP_LOGI(TAG, "outlet_set_on : %s", value == true ? "true" : "false"); + + if (value == true) { + gpio_set_level(OUTLET_GPIO, 0); + } else { + gpio_set_level(OUTLET_GPIO, 1); + } + + return 0; +} + + diff --git a/examples/smart_outlet/main/outlet.h b/examples/smart_outlet/main/outlet.h new file mode 100644 index 0000000..bced210 --- /dev/null +++ b/examples/smart_outlet/main/outlet.h @@ -0,0 +1,43 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2018 + * + * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, + * it is 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. + * + */ + +/* HomeKit Outlet Example +*/ + +#ifndef _OUTLET_H_ +#define _OUTLET_H_ + + + +/** + * @brief turn on/off the outlet + * + * @param value The "On" value + * + * @return none + */ +int outlet_set_on(bool value); + + +#endif /* _OUTLET_H_ */