#include "ocstack.h"
#include "logger.h"
#include "occlient.h"
+#include "ocpayload.h"
// Tracking user input
static int UNICAST_DISCOVERY = 0;
static int TEST_CASE = 0;
static int CONNECTIVITY = 0;
-static const char * UNICAST_DEVICE_DISCOVERY_QUERY = "coap://%s:6298/oic/d";
+static const char * UNICAST_DEVICE_DISCOVERY_QUERY = "coap://%s/oic/d";
static const char * MULTICAST_DEVICE_DISCOVERY_QUERY = "/oic/d";
-static const char * UNICAST_PLATFORM_DISCOVERY_QUERY = "coap://%s:6298/oic/p";
+static const char * UNICAST_PLATFORM_DISCOVERY_QUERY = "coap://%s/oic/p";
static const char * MULTICAST_PLATFORM_DISCOVERY_QUERY = "/oic/p";
-static const char * UNICAST_RESOURCE_DISCOVERY_QUERY = "coap://%s:6298/oic/res";
+static const char * UNICAST_RESOURCE_DISCOVERY_QUERY = "coap://%s/oic/res";
static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oic/res";
//The following variable determines the interface protocol (IPv4, IPv6, etc)
//to be used for sending unicast messages. Default set to IPv4.
static OCConnectivityType OC_CONNTYPE = CT_ADAPTER_IP;
-static std::string putPayload = "{\"oic\":[{\"rep\":{\"power\":15,\"state\":true}}]}";
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;
+// Size to hold IPV4_ADDRESS:PORT
+static const int IPV4_ADDR_SIZE = 24;
//Use ipv4addr for both InitDiscovery and InitPlatformOrDeviceDiscovery
char ipv4addr[IPV4_ADDR_SIZE];
void StripNewLineChar(char* str);
}
}
+OCPayload* putPayload()
+{
+ OCRepPayload* payload = OCRepPayloadCreate();
+
+ if(!payload)
+ {
+ std::cout << "Failed to create put payload object"<<std::endl;
+ std::exit(1);
+ }
+
+ OCRepPayloadSetPropInt(payload, "power", 15);
+ OCRepPayloadSetPropBool(payload, "state", true);
+
+ return (OCPayload*) payload;
+}
+
static void PrintUsage()
{
- OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1..17> -c <0|1|2>");
+ OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1..17> -c <0|1>");
OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources");
- OC_LOG(INFO, TAG, "-c 0 : Default IPv4 and IPv6 auto-selection");
- OC_LOG(INFO, TAG, "-c 1 : IPv4 Connectivity Type");
- OC_LOG(INFO, TAG, "-c 2 : IPv6 Connectivity Type (IPv6 not currently supported)");
+ OC_LOG(INFO, TAG, "-c 0 : Use Default connectivity(IP)");
+ OC_LOG(INFO, TAG, "-c 1 : IP Connectivity Type");
OC_LOG(INFO, TAG, "-t 1 : Discover Resources");
OC_LOG(INFO, TAG, "-t 2 : Discover Resources and Initiate Nonconfirmable Get Request");
OC_LOG(INFO, TAG, "-t 3 : Discover Resources and Initiate Nonconfirmable Get Request"
cbData.cd = NULL;
ret = OCDoResource(&handle, method, query.str().c_str(), 0,
- (method == OC_REST_PUT) ? putPayload.c_str() : NULL,
+ (method == OC_REST_PUT) ? putPayload() : NULL,
(OC_CONNTYPE), qos, &cbData, options, numOptions);
if (ret != OC_STACK_OK)
if(clientResponse)
{
OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
- OC_LOG_V(INFO, TAG, "JSON = %s =============> Put Response",
- clientResponse->resJSONPayload);
+ OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
+ OC_LOG(INFO, TAG, PCF("=============> Put Response"));
}
else
{
if(clientResponse)
{
OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
- OC_LOG_V(INFO, TAG, "JSON = %s =============> Post Response",
- clientResponse->resJSONPayload);
+ OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
+ OC_LOG(INFO, TAG, PCF("=============> Post Response"));
}
else
{
if(clientResponse)
{
OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
- OC_LOG_V(INFO, TAG, "JSON = %s =============> Delete Response",
- clientResponse->resJSONPayload);
+ OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
+ OC_LOG(INFO, TAG, PCF("=============> Delete Response"));
}
else
{
OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
- OC_LOG_V(INFO, TAG, "JSON = %s =============> Get Response", clientResponse->resJSONPayload);
+ OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
+ OC_LOG(INFO, TAG, PCF("=============> Get Response"));
if(clientResponse->numRcvdVendorSpecificHeaderOptions > 0)
{
OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
OC_LOG_V(INFO, TAG, "Callback Context for OBSERVE notification recvd successfully %d",
gNumObserveNotifies);
- OC_LOG_V(INFO, TAG, "JSON = %s =============> Obs Response",
- clientResponse->resJSONPayload);
+ OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
+ OC_LOG(INFO, TAG, PCF("=============> Obs Response"));
gNumObserveNotifies++;
if (gNumObserveNotifies == 15) //large number to test observing in DELETE case.
{
OC_LOG_V(INFO, TAG, "NONCE NUMBER: %u", clientResponse->sequenceNumber);
OC_LOG_V(INFO, TAG, "Callback Context for Presence notification recvd successfully %d",
gNumPresenceNotifies);
- OC_LOG_V(INFO, TAG, "JSON = %s =============> Presence Response",
- clientResponse->resJSONPayload);
+ OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
+ OC_LOG(INFO, TAG, PCF("=============> Presence Response"));
gNumPresenceNotifies++;
if (gNumPresenceNotifies == 20)
{
std::string connectionType = getConnectivityType (clientResponse->connType);
OC_LOG_V(INFO, TAG, "Discovered on %s", connectionType.c_str());
OC_LOG_V(INFO, TAG,
- "Device =============> Discovered %s @ %s:%d",
- clientResponse->resJSONPayload, clientResponse->devAddr.addr, clientResponse->devAddr.port);
+ "Device =============> Discovered @ %s:%d",
+ clientResponse->devAddr.addr,
+ clientResponse->devAddr.port);
+ OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
+ OC_CONNTYPE = clientResponse->connType;
parseClientResponse(clientResponse);
switch(TEST_CASE)
if(clientResponse)
{
- //OC_LOG truncates the response as it is too long.
- fprintf(stderr, "Discovery response: \n %s\n", clientResponse->resJSONPayload);
- fflush(stderr);
+ OC_LOG(INFO, TAG, PCF("Discovery Response:"));
+ OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
}
else
{
if(clientResponse)
{
- //OC_LOG truncates the response as it is too long.
- fprintf(stderr, "Discovery response: \n %s\n", clientResponse->resJSONPayload);
- fflush(stderr);
+ OC_LOG(INFO, TAG, PCF("Discovery Response:"));
+ OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
}
else
{
OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
std::ostringstream query;
std::ostringstream querySuffix;
- query << "coap://" << coapServerIP << ":" << coapServerPort << OC_PRESENCE_URI;
+ query << "coap://" << coapServerIP << ":" << coapServerPort << OC_RSRVD_PRESENCE_URI;
if(TEST_CASE == TEST_OBS_PRESENCE)
{
result = InvokeOCDoResource(query, OC_REST_PRESENCE, OC_LOW_QOS,
{
std::ostringstream multicastPresenceQuery;
multicastPresenceQuery.str("");
- multicastPresenceQuery << "coap://" << OC_MULTICAST_PREFIX << OC_PRESENCE_URI;
+ multicastPresenceQuery << "coap://" << OC_MULTICAST_PREFIX << OC_RSRVD_PRESENCE_URI;
result = InvokeOCDoResource(multicastPresenceQuery, OC_REST_PRESENCE, OC_LOW_QOS,
presenceCB, NULL, 0);
}
// ocserver is written to only process "power<X" query.
if (getWithQuery)
{
- OC_LOG(INFO, TAG, "Using query power<30");
- query << "?power<30";
+ OC_LOG(INFO, TAG, "Using query power<50");
+ query << "?power<50";
}
if (withVendorSpecificHeaderOptions)
OC_LOG(ERROR, TAG, "OCStack init error");
return 0;
}
+
+ if(CONNECTIVITY == CT_ADAPTER_DEFAULT || CONNECTIVITY == CT_IP)
+ {
+ OC_CONNTYPE = CT_ADAPTER_IP;
+ }
+ else
+ {
+ OC_LOG(INFO, TAG, "Default Connectivity type selected...");
+ PrintUsage();
+ }
+
if (UNICAST_DISCOVERY)
{
- OC_LOG(INFO, TAG, "Enter IPv4 address of the Server hosting resource (Ex: 192.168.0.15)\n");
- OC_LOG(INFO, TAG, "Ipv6 is currently not supported...");
+ OC_LOG(INFO, TAG, "Enter IP address with port number of the Server hosting resource");
+ OC_LOG(INFO, TAG, "as follows - eg: 192.168.0.15:45454 (IP:Port) \n");
if (fgets(ipv4addr, IPV4_ADDR_SIZE, stdin))
{
return OC_STACK_INVALID_PARAM;
}
}
- if(CONNECTIVITY == CT_ADAPTER_DEFAULT)
- {
- OC_CONNTYPE = CT_DEFAULT;
- }
- else if(CONNECTIVITY == CT_IPV4)
- {
- OC_CONNTYPE = CT_IP_USE_V4;
- }
- else if(CONNECTIVITY == CT_IPV6)
- {
- OC_CONNTYPE = CT_IP_USE_V6;
-
- //TODO: Remove when IPv6 is available.
- OC_LOG(ERROR, TAG, "IPv6 is currently not supported !!!!");
- PrintUsage();
- return -1;
- }
- else
- {
- OC_LOG(INFO, TAG, "Default Connectivity type selected...");
- PrintUsage();
- }
if(UNICAST_DISCOVERY == 0 && TEST_CASE == TEST_DISCOVER_DEV_REQ)
{