Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMustafa Ozcelikors2017-11-28 20:03:46 +0000
committerMustafa Ozcelikors2017-11-28 20:03:46 +0000
commitba679b89fb89bfc1214df5c54fde871bf7ce7f07 (patch)
treedc1676d03050f7856ba3ce878276c9a368252a1a
parent1a466757439c13234b2761858ec8db3cfd041cc6 (diff)
downloadorg.eclipse.app4mc.examples-ba679b89fb89bfc1214df5c54fde871bf7ce7f07.tar.gz
org.eclipse.app4mc.examples-ba679b89fb89bfc1214df5c54fde871bf7ce7f07.tar.xz
org.eclipse.app4mc.examples-ba679b89fb89bfc1214df5c54fde871bf7ce7f07.zip
ROVER - RoverCloud API added
Signed-off-by: Mustafa Ozcelikors <mozcelikors@gmail.com>
-rw-r--r--rover/include/roverapi/rover_cloud.hpp138
-rw-r--r--rover/src/roverapi/rover_cloud.cpp148
2 files changed, 286 insertions, 0 deletions
diff --git a/rover/include/roverapi/rover_cloud.hpp b/rover/include/roverapi/rover_cloud.hpp
new file mode 100644
index 0000000..0adc28e
--- /dev/null
+++ b/rover/include/roverapi/rover_cloud.hpp
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Rover Cloud API - Interfaces for Rover cloud application development - Header file
+ *
+ * Contributors:
+ * M.Ozcelikors <mozcelikors@gmail.com>, created API 17.11.2017
+ *
+ */
+
+#ifndef API_ROVER_CLOUD_HPP_
+#define API_ROVER_CLOUD_HPP_
+
+namespace rover
+{
+ /**
+ * @brief Contains the member functions to connect and send data to Eclipse Hono instance using several parameters
+ * such as host name, port, tenant name, user name, and password. This class wraps hono_interaction library for Rover-specific interactions.
+ */
+ class RoverCloud
+ {
+ private:
+ /**
+ * @brief Host name used for connecting to the Eclipse Hono using REST API
+ */
+ char * HOST_NAME;
+ /**
+ * @brief Port used for connecting to the Eclipse Hono using REST API
+ */
+ int PORT;
+ /**
+ * @brief Port used for registering a device to the Eclipse Hono using REST API
+ */
+ int REGISTRATION_PORT;
+ /**
+ * @brief Tenant name used for connecting to the Eclipse Hono using REST API
+ */
+ char * TENANT_NAME;
+
+ /**
+ * @brief Checks private attributes and gives an error message and returns 0 if they're invalid.
+ */
+ int attributeErrorCheck (void);
+
+ public:
+ /**
+ * @brief Constructor for the RoverCloud
+ */
+ RoverCloud();
+
+ /**
+ * @brief Sets private attribute HOST_NAME
+ * @param host_name
+ */
+ void setHostName (char * host_name);
+
+ /**
+ * @brief Sets private attribute PORT
+ * @param port
+ */
+ void setPort (int port);
+
+ /**
+ * @brief Sets private attribute TENANT_NAME
+ * @param tenant
+ */
+ void setTenantName (char * tenant);
+
+ /**
+ * @brief Sets up a hono connection using host name, port, and tenant name
+ * @param host_name
+ * @param port
+ * @param tenant
+ */
+ void setHono (char * host_name, int port, char * tenant);
+
+ /**
+ * @brief Retrieves private attribute HOST_NAME
+ */
+ char * getHostName (void);
+
+ /**
+ * @brief Retrieves private attribute PORT
+ */
+ int getPort (void);
+
+ /**
+ * @brief Retrieves private attribute TENANT_NAME
+ */
+ char * getTenantName (void);
+
+ /**
+ * @brief Sets the default REGISTRATION_PORT variable
+ * @param Port (int) to be set as REGISTRATION_PORT
+ * @return void
+ */
+ void setRegistrationPort (int port);
+
+ /**
+ * @brief Retrieves private attribute REGISTRATION_PORT
+ * @return Private attribute REGISTRATION_PORT
+ */
+ int getRegistrationPort (void);
+
+ /**
+ * @brief Constructs curl command to register a device to Hono instance given device ID using REST API
+ * @param device_id
+ * @return status code (int) is returned. 1 indicates successful operation and 0 indicates unsuccessful operation.
+ */
+ int registerDevice (char * device_id);
+
+ /**
+ * @brief Constructs curl command to send telemetry data to Eclipse Hono using REST API
+ * @return status code (int) is returned. 1 indicates successful operation and 0 indicates unsuccessful operation.
+ */
+ int sendTelemetry (char * device_id, char * user, char * password, char * field, double value);
+
+ /**
+ * @brief Constructs curl command to send event data to Eclipse Hono using REST API
+ * @return status code (int) is returned. 1 indicates successful operation and 0 indicates unsuccessful operation.
+ */
+ int sendEvent (char * device_id, char * user, char * password, char * field, double value);
+
+ /**
+ * @brief Retrieves Hono cloud status by constructing a dummy REST API telemetry sending command to Eclipse Hono
+ * @return status code (int) is returned. 1 indicates successful operation and 0 indicates unsuccessful operation.
+ */
+ int getHonoStatus (char * device_id, char * user, char * password);
+ };
+}
+
+
+#endif /* API_ROVER_CLOUD_HPP_ */
diff --git a/rover/src/roverapi/rover_cloud.cpp b/rover/src/roverapi/rover_cloud.cpp
new file mode 100644
index 0000000..2b8cff2
--- /dev/null
+++ b/rover/src/roverapi/rover_cloud.cpp
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Rover Cloud API - Interfaces for Rover cloud application development
+ *
+ * Contributors:
+ * M.Ozcelikors <mozcelikors@gmail.com>, created API 17.11.2017
+ *
+ */
+
+#include <roverapi/rover_cloud.hpp>
+
+#include <libraries/hono_interaction/hono_interaction.h>
+#include <libraries/status_library/status_library.h>
+
+#include <stdio.h>
+#include <string.h>
+
+rover::RoverCloud::RoverCloud()
+{
+ this->REGISTRATION_PORT = 1;
+ this->TENANT_NAME = "N";
+ this->PORT = 1;
+ this->HOST_NAME = "N";
+}
+
+int rover::RoverCloud::attributeErrorCheck (void)
+{
+ if (this->PORT == 1 || this->TENANT_NAME[0] == 'N' || this->HOST_NAME[0] == 'N')
+ {
+ fprintf (stderr, "Hono is not initialized. Please use: setHono function\n");
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+}
+
+int rover::RoverCloud::registerDevice (char * device_id)
+{
+ if (this->REGISTRATION_PORT != 1)
+ {
+ int status = 0;
+ status = registerDeviceToHonoInstance (this->HOST_NAME, this->REGISTRATION_PORT, this->TENANT_NAME, device_id);
+ return status;
+ }
+ else
+ {
+ fprintf (stderr, "Registration port is not initialized. Please use: setRegistrationPort function\n");
+ return 0;
+ }
+}
+
+int rover::RoverCloud::sendTelemetry (char * device_id, char * user, char * password, char * field, double value)
+{
+ if (this->attributeErrorCheck() == 1)
+ {
+ int status = 0;
+ status = sendTelemetryDataToHonoInstance (this->HOST_NAME, this->PORT, this->TENANT_NAME, device_id, user, password, field, value);
+ return status;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+int rover::RoverCloud::sendEvent (char * device_id, char * user, char * password, char * field, double value)
+{
+ if (this->attributeErrorCheck() == 1)
+ {
+ int status = 0;
+ status = sendEventDataToHonoInstance (this->HOST_NAME, this->PORT, this->TENANT_NAME, device_id, user, password, field, value);
+ return status;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+void rover::RoverCloud::setHono (char * host_name, int port, char * tenant)
+{
+
+ this->HOST_NAME = host_name;
+ this->PORT = port;
+ this->TENANT_NAME = tenant;
+}
+
+void rover::RoverCloud::setHostName (char * host_name)
+{
+ this->HOST_NAME = host_name;
+}
+
+void rover::RoverCloud::setPort (int port)
+{
+ this->PORT = port;
+}
+
+void rover::RoverCloud::setRegistrationPort (int port)
+{
+ this->REGISTRATION_PORT = port;
+}
+
+int rover::RoverCloud::getRegistrationPort (void)
+{
+ return this->REGISTRATION_PORT;
+}
+
+void rover::RoverCloud::setTenantName (char * tenant)
+{
+ this->TENANT_NAME = tenant;
+}
+
+char * rover::RoverCloud::getHostName (void)
+{
+ return this->HOST_NAME;
+}
+
+int rover::RoverCloud::getPort (void)
+{
+ return this->PORT;
+}
+
+char * rover::RoverCloud::getTenantName (void)
+{
+ return this->TENANT_NAME;
+}
+
+int rover::RoverCloud::getHonoStatus (char * device_id, char * user, char * password)
+{
+ if (this->attributeErrorCheck() == 1)
+ {
+ int status = 0;
+ status = retrieveHONOStatus (this->HOST_NAME, this->PORT, this->TENANT_NAME, device_id, user, password);
+ return status;
+ }
+ else
+ {
+ return 0;
+ }
+}

Back to the top