Giter VIP home page Giter VIP logo

cesarbr / knot-service-source Goto Github PK

View Code? Open in Web Editor NEW
4.0 19.0 19.0 1.04 MB

KNoT Service is part of KNoT project. It aims to provide a "proxy" service between KNoT Things and KNoT Cloud, allowing power constrained embedded device to interact with cloud services. The initial target platform are PAN devices, and Raspberry Pi GW. The PAN device used is a highly integrated, ultra low power (ULP) 2Mbps RF transceiver IC for the 2.4GHz ISM band (NRF24L01). On a second project phase, other radio access technologies such as LPWAN devices, Mesh devices, 3G Devices, Bluetooth Low Energy Devices, and Wi-Fi Devices are planned.

License: GNU Lesser General Public License v2.1

Makefile 0.57% M4 0.92% Shell 0.15% C++ 1.75% C 43.30% Python 3.68% Perl 48.78% Dockerfile 0.84%

knot-service-source's Introduction

	KNOT Service for Linux systems

KNOT service is part of KNOT project. It aims to provide a "proxy" service
for KNOT nodes, allowing power constrained embedded device to interact
with Meshblu cloud services.

The initial target platform are nRF24L01 nodes, and Raspiberry PI GW. nRF24L01
is a highly integrated, ultra low power (ULP) 2Mbps RF transceiver IC for the
2.4GHz ISM band. On a second project phase, other radio access technologies
such as Bluetooth Low Energy, and Wi-Fi are planned.

Dependencies:
knot-protocol-source
knot-hal-source
knot-cloud-sdk-c
ell >= 0.4
json-c v0.13.1
automake
libtool
libssl-dev
valgrind (optional)

How to install dependencies:
	$sudo apt-get install automake libtool libssl-dev valgrind

	To install libell, you have to clone the repository and follow the instructions:
		git://git.kernel.org/pub/scm/libs/ell/ell.git
	To install the latest version of json-c, you have to clone the repository and follow the instructions:
		https://github.com/json-c/json-c/releases/tag/json-c-0.13.1-20180305

How to build:
You have to install the knot-protocol-source and the knot-hal-source,
sothen you can run:
$./bootstrap-configure && make

How to check for memory leaks and open file descriptors:
$valgrind --leak-check=full --track-fds=yes ./src/knotd \
--config=src/knotd.conf --proto=ws

How to test (Unix sockets):
$src/knotd
$tools/ktool connect

How to run 'knotd' specifying host & port:
$src/knotd --config=./src/knotd.conf --proto=ws --host=localhost --port=3000

knot-service-source's People

Contributors

alla3 avatar cktakahasi avatar dvnp avatar figueredo avatar flaviocastrofilho avatar fnba avatar fnbalves avatar heitorfonseca avatar jcorde avatar pauloserrafh avatar ramonhpr avatar rodrigoalves1 avatar vitbaq avatar wiltonsantana avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

knot-service-source's Issues

Remove glib dependency

The glib library isn't being used anymore. Therefore, we need to remove this dependency from the knot service daemon.

cktakahasi$ grep -rnsi 
glibunit/inettest.c:30:#include <glib.h>
unit/ktest.c:30:#include <glib.h>
configure.ac:30:PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.28, dummy=no,
configure.ac:31: AC_MSG_ERROR(required glib >= 2.28))
configure.ac:32:AC_SUBST(GLIB_CFLAGS)
configure.ac:33:AC_SUBST(GLIB_LIBS)
Makefile.am:51:tools_ktool_LDADD = @GLIB_LIBS@
@JSON_LIBS@ @KNOTPROTO_LIBS@ @KNOTHAL_LIBS@
Makefile.am:53:tools_ktool_CFLAGS = $(AM_CFLAGS)
@JSON_CFLAGS@ @GLIB_CFLAGS@
@KNOTPROTO_CFLAGS@ @KNOTHAL_CFLAGS@
Makefile.am:57:unit_ktest_LDADD = @GLIB_LIBS@
@KNOTPROTO_LIBS@ @KNOTHAL_LIBS@
Makefile.am:59:unit_ktest_CFLAGS = $(AM_CFLAGS)
@GLIB_CFLAGS@ @KNOTPROTO_CFLAGS@
@KNOTHAL_CFLAGS@
Makefile.am:63:unit_inettest_LDADD = @GLIB_LIBS@
@KNOTPROTO_LIBS@ @KNOTHAL_LIBS@
Makefile.am:65:unit_inettest_CFLAGS = $(AM_CFLAGS)
@GLIB_CFLAGS@ @KNOTPROTO_CFLAGS@
@KNOTHAL_CFLAGS@
README:16:glib >= 2.28
README:25: $sudo apt-get install automake libtool glib2.0 libssl-dev valgrind 
tools/ktool.c:33:#include <glib.h>
src/node.h:46: * they can be alternatives to integrate to glib main loop or other

Replace downstream_callback

The downstream_callback function is called after setting a timeout when receives a command from the cloud. But now with AMQP protocol, it is possible to send to the thing at the moment it is received the command.

DoD:

  • The callback downstream_callback should be removed
  • The callback handle_downstream_message should send a specific message (data request or update data) to the thing.

Error is not displayed when gateway configuration file is not informed

We should show an error when gatewayConfig.json file isn't informed properly.

futex(0x7fd3545be868, FUTEX_WAKE_PRIVATE, 2147483647) = 0
openat(AT_FDCWD, "/etc/knot/gatewayConfig.json", O_RDONLY) = -1 ENOENT (No such file or directory)
exit_group(1) = ?
+++ exited with 1 +++
~/Work/knot/knot-service-source.git (master*) [03:04:14]

cktakahasi$ src/knotd --host=knot-test.cesar.org.br --port=3000 --nodetach 
~/Work/knot/knot-service-source.git (master*) [03:04:17]

Crash when send unregister message in rollback

How to reproduce:

  • start knotd
  • start mock-connector
  • after knotd receives the list message stop mock-connector
  • start test-conn to register device (it will receive an unregister request since no response can be provided by mock connector)
  • start test-conn (knotd will receive a SIGSEGV)

Test in valgrind:

knotd[32058]: Receive 2, exchange fog routingkey device.registered
knotd[32058]: Body: {"id":"0123456789abcdef","name":"Test"}
knotd[32058]: Malformed JSON message
knotd[32058]: Destroy received envelope
knotd[32058]: [session 0x6a87820] Waiting schema...
knotd[32058]: [session 0x6a87820] Waiting schema...
knotd[32058]: [session 0x6a87820] Waiting schema...
knotd[32058]: [session 0x6a87820] Waiting schema...
knotd[32058]: [session 0x6a87820] Waiting schema...
knotd[32058]: [session 0x6a87820] Removing (null) (rollback)
knotd[32058]: [session 0x6a87820] Sending downstream data fd(12)...
knotd[32058]: [session 0x6a87820] disconnected (node)
knotd[32058]: session_unref(0x6a87820): 1
knotd[32058]: session_unref(0x6a87820): 0
knotd[32058]: session_ref(0x6ab48a0): 1
knotd[32058]: session_ref(0x6ab48a0): 2
knotd[32058]: [session 0x6ab48a0] Session created
knotd[32058]: [session 0x6ab48a0] KNOT OP: 0x10 LEN: 48
knotd[32058]: [session 0x6ab48a0] Registering (id 0x0123456789abcdef)
knotd[32058]: Receive 3, exchange fog routingkey device.registered
knotd[32058]: Body: {"id":"0123456789abcdef","name":"Test"}
knotd[32058]: Malformed JSON message
knotd[32058]: Destroy received envelope
knotd[32058]: [session 0x6ab48a0] Waiting schema...
knotd[32058]: [session 0x6ab48a0] Waiting schema...
knotd[32058]: [session 0x6ab48a0] Waiting schema...
knotd[32058]: [session 0x6ab48a0] Waiting schema...
knotd[32058]: [session 0x6ab48a0] Waiting schema...
knotd[32058]: [session 0x6ab48a0] Removing (null) (rollback)
knotd[32058]: [session 0x6ab48a0] Sending downstream data fd(12)...
knotd[32058]: [session 0x6ab48a0] KNOT OP: 0x13 LEN: 00
==32058== Invalid read of size 1
==32058==    at 0x4C33DA3: strcmp (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32058==    by 0x10C07C: device_uuid_cmp (msg.c:192)
==32058==    by 0x4E49F40: l_queue_find (queue.c:346)
==32058==    by 0x10CE56: msg_unregister_resp (msg.c:761)
==32058==    by 0x10CE56: msg_process (msg.c:873)
==32058==    by 0x10CE56: session_node_data_cb (msg.c:965)
==32058==    by 0x4E4E322: io_callback (io.c:126)
==32058==    by 0x4E4D5B9: l_main_iterate (main.c:473)
==32058==    by 0x4E4D68B: l_main_run (main.c:520)
==32058==    by 0x4E4D8AA: l_main_run_with_signal (main.c:642)
==32058==    by 0x10BBBA: l_main_loop_run (main.c:75)
==32058==    by 0x10BBBA: main (main.c:141)
==32058==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==32058== 
==32058== 
==32058== Process terminating with default action of signal 11 (SIGSEGV)
==32058==  Access not within mapped region at address 0x0
==32058==    at 0x4C33DA3: strcmp (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32058==    by 0x10C07C: device_uuid_cmp (msg.c:192)
==32058==    by 0x4E49F40: l_queue_find (queue.c:346)
==32058==    by 0x10CE56: msg_unregister_resp (msg.c:761)
==32058==    by 0x10CE56: msg_process (msg.c:873)
==32058==    by 0x10CE56: session_node_data_cb (msg.c:965)
==32058==    by 0x4E4E322: io_callback (io.c:126)
==32058==    by 0x4E4D5B9: l_main_iterate (main.c:473)
==32058==    by 0x4E4D68B: l_main_run (main.c:520)
==32058==    by 0x4E4D8AA: l_main_run_with_signal (main.c:642)
==32058==    by 0x10BBBA: l_main_loop_run (main.c:75)
==32058==    by 0x10BBBA: main (main.c:141)
==32058==  If you believe this happened as a result of a stack
==32058==  overflow in your program's main thread (unlikely but
==32058==  possible), you can try to increase the size of the
==32058==  main thread stack using the --main-stacksize= flag.
==32058==  The main thread stack size used in this run was 8388608.
==32058== 

Destroy json object if couldn't declare queue

The functions: cloud_register_device, cloud_unregister_device, cloud_list_devices have a leak memory caused by the function amqp_declare_new_queue which raises an error due json_object isn't freed.

Send 'data' messages to message queue

  • Replace msg_data to use rabbitmq
  • Declare exchange cloud
  • Remove parsing function from proto.c to parser.c
  • Publish on binding key data.publish
  • Create function rabbitmq_publish_persistent_message

Add Docker container

It is possible to have a container docker that can run the inetbrd exposing the ports to other things. And also It should be possible to expose the DBus as TCP besides the default UNIX socket for clients handle the things.

Investigate RabbitMQ integration

As a developer, I want to understand how to use the rabbitmq-c library in order to communicate with the RabbitMQ server.

DoD:

  • Create basic examples with the library
  • Create examples with libell
  • Define new internal architecture
  • Define stories

Unable to build service with cloud-sdk-c version KNOT-v03.00-rc04

Unable to build knotd with cloud-sdk-c version KNOT-v03.00-rc04.
It seems to be related to the commit 1bdb2dd9800b4840d3152ca0435497e115f995ff changes the struct access to the schema field.
I think these changes were not reflected in the knotd code.

  CC       src/knotd-main.o
  CC       src/knotd-storage.o
  CC       src/knotd-settings.o
  CC       src/knotd-manager.o
  CC       src/knotd-msg.o
src/msg.c: In function 'knot_cloud_device_free':
src/msg.c:142:26: error: 'struct knot_cloud_device' has no member named 'schema'
  l_queue_destroy(mydevice->schema, l_free);
                          ^~
src/msg.c: In function 'schema_dup_foreach':
src/msg.c:153:2: error: unknown type name 'knot_msg_schema'; did you mean 'knot_schema'?
  knot_msg_schema *msg = data;
  ^~~~~~~~~~~~~~~
  knot_schema
src/msg.c: In function 'mydevice_dup':
src/msg.c:167:14: error: 'struct knot_cloud_device' has no member named 'schema'
  mydevice_dup->schema = l_queue_new();
              ^~
src/msg.c:169:26: error: 'const struct knot_cloud_device' has no member named 'schema'
  l_queue_foreach(mydevice->schema, schema_dup_foreach,
                          ^~
src/msg.c:170:16: error: 'struct knot_cloud_device' has no member named 'schema'
    mydevice_dup->schema);
                ^~
src/msg.c: In function 'schema_sensor_id_cmp':
src/msg.c:192:8: error: unknown type name 'knot_msg_schema'
  const knot_msg_schema *schema = entry_data;
        ^~~~~~~~~~~~~~~
src/msg.c:195:28: error: request for member 'sensor_id' in something not a structure or union
  return sensor_id == schema->sensor_id;
                            ^~
src/msg.c: At top level:
src/msg.c:198:8: error: unknown type name 'knot_msg_schema'
 static knot_msg_schema *schema_find(struct l_queue *schema,
        ^~~~~~~~~~~~~~~
src/msg.c: In function 'msg_register':
src/msg.c:335:16: error: 'struct knot_cloud_device' has no member named 'schema'
  device_pending->schema = l_queue_new();
                ^~
src/msg.c: In function 'msg_auth':
src/msg.c:502:33: error: 'struct knot_cloud_device' has no member named 'schema'
  l_queue_foreach(session->device->schema, schema_dup_foreach,
                                 ^~
src/msg.c: At top level:
src/msg.c:509:11: error: unknown type name 'knot_msg_schema'
     const knot_msg_schema *schema, bool eof)
           ^~~~~~~~~~~~~~~
src/msg.c: In function 'msg_schema':
src/msg.c:515:35: error: request for member 'values' in something not a structure or union
  err = knot_schema_is_valid(schema->values.type_id,
                                   ^~
src/msg.c:516:14: error: request for member 'values' in something not a structure or union
        schema->values.value_type,
              ^~
src/msg.c:517:14: error: request for member 'values' in something not a structure or union
        schema->values.unit);
              ^~
src/msg.c:539:47: error: request for member 'sensor_id' in something not a structure or union
  if (!schema_find(session->schema_list, schema->sensor_id))
                                               ^~
src/msg.c:545:12: error: implicit declaration of function 'knot_cloud_update_schema'; did you mean 'knot_cloud_update_config'? [-Werror=implicit-function-declaration]
   result = knot_cloud_update_schema(id, session->schema_list);
            ^~~~~~~~~~~~~~~~~~~~~~~~
            knot_cloud_update_config
src/msg.c: In function 'msg_data':
src/msg.c:558:8: error: unknown type name 'knot_msg_schema'
  const knot_msg_schema *schema;
        ^~~~~~~~~~~~~~~
src/msg.c:584:25: error: request for member 'values' in something not a structure or union
        sensor_id, schema->values.unit, schema->values.value_type);
                         ^~
src/msg.c:584:46: error: request for member 'values' in something not a structure or union
        sensor_id, schema->values.unit, schema->values.value_type);
                                              ^~
src/msg.c:588:13: error: request for member 'values' in something not a structure or union
       schema->values.value_type,
             ^~
src/msg.c: In function 'msg_setdata_resp':
src/msg.c:604:8: error: unknown type name 'knot_msg_schema'
  const knot_msg_schema *schema;
        ^~~~~~~~~~~~~~~
src/msg.c:636:34: error: request for member 'values' in something not a structure or union
        session, sensor_id, schema->values.unit,
                                  ^~
src/msg.c:637:14: error: request for member 'values' in something not a structure or union
        schema->values.value_type);
              ^~
src/msg.c:641:13: error: request for member 'values' in something not a structure or union
       schema->values.value_type,
             ^~
src/msg.c: In function 'msg_process':
src/msg.c:759:37: error: 'knot_msg' {aka 'const union <anonymous>'} has no member named 'schema'
   result = msg_schema(session, &kreq->schema, false);
                                     ^~
src/msg.c:762:37: error: 'knot_msg' {aka 'const union <anonymous>'} has no member named 'schema'
   result = msg_schema(session, &kreq->schema, true);
                                     ^~
src/msg.c: In function 'handle_schema_updated':
src/msg.c:1148:19: error: 'struct knot_cloud_device' has no member named 'schema'
    session->device->schema);
                   ^~
src/msg.c: In function 'create_devices_dbus':
src/msg.c:1207:28: error: 'const struct knot_cloud_device' has no member named 'schema'
  bool registered = mydevice->schema != NULL;
                            ^~
src/msg.c: In function 'send_pool_data_msg_foreach':
src/msg.c:1267:2: error: unknown type name 'knot_msg_schema'; did you mean 'knot_schema'?
  knot_msg_schema *schema_found;
  ^~~~~~~~~~~~~~~
  knot_schema
src/msg.c: In function 'on_cloud_receive':
src/msg.c:1345:7: error: 'SCHEMA_MSG' undeclared (first use in this function); did you mean 'EBADMSG'?
  case SCHEMA_MSG:
       ^~~~~~~~~~
       EBADMSG
src/msg.c:1345:7: note: each undeclared identifier is reported only once for each function it appears in
src/msg.c:1331:2: error: enumeration value 'CONFIG_MSG' not handled in switch [-Werror=switch-enum]
  switch (msg->type) {
  ^~~~~~
src/msg.c: In function 'schema_sensor_id_cmp':
src/msg.c:196:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
cc1: all warnings being treated as errors
make: *** [Makefile:901: src/knotd-msg.o] Error 1

knotd retrying to write value to Thing for all types of error

knotd tries to write new values to Thing even after receiving a KNOT_ERR_INVALID message.

Retries should be done only in specific cases, such as signal loss or when explicitly told to do so.

This leads to extra effort trying to do something that is impossible.

Authenticate devices

  • List devices on start
  • Send 'authenticate' command to message queue
  • Implement 'authenticate' on connector

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.