meta-digi-dey: add dey-examples-cloud-connector

These examples can be used to test Device Cloud functionality. There are three
test applications available:

 * device_request_listener: Listen for requests from the Device Cloud
 * upload_data_points: Upload test data points to the Device Cloud
 * upload_file: Uploads the contents of a file as binary data points

https://jira.digi.com/browse/DEL-3305
https://jira.digi.com/browse/DEL-3309
https://jira.digi.com/browse/DEL-3397

Signed-off-by: Diaz de Grenu, Jose <Jose.DiazdeGrenu@digi.com>
This commit is contained in:
Diaz de Grenu, Jose 2017-01-02 15:31:13 +01:00
parent 255030e94c
commit 368a3b5990
13 changed files with 765 additions and 0 deletions

View File

@ -0,0 +1,18 @@
SUMMARY = "DEY examples: Device cloud 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"
do_install() {
oe_runmake DESTDIR=${D} install
}
RDEPENDS_${PN} = "cloudconnector-cert"
COMPATIBLE_MACHINE = "(ccimx6$|ccimx6ul)"

View File

@ -0,0 +1,27 @@
#
# 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

@ -0,0 +1,38 @@
#
# 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.
#
PROGRAM := device_request_listener
CFLAGS += -Wall
CFLAGS += $(shell pkg-config --cflags cloudconnector)
LDLIBS += $(shell pkg-config --libs 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

@ -0,0 +1,88 @@
/*
* 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.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
* =======================================================================
*/
#include <signal.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include "device_request.h"
#define MAX_RESPONSE_SIZE 256
#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.
* @request_buffer_info: Buffer containing the device request.
* @response_buffer_info: Buffer to store the answer of the request.
*
* Logs information about the received request and executes the corresponding
* command.
*/
void get_time_cb(char const *const target,
ccapi_transport_t const transport,
ccapi_buffer_info_t const *const request_buffer_info,
ccapi_buffer_info_t *const response_buffer_info)
{
UNUSED_ARGUMENT(request_buffer_info);
log_debug("get_time_cb(): target='%s' - transport='%d'", target, transport);
response_buffer_info->buffer = malloc(sizeof(char) * MAX_RESPONSE_SIZE + 1);
if (response_buffer_info->buffer == NULL) {
log_error("%s\n", "get_time_cb(): response_buffer_info malloc error");
return;
}
time_t t = time(NULL);
response_buffer_info->length = snprintf(response_buffer_info->buffer,
MAX_RESPONSE_SIZE, "Time: %s", ctime(&t));
}
/*
* 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.
* @response_buffer_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 response_buffer_info,
ccapi_receive_error_t receive_error)
{
log_debug(
"get_time_status_cb(): target='%s' - transport='%d' - error='%d'",
target, transport, receive_error);
/* Free the response buffer */
if (response_buffer_info != NULL)
free(response_buffer_info->buffer);
}

View File

@ -0,0 +1,35 @@
/*
* 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.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
* =======================================================================
*/
#ifndef DEVICE_REQUEST_H_
#define DEVICE_REQUEST_H_
#include <cloudconnector/cloudconnector.h>
#define TARGET_GET_TIME "get_time"
void get_time_cb(char const *const target, ccapi_transport_t const transport,
ccapi_buffer_info_t const *const request_buffer_info,
ccapi_buffer_info_t *const response_buffer_info);
void get_time_status_cb(char const *const target,
ccapi_transport_t const transport,
ccapi_buffer_info_t *const response_buffer_info,
ccapi_receive_error_t receive_error);
#endif /* DEVICE_REQUEST_H_ */

View File

@ -0,0 +1,106 @@
/*
* 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.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, 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("sigint_handler(): received signal %d to close Cloud connection.\n", signum);
exit(0);
}
static void graceful_shutdown(void)
{
stop_cloud_connection();
wait_for_ccimp_threads();
}
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\n", 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\n", 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\n", TARGET_GET_TIME,
receive_error);
return EXIT_FAILURE;
}
printf("Waiting for Device Cloud request...\n");
printf("Press a key to exit\n");
getchar();
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,38 @@
#
# 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.
#
PROGRAM := upload_data_points
CFLAGS += -Wall
CFLAGS += $(shell pkg-config --cflags cloudconnector)
LDLIBS += $(shell pkg-config --libs 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

@ -0,0 +1,143 @@
/*
* 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.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, 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\n", 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;
}
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;
dp_error = ccapi_dp_create_collection(&collection);
if (dp_error != CCAPI_DP_ERROR_NONE) {
log_error("ccapi_dp_create_collection() error %d\n", 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("ccapi_dp_add_data_stream_to_collection_extra() error %d\n",
dp_error);
free(collection);
}
return dp_error;
}
ccapi_dp_error_t add_data_point(ccapi_dp_collection_handle_t dp_collection)
{
ccapi_dp_error_t dp_error;
ccapi_timestamp_t *timestamp = get_timestamp();
dp_error = ccapi_dp_add(dp_collection, STREAM_NAME, get_incremental(), timestamp);
if (dp_error != CCAPI_DP_ERROR_NONE) {
log_error("ccapi_dp_add() failed with error: %d\n", dp_error);
}
if (timestamp != NULL) {
if (timestamp->iso8601 != NULL) {
free((char *) timestamp->iso8601);
timestamp->iso8601 = NULL;
}
free(timestamp);
timestamp = NULL;
}
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\n");
dp_error = ccapi_dp_send_collection(CCAPI_TRANSPORT_TCP, dp_collection);
if (dp_error != CCAPI_DP_ERROR_NONE) {
log_error("ccapi_dp_send_collection() error %d\n", 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\n");
return ccapi_dp_destroy_collection(dp_collection);
}

View File

@ -0,0 +1,30 @@
/*
* 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.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, 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

@ -0,0 +1,116 @@
/*
* 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.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, 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("sigint_handler(): received signal %d to close Cloud connection.\n", signum);
exit(0);
}
static void graceful_shutdown(void)
{
if (running == 1) {
destroy_data_stream(dp_collection);
}
running = 0;
stop_cloud_connection();
wait_for_ccimp_threads();
}
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\n", 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\n", 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\n", 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\n", 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\n", start_error);
}
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,38 @@
#
# 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.
#
PROGRAM := upload_file
CFLAGS += -Wall
CFLAGS += $(shell pkg-config --cflags cloudconnector)
LDLIBS += $(shell pkg-config --libs 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

@ -0,0 +1,86 @@
/*
* 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.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, 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"
static void sigint_handler(int signum)
{
log_debug("sigint_handler(): received signal %d to close Cloud connection.\n", signum);
exit(0);
}
static void graceful_shutdown(void)
{
stop_cloud_connection();
wait_for_ccimp_threads();
}
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\n", 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\n", start_error);
return EXIT_FAILURE;
}
send_error = ccapi_dp_binary_send_file(CCAPI_TRANSPORT_TCP, argv[0], STREAM_NAME);
if (send_error != CCAPI_DP_B_ERROR_NONE) {
log_error("ccapi_dp_binary_send_file() failed, error %d\n", send_error);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

View File

@ -30,6 +30,7 @@ RDEPENDS_${PN}_append_ccimx6 = "\
${@bb.utils.contains("MACHINE_FEATURES", "bluetooth", "dey-examples-bt", "", d)} \
${@bb.utils.contains("MACHINE_FEATURES", "bluetooth", "dey-examples-btconfig", "", d)} \
dey-examples-can \
dey-examples-cloudconnector \
${@bb.utils.contains("MACHINE_FEATURES", "bluetooth", "dey-examples-hdp", "", d)} \
${@bb.utils.contains("MACHINE_FEATURES", "accel-graphics", "dey-examples-opengles", "", d)} \
dey-examples-v4l2 \
@ -40,6 +41,7 @@ RDEPENDS_${PN}_append_ccimx6ul = "\
${@bb.utils.contains("MACHINE_FEATURES", "bluetooth", "dey-examples-btconfig", "", d)} \
dey-examples-adc \
dey-examples-can \
dey-examples-cloudconnector \
${@bb.utils.contains("MACHINE_FEATURES", "bluetooth", "dey-examples-hdp", "", d)} \
dey-examples-tamper \
"