Skip to content

Commit

Permalink
Add Switchbot support.
Browse files Browse the repository at this point in the history
  • Loading branch information
h2zero committed Apr 10, 2022
1 parent 3fb34af commit f3d4c4b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
8 changes: 8 additions & 0 deletions main/ZgatewayBLEConnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,13 @@ class XMWSDJ04MMC_connect : public zBLEConnect {
void publishData() override;
};

class switchbot_connect : public zBLEConnect {
void notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pData, size_t length, bool isNotify);

public:
switchbot_connect(NimBLEAddress& addr) : zBLEConnect(addr) {}
void publishData() override;
};

#endif //ESP32
#endif //zBLEConnect_h
11 changes: 11 additions & 0 deletions main/ZgatewayBLEConnect.ino
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,16 @@ void XMWSDJ04MMC_connect::publishData() {
}
}

void switchbot_connect::publishData() {
NimBLEUUID serviceUUID("cba20d00-224d-11e6-9fb8-0002a5d5c51b");
NimBLEUUID charUUID("cba20002-224d-11e6-9fb8-0002a5d5c51b");
NimBLERemoteCharacteristic* pChar = getCharacteristic(serviceUUID, charUUID);
if (pChar && pChar->canWrite()) {
Log.notice(F("Writing" CR));
static byte ON[] = {0x57, 0x01, 0x01};
pChar->writeValue(ON, 3, false);
}
}

# endif //ZgatewayBT
#endif //ESP32
23 changes: 14 additions & 9 deletions main/ZgatewayBT.ino
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
OpenMQTTGateway - ESP8266 or Arduino program for home automation
/*
OpenMQTTGateway - ESP8266 or Arduino program for home automation
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal/BLE and a MQTT broker
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal/BLE and a MQTT broker
Send and receiving command by MQTT
This gateway enables to:
- publish MQTT data to a different topic related to BLE devices rssi signal
- publish MQTT data related to mi flora temperature, moisture, fertility and lux
- publish MQTT data related to mi jia indoor temperature & humidity sensor
Copyright: (c)Florian ROBERT
This file is part of OpenMQTTGateway.
OpenMQTTGateway is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
Expand Down Expand Up @@ -461,7 +461,7 @@ void procBLETask(void* pvParameters) {
}
}

/**
/**
* BLEscan used to retrieve BLE advertized data from devices without connection
*/
void BLEscan() {
Expand All @@ -484,7 +484,7 @@ void BLEscan() {
Log.trace(F("Process BLE stack free: %u" CR), uxTaskGetStackHighWaterMark(xProcBLETaskHandle));
}

/**
/**
* Connect to BLE devices and initiate the callbacks with a service/characteristic request
*/
void BLEconnect() {
Expand Down Expand Up @@ -513,6 +513,10 @@ void BLEconnect() {
XMWSDJ04MMC_connect BLEclient(addr);
BLEclient.processActions(BLEactions);
BLEclient.publishData();
} else if (p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::SBS1) {
switchbot_connect BLEclient(addr);
BLEclient.processActions(BLEactions);
BLEclient.publishData();
} else {
GENERIC_connect BLEclient(addr);
if (BLEclient.processActions(BLEactions)) {
Expand Down Expand Up @@ -945,7 +949,8 @@ void process_bledata(JsonObject& BLEdata) {
int mac_type = BLEdata["mac_type"].as<int>();
if (model_id >= 0) { // Broadcaster devices
Log.trace(F("Decoder found device: %s" CR), BLEdata["model_id"].as<const char*>());
if (model_id == TheengsDecoder::BLE_ID_NUM::HHCCJCY01HHCC) {
if (model_id == TheengsDecoder::BLE_ID_NUM::HHCCJCY01HHCC ||
model_id == TheengsDecoder::BLE_ID_NUM::SBS1) {
createOrUpdateDevice(mac, device_flags_connect, model_id, mac_type); // Device that broadcast and can be connected
} else {
createOrUpdateDevice(mac, device_flags_init, model_id, mac_type);
Expand Down
20 changes: 10 additions & 10 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ somfy_remote=Somfy_Remote_Lib@0.3.0
rtl_433_ESP = https://github.com/NorthernMan54/rtl_433_ESP.git#v0.0.4
emodbus = miq19/eModbus@1.0.0
gfSunInverter = https://github.com/BlackSmith/GFSunInverter.git#v1.0.1
decoder = https://github.com/theengs/decoder.git#v0.2.1
decoder = https://github.com/theengs/decoder.git#v0.2.2

[env]
framework = arduino
Expand Down Expand Up @@ -212,11 +212,11 @@ board_build.ldscript = eagle.flash.1m64.ld ;this frees more space for firmware u
[env:sonoff-rfbridge-direct]
platform = espressif8266@^2
board = esp8285
lib_deps =
lib_deps =
${com-esp.lib_deps}
${libraries.wifimanager8266}
${libraries.esppilight}
build_flags =
build_flags =
${com-esp.build_flags}
'-DZgatewayPilight="Pilight"'
'-DRF_RECEIVER_GPIO=4'
Expand Down Expand Up @@ -374,9 +374,9 @@ lib_deps =
${com-esp.lib_deps}
${libraries.wifimanager32}
${libraries.emodbus}
${libraries.gfSunInverter}
${libraries.gfSunInverter}
build_flags =
${com-esp.build_flags}
${com-esp.build_flags}
'-DZgatewayGFSunInverter="GFSunInverter"'
'-DGateway_Name="OpenMQTTGateway_ESP32_GFSunInverter"'

Expand Down Expand Up @@ -702,7 +702,7 @@ lib_deps =
${libraries.ble}
${libraries.decoder}
${libraries.irremoteesp}
build_flags =
build_flags =
${com-esp.build_flags}
'-DZgatewayBT="BT"'
'-DZgatewayIR="IR"'
Expand All @@ -726,7 +726,7 @@ build_flags =
'-DZgatewayRTL_433="rtl_433"'
'-DGateway_Name="OpenMQTTGateway_rtl_433_ESP"'
'-DvalueAsASubject=true' ; mqtt topic includes model and device
; '-DPUBLISH_UNPARSED=true' ; Publish details of undecoded signals
; '-DPUBLISH_UNPARSED=true' ; Publish details of undecoded signals
; '-DRTL_DEBUG=4' ; enable rtl_433 verbose device decode

[env:esp32dev-multi_receiver]
Expand Down Expand Up @@ -810,7 +810,7 @@ build_flags =
'-DZgatewayLORA="LORA"'
'-DZgatewayBT="BT"'
'-DGateway_Name="OpenMQTTGateway_ESP32_BLE_LORA"'

'-DLED_SEND_RECEIVE=21' # T-BEAM board V0.5
# '-DLED_SEND_RECEIVE=14' # T-BEAM board V0.7
# '-DLED_SEND_RECEIVE=4' # T-BEAM board V1.0+
Expand All @@ -823,7 +823,7 @@ build_flags =
'-DADC_GPIO=35'
'-DADC_DIVIDER=2'
# Reading battery level every minutes should be more than enought
'-DTimeBetweenReadingADC=60000'
'-DTimeBetweenReadingADC=60000'

[env:heltec-wifi-lora-32-868]
platform = ${com.esp32_platform}
Expand Down Expand Up @@ -990,7 +990,7 @@ lib_deps =
${libraries.wifimanager8266}
${libraries.irremoteesp}
${libraries.esp8266_mdns}
build_flags =
build_flags =
${com-esp.build_flags}
'-DZgatewayIR="IR"'
'-DTRIGGER_GPIO=13'
Expand Down

0 comments on commit f3d4c4b

Please sign in to comment.