######################################################################
# Build flags
######################################################################
-easy_setup_env.AppendUnique(CPPPATH = ['sdk/inc', 'sdk/src'])
+easy_setup_env.AppendUnique(CPPPATH = ['sdk/inc', 'sdk/src', 'sdk/common'])
if target_os not in ['windows', 'winrt']:
easy_setup_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
'../../resource/csdk/logger/include',
'../../resource/csdk/stack/include',
'../../extlibs/cjson',
- 'sdk/arduino/wifi/inc',
- 'sdk/arduino/wifi/src' ])
+ 'sdk/enrollee/arduino/wifi',
+ 'sdk/enrollee/common/src',
+ 'sdk/enrollee/common/inc'])
if target_os in ['android','linux']:
easy_setup_env.PrependUnique(CPPPATH = [
if target_os == 'arduino':
es_sdk_static = easy_setup_env.StaticLibrary('ESSDKLibrary',
- ['sdk/src/easysetup.cpp',
- 'sdk/src/resourceHandler.cpp',
- 'sdk/arduino/wifi/src/networkHandler.cpp'])
+ ['sdk/enrollee/common/src/easysetup.cpp',
+ 'sdk/enrollee/common/src/resourceHandler.cpp',
+ 'sdk/enrollee/arduino/wifi/networkHandler.cpp'])
easy_setup_env.InstallTarget(es_sdk_static, 'libESSDK')
'../../../../../resource/csdk/logger/include',
'../../../../../resource/csdk/stack/include',
'../../../../../extlibs/cjson',
- '../../../sdk/inc',
- '../../../sdk/arduino/wifi/inc'
+ '../../../sdk/common',
+ '../../../sdk/enrollee/arduino/wifi',
+ '../../../sdk/enrollee/common/inc',
+ '../../../sdk/enrollee/common/src'
])
thinserver_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
const char *getResult(OCStackResult result);
-PROGMEM const char TAG[] = "ArduinoServer";
+PROGMEM const char TAG[] = "ThinServer";
+
+char ssid[] = "hub2.4G";
+char passwd[] = "09877890";
void EventCallbackInApp(ES_RESULT eventFlag)
{
OC_LOG_INIT();
OC_LOG(DEBUG, TAG, PCF("OCServer is starting..."));
- WaitingForOnboarding(ES_WIFI, EventCallbackInApp);
+ FindNetworkForOnboarding(ES_WIFI, ssid, passwd, EventCallbackInApp);
// Initialize the OC Stack in Server mode
if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
return;
}
- PrepareToProvisioning(EventCallbackInApp);
+ InitializeProvisioning(EventCallbackInApp);
if (OCStartPresence(0) != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, PCF("OCStack process error"));
return;
}
- //ChangeLightRepresentation(NULL);
}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2014 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "networkHandler.h"
+
+PROGMEM const char TAG[] = "networkHandler";
+
+int findNetwork(const char *ssid);
+int ConnectToNetwork(const char *ssid, const char *pass);
+void printEncryptionType(int thisType);
+
+// Arduino WiFi Shield
+// Note : Arduino WiFi Shield currently does NOT support multicast and therefore
+// this server will NOT be listening on 224.0.1.187 multicast address.
+
+static const char ARDUINO_WIFI_SHIELD_UDP_FW_VER[] = "1.1.0";
+
+IPAddress myIP;
+
+ES_RESULT ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback cb)
+{
+ char *fwVersion;
+ int status = WL_IDLE_STATUS;
+ int res;
+
+ // check for the presence of the shield:
+ if (WiFi.status() == WL_NO_SHIELD)
+ {
+ OC_LOG(ERROR, TAG, PCF("WiFi shield not present"));
+ return ES_ERROR;
+ }
+
+ // Verify that WiFi Shield is running the firmware with all UDP fixes
+ fwVersion = WiFi.firmwareVersion();
+ OC_LOG_V(INFO, TAG, "WiFi Shield Firmware version %s", fwVersion);
+ if (strncmp(fwVersion, ARDUINO_WIFI_SHIELD_UDP_FW_VER, sizeof(ARDUINO_WIFI_SHIELD_UDP_FW_VER))
+ != 0)
+ {
+ OC_LOG(DEBUG, TAG, PCF("!!!!! Upgrade WiFi Shield Firmware version !!!!!!"));
+ return ES_ERROR;
+ }
+
+ while (findNetwork(ssid) == 0) // found
+ {
+ delay(1000);
+ }
+
+ if (cb != NULL)
+ {
+ cb(ES_NETWORKFOUND);
+ }
+
+ if (WiFi.status() == WL_CONNECTED)
+ WiFi.disconnect();
+
+ res = ConnectToNetwork(ssid, pass);
+
+ if (res == 0)
+ {
+ return ES_NETWORKCONNECTED;
+ }
+ else
+ {
+ return ES_NETWORKNOTCONNECTED;
+ }
+}
+
+int findNetwork(const char *ssid)
+{
+ int res = 0;
+ // scan for nearby networks:
+ Serial.println("** Scan Networks **");
+ int numSsid = WiFi.scanNetworks();
+ if (numSsid == -1)
+ {
+ Serial.println("Couldn't get a wifi connection");
+
+ return res;
+ }
+
+ // print the list of networks seen:
+ Serial.print("number of available networks:");
+ Serial.println(numSsid);
+
+ // print the network number and name for each network found:
+ for (int thisNet = 0; thisNet < numSsid; thisNet++)
+ {
+ Serial.print(thisNet);
+ Serial.print(") ");
+ Serial.print(WiFi.SSID(thisNet));
+ Serial.print("\tEncryption: ");
+ printEncryptionType(WiFi.encryptionType(thisNet));
+
+ if (strcmp(WiFi.SSID(thisNet), ssid) == 0)
+ {
+ res = 1;
+ }
+ }
+
+ return res;
+}
+
+int ConnectToNetwork(const char *ssid, const char *pass)
+{
+ int status = WL_IDLE_STATUS;
+
+ // attempt to connect to Wifi network:
+ while (status != WL_CONNECTED)
+ {
+ OC_LOG_V(INFO, TAG, "Attempting to connect to SSID: %s", ssid);
+
+ status = WiFi.begin((char *) ssid, (char *) pass);
+
+ // wait 10 seconds for connection:
+ delay(10000);
+ }
+ OC_LOG(DEBUG, TAG, PCF("Connected to wifi"));
+
+ myIP = WiFi.localIP();
+ OC_LOG_V(INFO, TAG, "IP Address: %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
+
+ char buf[50];
+ sprintf(buf, "IP Address: %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
+ Serial.println(buf);
+
+ return 0;
+}
+
+int getCurrentNetworkInfo(NetworkType targetType, NetworkInfo *info)
+{
+ if (targetType == ES_WIFI && WiFi.status() == WL_CONNECTED)
+ {
+ info->type = ES_WIFI;
+ info->ipaddr = WiFi.localIP();
+ strcpy(info->ssid, WiFi.SSID());
+
+ return 0;
+ }
+
+ return -1;
+}
+
+void printEncryptionType(int thisType)
+{
+ // read the encryption type and print out the name:
+ switch (thisType)
+ {
+ case ENC_TYPE_WEP:
+ Serial.println("WEP");
+ break;
+ case ENC_TYPE_TKIP:
+ Serial.println("WPA");
+ break;
+ case ENC_TYPE_CCMP:
+ Serial.println("WPA2");
+ break;
+ case ENC_TYPE_NONE:
+ Serial.println("None");
+ break;
+ case ENC_TYPE_AUTO:
+ Serial.println("Auto");
+ break;
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2014 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+// Do not remove the include below
+#include "Arduino.h"
+
+#include "logger.h"
+#include "ocstack.h"
+#include <string.h>
+
+// Arduino WiFi Shield
+#include <SPI.h>
+#include <WiFi.h>
+#include <WiFiUdp.h>
+
+#include "common.h"
+
+#ifndef ES_NETWORK_HANDLER_H_
+#define ES_NETWORK_HANDLER_H_
+
+#define MAXSSIDLEN 33
+#define MAXNETCREDLEN 20
+#define MAXNUMTYPE 5
+#define MAXADDRLEN 15
+
+typedef void (*NetworkEventCallback)(ES_RESULT);
+
+enum NetworkType
+{
+ ES_WIFI = 1, ES_BT = 2, ES_BLE = 3, ES_ZIGBEE = 4, ES_ETH = 5
+};
+
+typedef struct NETWORKINFO
+{
+ NetworkType type;
+
+ // for WiFI
+ IPAddress ipaddr;
+ char ssid[MAXSSIDLEN];
+
+ // for BT, BLE
+ byte mac[6];
+} NetworkInfo;
+
+ES_RESULT ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback);
+int getCurrentNetworkInfo(NetworkType targetType, NetworkInfo *info);
+
+#endif
#include "ocstack.h"
#include <string.h>
-#ifdef ARDUINOWIFI
-// Arduino WiFi Shield
-#include <SPI.h>
-#include <WiFi.h>
-#include <WiFiUdp.h>
-#else
-// Arduino Ethernet Shield
-#include <EthernetServer.h>
-#include <Ethernet.h>
-#include <Dns.h>
-#include <EthernetClient.h>
-#include <util.h>
-#include <EthernetUdp.h>
-#include <Dhcp.h>
-#endif
-
#include "common.h"
#include "networkHandler.h"
#include "resourceHandler.h"
OCStackResult Init();
-ES_RESULT WaitingForOnboarding(NetworkType networkType, EventCallback);
-//OCStackResult WaitingForOnboarding(NetworkType networkType, char *name);
-//OCStackResult WaitingForOnboarding(NetworkType networkType, char *name, char *pass);
+ES_RESULT FindNetworkForOnboarding(NetworkType networkType, EventCallback);
+ES_RESULT FindNetworkForOnboarding(NetworkType networkType, const char *name, const char *pass,
+ EventCallback);
+
+//OCStackResult FindNetworkForOnboarding(NetworkType networkType, char *name);
+//OCStackResult FindNetworkForOnboarding(NetworkType networkType, char *name, char *pass);
-ES_RESULT PrepareToProvisioning(EventCallback);
+ES_RESULT InitializeProvisioning(EventCallback);
#include "ocstack.h"
#include <string.h>
-#ifdef ARDUINOWIFI
-// Arduino WiFi Shield
-#include <SPI.h>
-#include <WiFi.h>
-#include <WiFiUdp.h>
-#else
-// Arduino Ethernet Shield
-#include <EthernetServer.h>
-#include <Ethernet.h>
-#include <Dns.h>
-#include <EthernetClient.h>
-#include <util.h>
-#include <EthernetUdp.h>
-#include <Dhcp.h>
-#endif
-
#include "common.h"
#include "networkHandler.h"
#include "octypes.h"
char cnn[MAXSSIDLEN]; // current network name
} NetResource;
-OCStackResult createProvisioningResource();
-OCStackResult createNetworkResource();
-void getTargetNetworkInfoFromProvResource(char *, char *);
+OCStackResult CreateProvisioningResource();
+OCStackResult CreateNetworkResource();
+void GetTargetNetworkInfoFromProvResource(char *, char *);
void RegisterResourceEventCallBack(ResourceEventCallback);
#endif
#include "easysetup.h"
-PROGMEM const char TAG[] = "ArduinoServer";
-
/// WiFi network info and credentials
char defaultSsid[] = "EasyConnect";
char defaultPass[] = "EasyConnect";
void EventCallbackInOnboarding(ES_RESULT event)
{
- Serial.println("[Callback] in onboarding process");
-
if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED)
{
if (g_cbForOnboarding != NULL)
{
ES_RESULT res = ES_OK;
- Serial.println("[Callback] in provisioning process");
-
if (event == ES_RECVTRIGGEROFPROVRES)
{
targetSsid = (char *) malloc(MAXSSIDLEN);
targetPass = (char *) malloc(MAXNETCREDLEN);
- getTargetNetworkInfoFromProvResource(targetSsid, targetPass);
+ GetTargetNetworkInfoFromProvResource(targetSsid, targetPass);
- res = ConnectToWiFiNetworkForOnboarding(targetSsid, targetPass,
- EventCallbackAfterProvisioning);
+ res = ConnectToWiFiNetwork(targetSsid, targetPass, EventCallbackAfterProvisioning);
if (g_cbForProvisioning != NULL)
{
void EventCallbackAfterProvisioning(ES_RESULT event)
{
- Serial.println("[Callback] after provisioning process");
-
if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED)
{
if (g_cbForProvisioning != NULL)
}
}
-ES_RESULT WaitingForOnboarding(NetworkType networkType, EventCallback cb)
+ES_RESULT FindNetworkForOnboarding(NetworkType networkType, EventCallback cb)
{
if (networkType == ES_WIFI)
{
g_cbForOnboarding = cb;
}
- return ConnectToWiFiNetworkForOnboarding(defaultSsid, defaultPass,
- EventCallbackInOnboarding);
+ return ConnectToWiFiNetwork(defaultSsid, defaultPass, EventCallbackInOnboarding);
+ }
+}
+
+ES_RESULT FindNetworkForOnboarding(NetworkType networkType, const char *ssid, const char *passwd,
+ EventCallback cb)
+{
+ if (!ssid || !passwd)
+ {
+ return ES_ERROR;
+ }
+
+ if (networkType == ES_WIFI)
+ {
+ if (g_cbForOnboarding == NULL)
+ {
+ g_cbForOnboarding = cb;
+ }
+
+ return ConnectToWiFiNetwork(ssid, passwd, EventCallbackInOnboarding);
}
}
-ES_RESULT PrepareToProvisioning(EventCallback cb)
+ES_RESULT InitializeProvisioning(EventCallback cb)
{
if (cb == NULL)
{
g_cbForProvisioning = cb;
}
- if (createProvisioningResource() != OC_STACK_OK)
+ if (CreateProvisioningResource() != OC_STACK_OK)
{
return ES_ERROR;
}
- if (createNetworkResource() != OC_STACK_OK)
+ if (CreateNetworkResource() != OC_STACK_OK)
{
return ES_ERROR;
}
#include "resourceHandler.h"
#include "cJSON.h"
-PROGMEM const char TAG[] = "ArduinoServer";
+PROGMEM const char TAG[] = "resourceHandler";
ProvResource g_prov;
NetResource g_net;
g_cbForResEvent = cb;
}
-void getTargetNetworkInfoFromProvResource(char *name, char *pass)
+void GetTargetNetworkInfoFromProvResource(char *name, char *pass)
{
if (name != NULL && pass != NULL)
{
}
}
-OCStackResult createProvisioningResource()
+OCStackResult CreateProvisioningResource()
{
g_prov.ps = 1; // need to provisioning
g_prov.tnt = ES_WIFI;
return res;
}
-OCStackResult createNetworkResource()
+OCStackResult CreateNetworkResource()
{
NetworkInfo netInfo;
OC_LOG_V(INFO, TAG, "Constructed Response: %s", jsonResponse);
- Serial.print("Constructed Response: ");
- Serial.println(jsonResponse);
-
return jsonResponse;
}
+++ /dev/null
-//******************************************************************
-//
-// Copyright 2015 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef __PROVISIONING_HANDLER_H_
-#define __PROVISIONING_HANDLER_H_
-
-#include "logger.h"
-#include "ocstack.h"
-#include "easysetupcommon.h"
-
-//-----------------------------------------------------------------------------
-// Defines
-//-----------------------------------------------------------------------------
-#define TAG "provisioninghandler"
-#define DEFAULT_CONTEXT_VALUE 0x99
-#ifndef MAX_LENGTH_IPv4_ADDR
-#define MAX_LENGTH_IPv4_ADDR 16
-#endif
-
-//-----------------------------------------------------------------------------
-// Typedefs
-//-----------------------------------------------------------------------------
-
-/**
- * List of methods that can be inititated from the client
- */
-OCStackResult InitProvisioningHandler();
-
-OCStackResult TerminateProvisioningHandler();
-
-void listeningFunc(void*);
-
-OCStackApplicationResult ProvisionEnrolleeResponse(void* ctx, OCDoHandle handle,
- OCClientResponse * clientResponse);
-
-OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char* query);
-
-OCStackApplicationResult GetProvisioningStatusResponse(void* ctx,
- OCDoHandle handle, OCClientResponse * clientResponse);
-
-OCStackResult InvokeOCDoResource(const char* query, OCMethod method,
- OCQualityOfService qos, OCClientResponseHandler cb, const char* request,
- OCHeaderOption * options, uint8_t numOptions);
-
-OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char* query);
-
-OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo_t *netInfo,
- OCProvisioningStatusCB provisioningStatusCallback);
-
-
-void StopProvisioningProcess();
-
-OCStackApplicationResult SubscribeProvPresenceCallback(void* ctx, OCDoHandle handle,
- OCClientResponse* clientResponse);
-
-OCStackResult SubscribeProvPresence(OCQualityOfService qos, const char* requestURI);
-
-OCStackApplicationResult FindProvisioningResourceResponse(void* ctx,
- OCDoHandle handle, OCClientResponse * clientResponse);
-
-OCStackResult FindProvisioningResource(OCQualityOfService qos,
- const char* requestURI);
-
-//Invoke Provisioning Status Callback
-void PrepareProvisioingStatusCB(ProvisioningInfo *provInfo,
- OCClientResponse * clientResponse, ProvStatus provStatus);
-
-#endif
-