Skip to content

Commit

Permalink
Added characteristic for WiFi Reset
Browse files Browse the repository at this point in the history
  • Loading branch information
maccoylton committed Nov 11, 2019
1 parent f870a4e commit 31e23b6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ bool accessory_paired = false;
/* global varibale to support LEDs set to 0 wehre the LED is connected to GND, 1 where +3.3v */
int led_off_value=1;

void wifi_reset_set(homekit_value_t value);


homekit_characteristic_t wifi_reset = HOMEKIT_CHARACTERISTIC_(CUSTOM_WIFI_RESET, false, .setter=wifi_reset_set);
homekit_characteristic_t ota_trigger = API_OTA_TRIGGER;
homekit_characteristic_t name = HOMEKIT_CHARACTERISTIC_(NAME, DEVICE_NAME);
homekit_characteristic_t manufacturer = HOMEKIT_CHARACTERISTIC_(MANUFACTURER, DEVICE_MANUFACTURER);
Expand Down Expand Up @@ -109,6 +112,12 @@ void identify(homekit_value_t _value) {
xTaskCreate(identify_task, "identify", 128, NULL, 2, NULL);
}

void wifi_reset_set(homekit_value_t value){
printf("Resetting Wifi Config\n");
wifi_config_reset();
printf("Restarting\n");
sdk_system_restart();
}

void reset_configuration_task() {
//Flash the LED first before we start the reset
Expand Down Expand Up @@ -180,6 +189,7 @@ homekit_accessory_t *accessories[] = {
&methane_level,
&ammonium_level,
&ota_trigger,
&wifi_reset,
NULL
}),
NULL
Expand Down Expand Up @@ -342,12 +352,18 @@ void on_homekit_event(homekit_event_t event) {
switch (event) {
case HOMEKIT_EVENT_SERVER_INITIALIZED:
printf("on_homekit_event: Server initialised\n");
if (homekit_is_paired()){
/* if server has started and we already have a pairing then initialise*/
accessory_paired = true;
accessory_init();
}
break;
case HOMEKIT_EVENT_CLIENT_CONNECTED:
printf("on_homekit_event: Client connected\n");
break;
case HOMEKIT_EVENT_CLIENT_VERIFIED:
printf("on_homekit_event: Client verified\n");
/* we weren't paired on started up but we now are */
if (!accessory_paired ){
accessory_paired = true;
accessory_init();
Expand All @@ -362,7 +378,7 @@ void on_homekit_event(homekit_event_t event) {
case HOMEKIT_EVENT_PAIRING_REMOVED:
printf("on_homekit_event: Pairing removed\n");
if (!homekit_is_paired())
/* if we have no more pairtings then restart */
/* if we have no more pairings then restart */
printf("on_homekit_event: no more pairings so restart\n");
sdk_system_restart();
break;
Expand Down

0 comments on commit 31e23b6

Please sign in to comment.