Skip to content

Commit

Permalink
memory optimizations in udplogger, esp-homekit and wifi thermostat
Browse files Browse the repository at this point in the history
  • Loading branch information
maccoylton committed Aug 21, 2020
1 parent a3d1628 commit cc7390c
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 40 deletions.
2 changes: 1 addition & 1 deletion components/UDPlogger
Submodule UDPlogger updated 2 files
+2 −2 udplogger.c
+3 −1 udplogger.h
2 changes: 1 addition & 1 deletion components/esp-homekit
1 change: 0 additions & 1 deletion src/latest-pre-release

This file was deleted.

152 changes: 152 additions & 0 deletions src/ledstrip
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
rBoot4LCM v1.0.1
0003ffff @ 1818
0003ffff @ 1028 => count: 1
led_pin=2, polarity=0, led_valid=1
Flash Size: 32 Mbit
Flash Mode: DOUT
Flash Speed: 40 MHz
rBoot Option: Big flash
rBoot Option: RTC data

Booting rom 0 at 2000, load addr 707d0.
␌N��NQ
�a�Q�B=�Z␑`C␁�TPQ�␑q␁���rP�␀␁�VE�␑@␌�i�@����␝ �ڂ��Q���rP�␅1�VE␋X@␌�i␄ 5��Z�␂␐
!!f�e 2020 10:54:35
phy ver: 273, pp ver: 8.3

standard_init: Start, Freep Heap=44820
standard_init: RTC power cycle count = 1
standard_init:SDK version: 0.9.9, free heap 42336
get_sysparam_info: Sysparam base address 4157440, num_sectors 4
get_sysparam_info: sysparam name: wifi_ssid, value:MacCoylton-WiFi, key length:9, value length:15
get_sysparam_info: sysparam name: wifi_password, value:**********
get_sysparam_info: sysparam name: On, value:n, key length:2, value length:1
WiFi check interval:
0a 00 00 00
get_sysparam_info: while loop status 1
load_characteristic_from_flash: WiFi check interval: int: 10
homekit_characteristic_bounds_check: WiFi check interval: Checking integer bounds
load_characteristic_from_flash: ota_beta: bool: load_characteristic_from_flash: Error in sysparams error:1 loading characteristic
load_characteristic_from_flash: lcm_beta: bool: load_characteristic_from_flash: Error in sysparams error:1 loading characteristic
Create accessory name
|manuf='manuf_unknown' serial='CC:50:E3:2B:22:18' model='model_unknown' revision='0.0.0' c#=0
wifi_check_stop_start Starting Task
standard_init: End, Freep Heap=39848
>>> wifi_config: Initializing WiFi config
>>> wifi_config: Connecting to MacCoylton-WiFi
mode : sta(cc:50:e3:2b:22:18)
add if0

checkWifiTask : no check performed, check interval: 10, accessory paired: 0Free Heap=38472, Free Stack=88
scandone
add 0
aid 17
cnt

connected with MacCoylton-WiFi, channel 1
dhcp client start...
ip:192.168.1.80,mask:255.255.255.0,gw:192.168.1.254
>>> wifi_config: Connected to WiFi network
on_wifi_ready: , Freep Heap=41904
get_sysparam_info: Sysparam base address 4157440, num_sectors 4
get_sysparam_info: sysparam name: wifi_ssid, value:MacCoylton-WiFi, key length:9, value length:15
get_sysparam_info: sysparam name: wifi_password, value:**********
get_sysparam_info: sysparam name: On, value:n, key length:2, value length:1
WiFi check interval:
0a 00 00 00
get_sysparam_info: while loop status 1
on_wifi_ready Reset Reason: Default Reset
on_wifi_ready: Exception Cause: 0
EPC 1: 0
EPC 2: 0
EPC 3: 0
Exv virtul address: 0
DEPC: 0
Return Address:0
on_wifi_ready: Calling homekit_server_init, Freep Heap=41904
on_wifi_ready: After calling homekit_Server_init, Freep Heap=28772
on_wifi_ready: End, Freep Heap=28772

checkWifiTask : no check performed, check interval: 10, accessory paired: 0Free Heap=28772, Free Stack=88
>>> HomeKit: Starting server
>>> HomeKit: Using existing accessory ID: 99:9A:A0:6D:70:4C
>>> HomeKit: Configuring mDNS
HomeKit: adding mDNS TXT record md=model_unknown
HomeKit: adding mDNS TXT record pv=1.0
HomeKit: adding mDNS TXT record id=99:9A:A0:6D:70:4C
HomeKit: adding mDNS TXT record c#=1
HomeKit: adding mDNS TXT record s#=1
HomeKit: adding mDNS TXT record ff=0
HomeKit: adding mDNS TXT record sf=1
HomeKit: adding mDNS TXT record ci=5
HomeKit: adding mDNS TXT record sh=Vk8Pzw==
on_homekit_event: Server initialised, Free Heap=23072
on_homekit_event: Acessory is NOT paired on initialisation, Free Heap=23072
wifi_check_stop_start Stopping Task
mDNS: Delaying probe until IP is acquired
Got IP, resuming mDNS
mDNS: Probing 1 Led_Strip-RGBW-2826776
mDNS: Probing 1 Led_Strip-RGBW-2826776
mDNS: Probing 2 Led_Strip-RGBW-2826776
mDNS: Probing 3 Led_Strip-RGBW-2826776
mDNS: Probe successful, announcing Led_Strip-RGBW-2826776 TXT md=model_unknown pv=1.0 id=99:9A:A0:6D:70:4C c#=1 s#=1 ff=0 sf=1 ci=5 sh=Vk8Pzw==
mDNS: Announcing 1 Led_Strip-RGBW-2826776
mDNS: Announcing 2 Led_Strip-RGBW-2826776
mDNS: Announcing 3 Led_Strip-RGBW-2826776
mDNS: Announcing 4 Led_Strip-RGBW-2826776
ip:192.168.1.80,mask:255.255.255.0,gw:192.168.1.254
>>> HomeKit: Clients connected: 1
>>> HomeKit: [Client 1] Got new client connection from 192.168.1.162
on_homekit_event: Client connected, Free Heap=24692
>>> HomeKit: [Client 1] Pair Setup Step 1/3
>>> HomeKit: Clients connected: 2
>>> HomeKit: [Client 2] Got new client connection from 192.168.1.162
>>> HomeKit: [Client 1] Have existing connection from 192.168.1.162 X
on_homekit_event: Client connected, Free Heap=19492
>>> HomeKit: [Client 1] Closing client connection from 192.168.1.162
>>> HomeKit: Clients connected: 1
on_homekit_event: Client disconnected, Free Heap=22088
>>> HomeKit: Clients connected: 2
>>> HomeKit: [Client 1] Got new client connection from 192.168.1.162
>>> HomeKit: [Client 2] Have existing connection from 192.168.1.162 X
on_homekit_event: Client connected, Free Heap=22088
>>> HomeKit: [Client 2] Pair Setup Step 1/3
>>> HomeKit: [Client 2] Closing client connection from 192.168.1.162
>>> HomeKit: Clients connected: 1
on_homekit_event: Client disconnected, Free Heap=22596
>>> HomeKit: [Client 1] Pair Setup Step 1/3
>>> HomeKit: Clients connected: 2
>>> HomeKit: [Client 2] Got new client connection from 192.168.1.162
>>> HomeKit: [Client 1] Have existing connection from 192.168.1.162 X
on_homekit_event: Client connected, Free Heap=18984
>>> HomeKit: [Client 1] Closing client connection from 192.168.1.162
>>> HomeKit: Clients connected: 1
on_homekit_event: Client disconnected, Free Heap=21580
>>> HomeKit: Clients connected: 2
>>> HomeKit: [Client 1] Got new client connection from 192.168.1.162
>>> HomeKit: [Client 2] Have existing connection from 192.168.1.162 X
on_homekit_event: Client connected, Free Heap=21580
>>> HomeKit: [Client 2] Pair Setup Step 1/3
!!! HomeKit: [Client 2] Failed to dump SPR public key (code -2)
>>> HomeKit: [Client 2] Closing client connection from 192.168.1.162
>>> HomeKit: Clients connected: 1
on_homekit_event: Client disconnected, Free Heap=20108
>>> HomeKit: Clients connected: 2
>>> HomeKit: [Client 2] Got new client connection from 192.168.1.162
>>> HomeKit: [Client 1] Have existing connection from 192.168.1.162 X
on_homekit_event: Client connected, Free Heap=20108
>>> HomeKit: [Client 1] Pair Setup Step 1/3
!!! HomeKit: [Client 1] Failed to dump SPR public key (code -2)
>>> HomeKit: [Client 1] Closing client connection from 192.168.1.162
>>> HomeKit: Clients connected: 1
on_homekit_event: Client disconnected, Free Heap=20392
>>> HomeKit: [Client 2] Pair Setup Step 1/3
!!! HomeKit: [Client 2] Failed to dump SPR public key (code -2)
>>> HomeKit: [Client 2] Closing client connection from 192.168.1.162
>>> HomeKit: Clients connected: 0
on_homekit_event: Client disconnected, Free Heap=22632
>>> HomeKit: Clients connected: 1
>>> HomeKit: [Client 1] Got new client connection from 192.168.1.162
on_homekit_event: Client connected, Free Heap=24504
>>> HomeKit: [Client 1] Pair Setup Step 1/3

86 changes: 51 additions & 35 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#define DEVICE_MODEL "RGBW"
#define DEVICE_SERIAL "12345678"
#define FW_VERSION "1.0"
#define IR_RECEIVE_BUFFER_SIZE 128
#define IR_DECODE_BUFFER_SIZE 32

#define LPF_SHIFT 8 // divide by 256
#define LPF_INTERVAL 10 // in milliseconds
Expand All @@ -67,7 +69,8 @@
// and apply the four other parameters in the accessories_information section
#include "ota-api.h"

hsi_color_t hsi_colours[16];
/*hsi_color_t hsi_colours[16];*/

const int status_led_gpio = 2; /*set the gloabl variable for the led to be sued for showing status */
int led_off_value=1; /* global varibale to support LEDs set to 0 where the LED is connected to GND, 1 where +3.3v */
// Global variables
Expand All @@ -84,6 +87,8 @@ int blue_default_gpio = BLUE_PWM_PIN;
rgb_color_t current_color = { { 0, 0, 0, 0 } };
rgb_color_t target_color = { { 0, 0, 0, 0 } };

hsi_color_t current_colour_hsi = { { 0, 0, 0 } };

homekit_characteristic_t wifi_reset = HOMEKIT_CHARACTERISTIC_(CUSTOM_WIFI_RESET, false, .setter=wifi_reset_set);
homekit_characteristic_t wifi_check_interval = HOMEKIT_CHARACTERISTIC_(CUSTOM_WIFI_CHECK_INTERVAL, 200, .setter=wifi_check_interval_set);
/* checks the wifi is connected and flashes status led to indicated connected */
Expand Down Expand Up @@ -127,22 +132,19 @@ homekit_characteristic_t colours_fade = HOMEKIT_CHARACTERISTIC_(CUSTOM_COLOURS_F
homekit_characteristic_t colours_smooth = HOMEKIT_CHARACTERISTIC_(CUSTOM_COLOURS_SMOOTH, false ,.setter=colours_smooth_set, .getter=colours_smooth_get);
homekit_characteristic_t pure_white = HOMEKIT_CHARACTERISTIC_(CUSTOM_COLOURS_PURE_WHITE, false , .setter=colours_pure_white_set);

double __ieee754_remainder(double x, double y) {
return x - y * floor(x/y);
}

void ir_dump_task(void *arg) {

ir_rx_init(IR_RX_GPIO, 1024);
ir_rx_init(IR_RX_GPIO, IR_RECEIVE_BUFFER_SIZE);

ir_decoder_t *nec_decoder = ir_generic_make_decoder(&nec_protocol_config);

int16_t buffer_size = sizeof(uint8_t) * 1024;
int16_t buffer_size = sizeof(uint8_t) * IR_DECODE_BUFFER_SIZE;
int8_t *buffer = malloc(buffer_size);
int size=0;
int index = 0;


printf("%s: Start, Freep Heap=%d\n", __func__, xPortGetFreeHeapSize());

while (1) {
size = ir_recv(nec_decoder, 0, buffer, buffer_size);
if (size <= 0)
Expand All @@ -161,8 +163,7 @@ void ir_dump_task(void *arg) {
int cmd = buffer[2];
int effect = off_effect;

index = 99;


switch (cmd)
{
case on_button:
Expand Down Expand Up @@ -208,64 +209,64 @@ void ir_dump_task(void *arg) {
effect = flash_effect;
break;
case aubergene_button:
index = aubergene_index;
current_colour_hsi = aubergene_colour;
break;
case cream_button:
index = cream_index;
current_colour_hsi = cream_colour;
break;
case purple_button:
index = purple_index;
current_colour_hsi = purple_colour;
break;
case pink_button:
index = pink_index;
current_colour_hsi = pink_colour;
break;
case blue_button:
index = blue_index;
current_colour_hsi = blue_colour;
break;
case light_green_button:
index = light_green_index;
current_colour_hsi = light_green_colour;
break;
case green5_button:
index = green5_index;
current_colour_hsi = green5_colour;
break;
case white_button:
index = white_index;
current_colour_hsi = white_colour;
break;
case light_blue_button:
index = light_blue_index;
current_colour_hsi = light_blue_colour;
break;
case dark_orange_button:
index = dark_orange_index;
current_colour_hsi = dark_orange_colour;
break;
case red_button:
index = red_index;
current_colour_hsi = red_colour;
break;
case green_button:
index = green_index;
current_colour_hsi = green_colour;
break;
case yellow_button:
index = yellow_index;
current_colour_hsi = yellow_colour;
break;
case green4_button:
index = green4_index;
current_colour_hsi = green4_colour;
break;
case orange_button:
index = orange_index;
current_colour_hsi = orange_colour;
break;
case sky_blue_button:
index = sky_blue_index;
current_colour_hsi = sky_blue_colour;
break;
default:
printf ("%s: LED command unknown %d\n",__func__, buffer[cmd]);
break;
}

if (index != 99){
printf ("%s: LED command %d\n",__func__, cmd);
hue.value = HOMEKIT_FLOAT (hsi_colours[index].hue);
saturation.value = HOMEKIT_FLOAT (hsi_colours[index].saturation);
brightness.value = HOMEKIT_INT (hsi_colours[index].brightness);
}
printf ("%s: LED command %d\n",__func__, cmd);


hue.value = HOMEKIT_FLOAT (current_colour_hsi.hue);
saturation.value = HOMEKIT_FLOAT (current_colour_hsi.saturation);
brightness.value = HOMEKIT_INT (current_colour_hsi.brightness);

homekit_characteristic_notify(&hue,hue.value );
homekit_characteristic_notify(&saturation,saturation.value );
Expand All @@ -292,10 +293,12 @@ void ir_dump_task(void *arg) {
}



void led_strip_init (){


/* set th default values for the GPIOs incase we need to rest them later */
printf("%s: Start, Freep Heap=%d\n", __func__, xPortGetFreeHeapSize());

rgbw_lights_init();

Expand All @@ -304,7 +307,7 @@ void led_strip_init (){
led_saturation = saturation.value.float_value;
led_brightness = brightness.value.int_value;

hsi_colours[white_index] = (hsi_color_t) {{0.0, 0.0, 100}};
/* hsi_colours[white_index] = (hsi_color_t) {{0.0, 0.0, 100}};
hsi_colours[red_index] = (hsi_color_t) {{ 0.0, 100.0, 100}};
hsi_colours[dark_orange_index] = (hsi_color_t) { { 15, 100, 78 }};
Expand All @@ -323,8 +326,12 @@ void led_strip_init (){
hsi_colours[aubergene_index] = (hsi_color_t) { { 280, 100, 50 }};
hsi_colours[purple_index] = (hsi_color_t) { { 280, 100, 75 }};
hsi_colours[pink_index] = (hsi_color_t) { { 300, 100, 100 }};

*/
/*
xTaskCreate(ir_dump_task, "read_ir_task", 256, NULL, 2, NULL);
*/

printf("%s: Snd, Freep Heap=%d\n", __func__, xPortGetFreeHeapSize());

}

Expand Down Expand Up @@ -378,8 +385,13 @@ homekit_server_config_t config = {

void recover_from_reset (int reason){
/* called if we restarted abnormally */
printf("%s: Start, Freep Heap=%d\n", __func__, xPortGetFreeHeapSize());

printf ("%s: reason %d\n", __func__, reason);
load_characteristic_from_flash(&on);

printf("%s: End, Freep Heap=%d\n", __func__, xPortGetFreeHeapSize());

}

void accessory_init_not_paired (void) {
Expand All @@ -388,6 +400,8 @@ void accessory_init_not_paired (void) {

void accessory_init (void ){
/* initalise anything you don't want started until wifi and pairing is confirmed */
printf("%s: Start, Freep Heap=%d\n", __func__, xPortGetFreeHeapSize());

get_sysparam_info();
printf ("%s: GPIOS are set as follows : W=%d, R=%d, G=%d, B=%d\n",__func__, white_gpio.value.int_value,red_gpio.value.int_value, green_gpio.value.int_value, blue_gpio.value.int_value );
led_strip_init ();
Expand All @@ -397,7 +411,9 @@ void accessory_init (void ){
homekit_characteristic_notify(&saturation,saturation.value );
homekit_characteristic_notify(&brightness,brightness.value );
homekit_characteristic_notify(&pure_white,pure_white.value );


printf("%s: End, Freep Heap=%d\n", __func__, xPortGetFreeHeapSize());

}

void user_init(void) {
Expand Down
Loading

0 comments on commit cc7390c

Please sign in to comment.