dey-examples: cccs: move cccs examples to dey-examples repository

ConnectCore Cloud Services examples are included in 'dey-examples' repository
so they can be built from here and also imported in Eclipse/Digi Application
Development Environment for Linux with the samples wizard.

The example 'upload_file' has been removed since currently there is no support
for binary data points in the CCCS daemon/client model.

https://onedigi.atlassian.net/browse/DEL-8628

Signed-off-by: Tatiana Leon <Tatiana.Leon@digi.com>
This commit is contained in:
Tatiana Leon 2023-09-04 18:25:12 +02:00
parent f13c0e60cf
commit 2f2f68dc34
15 changed files with 28 additions and 788 deletions

View File

@ -91,4 +91,4 @@ BOOT_SCRIPTS += "boot.scr:boot.scr"
SWUPDATE_UBOOTIMG ?= "false"
# ConnectCore Cloud Services packages to install
CCCS_PKGS ?= "cccs-gs-demo"
CCCS_PKGS ?= "cccs-gs-demo dey-examples-cccs"

View File

@ -0,0 +1,26 @@
# Copyright (C) 2017-2023 Digi International Inc.
require recipes-digi/dey-examples/dey-examples-src.inc
SUMMARY = "DEY examples: ConnectCore Cloud Services example applications"
SECTION = "examples"
LICENSE = "ISC"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/ISC;md5=f3b90e78ea0cffb20bf5cca7947a896d"
DEPENDS = "cccs"
S = "${WORKDIR}/git"
inherit pkgconfig
EXTRA_OEMAKE += "-f cccs-examples.mk"
do_compile() {
oe_runmake
}
do_install() {
oe_runmake DESTDIR=${D} install
}
RDEPENDS:${PN} = "cccs-daemon"

View File

@ -1,20 +0,0 @@
# Copyright (C) 2017, 2018 Digi International Inc.
SUMMARY = "DEY examples: Remote Manager test applications"
SECTION = "examples"
LICENSE = "MPL-2.0"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MPL-2.0;md5=815ca599c9df247a0c7f619bab123dad"
DEPENDS = "cloudconnector"
SRC_URI = "file://cloudconnector_test"
S = "${WORKDIR}/cloudconnector_test"
inherit pkgconfig
do_install() {
oe_runmake DESTDIR=${D} install
}
RDEPENDS:${PN} = "cloudconnector-cert"

View File

@ -1,27 +0,0 @@
#
# Copyright (c) 2017, Digi International Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, you can obtain one at http://mozilla.org/MPL/2.0/.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
SUBDIRS := device_request_listener upload_data_points upload_file
all: $(SUBDIRS)
.PHONY: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@
.PHONY: clean install
clean install:
for a in $(SUBDIRS); do $(MAKE) -C $$a $@; done

View File

@ -1,41 +0,0 @@
# ***************************************************************************
# Copyright (c) 2017-2023 Digi International Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
# Digi International Inc., 9350 Excelsior Blvd., Suite 700, Hopkins, MN 55343
#
# ***************************************************************************
PROGRAM := device_request_listener
CFLAGS += -Wall
CFLAGS += $(shell pkg-config --cflags cloudconnector)
LDLIBS += $(shell pkg-config --libs --static cloudconnector)
all: $(PROGRAM)
OBJS = device_request.o main.o
$(PROGRAM): $(OBJS)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
.PHONY: install
install: $(PROGRAM)
install -d $(DESTDIR)/usr/bin
install -m 0755 $(PROGRAM) $(DESTDIR)/usr/bin/
.PHONY: clean
clean:
-rm -f *.o $(PROGRAM)

View File

@ -1,89 +0,0 @@
/*
* Copyright (c) 2017-2023 Digi International Inc.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* Digi International Inc., 9350 Excelsior Blvd., Suite 700, Hopkins, MN 55343
* ===========================================================================
*/
#include <signal.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include "device_request.h"
#if !(defined UNUSED_ARGUMENT)
#define UNUSED_ARGUMENT(a) (void)(a)
#endif
/*
* get_time_cb() - Data callback for 'get_time' device requests
*
* @target: Target ID of the device request (get_time).
* @transport: Communication transport used by the device request.
* @req_buf_info: Buffer containing the device request.
* @resp_buf_info: Buffer to store the answer of the request.
*
* Logs information about the received request and executes the corresponding
* command.
*/
ccapi_receive_error_t get_time_cb(char const *const target,
ccapi_transport_t const transport,
ccapi_buffer_info_t const *const req_buf_info,
ccapi_buffer_info_t *const resp_buf_info)
{
time_t t = time(NULL);
char *time_str = ctime(&t);
UNUSED_ARGUMENT(req_buf_info);
log_debug("%s: target='%s' - transport='%d'", __func__, target, transport);
resp_buf_info->length = snprintf(NULL, 0, "Time: %s", time_str);
resp_buf_info->buffer = calloc(resp_buf_info->length + 1, sizeof(char));
if (resp_buf_info->buffer == NULL) {
log_error("%s: resp_buf_info calloc error", __func__);
return CCAPI_RECEIVE_ERROR_INSUFFICIENT_MEMORY;
}
resp_buf_info->length = sprintf(resp_buf_info->buffer, "Time: %s", time_str);
return CCAPI_RECEIVE_ERROR_NONE;
}
/*
* get_time_status_cb() - Status callback for 'get_time' device requests
*
* @target: Target ID of the device request (get_time)
* @transport: Communication transport used by the device request.
* @resp_buf_info: Buffer containing the response data.
* @receive_error: The error status of the receive process.
*
* This callback is executed when the response process has finished. It doesn't
* matter if everything worked or there was an error during the process.
*
* Cleans and frees the response buffer.
*/
void get_time_status_cb(char const *const target,
ccapi_transport_t const transport,
ccapi_buffer_info_t *const resp_buf_info,
ccapi_receive_error_t receive_error)
{
log_debug("%s: target='%s' - transport='%d' - error='%d'",
__func__, target, transport, receive_error);
/* Free the response buffer */
if (resp_buf_info != NULL)
free(resp_buf_info->buffer);
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (c) 2017-2023 Digi International Inc.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* Digi International Inc., 9350 Excelsior Blvd., Suite 700, Hopkins, MN 55343
* ===========================================================================
*/
#ifndef DEVICE_REQUEST_H_
#define DEVICE_REQUEST_H_
#include <cloudconnector/cloudconnector.h>
#define TARGET_GET_TIME "get_time"
ccapi_receive_error_t get_time_cb(char const *const target,
ccapi_transport_t const transport,
ccapi_buffer_info_t const *const req_buf_info,
ccapi_buffer_info_t *const resp_buf_info);
void get_time_status_cb(char const *const target,
ccapi_transport_t const transport,
ccapi_buffer_info_t *const resp_buf_info,
ccapi_receive_error_t receive_error);
#endif /* DEVICE_REQUEST_H_ */

View File

@ -1,107 +0,0 @@
/*
* Copyright (c) 2017-2023 Digi International Inc.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* Digi International Inc., 9350 Excelsior Blvd., Suite 700, Hopkins, MN 55343
* ===========================================================================
*/
#include <cloudconnector.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "device_request.h"
static void sigint_handler(int signum)
{
log_debug("%s: received signal %d to close Cloud connection.",
__func__, signum);
exit(0);
}
static void graceful_shutdown(void)
{
stop_cloud_connection();
}
static void add_sigkill_signal(void)
{
struct sigaction new_action;
struct sigaction old_action;
atexit(graceful_shutdown);
/* Setup signal hander. */
new_action.sa_handler = sigint_handler;
sigemptyset(&new_action.sa_mask);
new_action.sa_flags = 0;
sigaction(SIGINT, NULL, &old_action);
if (old_action.sa_handler != SIG_IGN)
sigaction(SIGINT, &new_action, NULL);
}
/*
* Use the following SCI request to test this example (insert your Device ID):
*
* <sci_request version="1.0">
* <data_service>
* <targets>
* <device id="00000000-00000000-00000000-00000000"/>
* </targets>
* <requests>
* <device_request target_name="get_time"/>
* </requests>
* </data_service>
* </sci_request>
*
*/
int main(void)
{
cc_init_error_t init_error;
cc_start_error_t start_error;
ccapi_receive_error_t receive_error;
add_sigkill_signal();
init_error = init_cloud_connection(NULL);
if (init_error != CC_INIT_ERROR_NONE) {
log_error("Cannot initialize cloud connection, error %d", init_error);
return EXIT_FAILURE;
}
start_error = start_cloud_connection();
if (start_error != CC_START_ERROR_NONE) {
log_error("Cannot start cloud connection, error %d", start_error);
return EXIT_FAILURE;
}
receive_error = ccapi_receive_add_target(TARGET_GET_TIME, get_time_cb,
get_time_status_cb, 0);
if (receive_error != CCAPI_RECEIVE_ERROR_NONE) {
log_error("Cannot register target '%s', error %d", TARGET_GET_TIME,
receive_error);
return EXIT_FAILURE;
}
printf("Waiting for Remote Manager request...\n");
printf("Press a key to exit\n");
getchar();
return EXIT_SUCCESS;
}

View File

@ -1,41 +0,0 @@
# ***************************************************************************
# Copyright (c) 2017-2023 Digi International Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
# Digi International Inc., 9350 Excelsior Blvd., Suite 700, Hopkins, MN 55343
#
# ***************************************************************************
PROGRAM := upload_data_points
CFLAGS += -Wall
CFLAGS += $(shell pkg-config --cflags cloudconnector)
LDLIBS += $(shell pkg-config --libs --static cloudconnector)
all: $(PROGRAM)
OBJS = data_point.o main.o
$(PROGRAM): $(OBJS)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
.PHONY: install
install: $(PROGRAM)
install -d $(DESTDIR)/usr/bin
install -m 0755 $(PROGRAM) $(DESTDIR)/usr/bin/
.PHONY: clean
clean:
-rm -f *.o $(PROGRAM)

View File

@ -1,150 +0,0 @@
/*
* Copyright (c) 2017-2023 Digi International Inc.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* Digi International Inc., 9350 Excelsior Blvd., Suite 700, Hopkins, MN 55343
* ===========================================================================
*/
#include <limits.h>
#include <stdio.h>
#include <time.h>
#include "data_point.h"
#define STREAM_NAME "incremental"
/*
* get_incremental() - Retrieves an incremental value each time
*/
static int get_incremental(void)
{
static int incremental = -1;
if (incremental == INT_MAX)
incremental = 0;
else
incremental++;
log_debug("Incremental = %d", incremental);
return incremental;
}
/*
* get_timestamp() - Get the current timestamp of the system
*
* Return: The timestamp of the system.
*/
static ccapi_timestamp_t *get_timestamp(void)
{
ccapi_timestamp_t *timestamp = NULL;
size_t len = strlen("2016-09-27T07:07:09.546Z") + 1;
char *date = NULL;
time_t now;
timestamp = (ccapi_timestamp_t*) malloc(sizeof(ccapi_timestamp_t));
if (timestamp == NULL)
return NULL;
date = (char*) malloc(sizeof(char) * len);
if (date == NULL) {
free(timestamp);
return NULL;
}
time(&now);
if (strftime(date, len, "%FT%TZ", gmtime(&now)) > 0) {
timestamp->iso8601 = date;
} else {
free(date);
timestamp->iso8601 = NULL;
}
return timestamp;
}
/*
* free_timestamp() - Free given timestamp structure
*
* @timestamp: The timestamp structure to release.
*/
static void free_timestamp(ccapi_timestamp_t *timestamp)
{
if (timestamp == NULL)
return;
if (timestamp->iso8601 != NULL) {
free((char *) timestamp->iso8601);
timestamp->iso8601 = NULL;
}
free(timestamp);
timestamp = NULL;
}
ccapi_dp_error_t init_data_stream(ccapi_dp_collection_handle_t *dp_collection)
{
ccapi_dp_collection_handle_t collection;
ccapi_dp_error_t dp_error = ccapi_dp_create_collection(&collection);
if (dp_error != CCAPI_DP_ERROR_NONE) {
log_error("%s: error %d", __func__, dp_error);
return dp_error;
} else {
*dp_collection = collection;
}
dp_error = ccapi_dp_add_data_stream_to_collection_extra(collection,
STREAM_NAME, "int32 ts_iso", "counts", NULL);
if (dp_error != CCAPI_DP_ERROR_NONE) {
log_error("%s: error %d", __func__, dp_error);
ccapi_dp_destroy_collection(collection);
*dp_collection = NULL;
}
return dp_error;
}
ccapi_dp_error_t add_data_point(ccapi_dp_collection_handle_t dp_collection)
{
ccapi_timestamp_t *timestamp = get_timestamp();
ccapi_dp_error_t dp_error = ccapi_dp_add(dp_collection, STREAM_NAME,
get_incremental(), timestamp);
if (dp_error != CCAPI_DP_ERROR_NONE)
log_error("%s: failed with error: %d", __func__, dp_error);
free_timestamp(timestamp);
return dp_error;
}
ccapi_dp_error_t send_data_stream(ccapi_dp_collection_handle_t dp_collection)
{
ccapi_dp_error_t dp_error;
log_debug("%s", "Sending Data Stream with new incremental value");
dp_error = ccapi_dp_send_collection(CCAPI_TRANSPORT_TCP, dp_collection);
if (dp_error != CCAPI_DP_ERROR_NONE)
log_error("%s: error %d", __func__, dp_error);
return dp_error;
}
ccapi_dp_error_t destroy_data_stream(ccapi_dp_collection_handle_t dp_collection)
{
log_debug("%s", "Destroying Data Stream");
return ccapi_dp_destroy_collection(dp_collection);
}

View File

@ -1,30 +0,0 @@
/*
* Copyright (c) 2017-2023 Digi International Inc.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* Digi International Inc., 9350 Excelsior Blvd., Suite 700, Hopkins, MN 55343
* ===========================================================================
*/
#ifndef DATA_POINT_H_
#define DATA_POINT_H_
#include <cloudconnector/cloudconnector.h>
ccapi_dp_error_t init_data_stream(ccapi_dp_collection_handle_t *dp_collection);
ccapi_dp_error_t add_data_point(ccapi_dp_collection_handle_t dp_collection);
ccapi_dp_error_t send_data_stream(ccapi_dp_collection_handle_t dp_collection);
ccapi_dp_error_t destroy_data_stream(ccapi_dp_collection_handle_t dp_collection);
#endif /* DATA_POINT_H_ */

View File

@ -1,116 +0,0 @@
/*
* Copyright (c) 2017-2023 Digi International Inc.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* Digi International Inc., 9350 Excelsior Blvd., Suite 700, Hopkins, MN 55343
* ===========================================================================
*/
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <cloudconnector/cloudconnector.h>
#include "data_point.h"
#define DP_SLEEP_TIME 5
#define DP_NUMBER 10
static int running = 1;
static ccapi_dp_collection_handle_t dp_collection;
static void sigint_handler(int signum)
{
log_debug("%s: received signal %d to close Cloud connection.",
__func__, signum);
exit(0);
}
static void graceful_shutdown(void)
{
if (running == 1)
destroy_data_stream(dp_collection);
running = 0;
stop_cloud_connection();
}
static void add_sigkill_signal(void)
{
struct sigaction new_action;
struct sigaction old_action;
atexit(graceful_shutdown);
/* Setup signal hander. */
new_action.sa_handler = sigint_handler;
sigemptyset(&new_action.sa_mask);
new_action.sa_flags = 0;
sigaction(SIGINT, NULL, &old_action);
if (old_action.sa_handler != SIG_IGN)
sigaction(SIGINT, &new_action, NULL);
}
int main(void)
{
cc_init_error_t init_error;
cc_start_error_t start_error;
ccapi_dp_error_t dp_error;
int i;
add_sigkill_signal();
init_error = init_cloud_connection(NULL);
if (init_error != CC_INIT_ERROR_NONE) {
log_error("Cannot initialize cloud connection, error %d", init_error);
return EXIT_FAILURE;
}
start_error = start_cloud_connection();
if (start_error != CC_START_ERROR_NONE) {
log_error("Cannot start cloud connection, error %d", start_error);
return EXIT_FAILURE;
}
dp_error = init_data_stream(&dp_collection);
if (dp_error != CCAPI_DP_ERROR_NONE) {
log_error("Cannot initialize data stream, error %d", start_error);
return EXIT_FAILURE;
}
running = CCAPI_TRUE;
while (running != CCAPI_FALSE) {
/* Collect DP_NUMBER data points sampled each DP_SLEEP_TIME seconds */
for (i = 0; i < DP_NUMBER; i++) {
dp_error = add_data_point(dp_collection);
if (dp_error != CCAPI_DP_ERROR_NONE) {
log_error("Cannot add data point, error %d", start_error);
i--;
}
sleep(DP_SLEEP_TIME);
}
/* Send the block of collected data points */
dp_error = send_data_stream(dp_collection);
if (dp_error != CCAPI_DP_ERROR_NONE)
log_error("Cannot send data stream, error %d", start_error);
}
return EXIT_SUCCESS;
}

View File

@ -1,41 +0,0 @@
# ***************************************************************************
# Copyright (c) 2017-2023 Digi International Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
# Digi International Inc., 9350 Excelsior Blvd., Suite 700, Hopkins, MN 55343
#
# ***************************************************************************
PROGRAM := upload_file
CFLAGS += -Wall
CFLAGS += $(shell pkg-config --cflags cloudconnector)
LDLIBS += $(shell pkg-config --libs --static cloudconnector)
all: $(PROGRAM)
OBJS = main.o
$(PROGRAM): $(OBJS)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
.PHONY: install
install: $(PROGRAM)
install -d $(DESTDIR)/usr/bin
install -m 0755 $(PROGRAM) $(DESTDIR)/usr/bin/
.PHONY: clean
clean:
-rm -f *.o $(PROGRAM)

View File

@ -1,88 +0,0 @@
/*
* Copyright (c) 2017-2023 Digi International Inc.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* Digi International Inc., 9350 Excelsior Blvd., Suite 700, Hopkins, MN 55343
* ===========================================================================
*/
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <cloudconnector/cloudconnector.h>
#define UNUSED_ARGUMENT(a) (void)(a)
#define STREAM_NAME "examples/uploaded_file"
#define UPLOAD_FILE "/etc/build"
static void sigint_handler(int signum)
{
log_debug("%s: received signal %d to close Cloud connection.",
__func__, signum);
exit(0);
}
static void graceful_shutdown(void)
{
stop_cloud_connection();
}
static void add_sigkill_signal(void)
{
struct sigaction new_action;
struct sigaction old_action;
atexit(graceful_shutdown);
/* Setup signal hander. */
new_action.sa_handler = sigint_handler;
sigemptyset(&new_action.sa_mask);
new_action.sa_flags = 0;
sigaction(SIGINT, NULL, &old_action);
if (old_action.sa_handler != SIG_IGN)
sigaction(SIGINT, &new_action, NULL);
}
int main(int argc, char *argv[])
{
cc_init_error_t init_error;
cc_start_error_t start_error;
ccapi_dp_b_error_t send_error;
UNUSED_ARGUMENT(argc);
add_sigkill_signal();
init_error = init_cloud_connection(NULL);
if (init_error != CC_INIT_ERROR_NONE) {
log_error("Cannot initialize cloud connection, error %d", init_error);
return EXIT_FAILURE;
}
start_error = start_cloud_connection();
if (start_error != CC_START_ERROR_NONE) {
log_error("Cannot start cloud connection, error %d", start_error);
return EXIT_FAILURE;
}
send_error = ccapi_dp_binary_send_file(CCAPI_TRANSPORT_TCP, UPLOAD_FILE, STREAM_NAME);
if (send_error != CCAPI_DP_B_ERROR_NONE) {
log_error("%s failed, error %d", __func__, send_error);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

View File

@ -17,7 +17,7 @@ RDEPENDS:${PN} = "\
${@bb.utils.contains("MACHINE_FEATURES", "mca", "dey-examples-adc-cmp \
dey-examples-tamper", "", d)} \
dey-examples-caamblob \
dey-examples-cloudconnector \
dey-examples-cccs \
dey-examples-digiapix \
dey-examples-rtc \
connectcore-demo-example-multimedia \