Skip to content
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

Trying to get the Light+Fan example running #72

Open
esemwy opened this issue Aug 3, 2017 · 1 comment
Open

Trying to get the Light+Fan example running #72

esemwy opened this issue Aug 3, 2017 · 1 comment

Comments

@esemwy
Copy link

esemwy commented Aug 3, 2017

I've made changes such that the example compiles, but I get a segmentation fault during the initial pairing. The changes consist of changing setValue calls to characteristics::setValue and adding connectionInfo* to the identify callbacks. I'm working on Raspbian. Can anyone out there enlighten me?

Pair Verify M1
Pair Verify M3
Verify success
Segmentation fault (core dumped)

I've determined that the fault happens sometime after connectionInfo::handleAccessoryRequest from this GDB back-trace, but I can't get any farther.

(gdb) bt
#0  0x00000000 in ?? ()
#1  0x000431d0 in connectionInfo::handleAccessoryRequest (this=0x69af8 <connection>) at PHKNetworkIP.cpp:881
#2  0x00040c50 in connectionLoop (threadInfo=0x69af8 <connection>) at PHKNetworkIP.cpp:308
#3  0x76ccbe90 in start_thread (arg=0x74dff450) at pthread_create.c:311
#4  0x76ab9598 in ?? () at ../ports/sysdeps/unix/sysv/linux/arm/nptl/../clone.S:92 from /lib/arm-linux-gnueabihf/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) 

Here's my version of the Accessory.cpp

/*
 * This accessory.cpp is configurated for light accessory + fan accessory
 */

#include "Accessory.h"

#include "PHKAccessory.h"

//Global Level of light strength
int lightStength = 0;
int fanSpeedVal = 0;

void lightIdentify(bool oldValue, bool newValue, connectionInfo *sender) {
    printf("Start Identify Light\n");
}

void fanIdentify(bool oldValue, bool newValue, connectionInfo *sender) {
    printf("Start Identify Fan\n");
}

AccessorySet *accSet;

void initAccessorySet() {
    currentDeviceType = deviceType_bridge;
    
    printf("Initial Accessory\n");

    Accessory *lightAcc = new Accessory();

    //Add Light
    accSet = &AccessorySet::getInstance();
    addInfoServiceToAccessory(lightAcc, "Light 1", "ET", "Light", "12345678", &lightIdentify);
    accSet->addAccessory(lightAcc);

    Service *lightService = new Service(serviceType_lightBulb);
    lightAcc->addService(lightService);

    stringCharacteristics *lightServiceName = new stringCharacteristics(charType_serviceName, premission_read, 0);
    lightServiceName->characteristics::setValue("Light");
    lightAcc->addCharacteristics(lightService, lightServiceName);

    boolCharacteristics *powerState = new boolCharacteristics(charType_on, premission_read|premission_write);
    powerState->characteristics::setValue("true");
    lightAcc->addCharacteristics(lightService, powerState);

    intCharacteristics *brightnessState = new intCharacteristics(charType_brightness, premission_read|premission_write, 0, 100, 1, unit_percentage);
    brightnessState->characteristics::setValue("50");
    lightAcc->addCharacteristics(lightService, brightnessState);

    //Add fan
    Accessory *fan = new Accessory();
    addInfoServiceToAccessory(fan, "Fan 1", "ET", "Fan", "12345678", &fanIdentify);
    accSet->addAccessory(fan);

    Service *fanService = new Service(serviceType_fan);
    fan->addService(fanService);

    stringCharacteristics *fanServiceName = new stringCharacteristics(charType_serviceName, premission_read, 0);
    fanServiceName->characteristics::setValue("Fan");
    fan->addCharacteristics(fanService, lightServiceName);

    boolCharacteristics *fanPower = new boolCharacteristics(charType_on, premission_read|premission_write);
    fanPower->characteristics::setValue("true");
    fan->addCharacteristics(fanService, fanPower);
};
@esemwy
Copy link
Author

esemwy commented Aug 3, 2017

Ah, it was newConnection that was undefined in the accessory. Added it and deadConnection. It runs now, but the accessory is not supported. Will continue... Assistance still welcome. I'm just trying to produce a simple accessory that prints state changes on the console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant