-
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support to Beewi Smart Door as broadcaster. #22
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -356,7 +356,7 @@ static void mijia_temp_hum_metadata_get(uint8_t *adv_data, size_t adv_data_len, | |
uint8_t len; | ||
mijia_temp_hum_t *mijia_temp_hum = mijia_temp_hum_data_get(adv_data, | ||
adv_data_len, &len); | ||
|
||
cb("MACAddress", _mactoa(mijia_temp_hum->mac), ctx); | ||
sprintf(s, "%hhu", mijia_temp_hum->message_counter); | ||
cb("MessageCounter", s, ctx); | ||
|
@@ -389,12 +389,89 @@ static broadcaster_ops_t mijia_temp_hum_ops = { | |
.is_broadcaster = mijia_temp_hum_is_broadcaster, | ||
.metadata_get = mijia_temp_hum_metadata_get, | ||
}; | ||
/* Beewi Smart Door */ | ||
#define BEEWI_SMART_DOOR_COMPANY_ID 0x000D | ||
#define BEEWI_SMART_DOOR_SERVICE_ID 0x08 | ||
#define BEEWI_SMART_DOOR_DATA_TBD1 0x0C | ||
#define BEEWI_SMART_DOOR_DATA_TBD2 0x06 //unused here | ||
|
||
|
||
typedef struct { | ||
uint16_t company_id; | ||
uint8_t service_id; | ||
uint8_t tbd1; | ||
uint8_t status; | ||
uint8_t tbd2; | ||
uint8_t battery; | ||
} __attribute__((packed)) beewi_smart_door_t; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure this is the exact format of the payload? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No doc at all they refused to communicate specs. This is just reverse enginering. Here is a complete packet : As there's always 0C before Status and 06 before Battery I've defined them as identifier.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, in that case, using the company ID to distinguish these devices isn't good enough. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll compare with advertised device name. That's what I'm already doing in another project. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying this but it doesn't seems to work :
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's probably because the device sends |
||
|
||
static beewi_smart_door_t *beewi_smart_door_data_get(uint8_t *adv_data, | ||
uint8_t adv_data_len, uint8_t *beewi_smart_door_len) | ||
{ | ||
uint8_t len; | ||
uint8_t *data = esp_ble_resolve_adv_data(adv_data, | ||
ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE, &len); | ||
|
||
if (beewi_smart_door_len) | ||
*beewi_smart_door_len = len; | ||
|
||
return (beewi_smart_door_t *)data; | ||
} | ||
|
||
static int beewi_smart_door_is_broadcaster(uint8_t *adv_data, | ||
size_t adv_data_len) | ||
{ | ||
uint8_t name_len; | ||
char *name = (char *)esp_ble_resolve_adv_data(adv_data, | ||
ESP_BLE_AD_TYPE_NAME_CMPL, &name_len); | ||
if (strncmp(name, "BeeWi Smart Door", name_len) != 0) | ||
return 0 | ||
; | ||
|
||
uint8_t len; | ||
beewi_smart_door_t *beewi_smart_door = beewi_smart_door_data_get(adv_data, | ||
adv_data_len, &len); | ||
|
||
/* Technically, we should also prevent connecting to the device, as it stops broadcasting | ||
then. Or just once to get device name, and other static infos. Interesting data as opening status & battery are broadcasted. | ||
Battery data is also available as characteristic, but not the essential data, the door status. | ||
Needs to blacklist the mac in service config to make this working*/ | ||
|
||
|
||
if (!beewi_smart_door || len != sizeof(beewi_smart_door_t)) | ||
return 0; | ||
|
||
else return 1; | ||
|
||
} | ||
|
||
static void beewi_smart_door_metadata_get(uint8_t *adv_data, | ||
size_t adv_data_len, int rssi, broadcaster_meta_data_cb_t cb, void *ctx) | ||
{ | ||
char s[6]; | ||
beewi_smart_door_t *beewi_smart_door = beewi_smart_door_data_get(adv_data, | ||
adv_data_len, NULL); | ||
|
||
if (beewi_smart_door->tbd1 == BEEWI_SMART_DOOR_DATA_TBD1) { | ||
sprintf(s,"%hhu",beewi_smart_door->status ); | ||
cb("Status", s, ctx); | ||
sprintf(s,"%hhu",beewi_smart_door->battery); | ||
cb("Battery", s, ctx); | ||
} | ||
} | ||
|
||
static broadcaster_ops_t beewi_smart_door_ops = { | ||
.name = "BeeWi Smart Door", | ||
.is_broadcaster = beewi_smart_door_is_broadcaster, | ||
.metadata_get = beewi_smart_door_metadata_get, | ||
}; | ||
|
||
/* Common */ | ||
static broadcaster_ops_t *broadcaster_ops[] = { | ||
&ibeacon_ops, | ||
&eddystone_ops, | ||
&mijia_temp_hum_ops, | ||
&beewi_smart_door_ops, | ||
NULL | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be a part of this commit.