Skip to content

Commit

Permalink
feat: Add RAWv@ data to NFC payload which is updated once a minute.
Browse files Browse the repository at this point in the history
It is enabled by:
CONFIG_RUUVITAG_NFC_SENSOR_DATA=y
and the frequency is controllable with:
CONFIG_RUUVITAG_NFC_SENSOR_DATA_FREQUENCY=1
  • Loading branch information
theBASTI0N committed Nov 14, 2020
1 parent 655f050 commit ed55d6d
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 147 deletions.
7 changes: 3 additions & 4 deletions prj.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
CONFIG_RUUVITAG_NFC_SENSOR_DATA=y
CONFIG_RUUVITAG_NFC_SENSOR_DATA_FREQUENCY=1
# Enable rebooting
CONFIG_REBOOT=y

Expand Down Expand Up @@ -27,14 +29,11 @@ CONFIG_BT=y
CONFIG_BT_BROADCASTER=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_GATT_CLIENT=y

CONFIG_BT_GATT_CACHING=n
CONFIG_BT_CTLR=y
CONFIG_BT_CTLR_TX_PWR_PLUS_4=y
CONFIG_BT_DEVICE_NAME="Ruuvi"

# Remove warning
CONFIG_BT_GATT_CACHING=n

# NFC
CONFIG_NFC_T2T_NRFXLIB=y
CONFIG_NFC_NDEF=y
Expand Down
2 changes: 1 addition & 1 deletion src/board_info/board_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void get_id(char *serial_number)
/* Expand binary device ID to hex string */
len = bin2hex(device_id, sizeof(device_id), serial_number,
RUUVI_DSN_LENGTH_CHAR + 1);
__ASSERT_NO_MSG(len == GADGETSRUUVI_DSN_LENGTH_CHAR_DSN_LENGTH_CHARS);
__ASSERT_NO_MSG(len == RUUVI_DSN_LENGTH_CHAR);

LOG_INF("Serial: %s", log_strdup(serial_number));
}
Expand Down
39 changes: 20 additions & 19 deletions src/bt_handler/bt_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static struct k_work ble_work;
BT_GAP_ADV_SLOW_INT_MIN, \
BT_GAP_ADV_SLOW_INT_MIN, NULL)

static uint8_t mfg_data[RUUVI_MFG_OFFSET + RUUVI_RAWv2_LEN +1];
static uint8_t mfg_data[RUUVI_MFG_OFFSET + RUUVI_RAWv2_LEN];

/* Set Scan Response data */
static const struct bt_data sd[] = {
Expand All @@ -57,13 +57,6 @@ static const struct bt_data bc[] = {
BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, sizeof(mfg_data)),
};

static struct bt_conn_cb m_conn_callbacks = {
.connected = connected,
.disconnected = disconnected,
.le_param_req = le_param_req,
.le_param_updated = le_param_updated
};

static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
Expand All @@ -77,6 +70,23 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
LOG_INF("disconnected (reason: %u)", reason);
}

static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param)
{
return true;
}

static void le_param_updated(struct bt_conn *conn, uint16_t interval, uint16_t latency, uint16_t timeout)
{

}

static struct bt_conn_cb m_conn_callbacks = {
.connected = connected,
.disconnected = disconnected,
.le_param_req = le_param_req,
.le_param_updated = le_param_updated
};

static void advertise(struct k_work *work)
{
int rc;
Expand All @@ -97,20 +107,11 @@ static void advertise(struct k_work *work)
LOG_INF("Ruuvitag is now beaconing.");
}

static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param)
{
return true;
}

static void le_param_updated(struct bt_conn *conn, uint16_t interval, uint16_t latency, uint16_t timeout)
{

}

void bt_update_packet(void){
ruuvi_update_endpoint(mfg_data);
/* Update advertisement data */
bt_le_adv_update_data(bc, ARRAY_SIZE(bc), sd, ARRAY_SIZE(sd));
LOG_DBG("Updating BLE packet");
}

void bt_init(void)
Expand All @@ -134,7 +135,7 @@ void bt_init(void)

#endif

LOG_DBG("Bluetooth initialized");
LOG_INF("Bluetooth initialized");
}

void bt_adv_stop(void)
Expand Down
25 changes: 18 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ static void dfu_init(void){
#endif
}

#if CONFIG_RUUVITAG_NFC_SENSOR_DATA
static int64_t last_nfc_update = 0;
#endif
static int64_t lastPressed = 0;
static int64_t btn_time = 0;

Expand All @@ -90,15 +93,14 @@ void main(void)
{
LOG_INF("Ruuvitag Started");
LOG_INF("Version: %s", log_strdup(CONFIG_RUUVITAG_APP_VERSION));

led_init();

button_init();

/*
* If button B is pressed, the device will be connectable
* and ready for a DFU. This state will be reverted after a specific
* amount of time, controllable by using CONFIG_RUUVITAG_DFU_TIMEOUT.
* Default is 2 minutes.
* This could be used in the future to perform any numbers
* of tasks.
*/
if(button_pressed_state()){
LOG_INF("Button Pressed at boot.\n");
Expand All @@ -112,8 +114,8 @@ void main(void)
ruuvi_endpoint_sensor_check();

/*
* This is required to allow the application to easily toggle
* between BT modes.
* Enables the filsesystem and mgmt groups that are required to
* enable dfu functionality.
*/
dfu_init();

Expand All @@ -122,12 +124,21 @@ void main(void)

/* NFC must be done after BT so that MAC can be received. */
ruuvi_nfc_init();
#if CONFIG_RUUVITAG_NFC_SENSOR_DATA
last_nfc_update = k_uptime_get();
#endif
while (true) {
toggle_green(1);
bt_update_packet();
/* Turn LEDs off */
toggle_green(0);

#if CONFIG_RUUVITAG_NFC_SENSOR_DATA
if(k_uptime_get() - last_nfc_update > RUUVI_NFC_REFRESH){
ruuvi_nfc_update();
last_nfc_update = k_uptime_get();
}
#endif

k_sleep(K_MSEC(980));
}
}
Loading

0 comments on commit ed55d6d

Please sign in to comment.