-
Notifications
You must be signed in to change notification settings - Fork 36
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
Library example #165
Comments
Hi, the For the simple hello world example, you need to
class MyCommissionerHandler : public ot::Commissioner::CommissionerHandler {
public:
bool OnJoinerFinalize(const ByteArray & aJoinerId,
const std::string &aVendorName,
const std::string &aVendorModel,
const std::string &aVendorSwVersion,
const ByteArray & aVendorStackVersion,
const std::string &aProvisioningUrl,
const ByteArray & aVendorData) override {
printf("a joiner from %s is commissioned\n", aVendorName.c_str());
return true;
}
};
MyCommissionerHandler myHandler;
auto commissioner = ot::Commissioner::Commissioner::Create(myHandler);
ot::Commissioner::Config config;
config.mEnableCcm = false;
config.mPskc = {}; // Set this to your pskc, you can get it with the `pskc` command on a OT CLI node.
commissioner->Init(config);
std::string existingCommissionerId;
commissioner->Petition(existingCommissionerId, <your-BR-address>, <your-BR-port>);
// Check if we succed.
printf("the commissioner is active: %s\n", commissioner->IsActive() ? "true" : "false");
ot::Commissioner::CommissionerDataset dataset;
dataset.mPresentFlags |= ot::Commissioner::CommissionerDataset::kSteeringDataBit;
dataset.mSteeringData = {0xFF}; // Set the steeering data to all-ones to allow all joiners.
commissioner->SetCommissionerDataset(dataset);
while (true) {
sleep(1);
} We don't need to run an event loop because the commissioner takes care of it in a background thread. The client just need to keep the commissioner instance from destroyed. Please note that most those commissioner APIs return an |
Thank you @wgtdkp for the detailed response to help me use the API. It is much appreciated. I am trying to implement what you indicate. I am getting a lot of linker errors trying to create a standalone app that implements the outline you describe above. I don't know if it is something I am doing incorrectly or if it is an issue with the source code / library packaging. Most of the errors relate to the libcommissioner.a library having undefined references to All the undefined references seem to relate to the source code that is part of the 'common' directory. ie; address.cpp, utils.cpp, error.cpp, and time.cpp. Are these 'common' things not being placed in the library that is produced? I have very little experience with cmake or ninja either. I would think a library should not have any undefined references (other than other libraries like mbedtls, etc). Should libcommissioner-common.a be installed to /usr/local/lib along with libcommissioner.a ? |
Hi, yes I think there could be some problems with the static library. actually we did only have good tests against the shared libraries since it will be used for the Java binding and Android App. I will fix this issue and for a quick fix, you can build cmake -GNinja -DBUILD_SHARED_LIBS=ON ..
sudo ninja install and link against the share library: # assume minim_commissioner.cpp is your mininum commissioner example.
clang++ -std=c++11 -Wall -g mini_commissioner.cpp -l:libcommissioner.so I agree with you that an minimum commissioner example would be helpful for using the commissioner library, I will create a PR for this maybe today or tomorrow. |
Thank you, using the shared library worked as a quick fix. That also installed the various mbed, event, and fmtd libraries that are needed to run. I had a misunderstanding about how OnJoinerFinalize() works and instead I am using OnJoinerRequest(). It seems OnJoinerFinalize() is too late in the Join flow to accept / reject a generic device. OnJoinerFinalize() only works if the joining device is programmed a certain way... It seems impossible to reject a generic device using OnJoinerFinalize() which I think is consistent with the Thread specification but a bit confusing. |
If you want to reject a joiner by its ot-commissioner/include/commissioner/commissioner.hpp Lines 146 to 159 in ce6b118
Typical Commissioner application should have a joiner dictionary that maps |
That is exactly what I discovered. I thought OnJoinerFinalize() would handle that, but even returning 'false' for OnJoinerFinalize() still allows the device to join. Looking at the Thread spec, the OnJoinerFinalize() only seems to matter if a provisioningurl is included, so I am not sure OnJoinerFinalize() is the best example for a minimal application. |
BTW, Thread Spec define steering data to filter out joiners by their |
In my application, I want to accept or reject devices based on EUI64 lookup in a database. In order to make that feature work, the steering data must be a wildcard so that ALL potential joiners contact the Commissioner and lookup occurs. If I understand correctly, lookup logic for this use case needs to be in OnJoinerRequest(). |
I think your requirement is well implemented by the commissioner CLI APP. What the CLI supporting is that: you can add joiners by ot-commissioner/src/app/commissioner_app.cpp Lines 1184 to 1203 in ce6b118
Not really necessary,you just need to update the steering data with all your joiners. Using steering data cannot always rejects a specific joiner as the steering data is actually a bloom filter, but I think it is good to always updates the steering data with the joiner ID/EUI64 to reject unwanted joiners earlier. ot-commissioner/src/app/commissioner_app.cpp Lines 231 to 259 in ce6b118
|
Are there any examples or guidelines for using the library? I cannot find any documentation at all.
My goal is to create a commissioner application that has some slight modifications from what ot-commissioner provides but non-interactive. I am not really sure where to start. It does not help that I am a C programmer, not C++. Even a simple 'hello world' example that starts the commissioner, performs an enableall meshcop, adds a custom 'On Join' handler so an application can accept/reject, and runs in whatever event loop is required for the example to continuing running until killed.
Thank you!
The text was updated successfully, but these errors were encountered: