Update the URI in the samples for Unicast discovery and device discovery.
Change-Id: Ice2ec98bb33033743c17f3259e6a86380c0afc0e
Signed-off-by: Sakthivel Samidurai <sakthivel.samidurai@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/285
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sachin Agrawal <sachin.agrawal@intel.com>
Reviewed-by: Joseph Morrow <joseph.l.morrow@intel.com>
Reviewed-by: Yuliya Kamatkova <yuliya.kamatkova@intel.com>
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
return "UNKNOWN";
}
}
+
+void StripNewLineChar(char* str) {
+ int i = 0;
+ if (str)
+ {
+ while( str[i])
+ {
+ if (str[i] == '\n')
+ str[i] = '\0';
+ i++;
+ }
+ }
+}
static int UNICAST_DISCOVERY = 0;
static int TEST_CASE = 0;
-static const char * TEST_APP_UNICAST_DISCOVERY_QUERY = "coap://0.0.0.0:5683/oc/core";
-static const char * TEST_APP_UNICAST_DEVICE_DISCOVERY_QUERY = "coap://0.0.0.0:5683/oc/core/d";
-
+static const char * UNICAST_DISCOVERY_QUERY = "coap://%s:5298/oc/core";
+static const char * UNICAST_DEVICE_DISCOVERY_QUERY = "coap://%s:5298/oc/core/d";
static const char * MULTICAST_DEVICE_DISCOVERY_QUERY = "/oc/core/d";
-
static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core";
//The following variable determines the interface (wifi, ethernet etc.)
//to be used for sending unicast messages. Default set to WIFI.
static std::string coapServerIP = "255.255.255.255";
static std::string coapServerPort = "5683";
static std::string coapServerResource = "/a/light";
+static const int IPV4_ADDR_SIZE = 16;
+//Use ipv4addr for both InitDiscovery and InitDeviceDiscovery
+char ipv4addr[IPV4_ADDR_SIZE];
+void StripNewLineChar(char* str);
// The handle for the observe registration
OCDoHandle gObserveDoHandle;
if(UNICAST_DISCOVERY)
{
- strncpy(szQueryUri, TEST_APP_UNICAST_DEVICE_DISCOVERY_QUERY,
- (strlen(TEST_APP_UNICAST_DEVICE_DISCOVERY_QUERY) + 1));
+ snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_DEVICE_DISCOVERY_QUERY, ipv4addr);
}
-
else
{
strncpy(szQueryUri, MULTICAST_DEVICE_DISCOVERY_QUERY,
if (UNICAST_DISCOVERY)
{
- strcpy(szQueryUri, TEST_APP_UNICAST_DISCOVERY_QUERY);
+ snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_DISCOVERY_QUERY, ipv4addr);
}
else
{
}
int main(int argc, char* argv[]) {
- uint8_t addr[20] = {0};
- uint8_t* paddr = NULL;
- uint16_t port = USE_RANDOM_PORT;
- uint8_t ifname[] = "eth0";
int opt;
while ((opt = getopt(argc, argv, "u:t:c:")) != -1)
return -1;
}
-
- /*Get Ip address on defined interface and initialize coap on it with random port number
- * this port number will be used as a source port in all coap communications*/
- if ( OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr,
- sizeof(addr)) == ERR_SUCCESS)
- {
- OC_LOG_V(INFO, TAG, "Starting occlient on address %s",addr);
- paddr = addr;
- }
-
/* Initialize OCStack*/
- if (OCInit((char *) paddr, port, OC_CLIENT) != OC_STACK_OK) {
+ if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK) {
OC_LOG(ERROR, TAG, "OCStack init error");
return 0;
}
+ if (UNICAST_DISCOVERY)
+ {
+ printf("Enter IPv4 address of the Server hosting resource (Ex: 192.168.0.15)\n");
+ if (fgets(ipv4addr, IPV4_ADDR_SIZE, stdin))
+ {
+ //Strip newline char from ipv4addr
+ StripNewLineChar(ipv4addr);
+ }
+ else
+ {
+ OC_LOG(ERROR, TAG, "!! Bad input for IPV4 address. !!");
+ return OC_STACK_INVALID_PARAM;
+ }
+ }
if(UNICAST_DISCOVERY == 0 && TEST_CASE == TEST_DISCOVER_DEV_REQ)
{
#include "logger.h"
#include "occlientbasicops.h"
+static int IPV4_ADDR_SIZE = 16;
static int UNICAST_DISCOVERY = 0;
static int TEST_CASE = 0;
-static const char * TEST_APP_UNICAST_DISCOVERY_QUERY = "coap://0.0.0.0:5683/oc/core";
+static const char * UNICAST_DISCOVERY_QUERY = "coap://%s:5298/oc/core";
static std::string putPayload = "{\"state\":\"off\",\"power\":10}";
char szQueryUri[64] = { 0 };
if (UNICAST_DISCOVERY)
{
- strcpy(szQueryUri, TEST_APP_UNICAST_DISCOVERY_QUERY);
+ char ipv4addr[IPV4_ADDR_SIZE];
+ printf("Enter IPv4 address of the Server hosting resource (Ex: 192.168.0.15)\n");
+ if (fgets(ipv4addr, IPV4_ADDR_SIZE, stdin))
+ {
+ //Strip newline char from ipv4addr
+ StripNewLineChar(ipv4addr);
+ snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_DISCOVERY_QUERY, ipv4addr);
+ }
+ else
+ {
+ OC_LOG(ERROR, TAG, "!! Bad input for IPV4 address. !!");
+ return OC_STACK_INVALID_PARAM;
+ }
}
else
{
cbData.cd = NULL;
if (UNICAST_DISCOVERY)
{
- ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_CONNTYPE),
+ ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
OC_LOW_QOS, &cbData, NULL, 0);
}
else
int main(int argc, char* argv[])
{
- uint8_t addr[20] = {0};
- uint8_t* paddr = NULL;
- uint16_t port = USE_RANDOM_PORT;
- uint8_t ifname[] = "eth0";
int opt;
while ((opt = getopt(argc, argv, "u:t:c:")) != -1)
return -1;
}
-
- /*Get Ip address on defined interface and initialize coap on it with random port number
- * this port number will be used as a source port in all coap communications*/
- if ( OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr,
- sizeof(addr)) == ERR_SUCCESS)
- {
- OC_LOG_V(INFO, TAG, "Starting occlient on address %s",addr);
- paddr = addr;
- }
-
/* Initialize OCStack*/
- if (OCInit((char *) paddr, port, OC_CLIENT) != OC_STACK_OK)
+ if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack init error");
return 0;
OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
OCClientResponse * clientResponse);
-
+void StripNewLineChar(char* str);
#endif
}
int main(int argc, char* argv[]) {
- uint8_t addr[20] = {0};
- uint8_t* paddr = NULL;
- uint16_t port = USE_RANDOM_PORT;
- uint8_t ifname[] = "eth0";
int opt;
while ((opt = getopt(argc, argv, "t:c:")) != -1)
return -1;
}
- /*Get Ip address on defined interface and initialize coap on it with random port number
- * this port number will be used as a source port in all coap communications*/
- if ( OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr,
- sizeof(addr)) == ERR_SUCCESS)
- {
- OC_LOG_V(INFO, TAG, "Starting occlient on address %s",addr);
- paddr = addr;
- }
/* Initialize OCStack*/
- if (OCInit((char *) paddr, port, OC_CLIENT) != OC_STACK_OK) {
+ if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK) {
OC_LOG(ERROR, TAG, "OCStack init error");
return 0;
}
static int UNICAST_DISCOVERY = 0;
static int TEST_CASE = 0;
-static const char * TEST_APP_UNICAST_DISCOVERY_QUERY = "coap://0.0.0.0:5683/oc/core";
+static const char * UNICAST_DISCOVERY_QUERY = "coap://%s:5298/oc/core";
static std::string putPayload = "{\"state\":\"off\",\"power\":10}";
static std::string coapServerIP = "255.255.255.255";
static std::string coapServerPort = "5683";
//to be used for sending unicast messages. Default set to WIFI.
static OCConnectivityType OC_CONNTYPE = OC_WIFI;
static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core";
+static int IPV4_ADDR_SIZE = 16;
+void StripNewLineChar(char* str);
int gQuitFlag = 0;
char szQueryUri[64] = { 0 };
if (UNICAST_DISCOVERY)
{
- strcpy(szQueryUri, TEST_APP_UNICAST_DISCOVERY_QUERY);
+ char ipv4addr[IPV4_ADDR_SIZE];
+ printf("Enter IPv4 address of the Server hosting resource (Ex: 192.168.0.15)\n");
+ if (fgets(ipv4addr, IPV4_ADDR_SIZE, stdin))
+ {
+ //Strip newline char from ipv4addr
+ StripNewLineChar(ipv4addr);
+ snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_DISCOVERY_QUERY, ipv4addr);
+ }
+ else
+ {
+ OC_LOG(ERROR, TAG, "!! Bad input for IPV4 address. !!");
+ return OC_STACK_INVALID_PARAM;
+ }
}
else
{
int main(int argc, char* argv[])
{
- uint8_t addr[20] = {0};
- uint8_t* paddr = NULL;
- uint16_t port = USE_RANDOM_PORT;
- uint8_t ifname[] = "eth0";
int opt;
while ((opt = getopt(argc, argv, "u:t:c:")) != -1)
return -1;
}
-
- /*Get Ip address on defined interface and initialize coap on it with random port number
- * this port number will be used as a source port in all coap communications*/
- if ( OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr,
- sizeof(addr)) == ERR_SUCCESS)
- {
- OC_LOG_V(INFO, TAG, "Starting occlient on address %s",addr);
- paddr = addr;
- }
-
/* Initialize OCStack*/
- if (OCInit((char *) paddr, port, OC_CLIENT) != OC_STACK_OK)
+ if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack init error");
return 0;