mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
examples: add simple skald_bthome example
This commit is contained in:
parent
79a90bd566
commit
8beb409743
@ -77,6 +77,7 @@ Here is a quick overview of the examples available in the RIOT:
|
||||
|---------|-------------|
|
||||
| [skald_eddystone](./skald_eddystone/README.md) | This example demonstrates the usage of `Skald` for creating an Google `Eddystone` beacon. |
|
||||
| [skald_ibeacon](./skald_ibeacon/README.md) | This example demonstrates the usage of `Skald` for creating an Apple `iBeacon`. |
|
||||
| [skald_bthome](./skald_bthome/README.md) | This example demonstrates the usage of `Skald` for sending SAUL measurements via [`BTHome`](https://bthome.io). |
|
||||
|
||||
### MQTT
|
||||
|
||||
|
24
examples/skald_bthome/Makefile
Normal file
24
examples/skald_bthome/Makefile
Normal file
@ -0,0 +1,24 @@
|
||||
# name of your application
|
||||
APPLICATION = skald_bthome
|
||||
|
||||
# If no BOARD is found in the environment, use this default:
|
||||
BOARD ?= nrf52dk
|
||||
|
||||
# This has to be the absolute path to the RIOT base directory:
|
||||
RIOTBASE ?= $(CURDIR)/../..
|
||||
|
||||
# include Skald
|
||||
USEMODULE += skald_bthome
|
||||
|
||||
DEVELHELP ?= 1
|
||||
|
||||
BTHOME_NAME = "RIOT"
|
||||
BTHOME_ADV_INTERVAL ?= 60000
|
||||
|
||||
CFLAGS += -DBTHOME_NAME="\"$(BTHOME_NAME)\""
|
||||
CFLAGS += -DBTHOME_ADV_INTERVAL=$(BTHOME_ADV_INTERVAL)
|
||||
|
||||
# Change this to 0 show compiler invocation lines by default:
|
||||
QUIET ?= 1
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
7
examples/skald_bthome/README.md
Normal file
7
examples/skald_bthome/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Skald BTHome Example
|
||||
|
||||
This example demonstrates the usage of `Skald` for creating a BTHome
|
||||
setup, advertising sensors in the SAUL registry.
|
||||
|
||||
Simply compile and flash, and verify your newly created beacon with any type of
|
||||
BLE scanner / BTHome receiver (e.g. Home Assistant).
|
54
examples/skald_bthome/main.c
Normal file
54
examples/skald_bthome/main.c
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Martine S. Lenders
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup examples
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief BLE BTHome example using Skald
|
||||
*
|
||||
* @author Martine S. Lenders <mail@martine-lenders.eu>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ztimer.h"
|
||||
|
||||
#include "net/skald/bthome.h"
|
||||
|
||||
#ifndef CONFIG_BTHOME_SAUL_REG_DEVS
|
||||
#define CONFIG_BTHOME_SAUL_REG_DEVS (16U)
|
||||
#endif
|
||||
|
||||
#ifndef BTHOME_ADV_INTERVAL
|
||||
#define BTHOME_ADV_INTERVAL (60000U)
|
||||
#endif
|
||||
|
||||
static skald_bthome_ctx_t _ctx;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ztimer_sleep(ZTIMER_MSEC, 2000);
|
||||
printf("Skald and the tale of Harald's home\n");
|
||||
|
||||
if (skald_bthome_init(&_ctx, NULL, BTHOME_NAME, 0) < 0) {
|
||||
return 1;
|
||||
}
|
||||
if (skald_bthome_add_uint24_measurement(&_ctx, BTHOME_ID_TEMPERATURE_FACTOR_0_01, 2500) < 0) {
|
||||
return 1;
|
||||
}
|
||||
if (skald_bthome_add_int16_measurement(&_ctx, BTHOME_ID_HUMIDITY_FACTOR_0_01, 5055) < 0) {
|
||||
printf("H %u\n", _ctx.skald.pkt.len);
|
||||
return 1;
|
||||
}
|
||||
skald_bthome_advertise(&_ctx, BTHOME_ADV_INTERVAL);
|
||||
return 0;
|
||||
}
|
@ -72,7 +72,7 @@ typedef enum {
|
||||
* 0 = Closed, 1 = Open
|
||||
*/
|
||||
BTHOME_ID_OPENING_BINARY = 0x11,
|
||||
BTHOME_ID_C02 = 0x12, /**< CO2 in _v_ ppm (uint16_t) */
|
||||
BTHOME_ID_CO2 = 0x12, /**< CO2 in _v_ ppm (uint16_t) */
|
||||
BTHOME_ID_TVOC = 0x13, /**< TVOC in _v_ ug/m3 (uint16_t) */
|
||||
BTHOME_ID_MOISTURE_FACTOR_0_01 = 0x14, /**< Moisture in _v_ * 0.01 % (uint16_t) */
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user