Skip to content

Commit

Permalink
0.0.1 first release
Browse files Browse the repository at this point in the history
home kit framework, no logic yet
  • Loading branch information
HomeACcessoryKid committed Oct 24, 2018
1 parent fe5d78c commit 75b568a
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "esp-cjson"]
path = esp-cjson
url = https://github.com/HomeACcessoryKid/esp-cjson
[submodule "esp-homekit"]
path = esp-homekit
url = https://github.com/HomeACcessoryKid/esp-homekit
[submodule "esp-wolfssl"]
path = esp-wolfssl
url = https://github.com/HomeACcessoryKid/esp-wolfssl
8 changes: 7 additions & 1 deletion Makefile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
PROGRAM = main

EXTRA_COMPONENTS = \
extras/http-parser \
extras/rboot-ota \
$(abspath esp-wolfssl) \
$(abspath esp-cjson) \
$(abspath esp-homekit)

FLASH_SIZE ?= 8
HOMEKIT_SPI_FLASH_BASE_ADDR ?= 0x8C000

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

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

1 change: 1 addition & 0 deletions esp-cjson
Submodule esp-cjson added at 2216b1
1 change: 1 addition & 0 deletions esp-homekit
Submodule esp-homekit added at 51203a
1 change: 1 addition & 0 deletions esp-wolfssl
Submodule esp-wolfssl added at 62252d
18 changes: 11 additions & 7 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void log_send(void *pvParameters){
}
}

bool hold=0,calibrate=0,reverse=0;
bool hold=0,calibrate=0,reverse=0,obstruction=0;
bool changed=0;
int target=0,current=0,state=2; //homekit values

Expand Down Expand Up @@ -234,9 +234,12 @@ void motor_init() {
//xTaskCreate(motor_loop_task, "loop", 512, NULL, 1, NULL);
}

homekit_value_t obstruction_get() {
return HOMEKIT_BOOL(obstruction);
}

homekit_value_t hold_get() {
return HOMEKIT_BOOL(on);
return HOMEKIT_BOOL(hold);
}
void hold_set(homekit_value_t value) {
if (value.format != homekit_format_bool) {
Expand Down Expand Up @@ -292,11 +295,7 @@ void state_set(homekit_value_t value) {
}

void identify_task(void *_args) {
int oldmode;
oldmode=mode;
mode=10; changed=1;
vTaskDelay(5000 / portTICK_PERIOD_MS); //5 sec
mode=oldmode; changed=1;
vTaskDelete(NULL);
}

Expand Down Expand Up @@ -344,6 +343,10 @@ homekit_accessory_t *accessories[] = {
.getter=hold_get,
.setter=hold_set
),
HOMEKIT_CHARACTERISTIC(
OBSTRUCTION_DETECTED, false,
.getter=obstruction_get,
),
&ota_trigger,
&calibrated,
&reversed,
Expand All @@ -355,14 +358,15 @@ homekit_accessory_t *accessories[] = {
};



homekit_server_config_t config = {
.accessories = accessories,
.password = "111-11-111"
};

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

motor_init();

Expand Down
75 changes: 75 additions & 0 deletions ota-api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <stdlib.h> //for printf
#include <stdio.h>
#include <string.h>

#include <espressif/esp_wifi.h>
#include <espressif/esp_sta.h>
#include <rboot-api.h>
#include <sysparam.h>

// the first function is the ONLY thing needed for a repo to support ota after having started with ota-boot
// in ota-boot the user gets to set the wifi and the repository details and it then installs the ota-main binary

void ota_update(void *arg) { //arg not used
rboot_set_temp_rom(1); //select the OTA main routine
sdk_system_restart(); //#include <rboot-api.h>
// there is a bug in the esp SDK such that if you do not power cycle the chip after serial flashing, restart is unreliable
}

// this function is optional to couple Homekit parameters to the sysparam variables and github parameters
unsigned int ota_read_sysparam(char **manufacturer,char **serial,char **model,char **revision) {
sysparam_status_t status;
char *value;

status = sysparam_get_string("ota_repo", &value);
if (status == SYSPARAM_OK) {
strchr(value,'/')[0]=0;
*manufacturer=value;
*model=value+strlen(value)+1;
} else {
*manufacturer="manuf_unknown";
*model="model_unknown";
}
status = sysparam_get_string("ota_version", &value);
if (status == SYSPARAM_OK) {
*revision=value;
} else *revision="0.0.0";

uint8_t macaddr[6];
sdk_wifi_get_macaddr(STATION_IF, macaddr);
*serial=malloc(18);
sprintf(*serial,"%02X:%02X:%02X:%02X:%02X:%02X",macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);

unsigned int c_hash=0;
char version[16];
char* rev=version;
char* dot;
strncpy(rev,*revision,16);
if ((dot=strchr(rev,'.'))) {dot[0]=0; c_hash= atoi(rev); rev=dot+1;}
if ((dot=strchr(rev,'.'))) {dot[0]=0; c_hash=c_hash*1000+atoi(rev); rev=dot+1;}
c_hash=c_hash*1000+atoi(rev);
//c_hash=c_hash*10 +configuration_variant; //possible future extension
printf("manuf=\'%s\' serial=\'%s\' model=\'%s\' revision=\'%s\' c#=%d\n",*manufacturer,*serial,*model,*revision,c_hash);
return c_hash;
}




#include <homekit/characteristics.h>
#include <esplibs/libmain.h>
#include <etstimer.h>

static ETSTimer update_timer;

void ota_set(homekit_value_t value) {
if (value.format != homekit_format_bool) {
printf("Invalid ota-value format: %d\n", value.format);
return;
}
if (value.bool_value) {
//make a distinct light pattern or other feedback to the user = call identify routine
sdk_os_timer_setfn(&update_timer, ota_update, NULL);
sdk_os_timer_arm(&update_timer, 500, 0); //wait 0.5 seconds to trigger the reboot so gui can update and events sent
}
}
27 changes: 27 additions & 0 deletions ota-api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef __HOMEKIT_CUSTOM_CHARACTERISTICS__
#define __HOMEKIT_CUSTOM_CHARACTERISTICS__

#define HOMEKIT_CUSTOM_UUID(value) (value "-0e36-4a42-ad11-745a73b84f2b")

#define HOMEKIT_SERVICE_CUSTOM_SETUP HOMEKIT_CUSTOM_UUID("000000FF")

#define HOMEKIT_CHARACTERISTIC_CUSTOM_OTA_TRIGGER HOMEKIT_CUSTOM_UUID("F0000001")
#define HOMEKIT_DECLARE_CHARACTERISTIC_CUSTOM_OTA_TRIGGER(_value, ...) \
.type = HOMEKIT_CHARACTERISTIC_CUSTOM_OTA_TRIGGER, \
.description = "}FirmwareUpdate", \
.format = homekit_format_bool, \
.permissions = homekit_permissions_paired_read \
| homekit_permissions_paired_write \
| homekit_permissions_notify, \
.value = HOMEKIT_BOOL_(_value), \
##__VA_ARGS__

unsigned int ota_read_sysparam(char **manufacturer,char **serial,char **model,char **revision);

void ota_update(void *arg);

void ota_set(homekit_value_t value);

#define API_OTA_TRIGGER HOMEKIT_CHARACTERISTIC_(CUSTOM_OTA_TRIGGER, false, .setter=ota_set)

#endif

0 comments on commit 75b568a

Please sign in to comment.