cccs: add ConnectCore Cloud Services upload binary file example
https://onedigi.atlassian.net/browse/DEL-8628 Signed-off-by: Tatiana Leon <Tatiana.Leon@digi.com>
This commit is contained in:
parent
a3435686c3
commit
b17458c8b7
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
SUBDIRS := \
|
||||
cccs-data-request-example \
|
||||
cccs-upload-binary-file-example \
|
||||
cccs-upload-data-points-example
|
||||
|
||||
all: $(SUBDIRS)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
#
|
||||
# Copyright 2023, Digi International Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and/or distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
BINARY := cccs-upload-binary-file-example
|
||||
|
||||
CFLAGS += -Wall
|
||||
|
||||
CFLAGS += $(shell pkg-config --cflags cccs)
|
||||
LDLIBS += $(shell pkg-config --libs --static cccs)
|
||||
|
||||
SRCS := $(wildcard *.c)
|
||||
OBJS := $(SRCS:.c=.o)
|
||||
|
||||
$(BINARY): $(OBJS)
|
||||
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
|
||||
|
||||
.PHONY: install
|
||||
install: $(BINARY)
|
||||
install -d $(DESTDIR)/usr/bin
|
||||
install -m 0755 $^ $(DESTDIR)/usr/bin/
|
||||
|
||||
.PHONY: all
|
||||
all: $(BINARY)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-rm -f *.o $(BINARY)
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
Digi ConnectCore Cloud Services Upload Binary File Example Application
|
||||
======================================================================
|
||||
|
||||
Example application to upload a binary file to Remote Manager using ConnectCore
|
||||
Cloud Services.
|
||||
|
||||
This application uploads the content of file `/etc/build` as a binary data point
|
||||
to stream `binary_dp`.
|
||||
|
||||
Running the application
|
||||
-----------------------
|
||||
This application requires `cccsd` (ConnectCore Cloud Services daemon) running
|
||||
on the device.
|
||||
|
||||
Once the binary is in the target, launch the application:
|
||||
|
||||
```
|
||||
# ./cccs-upload-binary-file-example
|
||||
cccs-upload-binary-file-example[35036]: [DEBUG] CCCSD: Connected to CCCSD (s=4)
|
||||
cccs-upload-binary-file-example[35036]: [DEBUG] CCCS daemon ready
|
||||
cccs-upload-binary-file-example[35036]: [INFO] Sending binary file '/etc/build'
|
||||
cccs-upload-binary-file-example[35036]: [INFO] DP: Sending data points to CCCSD
|
||||
cccs-upload-binary-file-example[35036]: [DEBUG] CCCSD: Connected to CCCSD (s=4)
|
||||
cccs-upload-binary-file-example[35036]: [DEBUG] CCCSD: Success from CCCSD
|
||||
cccs-upload-binary-file-example[35036]: [DEBUG] DP: Binary data point uploaded to 'binary_dp'
|
||||
#
|
||||
```
|
||||
|
||||
Compiling the application
|
||||
-------------------------
|
||||
This example can be compiled using a Digi Embedded Yocto based toolchain. Make
|
||||
sure to source the corresponding toolchain of the platform you are using,
|
||||
for example, for ConnectCore 6UL:
|
||||
|
||||
```
|
||||
~$ . <DEY-toolchain-path>/environment-setup-cortexa7t2hf-neon-dey-linux-gnueabi
|
||||
~$ make
|
||||
```
|
||||
|
||||
For more information, see the [Digi Embedded Yocto online documentation](https://github.com/digi-embedded/meta-digi).
|
||||
|
||||
License
|
||||
-------
|
||||
Copyright 2023, Digi International Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose
|
||||
with or without fee is hereby granted, provided that the above copyright notice
|
||||
and this permission notice appear in all copies.
|
||||
|
||||
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.
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright 2023, Digi International Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <cccs_services.h>
|
||||
#include <libgen.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define STREAM_NAME "binary_dp"
|
||||
#define UPLOAD_FILE "/etc/build"
|
||||
|
||||
/*
|
||||
* sigaction_handler() - Handler to execute after receiving a signal
|
||||
*
|
||||
* @signum: Received signal.
|
||||
*/
|
||||
static void sigaction_handler(int signum)
|
||||
{
|
||||
log_debug("%s: received signal %d", __func__, signum);
|
||||
|
||||
/* 'atexit' executes the cleanup function */
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* cleanup() - Frees all the allocated memory before exiting
|
||||
*/
|
||||
static void cleanup(void)
|
||||
{
|
||||
deinit_logger();
|
||||
}
|
||||
|
||||
/*
|
||||
* register_signals() - Registers program signals
|
||||
*/
|
||||
static void register_signals(void)
|
||||
{
|
||||
struct sigaction new_action;
|
||||
struct sigaction old_action;
|
||||
|
||||
atexit(cleanup);
|
||||
|
||||
new_action.sa_handler = sigaction_handler;
|
||||
new_action.sa_flags = 0;
|
||||
sigemptyset(&new_action.sa_mask);
|
||||
|
||||
sigaction(SIGINT, NULL, &old_action);
|
||||
if (old_action.sa_handler != SIG_IGN)
|
||||
sigaction(SIGINT, &new_action, NULL);
|
||||
|
||||
sigaction(SIGHUP, &old_action, NULL);
|
||||
if (old_action.sa_handler != SIG_IGN)
|
||||
sigaction(SIGHUP, &new_action, NULL);
|
||||
|
||||
sigaction(SIGTERM, &old_action, NULL);
|
||||
if (old_action.sa_handler != SIG_IGN)
|
||||
sigaction(SIGTERM, &new_action, NULL);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *name = basename(argv[0]);
|
||||
cccs_comm_error_t ret;
|
||||
cccs_resp_t resp;
|
||||
|
||||
init_logger(LOG_DEBUG, LOG_CONS | LOG_NDELAY | LOG_PID | LOG_PERROR, name);
|
||||
|
||||
register_signals();
|
||||
|
||||
if (!cccs_is_daemon_ready(CCCSD_NO_WAIT)) {
|
||||
log_error("%s: CCCS daemon not ready... exiting", __func__);
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
log_info("Sending binary file '%s'", UPLOAD_FILE);
|
||||
|
||||
ret = cccs_send_dp_binary_file(UPLOAD_FILE, STREAM_NAME, 5, &resp);
|
||||
if (ret != CCCS_SEND_ERROR_NONE) {
|
||||
log_error("%s: error sending binary file: CCCSD error %d", __func__, ret);
|
||||
} else if (resp.code != 0) {
|
||||
if (resp.hint)
|
||||
log_error("%s: error sending binary file: CCCSD error %s (%d)", __func__, resp.hint, resp.code);
|
||||
else
|
||||
log_error("%s: error sending binary file: CCCSD error %d", __func__, resp.code);
|
||||
}
|
||||
|
||||
free(resp.hint);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -270,4 +270,27 @@ The uploads takes place every 10 new samples, that is every 50 seconds.
|
|||
<platform>ccimx93-dvk</platform>
|
||||
</platforms>
|
||||
</sample>
|
||||
<sample id="cccs-upload-binary-file-example">
|
||||
<name>Digi CCCS upload binary file Example</name>
|
||||
<description>
|
||||
Example application to upload a binary file to Remote Manager using ConnectCore
|
||||
Cloud Services.
|
||||
This application uploads the content of file `/etc/build` as a binary data point
|
||||
to stream `binary_dp`.
|
||||
</description>
|
||||
<path>cccs-upload-binary-file-example</path>
|
||||
<platforms>
|
||||
<platform>ccimx6sbc</platform>
|
||||
<platform>ccimx6qpsbc</platform>
|
||||
<platform>ccimx6ulstarter</platform>
|
||||
<platform>ccimx6ulsbc</platform>
|
||||
<platform>ccimx8x-sbc-express</platform>
|
||||
<platform>ccimx8x-sbc-pro</platform>
|
||||
<platform>ccimx8mn-dvk</platform>
|
||||
<platform>ccimx8mm-dvk</platform>
|
||||
<platform>ccmp15-dvk</platform>
|
||||
<platform>ccmp13-dvk</platform>
|
||||
<platform>ccimx93-dvk</platform>
|
||||
</platforms>
|
||||
</sample>
|
||||
</samples>
|
||||
|
|
|
|||
Loading…
Reference in New Issue