Skip to content

Commit c2e7abd

Browse files
0.2.0 replace UDP logger with recent version
1 parent 2c6d637 commit c2e7abd

File tree

5 files changed

+40
-55
lines changed

5 files changed

+40
-55
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "esp-wolfssl"]
88
path = esp-wolfssl
99
url = https://github.com/HomeACcessoryKid/esp-wolfssl
10+
[submodule "UDPlogger"]
11+
path = UDPlogger
12+
url = https://github.com/HomeACcessoryKid/UDPlogger

Makefile

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ EXTRA_COMPONENTS = \
55
extras/rboot-ota \
66
$(abspath esp-wolfssl) \
77
$(abspath esp-cjson) \
8-
$(abspath esp-homekit)
8+
$(abspath esp-homekit) \
9+
$(abspath UDPlogger) \
910

1011
FLASH_SIZE ?= 8
1112
HOMEKIT_SPI_FLASH_BASE_ADDR ?= 0x8C000
1213

1314
EXTRA_CFLAGS += -I../.. -DHOMEKIT_SHORT_APPLE_UUIDS
15+
EXTRA_CFLAGS += -DUDPLOG_PRINTF_TO_UDP
16+
17+
ifdef VERSION
18+
EXTRA_CFLAGS += -DVERSION=\"$(VERSION)\"
19+
endif
1420

1521
include $(SDK_PATH)/common.mk
1622

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# AQARA-ZNCLDJ11LM
2-
Aqara curtain motor homekit software. (c) 2018 HomeAccessoryKid
2+
Aqara curtain motor homekit software. (c) 2018-2020 HomeAccessoryKid
33

44
This homekit software drives a curtain motor Aqara ZNCLDJ11LM as offered on
55
e.g. alibaba. It uses any ESP8266 with as little as 1MB flash.

UDPlogger

Submodule UDPlogger added at 37426f8

main.c

+28-53
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,11 @@
1616
#include <homekit/characteristics.h>
1717
#include <string.h>
1818
#include "lwip/api.h"
19+
#include <udplogger.h>
1920

20-
//use nc -kulnw0 34567 to collect this output
21-
#define LOG(message, ...) sprintf(string+strlen(string),message, ##__VA_ARGS__)
22-
char string[1450]={0}; //in the end I do not know to prevent overflow, so I use the max size of 1 UDP packet
23-
void log_send(void *pvParameters){
24-
struct netconn* conn;
25-
int i=0,len;
26-
27-
while (sdk_wifi_station_get_connect_status() != STATION_GOT_IP) vTaskDelay(20); //Check if we have an IP every 200ms
28-
// Create UDP connection
29-
conn = netconn_new(NETCONN_UDP);
30-
if (netconn_bind( conn, IP_ADDR_ANY, 33333) != ERR_OK) netconn_delete(conn);
31-
if (netconn_connect(conn, IP_ADDR_BROADCAST, 34567) != ERR_OK) netconn_delete(conn);
32-
33-
while(1){
34-
len=strlen(string);
35-
if ((!i && len) || len>1000) {
36-
struct netbuf* buf = netbuf_new();
37-
void* data = netbuf_alloc(buf,len);
38-
memcpy (data,string,len);
39-
string[0]=0; //there is a risk of new LOG to add to string after we measured len
40-
if (netconn_send(conn, buf) == ERR_OK) netbuf_delete(buf);
41-
i=10;
42-
}
43-
if (!i) i=10; //sends output every 100ms if not more than 1000 bytes
44-
i--;
45-
vTaskDelay(1); //with len>1000 and delay=10ms, we might handle 800kbps throughput
46-
}
47-
}
48-
//==================== END OF UDP LOG COLLECTOR ===================
21+
#ifndef VERSION
22+
#error You must set VERSION=x.y.z to match github version tag x.y.z
23+
#endif
4924

5025
//hardcoded CRC16_MODBUS
5126
char _open[]={0x03,0x01,0xb9,0x24}; //n=4
@@ -74,7 +49,7 @@ char _setdir1[]={0x02,0x03,0x01,0x01,0x13,0xe7}; //n=6
7449
#define _setdir1_n 6
7550
char _setpos[]={0x03,0x04,0x00,0x00,0x00}; //n=5 still needs value and CRC filled in
7651
#define _setpos_n 5
77-
#define SEND(message) do {LOG(#message "\n"); \
52+
#define SEND(message) do {UDPLUO(#message "\n"); \
7853
taskENTER_CRITICAL(); \
7954
memcpy(order.chars, _ ## message, _ ## message ## _n); \
8055
order.len=_ ## message ## _n; \
@@ -159,23 +134,23 @@ homekit_value_t calibrate_get() {
159134
}
160135
void calibrate_set(homekit_value_t value) {
161136
if (value.format != homekit_format_bool) {
162-
LOG("Invalid calibrated-value format: %d\n", value.format);
137+
UDPLUO("Invalid calibrated-value format: %d\n", value.format);
163138
return;
164139
}
165140
calibrated = value.bool_value;
166-
LOG("Calibrate: %d\n", calibrated);
141+
UDPLUO("Calibrate: %d\n", calibrated);
167142
if ( calibrated) xTaskCreate(calibrate_task, "calibrated", 256, NULL, 1, NULL);
168143
else {SEND(uncal); SEND(reqpos);}
169144
}
170145

171146

172147
void reverse_set(homekit_value_t value) {
173148
if (value.format != homekit_format_bool) {
174-
LOG("Invalid reversed-value format: %d\n", value.format);
149+
UDPLUO("Invalid reversed-value format: %d\n", value.format);
175150
return;
176151
}
177152
reversed = value.bool_value;
178-
LOG("Reverse: %d\n", reversed);
153+
UDPLUO("Reverse: %d\n", reversed);
179154
if (reversed) SEND(setdir1); else SEND(setdir0);
180155
SEND(reqdir);
181156
SEND(reqcal);
@@ -201,20 +176,20 @@ homekit_value_t hold_get() {
201176
}
202177
void hold_set(homekit_value_t value) {
203178
if (value.format != homekit_format_bool) {
204-
LOG("Invalid hold-value format: %d\n", value.format);
179+
UDPLUO("Invalid hold-value format: %d\n", value.format);
205180
return;
206181
}
207-
LOG("H:%3d\n",value.bool_value);
182+
UDPLUO("H:%3d\n",value.bool_value);
208183
hold = value.bool_value;
209184
}
210185

211186

212187
void target_set(homekit_value_t value) {
213188
if (value.format != homekit_format_uint8) {
214-
LOG("Invalid target-value format: %d\n", value.format);
189+
UDPLUO("Invalid target-value format: %d\n", value.format);
215190
return;
216191
}
217-
LOG("T:%3d\n",value.int_value);
192+
UDPLUO("T:%3d\n",value.int_value);
218193

219194
uint crc = 0xFFFF;
220195
int i,j;
@@ -244,7 +219,7 @@ void target_set(homekit_value_t value) {
244219
// }
245220

246221
void identify(homekit_value_t _value) {
247-
LOG("Identify\n");
222+
UDPLUO("Identify\n");
248223
// xTaskCreate(identify_task, "identify", 256, NULL, 2, NULL);
249224
}
250225

@@ -255,15 +230,15 @@ void sender_task(void *pvParameters){
255230
int i,attempt;
256231
struct _order ordr;
257232

258-
if( senderQueue == 0 ) {LOG("NO SEND QUEUE!\n");vTaskDelete(NULL);}
233+
if( senderQueue == 0 ) {UDPLUO("NO SEND QUEUE!\n");vTaskDelete(NULL);}
259234
ulTaskNotifyTake( pdTRUE, 0 );
260235
while(1) {
261236
if( xQueueReceive( senderQueue, (void*)&ordr, (TickType_t) portMAX_DELAY ) ) {
262237
attempt=3;
263238
do {uart_putc(1,0x55);uart_putc(1,0xfe);uart_putc(1,0xfe);
264239
for (i=0;i<ordr.len;i++) uart_putc(1,ordr.chars[i]);
265240
uart_flush_txfifo(1);
266-
for (i=0;i<ordr.len;i++) LOG("%02x",ordr.chars[i]); LOG(" sent\n");
241+
for (i=0;i<ordr.len;i++) UDPLUO("%02x",ordr.chars[i]); UDPLUO(" sent\n");
267242
if (ulTaskNotifyTake( pdTRUE, CONFIRM_TIMEOUT )==pdTRUE) break; //semafore to signal a response received
268243
} while (--attempt);
269244
}
@@ -287,7 +262,7 @@ void report_task(void *pvParameters){
287262
bool obstructed;
288263
struct _report rep;
289264

290-
if( reportQueue == 0 ) {LOG("NO REPORT QUEUE!\n");vTaskDelete(NULL);}
265+
if( reportQueue == 0 ) {UDPLUO("NO REPORT QUEUE!\n");vTaskDelete(NULL);}
291266
while(1) {
292267
if( xQueueReceive( reportQueue, (void*)&rep, (TickType_t) timer ) ) {
293268
obstructed=false; timer=100;
@@ -306,8 +281,8 @@ void report_task(void *pvParameters){
306281

307282
if (rep.position==0xff) aware=0; else aware=1;
308283

309-
LOG("pos=%02x,dir=%02x,sta=%02x,cal=%02x,",rep.position,rep.direction,rep.status,rep.calibr);
310-
LOG("state=%d, obstructed=%d\n",state.value.int_value,obstruction.value.bool_value);
284+
UDPLUO("pos=%02x,dir=%02x,sta=%02x,cal=%02x,",rep.position,rep.direction,rep.status,rep.calibr);
285+
UDPLUO("state=%d, obstructed=%d\n",state.value.int_value,obstruction.value.bool_value);
311286
}
312287
SEND(reqcal); SEND(reqpos); SEND(reqsta);
313288
}
@@ -319,9 +294,9 @@ int idx=0;
319294

320295
void parse(int positions) {
321296
int i=0;
322-
if (positions<4) LOG("%02x%02x\n",buff[0],buff[1]);
297+
if (positions<4) UDPLUO("%02x%02x\n",buff[0],buff[1]);
323298
else {
324-
for (i=3;i<positions-2;i++) LOG("%02x",buff[i]); LOG("\n");
299+
for (i=3;i<positions-2;i++) UDPLUO("%02x",buff[i]); UDPLUO("\n");
325300

326301
if (buff[3]==0x03 && buff[4]==0x01) xTaskNotifyGive( SendTask ); // open confirmation
327302
if (buff[3]==0x03 && buff[4]==0x02) xTaskNotifyGive( SendTask ); //close confirmation
@@ -406,11 +381,11 @@ void uart_parse_input(void *pvParameters) {
406381
//int i;
407382
for(;;) {
408383
buff[idx++]=uart_getc(0);
409-
//for (i=1;i<idx;i++) LOG(" ");
410-
//LOG("v%d\n",idx);
384+
//for (i=1;i<idx;i++) UDPLUO(" ");
385+
//UDPLUO("v%d\n",idx);
411386
while (idx){
412-
//for (i=0;i<16;i++) LOG("%02x.",buff[i]);
413-
//LOG(" %d\n",idx);
387+
//for (i=0;i<16;i++) UDPLUO("%02x.",buff[i]);
388+
//UDPLUO(" %d\n",idx);
414389
if (!(buff[0]==0x88 || buff[0]==0x55)) { shift_buff(1); continue;}
415390
if (buff[0]==0x88 && buff[1]==0xf8) {parse(2); shift_buff(2); continue;}
416391
if (buff[0]==0x88 && idx>=2) { shift_buff(1); continue;}
@@ -436,7 +411,7 @@ void uart_parse_input(void *pvParameters) {
436411
if (!crc16(16)) parse(16);
437412
shift_buff(16); continue;
438413
} //BUG FIX these shifts for failures should be 1 only
439-
if (idx==16) LOG("something went wrong: idx=16!\n");
414+
if (idx==16) UDPLUO("something went wrong: idx=16!\n");
440415
break;
441416
}
442417
}
@@ -503,8 +478,8 @@ homekit_server_config_t config = {
503478
};
504479

505480
void user_init(void) {
506-
xTaskCreate(log_send, "logsend", 256, NULL, 4, NULL); //is prio4 a good idea??
507-
LOG("Aqara Curtain Motor\n");
481+
udplog_init(2);
482+
UDPLUS("\n\n\nAqara Curtain Motor " VERSION "\n");
508483

509484
motor_init();
510485

0 commit comments

Comments
 (0)