Skip to contentSkip to conversation

Introducing Soletta peripheral node-type

RFC In review Vinicius Costa Gomes 2 participants 16 messages Jul 2, 2015 – Jul 3, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Introducing Soletta peripheral node-type

Hi,

We have been working on Soletta[1] for a few months and now that it has been open sourced, it makes sense to show what it can do using BlueZ. This implements a very simple node type that behaves as a Heart Rate Sensor in the peripheral mode.

Just a overview about Soletta, it provides a way to write IoT applications targeting a broad range of devices (from the smallest edge to the smarttest hub).

You would express your application logic using a Flow Based language to connect various nodes, write your custom node types using the libsolleta C API. And the Soletta developers would worry about porting the libsoletta library to the multitude of targets and providing a useful collection of node types.

Using the support we already have in BlueZ for the Bluetooth LE peripheral mode, writing a Soletta node type for the Heartrate Sensor role seems a very good match. And it brings some very interesting use cases with the linux-micro target.

The way I thought best about integrating BlueZ with Soletta was to add another mainloop backend using libsoletta so every event would be handled consistently. See patch 02/13.

Most of the changes not related to either adding the mainloop support, or adding the node type code are related to some lack of configurability to the peripheral code, perhaps having a way to the callback that will register the service to have a say in some parameters?

The most important question is: is BlueZ the right place to have this code?

What do you say?

Any questions about the project, we are hanging out in #soletta @ freenode.net.

Cheers,

[1] https://github.com/solettaproject/soletta

Vinicius Costa Gomes (13):
build: Add configure-time checks for soletta
shared: Add a mainloop implementation using soletta peripheral/gatt: Fix usage of mainloop_ functions peripheral/gatt: Add a way to external services to register services peripheral/gap: Fix missing includes
peripheral/gap: Init the gatt_server
peripheral: Disable support for static random addresses peripheral/gap: Set the discoverable flag in the advertising peripheral/gatt: Use LOW security level soletta/heartrate: Add a node-type for the Heartrate profile .gitignore: Ignore soletta generated files
build: Add heartrate soletta node type to the build system
soletta: Add a sample flow using the heartrate node

 .gitignore                   |   4 +
 Makefile.am                  |   7 +-
 Makefile.tools               |  20 +++
 configure.ac                 |  38 ++++++
 peripheral/gap.c             |  12 +-
 peripheral/gatt.c            | 124 ++++++++++++-----
 peripheral/gatt.h            |   6 +
 soletta/heartrate-src.json   |  30 +++++
 soletta/heartrate.c          | 298 ++++++++++++++++++++++++++++++++++++++++
 soletta/heartrate.fbp        |   1 +
 soletta/sol-flow.conf        |   2 +
 src/shared/io-soletta.c      | 315 +++++++++++++++++++++++++++++++++++++++++++
 src/shared/timeout-soletta.c | 112 +++++++++++++++
 13 files changed, 934 insertions(+), 35 deletions(-)
 create mode 100644 soletta/heartrate-src.json
 create mode 100644 soletta/heartrate.c
 create mode 100644 soletta/heartrate.fbp
 create mode 100644 soletta/sol-flow.conf
 create mode 100644 src/shared/io-soletta.c
 create mode 100644 src/shared/timeout-soletta.c

--
2.4.5

#1 lore raw

RFC 1/13 build: Add configure-time checks for soletta

The idea will be to re-use the work done in peripheral/ so we can easily export node types for common Bluetooth profiles (the focus right now is GATT profiles).

[1] https://github.com/solettaproject/soletta

---
 configure.ac | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
configure.ac +38 -0
index c65d19a..5c3f832 100644
@@ -283,4 +283,42 @@ fi
 AC_DEFINE_UNQUOTED(ANDROID_STORAGEDIR, "${storagedir}/android",
 			[Directory for the Android daemon storage files])
 
+AC_ARG_ENABLE(soletta, AC_HELP_STRING([--enable-soletta],
+			[enable building BlueZ soletta nodes]),
+					[enable_soletta=${enableval}])
+AM_CONDITIONAL(SOLETTA, test "${enable_soletta}" = "yes")
+
+if (test "${enable_soletta}" = "yes"); then
+	PKG_CHECK_MODULES(SOLETTA, soletta, dummy=yes,
+					AC_MSG_ERROR(soletta is required))
+	AC_SUBST(SOLETTA_CFLAGS)
+	AC_SUBST(SOLETTA_LIBS)
+	solettaprefix="`$PKG_CONFIG --variable=prefix soletta`"
+	AC_SUBST(SOLETTA_PREFIX, [${solettaprefix}])
+fi
+
+AC_ARG_WITH([solettamodulesdir], AC_HELP_STRING([--with-solettamodulesdir=DIR],
+			[path to soletta modules directory]), [path_solettamodulesdir=${withval}])
+if (test "${enable_soletta}" != "no" && test -z "${path_solettamodulesdir}"); then
+	AC_MSG_CHECKING([soletta modules directory])
+	path_solettamodulesdir="`$PKG_CONFIG --variable=modulesdir soletta`"
+	if (test -z "${path_solettamodulesdir=}"); then
+		AC_MSG_ERROR([soletta modules directory is required])
+	fi
+	AC_MSG_RESULT([${path_solettamodulesdir}])
+fi
+AC_SUBST(SOLETTA_MODULESDIR, [${path_solettamodulesdir}])
+
+AC_ARG_WITH([solettadescdir], AC_HELP_STRING([--with-solettadescdir=DIR],
+			[path to soletta node type descriptions directory]), [path_solettadescdir=${withval}])
+if (test "${enable_soletta}" != "no" && test -z "${path_solettadescdir}"); then
+	AC_MSG_CHECKING([soletta modules directory])
+	path_solettadescdir="`$PKG_CONFIG --variable=pkgdatadir soletta`"
+	if (test -z "${path_solettadescdir=}"); then
+		AC_MSG_ERROR([soletta descriptions directory is required])
+	fi
+	AC_MSG_RESULT([${path_solettadescdir}])
+fi
+AC_SUBST(SOLETTA_DESCDIR, [${path_solettadescdir}])
+
 AC_OUTPUT(Makefile src/bluetoothd.8 lib/bluez.pc)
Signature · 1 line
2.4.5
#2 lore raw

RFC 2/13 shared: Add a mainloop implementation using soletta

In reply to Vinicius Costa Gomes

This will allow apps willing to integrate directly with the solleta mainloop, with no need to implement custom ways (threads and pipes) to communicate via Bluetooth and send/receive soletta flow packets.

---
 Makefile.am                  |   7 +-
 src/shared/io-soletta.c      | 315 +++++++++++++++++++++++++++++++++++++++++++
 src/shared/timeout-soletta.c | 112 +++++++++++++++
 3 files changed, 433 insertions(+), 1 deletion(-)
 create mode 100644 src/shared/io-soletta.c
 create mode 100644 src/shared/timeout-soletta.c
Makefile.am +6 -1
index 76d1723..f300d32 100644
@@ -95,7 +95,7 @@ gdbus_libgdbus_internal_la_SOURCES = gdbus/gdbus.h \
 				gdbus/mainloop.c gdbus/watch.c \
 				gdbus/object.c gdbus/client.c gdbus/polkit.c
 
-noinst_LTLIBRARIES += src/libshared-glib.la src/libshared-mainloop.la
+noinst_LTLIBRARIES += src/libshared-glib.la src/libshared-mainloop.la src/libshared-soletta.la
 
 shared_sources = src/shared/io.h src/shared/timeout.h \
 			src/shared/queue.h src/shared/queue.c \
@@ -128,6 +128,11 @@ src_libshared_mainloop_la_SOURCES = $(shared_sources) \
 				src/shared/io-mainloop.c \
 				src/shared/timeout-mainloop.c \
 				src/shared/mainloop.h src/shared/mainloop.c
+if SOLETTA
+src_libshared_soletta_la_SOURCES = $(shared_sources) \
+				src/shared/io-soletta.c \
+				src/shared/timeout-soletta.c
+endif
 
 attrib_sources = attrib/att.h attrib/att-database.h attrib/att.c \
 		attrib/gatt.h attrib/gatt.c \
src/shared/io-soletta.c new file +315 -0

315 lines not on this page · raw message

src/shared/timeout-soletta.c new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.4.5
#3 lore raw

RFC 3/13 peripheral/gatt: Fix usage of mainloop_ functions

In reply to Vinicius Costa Gomes

If we want that this example is mainloop agnostic, it should use the mainloop agnostic functions.

---
 peripheral/gatt.c | 72 +++++++++++++++++++++++++++++++++----------------------
 1 file changed, 43 insertions(+), 29 deletions(-)
peripheral/gatt.c +43 -29
index 4c5531d..a66292f 100644
@@ -25,6 +25,7 @@
 #include <config.h>
 #endif
 
+#include <errno.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -34,7 +35,7 @@
 #include "lib/bluetooth.h"
 #include "lib/l2cap.h"
 #include "lib/uuid.h"
-#include "src/shared/mainloop.h"
+#include "src/shared/io.h"
 #include "src/shared/util.h"
 #include "src/shared/queue.h"
 #include "src/shared/att.h"
@@ -53,7 +54,7 @@ struct gatt_conn {
 	struct bt_gatt_client *client;
 };
 
-static int att_fd = -1;
+static struct io *att_io = NULL;
 static struct queue *conn_list = NULL;
 static struct gatt_db *gatt_db = NULL;
 static struct gatt_db *gatt_cache = NULL;
@@ -153,41 +154,43 @@ static struct gatt_conn *gatt_conn_new(int fd)
 	return conn;
 }
 
-static void att_conn_callback(int fd, uint32_t events, void *user_data)
+static bool att_conn_callback(struct io *io, void *user_data)
 {
 	struct gatt_conn *conn;
 	struct sockaddr_l2 addr;
 	socklen_t addrlen;
-	int new_fd;
+	int fd, new_fd;
 
-	if (events & (EPOLLERR | EPOLLHUP)) {
-		mainloop_remove_fd(fd);
-		return;
-	}
+	fd = io_get_fd(io);
+
+	fprintf(stderr, "att_conn_callback io %p\n", io);
 
 	memset(&addr, 0, sizeof(addr));
 	addrlen = sizeof(addr);
 
-	new_fd = accept(att_fd, (struct sockaddr *) &addr, &addrlen);
+	new_fd = accept(fd, (struct sockaddr *) &addr, &addrlen);
 	if (new_fd < 0) {
 		fprintf(stderr, "Failed to accept new ATT connection: %m\n");
-		return;
+		return true;
 	}
 
 	conn = gatt_conn_new(new_fd);
 	if (!conn) {
 		fprintf(stderr, "Failed to create GATT connection\n");
 		close(new_fd);
-		return;
+		return true;
 	}
 
 	if (!queue_push_tail(conn_list, conn)) {
 		fprintf(stderr, "Failed to add GATT connection\n");
 		gatt_conn_destroy(conn);
 		close(new_fd);
+		return true;
 	}
 
 	printf("New device connected\n");
+
+	return true;
 }
 
 static void gap_device_name_read(struct gatt_db_attribute *attrib,
@@ -243,13 +246,16 @@ static void populate_devinfo_service(struct gatt_db *db)
 void gatt_server_start(void)
 {
 	struct sockaddr_l2 addr;
+	int fd;
+
+	fprintf(stderr, "gatt_server_start\n");
 
-	if (att_fd >= 0)
+	if (att_io)
 		return;
 
-	att_fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET | SOCK_CLOEXEC,
+	fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET | SOCK_CLOEXEC | SOCK_NONBLOCK,
 							BTPROTO_L2CAP);
-	if (att_fd < 0) {
+	if (fd < 0) {
 		fprintf(stderr, "Failed to create ATT server socket: %m\n");
 		return;
 	}
@@ -260,24 +266,21 @@ void gatt_server_start(void)
 	memcpy(&addr.l2_bdaddr, static_addr, 6);
 	addr.l2_bdaddr_type = BDADDR_LE_RANDOM;
 
-	if (bind(att_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+	if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
 		fprintf(stderr, "Failed to bind ATT server socket: %m\n");
-		close(att_fd);
-		att_fd = -1;
+		close(fd);
 		return;
 	}
 
-	if (listen(att_fd, 1) < 0) {
+	if (listen(fd, 1) < 0) {
 		fprintf(stderr, "Failed to listen on ATT server socket: %m\n");
-		close(att_fd);
-		att_fd = -1;
+		close(fd);
 		return;
 	}
 
 	gatt_db = gatt_db_new();
 	if (!gatt_db) {
-		close(att_fd);
-		att_fd = -1;
+		close(fd);
 		return;
 	}
 
@@ -290,20 +293,33 @@ void gatt_server_start(void)
 	if (!conn_list) {
 		gatt_db_unref(gatt_db);
 		gatt_db = NULL;
-		close(att_fd);
-		att_fd = -1;
+		close(fd);
+		return;
+	}
+
+	att_io = io_new(fd);
+
+	fprintf(stderr, "att_io %p\n", att_io);
+
+	if (!att_io) {
+		gatt_db_unref(gatt_db);
+		gatt_db = NULL;
+		close(fd);
+		queue_destroy(conn_list, NULL);
 		return;
 	}
 
-	mainloop_add_fd(att_fd, EPOLLIN, att_conn_callback, NULL, NULL);
+	if (!io_set_read_handler(att_io, att_conn_callback, NULL, NULL))
+		fprintf(stderr, "Failed to add read handler\n");
 }
 
 void gatt_server_stop(void)
 {
-	if (att_fd < 0)
+	if (!att_io)
 		return;
 
-	mainloop_remove_fd(att_fd);
+	io_destroy(att_io);
+	att_io = NULL;
 
 	queue_destroy(conn_list, gatt_conn_destroy);
 
@@ -313,6 +329,4 @@ void gatt_server_stop(void)
 	gatt_db_unref(gatt_db);
 	gatt_db = NULL;
 
-	close(att_fd);
-	att_fd = -1;
 }
Signature · 1 line
2.4.5
#4 lore raw

RFC 4/13 peripheral/gatt: Add a way to external services to register services

In reply to Vinicius Costa Gomes

This will allow profiles implemented using the peripheral/ helpers to register asynchronously their services. This cannot be done directly because when gatt_service_start() the GATT database doesn't exist yet.

---
 peripheral/gatt.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 peripheral/gatt.h |  6 ++++++
 2 files changed, 53 insertions(+)
peripheral/gatt.c +47 -0
index a66292f..a859adc 100644
@@ -54,6 +54,11 @@ struct gatt_conn {
 	struct bt_gatt_client *client;
 };
 
+struct service_registerer_data {
+	gatt_service_register_t callback;
+	void *user_data;
+};
+
 static struct io *att_io = NULL;
 static struct queue *conn_list = NULL;
 static struct gatt_db *gatt_db = NULL;
@@ -63,6 +68,8 @@ static uint8_t static_addr[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 static uint8_t dev_name[20];
 static uint8_t dev_name_len = 0;
 
+static struct queue *registered_services = NULL;
+
 void gatt_set_static_address(uint8_t addr[6])
 {
 	memcpy(static_addr, addr, sizeof(static_addr));
@@ -243,6 +250,21 @@ static void populate_devinfo_service(struct gatt_db *db)
 	gatt_db_service_set_active(service, true);
 }
 
+void gatt_server_init(void)
+{
+	registered_services = queue_new();
+}
+
+static void register_each_service(void *data, void *user_data)
+{
+	struct gatt_db *db = user_data;
+	struct service_registerer_data *registerer = data;
+
+	fprintf(stderr, "registering service %p\n", registerer);
+
+	registerer->callback(db, registerer->user_data);
+}
+
 void gatt_server_start(void)
 {
 	struct sockaddr_l2 addr;
@@ -287,6 +309,8 @@ void gatt_server_start(void)
 	populate_gap_service(gatt_db);
 	populate_devinfo_service(gatt_db);
 
+	queue_foreach(registered_services, register_each_service, gatt_db);
+
 	gatt_cache = gatt_db_new();
 
 	conn_list = queue_new();
@@ -323,10 +347,33 @@ void gatt_server_stop(void)
 
 	queue_destroy(conn_list, gatt_conn_destroy);
 
+	queue_destroy(registered_services, free);
+	registered_services = NULL;
+
 	gatt_db_unref(gatt_cache);
 	gatt_cache = NULL;
 
 	gatt_db_unref(gatt_db);
 	gatt_db = NULL;
+}
+
+int gatt_server_add_service(gatt_service_register_t callback, void *user_data)
+{
+	struct service_registerer_data *registerer;
+
+	fprintf(stderr, "gatt_server_add_service %p data %p\n", callback, user_data);
+
+	registerer = new0(struct service_registerer_data, 1);
+	if (!registerer)
+		return -ENOMEM;
+
+	registerer->callback = callback;
+	registerer->user_data = user_data;
+
+	if (!queue_push_tail(registered_services, registerer)) {
+		free(registerer);
+		return -ENOMEM;
+	}
 
+	return 0;
 }
peripheral/gatt.h +6 -0
index 5b68f35..5e16875 100644
@@ -26,5 +26,11 @@
 void gatt_set_static_address(uint8_t addr[6]);
 void gatt_set_device_name(uint8_t name[20], uint8_t len);
 
+void gatt_server_init(void);
+
 void gatt_server_start(void);
 void gatt_server_stop(void);
+
+typedef void (*gatt_service_register_t)(struct gatt_db *db, void *user_data);
+
+int gatt_server_add_service(gatt_service_register_t callback, void *user_data);
Signature · 1 line
2.4.5
#5 lore raw

RFC 5/13 peripheral/gap: Fix missing includes

In reply to Vinicius Costa Gomes
---
 peripheral/gap.c | 6 ++++++
 1 file changed, 6 insertions(+)
peripheral/gap.c +6 -0
index f659f7f..a78dc45 100644
@@ -27,9 +27,15 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <stdbool.h>
 
 #include "lib/bluetooth.h"
 #include "lib/mgmt.h"
+#include "lib/uuid.h"
+#include "src/shared/att.h"
+#include "src/shared/queue.h"
+#include "src/shared/gatt-db.h"
+
 #include "src/shared/util.h"
 #include "src/shared/mgmt.h"
 #include "peripheral/gatt.h"
Signature · 1 line
2.4.5
#6 lore raw

RFC 6/13 peripheral/gap: Init the gatt_server

In reply to Vinicius Costa Gomes

This will init the list that will have all the callbacks that will register the services not part of the core.

---
 peripheral/gap.c | 2 ++
 1 file changed, 2 insertions(+)
peripheral/gap.c +2 -0
index a78dc45..fe65700 100644
@@ -535,6 +535,8 @@ void gap_start(void)
 		return;
 	}
 
+	gatt_server_init();
+
 	if (!mgmt_send(mgmt, MGMT_OP_READ_COMMANDS,
 				MGMT_INDEX_NONE, 0, NULL,
 				read_commands_complete, NULL, NULL)) {
Signature · 1 line
2.4.5
#7 lore raw

RFC 7/13 peripheral: Disable support for static random addresses

In reply to Vinicius Costa Gomes

This is mostly to make testing easier. I don't have any device which support this properly.

---
 peripheral/gap.c  | 2 +-
 peripheral/gatt.c | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)
peripheral/gap.c +1 -1
index fe65700..9c45057 100644
@@ -48,7 +48,7 @@ static bool adv_features = false;
 static bool adv_instances = false;
 static bool require_connectable = true;
 
-static uint8_t static_addr[6] = { 0x90, 0x78, 0x56, 0x34, 0x12, 0xc0 };
+static uint8_t static_addr[6] = { 0 };
 static uint8_t dev_name[260] = { 0x00, };
 static uint8_t dev_name_len = 0;
 
peripheral/gatt.c +1 -2
index a859adc..0cb4f6d 100644
@@ -285,8 +285,7 @@ void gatt_server_start(void)
 	memset(&addr, 0, sizeof(addr));
 	addr.l2_family = AF_BLUETOOTH;
 	addr.l2_cid = htobs(ATT_CID);
-	memcpy(&addr.l2_bdaddr, static_addr, 6);
-	addr.l2_bdaddr_type = BDADDR_LE_RANDOM;
+	addr.l2_bdaddr_type = BDADDR_LE_PUBLIC;
 
 	if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
 		fprintf(stderr, "Failed to bind ATT server socket: %m\n");
Signature · 1 line
2.4.5
#8 lore raw

RFC 8/13 peripheral/gap: Set the discoverable flag in the advertising

In reply to Vinicius Costa Gomes
---
 peripheral/gap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
peripheral/gap.c +1 -1
index 9c45057..e95394c 100644
@@ -98,7 +98,7 @@ static void add_advertising(uint16_t index)
 	memset(buf, 0, sizeof(*cp) + sizeof(ad));
 	cp = buf;
 	cp->instance = 0x01;
-	cp->flags = cpu_to_le32((1 << 0) | (1 << 1) | (1 << 4));
+	cp->flags = cpu_to_le32((1 << 0) | (1 << 1) | (1 << 3) | (1 << 4));
 	cp->duration = cpu_to_le16(0);
 	cp->timeout = cpu_to_le16(0);
 	cp->adv_data_len = sizeof(ad);
Signature · 1 line
2.4.5
#9 lore raw

RFC 9/13 peripheral/gatt: Use LOW security level

In reply to Vinicius Costa Gomes

Mostly to help testing. And for heartrate, the profile being implemented in later patches, this is a valid security level for useful use cases.

---
 peripheral/gatt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
peripheral/gatt.c +1 -1
index 0cb4f6d..0b5d5fe 100644
@@ -134,7 +134,7 @@ static struct gatt_conn *gatt_conn_new(int fd)
 	bt_att_set_close_on_unref(conn->att, true);
 	bt_att_register_disconnect(conn->att, gatt_conn_disconnect, conn, NULL);
 
-	bt_att_set_security(conn->att, BT_SECURITY_MEDIUM);
+	bt_att_set_security(conn->att, BT_SECURITY_LOW);
 
 	conn->gatt = bt_gatt_server_new(gatt_db, conn->att, mtu);
 	if (!conn->gatt) {
Signature · 1 line
2.4.5
#10 lore raw

RFC 10/13 soletta/heartrate: Add a node-type for the Heartrate profile

In reply to Vinicius Costa Gomes

This simple node type exports a node with only a input port that receives pulses that will be exported via the Heartrate service as beats per minute.

---
 soletta/heartrate-src.json |  30 +++++
 soletta/heartrate.c        | 298 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 328 insertions(+)
 create mode 100644 soletta/heartrate-src.json
 create mode 100644 soletta/heartrate.c
soletta/heartrate-src.json new file +30 -0
new file mode 100644
index 0000000..3db72ce
@@ -0,0 +1,30 @@
+{
+  "name": "Bluetooth",
+  "meta": {
+    "author": "Intel Corporation",
+    "version": "1"
+  },
+  "types": [
+    {
+      "category": "output/hw",
+      "description": "Bluetooth Smart Heart Rate Profile server",
+      "in_ports": [
+        {
+          "data_type": "any",
+          "description": "each packet is a beat",
+          "methods": {
+            "process": "heartrate_in_process"
+          },
+          "name": "IN"
+        }
+      ],
+      "methods": {
+        "close": "heartrate_close",
+        "open": "heartrate_open"
+      },
+      "name": "heartrate",
+      "private_data_type": "heartrate_data",
+      "url": "http://soletta.org/doc/latest/node_types/heartrate.html"
+    }
+  ]
+}
soletta/heartrate.c new file +298 -0

298 lines not on this page · raw message

Signature · 1 line
2.4.5
#11 lore raw

RFC 11/13 .gitignore: Ignore soletta generated files

In reply to Vinicius Costa Gomes
---
 .gitignore | 4 ++++
 1 file changed, 4 insertions(+)
.gitignore +4 -0
index 7c1b7e0..6958ce9 100644
@@ -154,6 +154,10 @@ android/test-ipc
 android/test-*.log
 android/test-*.trs
 
+soletta/heartrate-gen.c
+soletta/heartrate-gen.h
+soletta/heartrate.json
+
 cscope.in.out
 cscope.out
 cscope.po.out
Signature · 1 line
2.4.5
#12 lore raw

RFC 12/13 build: Add heartrate soletta node type to the build system

In reply to Vinicius Costa Gomes
---
 Makefile.tools | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
Makefile.tools +20 -0
index 1899fcb..9b330cb 100644
@@ -73,6 +73,26 @@ peripheral_btsensor_SOURCES = peripheral/main.c \
 peripheral_btsensor_LDADD = src/libshared-mainloop.la \
 				lib/libbluetooth-internal.la
 
+if SOLETTA
+soletta_descdir = @SOLETTA_DESCDIR@/flow/descriptions/
+soletta_desc_DATA = soletta/heartrate.json
+solettamodulesdir = @SOLETTA_MODULESDIR@/flow
+solettamodules_LTLIBRARIES = soletta/heartrate.la
+soletta_heartrate_la_SOURCES = soletta/heartrate.c peripheral/gap.h peripheral/gap.c \
+				peripheral/gatt.h peripheral/gatt.c
+soletta_heartrate_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version
+soletta_heartrate_la_LIBADD = src/libshared-soletta.la \
+			lib/libbluetooth-internal.la \
+			@SOLETTA_LIBS@
+soletta_heartrate_la_CFLAGS = $(AM_CFLAGS) @SOLETTA_CFLAGS@ -DSOL_FLOW_NODE_TYPE_MODULE_EXTERNAL
+
+soletta/%-gen.c soletta/%-gen.h: soletta/heartrate-src.json
+		$(AM_V_GEN)$(PYTHON) @SOLETTA_PREFIX@/bin/sol-flow-node-type-gen.py $< soletta/$*-gen.h soletta/$*-gen.c soletta/heartrate.json
+
+BUILT_SOURCES += soletta/heartrate-gen.c soletta/heartrate-gen.h
+
+endif
+
 tools_3dsp_SOURCES = tools/3dsp.c monitor/bt.h
 tools_3dsp_LDADD = src/libshared-mainloop.la
 
Signature · 1 line
2.4.5
#13 lore raw

RFC 13/13 soletta: Add a sample flow using the heartrate node

In reply to Vinicius Costa Gomes

The flow and associated conffile, defines a very simple flow using the heartrate node.

With soletta already installed you just run it, something like this:

$ sol-fbp-runner heartrate.fbp

It will look for the sol-flow.conf (which would define options for the nodes) in the current directory.

---
 soletta/heartrate.fbp | 1 +
 soletta/sol-flow.conf | 2 ++
 2 files changed, 3 insertions(+)
 create mode 100644 soletta/heartrate.fbp
 create mode 100644 soletta/sol-flow.conf
soletta/heartrate.fbp new file +1 -0
new file mode 100644
index 0000000..63185c4
@@ -0,0 +1 @@
+Timer(timer:interval=1000) OUT -> IN Heartrate(heartrate)
soletta/sol-flow.conf new file +2 -0
new file mode 100644
index 0000000..08ea12e
@@ -0,0 +1,2 @@
+[SolettaNodeEntry Heartrate]
+Type=heartrate
Signature · 1 line
2.4.5
#14 lore raw
In reply to Vinicius Costa Gomes

Hi Vinicius,

Quoted 17 lines · Vinicius Costa Gomes

Hi,

We have been working on Soletta[1] for a few months and now that it has been open sourced, it makes sense to show what it can do using BlueZ. This implements a very simple node type that behaves as a Heart Rate Sensor in the peripheral mode.

Just a overview about Soletta, it provides a way to write IoT applications targeting a broad range of devices (from the smallest edge to the smarttest hub).

You would express your application logic using a Flow Based language to connect various nodes, write your custom node types using the libsolleta C API. And the Soletta developers would worry about porting the libsoletta library to the multitude of targets and providing a useful collection of node types.

Quoted 4 lines

Using the support we already have in BlueZ for the Bluetooth LE peripheral mode, writing a Soletta node type for the Heartrate Sensor role seems a very good match. And it brings some very interesting use cases with the linux-micro target.

I guess it would be a good idea to have a README in peripheral directory explaining the setup/architecture, etc, much like we did for Android.

Quoted 11 lines

The way I thought best about integrating BlueZ with Soletta was to add another mainloop backend using libsoletta so every event would be handled consistently. See patch 02/13.

Most of the changes not related to either adding the mainloop support, or adding the node type code are related to some lack of configurability to the peripheral code, perhaps having a way to the callback that will register the service to have a say in some parameters?

The most important question is: is BlueZ the right place to have this code?

It seems like it as long as we don't make our shared code public, as a shared library, I believe BlueZ will be the right place.

Quoted 1 line

What do you say?

I suppose we need a bit more information regarding what kind of setups this is targeting, I suppose this is to be run on systems without D-Bus, something like all-in-one design? I don't mind having another mainloop but the unit tests are currently limited to glib only so it won't catch bugs/regressions with other mainloops perhaps we need to address this.

The IoT setups seems to be pretty open right now, from what I heard there are setups that would run systemd+bluetoothd(dual-mode/le-only), bluetoothd(dual-mode/le-only), all-in-one(le-only) setups, for le-only setups Im afraid we will need to make the code even more modular to reduce the memory footprint, so perhaps we should nail down what setups really make sense to be supported upstream

For example setups that require classic will very likely require audio or/and obexd which probably pulls everything we have, so I guess it makes little sense to put any effort making this part of the code more memory efficient.

Quoted 21 lines

Any questions about the project, we are hanging out in #soletta @ freenode.net.

Cheers,

[1] https://github.com/solettaproject/soletta

Vinicius Costa Gomes (13):
build: Add configure-time checks for soletta
shared: Add a mainloop implementation using soletta peripheral/gatt: Fix usage of mainloop_ functions peripheral/gatt: Add a way to external services to register services peripheral/gap: Fix missing includes
peripheral/gap: Init the gatt_server
peripheral: Disable support for static random addresses peripheral/gap: Set the discoverable flag in the advertising peripheral/gatt: Use LOW security level soletta/heartrate: Add a node-type for the Heartrate profile .gitignore: Ignore soletta generated files
build: Add heartrate soletta node type to the build system
soletta: Add a sample flow using the heartrate node

Quoted 11 lines
 .gitignore                   |   4 +
 Makefile.am                  |   7 +-
 Makefile.tools               |  20 +++
 configure.ac                 |  38 ++++++
 peripheral/gap.c             |  12 +-
 peripheral/gatt.c            | 124 ++++++++++++-----
 peripheral/gatt.h            |   6 +
 soletta/heartrate-src.json   |  30 +++++
 soletta/heartrate.c          | 298 ++++++++++++++++++++++++++++++++++++++++
 soletta/heartrate.fbp        |   1 +
 soletta/sol-flow.conf        |   2 +

Id put soletta code under peripheral/soletta as it appears to depend on that anyway.

Quoted 16 lines
 src/shared/io-soletta.c      | 315 +++++++++++++++++++++++++++++++++++++++++++
 src/shared/timeout-soletta.c | 112 +++++++++++++++
 13 files changed, 934 insertions(+), 35 deletions(-)
 create mode 100644 soletta/heartrate-src.json
 create mode 100644 soletta/heartrate.c
 create mode 100644 soletta/heartrate.fbp
 create mode 100644 soletta/sol-flow.conf
 create mode 100644 src/shared/io-soletta.c
 create mode 100644 src/shared/timeout-soletta.c

--
2.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Luiz Augusto von Dentz
#15 lore raw

Hi Luiz,

Quoted 20 lines · Luiz Augusto von Dentz

Hi Vinicius,

Quoted 17 lines · Vinicius Costa Gomes

Hi,

We have been working on Soletta[1] for a few months and now that it has been open sourced, it makes sense to show what it can do using BlueZ. This implements a very simple node type that behaves as a Heart Rate Sensor in the peripheral mode.

Just a overview about Soletta, it provides a way to write IoT applications targeting a broad range of devices (from the smallest edge to the smarttest hub).

You would express your application logic using a Flow Based language to connect various nodes, write your custom node types using the libsolleta C API. And the Soletta developers would worry about porting the libsoletta library to the multitude of targets and providing a useful collection of node types.

Quoted 8 lines
Quoted 4 lines

Using the support we already have in BlueZ for the Bluetooth LE peripheral mode, writing a Soletta node type for the Heartrate Sensor role seems a very good match. And it brings some very interesting use cases with the linux-micro target.

I guess it would be a good idea to have a README in peripheral directory explaining the setup/architecture, etc, much like we did for Android.

Of course. I absolutely agree.

Quoted 11 lines
Quoted 11 lines

The way I thought best about integrating BlueZ with Soletta was to add another mainloop backend using libsoletta so every event would be handled consistently. See patch 02/13.

Most of the changes not related to either adding the mainloop support, or adding the node type code are related to some lack of configurability to the peripheral code, perhaps having a way to the callback that will register the service to have a say in some parameters?

Quoted 5 lines
Quoted 1 line

The most important question is: is BlueZ the right place to have this code?

It seems like it as long as we don't make our shared code public, as a shared library, I believe BlueZ will be the right place.

Cool.

Quoted 8 lines
Quoted 1 line

What do you say?

I suppose we need a bit more information regarding what kind of setups this is targeting, I suppose this is to be run on systems without D-Bus, something like all-in-one design? I don't mind having another mainloop but the unit tests are currently limited to glib only so it won't catch bugs/regressions with other mainloops perhaps we need to address this.

The setup that this series is targeting is the all-in-one one. And as it was the most intrusive (from the BlueZ perspective) it made sense to start from it. And it aligns nicely with Soletta having a PID 1 implementation.

(I will take a look and see what I can do about the tests.)

Quoted 7 lines

The IoT setups seems to be pretty open right now, from what I heard there are setups that would run systemd+bluetoothd(dual-mode/le-only), bluetoothd(dual-mode/le-only), all-in-one(le-only) setups, for le-only setups Im afraid we will need to make the code even more modular to reduce the memory footprint, so perhaps we should nail down what setups really make sense to be supported upstream

Just for reference, we tried to see how small the binary would be for this, we got to an ~180KB static binary when linking the heartrate module with the soletta PID 1 implementation, but did not measure memory consumption. Will put together the steps to build this in the README.

But I still can see interesting use cases for having some (mostly the client side of GATT profiles) profiles implemented inside the Soletta project (using the D-Bus APIs). This being the bluetoothd+systemd setup, I presume.

The bluetoothd(dual-mode/le-only) case I wasn't thinking about it, and I still can't think of use cases for it, I guess I didn't understand it.

Quoted 5 lines

For example setups that require classic will very likely require audio or/and obexd which probably pulls everything we have, so I guess it makes little sense to put any effort making this part of the code more memory efficient.

I agree.

Quoted 34 lines
Quoted 22 lines

Any questions about the project, we are hanging out in #soletta @ freenode.net.

Cheers,

[1] https://github.com/solettaproject/soletta

Vinicius Costa Gomes (13):
build: Add configure-time checks for soletta
shared: Add a mainloop implementation using soletta peripheral/gatt: Fix usage of mainloop_ functions peripheral/gatt: Add a way to external services to register services peripheral/gap: Fix missing includes
peripheral/gap: Init the gatt_server
peripheral: Disable support for static random addresses peripheral/gap: Set the discoverable flag in the advertising peripheral/gatt: Use LOW security level soletta/heartrate: Add a node-type for the Heartrate profile .gitignore: Ignore soletta generated files
build: Add heartrate soletta node type to the build system
soletta: Add a sample flow using the heartrate node

Quoted 11 lines
 .gitignore                   |   4 +
 Makefile.am                  |   7 +-
 Makefile.tools               |  20 +++
 configure.ac                 |  38 ++++++
 peripheral/gap.c             |  12 +-
 peripheral/gatt.c            | 124 ++++++++++++-----
 peripheral/gatt.h            |   6 +
 soletta/heartrate-src.json   |  30 +++++
 soletta/heartrate.c          | 298 ++++++++++++++++++++++++++++++++++++++++
 soletta/heartrate.fbp        |   1 +
 soletta/sol-flow.conf        |   2 +
Quoted 2 lines

Id put soletta code under peripheral/soletta as it appears to depend on that anyway.

Yes, it depends on it. Sure.

Cheers,
--
Vinicius