1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 #include "easysetup.h"
32 void *listeningFunc(void*);
36 * @brief Target SSID of the Soft Access point to which the device has to connect
38 static char ssid[] = "EasySetup123";
42 * @brief Password of the Soft Access point to which the device has to connect
44 static char passwd[] = "EasySetup123";
48 cout<<"============"<<endl;
49 cout<<"S: start easy setup"<<endl;
50 cout<<"P: start provisioning resources"<<endl;
51 cout<<"T: terminate"<<endl;
52 cout<<"Q: quit"<<endl;
53 cout<<"============"<<endl;
56 void EventCallbackInApp(ESResult esResult, EnrolleeState enrolleeState)
58 cout<<"Easy setup event callback"<<endl;
62 if(enrolleeState == ES_ON_BOARDED_STATE)
64 cout<<"Device is successfully OnBoared on Adhoc network"<<endl;
66 else if (enrolleeState == ES_PROVISIONED_STATE)
68 cout<<"Device is provisioned with target network's credentials"<<endl;
70 else if (enrolleeState == ES_ON_BOARDED_TARGET_NETWORK_STATE)
72 cout<<"Device is onboarded/connected with target network"<<endl;
76 cout<<"Wrong state !! Easy setup is failed at Enrollee state = "<<enrolleeState<<endl;
81 cout<<"Easy stup is failed at Enrollee state = "<<enrolleeState<<endl;
90 cout<<"StartEasySetup and onboarding started.."<<endl;
92 if(InitEasySetup(CT_ADAPTER_IP, ssid, passwd, EventCallbackInApp) == ES_ERROR)
94 cout<<"StartEasySetup and onboarding Fail!!"<<endl;
98 pthread_t thread_handle;
99 if (pthread_create(&thread_handle, NULL, listeningFunc, NULL))
101 cout<<"Thread creation failed"<<endl;
105 void StartProvisioning()
107 cout<<"Starting Enrollee Provisioning"<<endl;
109 // Initialize the OC Stack in Server mode
110 if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
112 cout<<"OCStack init error!!"<<endl;
116 if (InitProvisioning() == ES_ERROR)
118 cout<<"Init Provisioning Failed!!"<<endl;
122 cout<<"InitProvisioning Success"<<endl;
127 cout<<"StopEasySetup IN"<<endl;
129 if (TerminateEasySetup() == ES_ERROR)
131 cout<<"TerminateEasySetup Failed!!"<<endl;
136 if (OCStop() != OC_STACK_OK)
138 cout<<"OCStack stop failed!!"<<endl;
142 cout<<"StopEasySetup OUT"<<endl;
147 cout<<"#########################"<<endl;
148 cout<<"EasySetup Enrollee SAMPLE"<<endl;
149 cout<<"#########################"<<endl;
168 case 'S': // start easy setup
173 case 'P': // start provisioning
178 case 'T': // stop easy setup
184 cout<<"wrong option"<<endl;
187 if (option == 'Q' || option == 'q') break;
192 void *listeningFunc(void*)
194 OCStackResult result;
198 result = OCProcess();
199 if (result != OC_STACK_OK)
201 cout<<"OCStack stop error";