This commit is contained in:
openshwprojects
2022-02-19 15:04:57 +01:00
4 changed files with 35 additions and 11 deletions

View File

@@ -300,6 +300,9 @@ typedef struct template_s {
template_t g_templates [] = {
{ Setup_Device_Empty, "Empty"},
// BK7231N devices
{ Setup_Device_BK7231N_CB2S_QiachipSmartSwitch, "[BK7231N][CB2S] QiaChip Smart Switch"},
// BK7231T devices
{ Setup_Device_TuyaWL_SW01_16A, "WL SW01 16A"},
{ Setup_Device_TuyaSmartLife4CH10A, "Smart Life 4CH 10A"},
{ Setup_Device_IntelligentLife_NF101A, "Intelligent Life NF101A"},

View File

@@ -17,6 +17,7 @@
extern UINT32 flash_read(char *user_buf, UINT32 count, UINT32 address);
static int http_rest_error(http_request_t *request, int code, char *msg);
static int http_rest_get(http_request_t *request);
static int http_rest_post(http_request_t *request);
@@ -580,7 +581,6 @@ static int http_rest_post_pins(http_request_t *request){
char *json_str = request->bodystart;
int json_len = strlen(json_str);
http_setup(request, httpMimeTypeText);
memset(p, 0, sizeof(jsmn_parser));
memset(t, 0, sizeof(jsmntok_t)*128);
@@ -589,22 +589,18 @@ static int http_rest_post_pins(http_request_t *request){
if (r < 0) {
ADDLOG_ERROR(LOG_FEATURE_API, "Failed to parse JSON: %d", r);
sprintf(tmp,"Failed to parse JSON: %d\n", r);
poststr(request, tmp);
poststr(request, NULL);
os_free(p);
os_free(t);
return 0;
return http_rest_error(request, 400, tmp);
}
/* Assume the top-level element is an object */
if (r < 1 || t[0].type != JSMN_OBJECT) {
ADDLOG_ERROR(LOG_FEATURE_API, "Object expected", r);
sprintf(tmp,"Object expected\n");
poststr(request, tmp);
poststr(request, NULL);
os_free(p);
os_free(t);
return 0;
return http_rest_error(request, 400, tmp);
}
/* Loop over all keys of the root object */
@@ -618,9 +614,9 @@ static int http_rest_post_pins(http_request_t *request){
int roleval, pr;
jsmntok_t *g = &t[i + j + 2];
roleval = atoi(json_str + g->start);
pr = PIN_GetPinRoleForPinIndex(i);
pr = PIN_GetPinRoleForPinIndex(j);
if(pr != roleval) {
PIN_SetPinRoleForPinIndex(i,roleval);
PIN_SetPinRoleForPinIndex(j,roleval);
iChanged++;
}
}
@@ -648,18 +644,23 @@ static int http_rest_post_pins(http_request_t *request){
}
if (iChanged){
PIN_SaveToFlash();
ADDLOG_DEBUG(LOG_FEATURE_API, "Changed %d - saved to flash", iChanged);
}
poststr(request, NULL);
os_free(p);
os_free(t);
return http_rest_error(request, 200, "OK");
return 0;
}
static int http_rest_error(http_request_t *request, int code, char *msg){
request->responseCode = HTTP_RESPONSE_SERVER_ERROR;
http_setup(request, httpMimeTypeJson);
hprintf128(request, "{\"error\":%d, \"msg\"=\"%s\"}", code, msg);
if (code != 200){
hprintf128(request, "{\"error\":%d, \"msg\":\"%s\"}", code, msg);
} else {
hprintf128(request, "{\"success\":%d, \"msg\":\"%s\"}", code, msg);
}
poststr(request,NULL);
return 0;
}

View File

@@ -250,6 +250,25 @@ void Setup_Device_EmaxHome_EDU8774() {
PIN_SaveToFlash();
}
// TODO - ELEKTRODA LINK
// QiachipSmartSwitch
void Setup_Device_BK7231N_CB2S_QiachipSmartSwitch() {
PIN_ClearPins();
// Button
PIN_SetPinRoleForPinIndex(7, IOR_Button);
PIN_SetPinChannelForPinIndex(7, 1);
// Relay
PIN_SetPinRoleForPinIndex(8, IOR_Relay);
PIN_SetPinChannelForPinIndex(8, 1);
// Led
PIN_SaveToFlash();
}
// https://www.tokmanni.fi/alypistorasia-home-connect-ip20-6419860720456
// Marked as Smart-PFW02-G
// Relay (with npn-transistor) at PWM4 P24

View File

@@ -65,6 +65,7 @@ void Setup_Device_NedisWIFIPO120FWT_16A();
void Setup_Device_NedisWIFIP130FWT_10A();
void Setup_Device_EmaxHome_EDU8774();
void Setup_Device_TuyaSmartPFW02G();
void Setup_Device_BK7231N_CB2S_QiachipSmartSwitch();
#endif