Very minimal, working BLE advertising
This commit is contained in:
parent
8cfb87ef32
commit
3749d689ba
2 changed files with 29 additions and 2 deletions
|
|
@ -2,4 +2,11 @@ CONFIG_LOG=y
|
|||
CONFIG_PWM=y
|
||||
CONFIG_CBPRINTF_FP_SUPPORT=y
|
||||
CONFIG_I2C=y
|
||||
CONFIG_ADC=y
|
||||
CONFIG_ADC=y
|
||||
|
||||
CONFIG_BT=y
|
||||
CONFIG_BT_PERIPHERAL=y
|
||||
CONFIG_BT_DEBUG_LOG=y
|
||||
CONFIG_BT_DEVICE_NAME="para"
|
||||
# CONFIG_BT_SETTINGS=n
|
||||
# CONFIG_SETTINGS=n
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
#include <logging/log.h>
|
||||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
#include <zephyr/settings/settings.h>
|
||||
#include <zephyr/zephyr.h>
|
||||
|
||||
#include "prst/adc.h"
|
||||
|
|
@ -9,6 +11,15 @@
|
|||
|
||||
LOG_MODULE_REGISTER(main, LOG_LEVEL_DBG);
|
||||
|
||||
static const struct bt_data ad[] = {
|
||||
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
|
||||
BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME),
|
||||
};
|
||||
|
||||
static const struct bt_data sd[] = {
|
||||
BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME),
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
RET_IF_ERR(prst_adc_init());
|
||||
RET_IF_ERR(prst_led_init());
|
||||
|
|
@ -19,6 +30,16 @@ int main(void) {
|
|||
prst_adc_read_t batt;
|
||||
prst_adc_soil_moisture_t soil;
|
||||
prst_adc_photo_sensor_t photo;
|
||||
|
||||
RET_IF_ERR(bt_enable(/*bt_reader_cb_t=*/NULL));
|
||||
|
||||
if (IS_ENABLED(CONFIG_SETTINGS)) {
|
||||
RET_IF_ERR_MSG(settings_load(), "Error in settings_load()");
|
||||
}
|
||||
|
||||
RET_IF_ERR(
|
||||
bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd)));
|
||||
|
||||
while (true) {
|
||||
RET_IF_ERR(prst_adc_batt_read(&batt));
|
||||
RET_IF_ERR(prst_adc_soil_read(batt.voltage, &soil));
|
||||
|
|
@ -28,7 +49,6 @@ int main(void) {
|
|||
LOG_INF("Soil: %.0f %% (%.3f mV)", 100 * soil.percentage,
|
||||
soil.adc_read.voltage);
|
||||
LOG_INF("Photo: %u lx (%.3f mV)", photo.brightness, soil.adc_read.voltage);
|
||||
|
||||
k_msleep(500);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue