Closed robot0518 closed 7 years ago
You might want to split different devices into different configuration and Accessory.cpp. The code can support many devices, but I think this might become the classic "single point of failure" if you have more than one type of devices managed on a program (if you are turning on the lamp while someone else is adjusting the thermostat, having two processes doing each of them seems smart)
If you want to add multiple devices to a single program, you need to create an Accessory object for each device in the Accessory.cpp with their services and characteristic, and then add them to the accessory set (accSet in the sample code). Since you have different devices, you may want to write a callback for each device, and link it to the characteristic
For the configuration.h: if you only going to have one process, you can just keep it intact. It should run without any change. If you are splitting the task, then you need to change deviceIdentity and deviceUUID. Both are hex string (so characters are between 0-9, and A-F), and you can just change it to any random string (as long you don't have two processes with the identical string, you are okay). You also need to change the controllerRecordsAddress and the deviceName for different processes, but I think this is trivial?
I know this is rather complex compared to just have a configuration file, but configuration file usually hard to debug (compiler output is nasty, but at least you want something is wrong), and I'm trying to see if I can increase security by just making everyone has a different version of the binary, so please be patient this process, the end result is fun. :-)
thanks. I tryed add a device as bridge (using the Example Accessory Configuration/Fan+Light.cpp), Home app told me the device is not supported (This accessory requires a firmware update before it can be used in the Home app. Try updating it using the manufacturer's app.) can you help me fix this?
Greetings.
Found the bug: you need to add permission for notification for power state. So, replace line 42 with boolCharacteristics powerState = new boolCharacteristics(charType_on, premission_read|premission_write|premission_notify); Line 46: intCharacteristics brightnessState = new intCharacteristics(charType_brightness, premission_read|premission_write|premission_notify, 0, 100, 1, unit_percentage); Line 62: boolCharacteristics *fanPower = new boolCharacteristics(charType_on, premission_read|premission_write|premission_notify);
Tell me if it works, I will push it after your confirmation.
It works! thank you very much!
thanks for sharing. i wanted set up more devices such as light,thermostat, switch, lamp ... how to write configuartion? thanks!