Skip to content

Commit 75b568a

Browse files
0.0.1 first release
home kit framework, no logic yet
1 parent fe5d78c commit 75b568a

8 files changed

+132
-8
lines changed

.gitmodules

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[submodule "esp-cjson"]
2+
path = esp-cjson
3+
url = https://github.com/HomeACcessoryKid/esp-cjson
4+
[submodule "esp-homekit"]
5+
path = esp-homekit
6+
url = https://github.com/HomeACcessoryKid/esp-homekit
7+
[submodule "esp-wolfssl"]
8+
path = esp-wolfssl
9+
url = https://github.com/HomeACcessoryKid/esp-wolfssl

Makefile

100755100644
+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
PROGRAM = main
22

3+
EXTRA_COMPONENTS = \
4+
extras/http-parser \
5+
extras/rboot-ota \
6+
$(abspath esp-wolfssl) \
7+
$(abspath esp-cjson) \
8+
$(abspath esp-homekit)
9+
310
FLASH_SIZE ?= 8
411
HOMEKIT_SPI_FLASH_BASE_ADDR ?= 0x8C000
512

@@ -9,4 +16,3 @@ include $(SDK_PATH)/common.mk
916

1017
monitor:
1118
$(FILTEROUTPUT) --port $(ESPPORT) --baud $(ESPBAUD) --elf $(PROGRAM_OUT)
12-

esp-cjson

Submodule esp-cjson added at 2216b13

esp-homekit

Submodule esp-homekit added at 51203ab

esp-wolfssl

Submodule esp-wolfssl added at 62252d7

main.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void log_send(void *pvParameters){
4747
}
4848
}
4949

50-
bool hold=0,calibrate=0,reverse=0;
50+
bool hold=0,calibrate=0,reverse=0,obstruction=0;
5151
bool changed=0;
5252
int target=0,current=0,state=2; //homekit values
5353

@@ -234,9 +234,12 @@ void motor_init() {
234234
//xTaskCreate(motor_loop_task, "loop", 512, NULL, 1, NULL);
235235
}
236236

237+
homekit_value_t obstruction_get() {
238+
return HOMEKIT_BOOL(obstruction);
239+
}
237240

238241
homekit_value_t hold_get() {
239-
return HOMEKIT_BOOL(on);
242+
return HOMEKIT_BOOL(hold);
240243
}
241244
void hold_set(homekit_value_t value) {
242245
if (value.format != homekit_format_bool) {
@@ -292,11 +295,7 @@ void state_set(homekit_value_t value) {
292295
}
293296

294297
void identify_task(void *_args) {
295-
int oldmode;
296-
oldmode=mode;
297-
mode=10; changed=1;
298298
vTaskDelay(5000 / portTICK_PERIOD_MS); //5 sec
299-
mode=oldmode; changed=1;
300299
vTaskDelete(NULL);
301300
}
302301

@@ -344,6 +343,10 @@ homekit_accessory_t *accessories[] = {
344343
.getter=hold_get,
345344
.setter=hold_set
346345
),
346+
HOMEKIT_CHARACTERISTIC(
347+
OBSTRUCTION_DETECTED, false,
348+
.getter=obstruction_get,
349+
),
347350
&ota_trigger,
348351
&calibrated,
349352
&reversed,
@@ -355,14 +358,15 @@ homekit_accessory_t *accessories[] = {
355358
};
356359

357360

361+
358362
homekit_server_config_t config = {
359363
.accessories = accessories,
360364
.password = "111-11-111"
361365
};
362366

363367
void user_init(void) {
364368
xTaskCreate(log_send, "logsend", 256, NULL, 4, NULL); //is prio4 a good idea??
365-
LOG("Aqara Curtain Motor SDK version:%s\n", sdk_system_get_sdk_version());
369+
LOG("Aqara Curtain Motor\n");
366370

367371
motor_init();
368372

ota-api.c

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include <stdlib.h> //for printf
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
#include <espressif/esp_wifi.h>
6+
#include <espressif/esp_sta.h>
7+
#include <rboot-api.h>
8+
#include <sysparam.h>
9+
10+
// the first function is the ONLY thing needed for a repo to support ota after having started with ota-boot
11+
// in ota-boot the user gets to set the wifi and the repository details and it then installs the ota-main binary
12+
13+
void ota_update(void *arg) { //arg not used
14+
rboot_set_temp_rom(1); //select the OTA main routine
15+
sdk_system_restart(); //#include <rboot-api.h>
16+
// there is a bug in the esp SDK such that if you do not power cycle the chip after serial flashing, restart is unreliable
17+
}
18+
19+
// this function is optional to couple Homekit parameters to the sysparam variables and github parameters
20+
unsigned int ota_read_sysparam(char **manufacturer,char **serial,char **model,char **revision) {
21+
sysparam_status_t status;
22+
char *value;
23+
24+
status = sysparam_get_string("ota_repo", &value);
25+
if (status == SYSPARAM_OK) {
26+
strchr(value,'/')[0]=0;
27+
*manufacturer=value;
28+
*model=value+strlen(value)+1;
29+
} else {
30+
*manufacturer="manuf_unknown";
31+
*model="model_unknown";
32+
}
33+
status = sysparam_get_string("ota_version", &value);
34+
if (status == SYSPARAM_OK) {
35+
*revision=value;
36+
} else *revision="0.0.0";
37+
38+
uint8_t macaddr[6];
39+
sdk_wifi_get_macaddr(STATION_IF, macaddr);
40+
*serial=malloc(18);
41+
sprintf(*serial,"%02X:%02X:%02X:%02X:%02X:%02X",macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
42+
43+
unsigned int c_hash=0;
44+
char version[16];
45+
char* rev=version;
46+
char* dot;
47+
strncpy(rev,*revision,16);
48+
if ((dot=strchr(rev,'.'))) {dot[0]=0; c_hash= atoi(rev); rev=dot+1;}
49+
if ((dot=strchr(rev,'.'))) {dot[0]=0; c_hash=c_hash*1000+atoi(rev); rev=dot+1;}
50+
c_hash=c_hash*1000+atoi(rev);
51+
//c_hash=c_hash*10 +configuration_variant; //possible future extension
52+
printf("manuf=\'%s\' serial=\'%s\' model=\'%s\' revision=\'%s\' c#=%d\n",*manufacturer,*serial,*model,*revision,c_hash);
53+
return c_hash;
54+
}
55+
56+
57+
58+
59+
#include <homekit/characteristics.h>
60+
#include <esplibs/libmain.h>
61+
#include <etstimer.h>
62+
63+
static ETSTimer update_timer;
64+
65+
void ota_set(homekit_value_t value) {
66+
if (value.format != homekit_format_bool) {
67+
printf("Invalid ota-value format: %d\n", value.format);
68+
return;
69+
}
70+
if (value.bool_value) {
71+
//make a distinct light pattern or other feedback to the user = call identify routine
72+
sdk_os_timer_setfn(&update_timer, ota_update, NULL);
73+
sdk_os_timer_arm(&update_timer, 500, 0); //wait 0.5 seconds to trigger the reboot so gui can update and events sent
74+
}
75+
}

ota-api.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef __HOMEKIT_CUSTOM_CHARACTERISTICS__
2+
#define __HOMEKIT_CUSTOM_CHARACTERISTICS__
3+
4+
#define HOMEKIT_CUSTOM_UUID(value) (value "-0e36-4a42-ad11-745a73b84f2b")
5+
6+
#define HOMEKIT_SERVICE_CUSTOM_SETUP HOMEKIT_CUSTOM_UUID("000000FF")
7+
8+
#define HOMEKIT_CHARACTERISTIC_CUSTOM_OTA_TRIGGER HOMEKIT_CUSTOM_UUID("F0000001")
9+
#define HOMEKIT_DECLARE_CHARACTERISTIC_CUSTOM_OTA_TRIGGER(_value, ...) \
10+
.type = HOMEKIT_CHARACTERISTIC_CUSTOM_OTA_TRIGGER, \
11+
.description = "}FirmwareUpdate", \
12+
.format = homekit_format_bool, \
13+
.permissions = homekit_permissions_paired_read \
14+
| homekit_permissions_paired_write \
15+
| homekit_permissions_notify, \
16+
.value = HOMEKIT_BOOL_(_value), \
17+
##__VA_ARGS__
18+
19+
unsigned int ota_read_sysparam(char **manufacturer,char **serial,char **model,char **revision);
20+
21+
void ota_update(void *arg);
22+
23+
void ota_set(homekit_value_t value);
24+
25+
#define API_OTA_TRIGGER HOMEKIT_CHARACTERISTIC_(CUSTOM_OTA_TRIGGER, false, .setter=ota_set)
26+
27+
#endif

0 commit comments

Comments
 (0)