-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split into different platform modules, add support for ESP8266_RTOS_SDK
- Loading branch information
1 parent
1dac03f
commit bed2c8d
Showing
43 changed files
with
230 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
[submodule "components/cJSON"] | ||
path = components/esp-8266/cJSON | ||
url = https://github.com/maximkulkin/esp-cjson | ||
[submodule "components/wolfssl"] | ||
path = components/common/wolfssl | ||
url = https://github.com/maximkulkin/esp-wolfssl | ||
[submodule "components/homekit"] | ||
path = components/common/homekit | ||
url = https://github.com/maximkulkin/esp-homekit | ||
[submodule "components/http-parser"] | ||
path = components/esp-32/http-parser | ||
[submodule "components/esp32/idf/http-parser"] | ||
path = components/esp-idf/http-parser | ||
url = https://github.com/maximkulkin/esp-http-parser.git | ||
[submodule "components/wifi_config"] | ||
path = components/esp-8266/wifi_config | ||
url = https://github.com/maximkulkin/esp-wifi-config | ||
[submodule "components/WS2812FX"] | ||
path = components/esp-8266/WS2812FX | ||
[submodule "components/esp8266-idf/http-parser"] | ||
path = components/esp8266-rtos-sdk/http-parser | ||
url = https://github.com/maximkulkin/esp-http-parser.git | ||
[submodule "components/esp8266-open-rtos/WS2812FX"] | ||
path = components/esp8266-open-rtos/WS2812FX | ||
url = https://github.com/pcsaito/WS2812FX-rtos | ||
[submodule "components/led-status"] | ||
path = components/esp-8266/led-status | ||
[submodule "components/esp8266-open-rtos/cJSON"] | ||
path = components/esp8266-open-rtos/cJSON | ||
url = https://github.com/maximkulkin/esp-cjson | ||
[submodule "components/esp8266-open-rtos/led-status"] | ||
path = components/esp8266-open-rtos/led-status | ||
url = https://github.com/maximkulkin/esp-led-status.git | ||
[submodule "components/esp-8266/qrcode"] | ||
path = components/esp-8266/qrcode | ||
[submodule "components/esp8266-open-rtos/qrcode"] | ||
path = components/esp8266-open-rtos/qrcode | ||
url = https://github.com/maximkulkin/esp-qrcode.git | ||
[submodule "components/esp8266-open-rtos/wifi_config"] | ||
path = components/esp8266-open-rtos/wifi_config | ||
url = https://github.com/maximkulkin/esp-wifi-config |
Submodule http-parser
deleted from
b6f4f5
Submodule wifi_config
deleted from
fe2e98
Submodule http-parser
added at
59eec2
Submodule cJSON
updated
from 000000 to 2216b1
Submodule wifi_config
added at
06901b
Submodule http-parser
added at
59eec2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build/ | ||
firmware/ | ||
sdkconfig | ||
sdkconfig.old |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
PROJECT_NAME = led | ||
|
||
EXTRA_CFLAGS += -I$(abspath ../../..) -DHOMEKIT_SHORT_APPLE_UUIDS | ||
|
||
EXTRA_COMPONENT_DIRS += \ | ||
$(abspath ../../../components/common) \ | ||
$(abspath ../../../components/esp8266-rtos-sdk) | ||
|
||
include $(IDF_PATH)/make/project.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
COMPONENT_DEPENDS = homekit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
#include <stdio.h> | ||
#include <esp_wifi.h> | ||
#include <esp_event_loop.h> | ||
#include <esp_log.h> | ||
#include <nvs_flash.h> | ||
|
||
#include <freertos/FreeRTOS.h> | ||
#include <freertos/task.h> | ||
#include <driver/gpio.h> | ||
|
||
#include <homekit/homekit.h> | ||
#include <homekit/characteristics.h> | ||
#include "wifi.h" | ||
|
||
|
||
void on_wifi_ready(); | ||
|
||
esp_err_t event_handler(void *ctx, system_event_t *event) | ||
{ | ||
switch(event->event_id) { | ||
case SYSTEM_EVENT_STA_START: | ||
printf("STA start\n"); | ||
esp_wifi_connect(); | ||
break; | ||
case SYSTEM_EVENT_STA_GOT_IP: | ||
printf("WiFI ready\n"); | ||
on_wifi_ready(); | ||
break; | ||
case SYSTEM_EVENT_STA_DISCONNECTED: | ||
printf("STA disconnected\n"); | ||
esp_wifi_connect(); | ||
break; | ||
default: | ||
break; | ||
} | ||
return ESP_OK; | ||
} | ||
|
||
static void wifi_init() { | ||
tcpip_adapter_init(); | ||
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL)); | ||
|
||
wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT(); | ||
ESP_ERROR_CHECK(esp_wifi_init(&wifi_init_config)); | ||
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); | ||
|
||
wifi_config_t wifi_config = { | ||
.sta = { | ||
.ssid = WIFI_SSID, | ||
.password = WIFI_PASSWORD, | ||
}, | ||
}; | ||
|
||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); | ||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config)); | ||
ESP_ERROR_CHECK(esp_wifi_start()); | ||
} | ||
|
||
const int led_gpio = 2; | ||
bool led_on = false; | ||
|
||
void led_write(bool on) { | ||
gpio_set_level(led_gpio, on ? 1 : 0); | ||
} | ||
|
||
void led_init() { | ||
gpio_set_direction(led_gpio, GPIO_MODE_OUTPUT); | ||
led_write(led_on); | ||
} | ||
|
||
void led_identify_task(void *_args) { | ||
for (int i=0; i<3; i++) { | ||
for (int j=0; j<2; j++) { | ||
led_write(true); | ||
vTaskDelay(100 / portTICK_PERIOD_MS); | ||
led_write(false); | ||
vTaskDelay(100 / portTICK_PERIOD_MS); | ||
} | ||
|
||
vTaskDelay(250 / portTICK_PERIOD_MS); | ||
} | ||
|
||
led_write(led_on); | ||
|
||
vTaskDelete(NULL); | ||
} | ||
|
||
void led_identify(homekit_value_t _value) { | ||
printf("LED identify\n"); | ||
xTaskCreate(led_identify_task, "LED identify", 512, NULL, 2, NULL); | ||
} | ||
|
||
homekit_value_t led_on_get() { | ||
return HOMEKIT_BOOL(led_on); | ||
} | ||
|
||
void led_on_set(homekit_value_t value) { | ||
if (value.format != homekit_format_bool) { | ||
printf("Invalid value format: %d\n", value.format); | ||
return; | ||
} | ||
|
||
led_on = value.bool_value; | ||
led_write(led_on); | ||
} | ||
|
||
|
||
homekit_accessory_t *accessories[] = { | ||
HOMEKIT_ACCESSORY(.id=1, .category=homekit_accessory_category_lightbulb, .services=(homekit_service_t*[]){ | ||
HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]){ | ||
HOMEKIT_CHARACTERISTIC(NAME, "Sample LED"), | ||
HOMEKIT_CHARACTERISTIC(MANUFACTURER, "HaPK"), | ||
HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "037A2BABF19D"), | ||
HOMEKIT_CHARACTERISTIC(MODEL, "MyLED"), | ||
HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "0.1"), | ||
HOMEKIT_CHARACTERISTIC(IDENTIFY, led_identify), | ||
NULL | ||
}), | ||
HOMEKIT_SERVICE(LIGHTBULB, .primary=true, .characteristics=(homekit_characteristic_t*[]){ | ||
HOMEKIT_CHARACTERISTIC(NAME, "Sample LED"), | ||
HOMEKIT_CHARACTERISTIC( | ||
ON, false, | ||
.getter=led_on_get, | ||
.setter=led_on_set | ||
), | ||
NULL | ||
}), | ||
NULL | ||
}), | ||
NULL | ||
}; | ||
|
||
homekit_server_config_t config = { | ||
.accessories = accessories, | ||
.password = "111-11-111" | ||
}; | ||
|
||
void on_wifi_ready() { | ||
homekit_server_init(&config); | ||
} | ||
|
||
void app_main(void) { | ||
// Initialize NVS | ||
esp_err_t ret = nvs_flash_init(); | ||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) { | ||
ESP_ERROR_CHECK(nvs_flash_erase()); | ||
ret = nvs_flash_init(); | ||
} | ||
ESP_ERROR_CHECK( ret ); | ||
|
||
wifi_init(); | ||
led_init(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.