EricssonResearch / calvin-constrained

C based implementation of Calvin runtime for constrained devices
Apache License 2.0
7 stars 7 forks source link

Compilation issues with CoAP client. #12

Open kulhadia opened 5 years ago

kulhadia commented 5 years ago

Hello, I am compiling the calvin-constrained with CoAP client and it fails. I am facing below-mentioned issues.

  1. In the Makefile (runtime/south/platform/x86/Makefile) CC_FLAGS, CC_LDFLAGS, and CC_LIBS entries are not retrieved as pkg-config command could not set the values for CC_FLAGS, CC_LDFLAGS, and CC_LIBS for libcoap package. ..... ifeq ($(LIBCOAP),1) CC_SRC_C += runtime/south/platform/x86/calvinsys/cc_libcoap_client.c CC_CFLAGS += -DCC_USE_LIBCOAP_CLIENT=1 CC_CFLAGS += $(shell pkg-config --cflags-only-I libcoap-1) CC_LDFLAGS += $(shell pkg-config --libs-only-L libcoap-1) CC_LIBS += $(shell pkg-config --libs-only-l libcoap-1) endif .......

As I could not locate the libcoap package by default, I installed it manually but I am not sure what to put into the .pc file for libcoap to make pkg-config command succeed.

libcoap Package installed : libcoap-1-0:amd64 4.1.2-1 amd64 C-Implementation of CoAP List of files owned by the package:
/. /usr /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/libcoap-1.so.0.0.0 /usr/share /usr/share/doc /usr/share/doc/libcoap-1-0 /usr/share/doc/libcoap-1-0/CONTRIBUTE.gz /usr/share/doc/libcoap-1-0/TODO /usr/share/doc/libcoap-1-0/changelog.Debian.gz /usr/share/doc/libcoap-1-0/copyright /usr/lib/x86_64-linux-gnu/libcoap-1.so.0

  1. coap.h not found (referred in runtime/south/platform/x86/calvinsys/cc_libcoap_client.c ).

Compilation Log: $ make -f runtime/south/platform/x86/Makefile LIBCOAP=1 CONFIG="runtime/south/platform/x86/cc_config_x86_coap.h" Renaming mp_decode_uint in msgpuck/msgpuck.h Package libcoap-1 was not found in the pkg-config search path. Perhaps you should add the directory containing libcoap-1.pc' to the PKG_CONFIG_PATH environment variable No package 'libcoap-1' found Package libcoap-1 was not found in the pkg-config search path. Perhaps you should add the directory containinglibcoap-1.pc' to the PKG_CONFIG_PATH environment variable No package 'libcoap-1' found Package libcoap-1 was not found in the pkg-config search path. Perhaps you should add the directory containing `libcoap-1.pc' to the PKG_CONFIG_PATH environment variable No package 'libcoap-1' found Building calvin gcc main.c runtime/south/platform/x86/cc_platform_x86.c runtime/south/transport/socket/cc_transport_socket.c runtime/south/platform/x86/calvinsys/cc_test_gpio.c runtime/south/platform/x86/calvinsys/cc_test_temperature.c runtime/south/platform/x86/calvinsys/cc_libcoap_client.c cc_api.c runtime/north/cc_common.c runtime/north/scheduler/np_scheduler/cc_scheduler.c runtime/north/cc_node.c runtime/north/cc_proto.c runtime/north/cc_transport.c runtime/north/cc_tunnel.c runtime/north/cc_link.c runtime/north/cc_actor_store.c runtime/north/cc_actor.c runtime/north/cc_port.c runtime/north/cc_fifo.c runtime/north/cc_token.c runtime/north/cc_app_manager.c msgpuck/msgpuck.c runtime/north/coder/cc_coder_msgpuck.c calvinsys/cc_calvinsys.c calvinsys/common/cc_calvinsys_timer.c calvinsys/common/cc_calvinsys_attribute.c calvinsys/common/cc_calvinsys_schedule.c jsmn/jsmn.c actors/sensor/cc_actor_accelerometer.c actors/sensor/cc_actor_coap_source.c actors/sensor/cc_actor_triggered_temperature.c actors/sensor/cc_actor_soil_moisture.c actors/sensor/cc_actor_temperature_tagged.c actors/sensor/cc_actor_temperature.c actors/sensor/cc_actor_gyroscope.c actors/io/cc_actor_light.c actors/io/cc_actor_button.c actors/io/cc_actor_log.c actors/std/cc_actor_counttimer.c actors/std/cc_actor_identity.c actors/context/cc_actor_registry_attribute.c actors/test/cc_actor_replica_identity.c actors/media/cc_actor_camera.c -o calvin_c -Wall -Os -fdata-sections -ffunction-sections -I. -DCC_USE_FDS=1 -DCC_USE_LIBCOAP_CLIENT=1 -DCC_CONFIGFILE_H=\""runtime/south/platform/x86/cc_config_x86_coap.h\"" -Wl,--gc-sections
runtime/south/transport/socket/cc_transport_socket.c: In function ‘cc_transport_socket_create’: runtime/south/transport/socket/cc_transport_socket.c:362:47: warning: ‘:’ directive writing 1 byte into a region of size between 0 and 39 [-Wformat-overflow=] sprintf(transport_client->uri, "calvinip://%s:%d", transport_socket->ip, transport_socket->port); ^ In file included from /usr/include/stdio.h:862:0, from runtime/south/transport/socket/cc_transport_socket.c:16: /usr/include/x86_64-linux-gnu/bits/stdio2.h:33:10: note: ‘builtin___sprintf_chk’ output between 14 and 63 bytes into a destination of size 50 return builtin_sprintf_chk (s, USE_FORTIFY_LEVEL - 1, ^~~~~~~~~~~~~~ bos (s), fmt, __va_arg_pack ());


runtime/south/platform/x86/calvinsys/cc_libcoap_client.c:26:10: **fatal error: coap/coap.h: No such file or directory
 #include <coap/coap.h>**
          ^~~~~~~~~~~~~
compilation terminated.
runtime/north/cc_app_manager.c: In function ‘cc_app_manager_load_script’:
runtime/north/cc_app_manager.c:241:17: warning: implicit declaration of function ‘cc_platform_file_read’; did you mean ‘cc_platform_mem_free’? [-Wimplicit-function-declaration]
   if ((result = cc_platform_file_read(script, &file_buffer, &size)) != CC_SUCCESS) {
                 ^~~~~~~~~~~~~~~~~~~~~
                 cc_platform_mem_free
actors/std/cc_actor_counttimer.c: In function ‘cc_actor_counttimer_fire’:
actors/std/cc_actor_counttimer.c:315:3: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
   if (cc_actor_counttimer_stop(actor))
   ^~
actors/std/cc_actor_counttimer.c:318:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
  return fired;
  ^~~~~~
runtime/south/platform/x86/Makefile:37: recipe for target 'calvin' failed
make: *** [calvin] Error 1
$

Could you please correct me if I am not following the right procedure to compile with coap client as compilation does not work for me out of the box.
Looking for your support.

Thanks!!  
fswensson commented 5 years ago

Hi,

If the package isn't available in your environment follow the installation instructions at https://libcoap.net/doc/install.html and change runtime/south/platform/x86/Makefile with:

ifeq ($(LIBCOAP),1) CC_SRC_C += runtime/south/platform/x86/calvinsys/cc_libcoap_client.c CC_CFLAGS += -DCC_USE_LIBCOAP_CLIENT=1 CC_CFLAGS += -I/usr/local/include/coap2 CC_LDFLAGS += -L/usr/local/lib -lcoap-2

CC_CFLAGS += $(shell pkg-config --cflags-only-I libcoap-1)

CC_LDFLAGS += $(shell pkg-config --libs-only-L libcoap-1)

CC_LIBS += $(shell pkg-config --libs-only-l libcoap-1)

endif

The Coap support in calvin-constrained has not been tested for a while and there was some errors and the library has been updated and I have updated calvin-constrained accordingly, so update the calvin-constrained repo to get the latest changes.

To test it first compile the constrained runtime with support for Coap:

make -f runtime/south/platform/x86/Makefile LIBCOAP=1 CONFIG="runtime/south/platform/x86/cc_config_x86_coap.h"

And to test it locally on the constrained runtime:

  1. Compile the calvin_scripts/temp_test.calvin script:

cscompiler calvin_scripts/temp_test.calvin python Tools/json2msgpack.py calvin_scripts/temp_test.json > calvin_scripts/temp_test.msgpack

  1. Start the constrained runtime with the temp_test script reading from a Coap source with URI coap://127.0.0.1:55654/3303/0/5700 (change it according to your environment):

./calvin_c -a '{"indexed_public": {"node_name": {"name": "constrained"}}}' -p '{"coap": {"actors": {"sensor.Temperature": "io.temperature"}, "capabilities": {"io.temperature": "coap://127.0.0.1:55654/3303/0/5700"}}}' -s calvin_scripts/temp_test.msgpack

To run it distributed with only the Coap actor on the constrained runtime:

  1. Start a calvin-base runtime:

csruntime -n 127.0.0.1 --name base

  1. Start a calvin-constrained runtime connecting to the base runtime.

./calvin_c -a '{"indexed_public": {"node_name": {"name": "constrained"}}}' -p '{"coap": {"actors": {"sensor.Temperature": "io.temperature"}, "capabilities": {"io.temperature": "coap://127.0.0.1:55654/3303/0/5700"}}}' -u '["calvinip://127.0.0.1:5000"]'

  1. Deploy a calvin-script that migrates a sensor actor to the constrained runtime:

temp : sensor.Temperature(period=1) snk : io.Print()

temp.centigrade > snk.token

rule device: node_attr_match(node_name={"name": "constrained"}) apply temp: device

Br Fredrik