Add control from JSON payload

This commit is contained in:
Robert Marshall 2021-08-22 21:42:47 +01:00
parent eacb06c0ae
commit 44b91c86f2
4 changed files with 48 additions and 25 deletions

View file

@ -1,36 +1,17 @@
#include "LED.cpp"
#include "JsonLightControl.cpp"
#include <BLEUtils.h>
class BluetoothLEDCallback : public BLECharacteristicCallbacks {
LED *_seatingLeds, *_kitchenLeds;
JsonLightControl *_lightControl;
void onWrite(BLECharacteristic *characteristic) {
std::string value = characteristic->getValue();
if (value.length() > 0) {
Serial.println(value.c_str());
if (value == "all on"){
_seatingLeds->on();
_kitchenLeds->on();
}
if (value == "all off"){
_seatingLeds->off();
_kitchenLeds->off();
}
if (value == "seating on")
_seatingLeds->on();
if (value == "kitchen on")
_kitchenLeds->on();
if (value == "seating off")
_seatingLeds->off();
if (value == "kitchen off")
_kitchenLeds->off();
}
_lightControl->action(value);
}
public:
BluetoothLEDCallback(LED *seatingLeds, LED *kitchenLeds){
_seatingLeds = seatingLeds;
_kitchenLeds = kitchenLeds;
BluetoothLEDCallback(JsonLightControl *lightControl){
_lightControl = lightControl;
}
};