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 if(InitProvisioning()== ES_ERROR)
111 cout<<"Init Provisioning Failed"<<endl;
114 cout<<"InitProvisioning:Success"<<endl;
119 cout<<"StopEasySetup IN"<<endl;
120 if(TerminateEasySetup()== ES_ERROR)
122 cout<<"return value is: ES_ERROR"<<endl;
125 cout<<"StopEasySetup OUT"<<endl;
130 cout<<"#########################"<<endl;
131 cout<<"EasySetup Enrollee SAMPLE"<<endl;
132 cout<<"#########################"<<endl;
151 case 'S': // start easy setup
156 case 'P': // start provisioning
161 case 'T': // stop easy setup
167 cout<<"wrong option"<<endl;
170 if(option=='Q') break;
175 void *listeningFunc(void*)
177 OCStackResult result;
181 result = OCProcess();
182 if (result != OC_STACK_OK)
184 cout<<"OCStack stop error";