From 44c35350f8131e9998274ce4b3194d116250d379 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 2 Jul 2015 19:59:55 +0200 Subject: o Adding a temperature characteristic. Reading values from the nrf8001. --- services.h | 41 ++++++++++++++++++++++++------- services_lock.h | 41 ++++++++++++++++++++++++------- trygvisio_soil_moisture.ino | 59 +++++++++++++++++++++++++++++++++++++-------- trygvisio_soil_moisture.xml | 22 +++++++++++++++++ ublue_setup.gen.out.txt | 39 ++++++++++++++++++------------ 5 files changed, 158 insertions(+), 44 deletions(-) diff --git a/services.h b/services.h index f8f1ff4..94efd74 100644 --- a/services.h +++ b/services.h @@ -11,7 +11,7 @@ #define SETUP_ID 0 #define SETUP_FORMAT 3 /** nRF8001 D */ -#define ACI_DYNAMIC_DATA_SIZE 162 +#define ACI_DYNAMIC_DATA_SIZE 180 /* Service: Gap - Characteristic: Device name - Pipe: SET */ #define PIPE_GAP_DEVICE_NAME_SET 1 @@ -41,8 +41,16 @@ #define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO 7 #define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO_MAX_SIZE 20 +/* Service: Soil Moisture - Characteristic: Intermediate Temperature - Pipe: TX */ +#define PIPE_SOIL_MOISTURE_INTERMEDIATE_TEMPERATURE_TX 8 +#define PIPE_SOIL_MOISTURE_INTERMEDIATE_TEMPERATURE_TX_MAX_SIZE 10 -#define NUMBER_OF_PIPES 7 +/* Service: Soil Moisture - Characteristic: Intermediate Temperature - Pipe: SET */ +#define PIPE_SOIL_MOISTURE_INTERMEDIATE_TEMPERATURE_SET 9 +#define PIPE_SOIL_MOISTURE_INTERMEDIATE_TEMPERATURE_SET_MAX_SIZE 10 + + +#define NUMBER_OF_PIPES 9 #define SERVICES_PIPE_TYPE_MAPPING_CONTENT {\ {ACI_STORE_LOCAL, ACI_SET}, \ @@ -52,6 +60,8 @@ {ACI_STORE_LOCAL, ACI_TX}, \ {ACI_STORE_LOCAL, ACI_SET}, \ {ACI_STORE_LOCAL, ACI_RX_ACK_AUTO}, \ + {ACI_STORE_LOCAL, ACI_TX}, \ + {ACI_STORE_LOCAL, ACI_SET}, \ } #define GAP_PPCP_MAX_CONN_INT 0xffff /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */ @@ -59,7 +69,7 @@ #define GAP_PPCP_SLAVE_LATENCY 0 #define GAP_PPCP_CONN_TIMEOUT 0xffff /** Connection Supervision timeout multiplier as a multiple of 10msec, 0xFFFF means no specific value requested */ -#define NB_SETUP_MESSAGES 21 +#define NB_SETUP_MESSAGES 23 #define SETUP_MESSAGES_CONTENT {\ {0x00,\ {\ @@ -68,7 +78,7 @@ },\ {0x00,\ {\ - 0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x07,0x01,0x01,0x00,0x00,0x06,0x00,0x01,\ + 0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x09,0x01,0x01,0x00,0x00,0x06,0x00,0x01,\ 0xd1,0x0f,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ },\ },\ @@ -151,7 +161,14 @@ },\ {0x00,\ {\ - 0x0c,0x06,0x21,0x18,0x02,0x00,0x13,0x29,0x02,0x01,0x00,0x00,0x00,\ + 0x1f,0x06,0x21,0x18,0x02,0x00,0x13,0x29,0x02,0x01,0x00,0x00,0x04,0x04,0x05,0x05,0x00,0x14,0x28,0x03,\ + 0x01,0x12,0x15,0x00,0x1e,0x2a,0x16,0x04,0x0b,0x0a,0x00,0x15,\ + },\ + },\ + {0x00,\ + {\ + 0x1c,0x06,0x21,0x34,0x2a,0x1e,0x01,0xaa,0xbb,0xcc,0xdd,0xee,0xff,0x99,0x88,0x77,0x66,0x46,0x14,0x03,\ + 0x02,0x00,0x16,0x29,0x02,0x01,0x00,0x00,0x00,\ },\ },\ {0x00,\ @@ -162,8 +179,13 @@ },\ {0x00,\ {\ - 0x19,0x06,0x40,0x1c,0x00,0x00,0x2a,0x1b,0x01,0x00,0x80,0x04,0x00,0x0f,0x00,0x00,0x00,0x11,0x02,0x04,\ - 0x82,0x04,0x00,0x12,0x00,0x13,\ + 0x1f,0x06,0x40,0x1c,0x00,0x00,0x2a,0x1b,0x01,0x00,0x80,0x04,0x00,0x0f,0x00,0x00,0x00,0x11,0x02,0x04,\ + 0x82,0x04,0x00,0x12,0x00,0x13,0x2a,0x1e,0x01,0x00,0x82,0x04,\ + },\ + },\ + {0x00,\ + {\ + 0x07,0x06,0x40,0x38,0x00,0x15,0x00,0x16,\ },\ },\ {0x00,\ @@ -173,12 +195,13 @@ },\ {0x00,\ {\ - 0x12,0x06,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x15,0x06,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,\ },\ },\ {0x00,\ {\ - 0x06,0x06,0xf0,0x00,0x03,0x9c,0x07,\ + 0x06,0x06,0xf0,0x00,0x03,0xb7,0x68,\ },\ },\ } diff --git a/services_lock.h b/services_lock.h index 57af1da..d3a271b 100644 --- a/services_lock.h +++ b/services_lock.h @@ -15,7 +15,7 @@ #define SETUP_ID 0 #define SETUP_FORMAT 3 /** nRF8001 D */ -#define ACI_DYNAMIC_DATA_SIZE 162 +#define ACI_DYNAMIC_DATA_SIZE 180 /* Service: Gap - Characteristic: Device name - Pipe: SET */ #define PIPE_GAP_DEVICE_NAME_SET 1 @@ -45,8 +45,16 @@ #define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO 7 #define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO_MAX_SIZE 20 +/* Service: Soil Moisture - Characteristic: Intermediate Temperature - Pipe: TX */ +#define PIPE_SOIL_MOISTURE_INTERMEDIATE_TEMPERATURE_TX 8 +#define PIPE_SOIL_MOISTURE_INTERMEDIATE_TEMPERATURE_TX_MAX_SIZE 10 -#define NUMBER_OF_PIPES 7 +/* Service: Soil Moisture - Characteristic: Intermediate Temperature - Pipe: SET */ +#define PIPE_SOIL_MOISTURE_INTERMEDIATE_TEMPERATURE_SET 9 +#define PIPE_SOIL_MOISTURE_INTERMEDIATE_TEMPERATURE_SET_MAX_SIZE 10 + + +#define NUMBER_OF_PIPES 9 #define SERVICES_PIPE_TYPE_MAPPING_CONTENT {\ {ACI_STORE_LOCAL, ACI_SET}, \ @@ -56,6 +64,8 @@ {ACI_STORE_LOCAL, ACI_TX}, \ {ACI_STORE_LOCAL, ACI_SET}, \ {ACI_STORE_LOCAL, ACI_RX_ACK_AUTO}, \ + {ACI_STORE_LOCAL, ACI_TX}, \ + {ACI_STORE_LOCAL, ACI_SET}, \ } #define GAP_PPCP_MAX_CONN_INT 0xffff /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */ @@ -63,7 +73,7 @@ #define GAP_PPCP_SLAVE_LATENCY 0 #define GAP_PPCP_CONN_TIMEOUT 0xffff /** Connection Supervision timeout multiplier as a multiple of 10msec, 0xFFFF means no specific value requested */ -#define NB_SETUP_MESSAGES 21 +#define NB_SETUP_MESSAGES 23 #define SETUP_MESSAGES_CONTENT {\ {0x00,\ {\ @@ -72,7 +82,7 @@ },\ {0x00,\ {\ - 0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x07,0x01,0x01,0x00,0x00,0x06,0x00,0x01,\ + 0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x09,0x01,0x01,0x00,0x00,0x06,0x00,0x01,\ 0xd1,0x0f,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ },\ },\ @@ -155,7 +165,14 @@ },\ {0x00,\ {\ - 0x0c,0x06,0x21,0x18,0x02,0x00,0x13,0x29,0x02,0x01,0x00,0x00,0x00,\ + 0x1f,0x06,0x21,0x18,0x02,0x00,0x13,0x29,0x02,0x01,0x00,0x00,0x04,0x04,0x05,0x05,0x00,0x14,0x28,0x03,\ + 0x01,0x12,0x15,0x00,0x1e,0x2a,0x16,0x04,0x0b,0x0a,0x00,0x15,\ + },\ + },\ + {0x00,\ + {\ + 0x1c,0x06,0x21,0x34,0x2a,0x1e,0x01,0xaa,0xbb,0xcc,0xdd,0xee,0xff,0x99,0x88,0x77,0x66,0x46,0x14,0x03,\ + 0x02,0x00,0x16,0x29,0x02,0x01,0x00,0x00,0x00,\ },\ },\ {0x00,\ @@ -166,8 +183,13 @@ },\ {0x00,\ {\ - 0x19,0x06,0x40,0x1c,0x00,0x00,0x2a,0x1b,0x01,0x00,0x80,0x04,0x00,0x0f,0x00,0x00,0x00,0x11,0x02,0x04,\ - 0x82,0x04,0x00,0x12,0x00,0x13,\ + 0x1f,0x06,0x40,0x1c,0x00,0x00,0x2a,0x1b,0x01,0x00,0x80,0x04,0x00,0x0f,0x00,0x00,0x00,0x11,0x02,0x04,\ + 0x82,0x04,0x00,0x12,0x00,0x13,0x2a,0x1e,0x01,0x00,0x82,0x04,\ + },\ + },\ + {0x00,\ + {\ + 0x07,0x06,0x40,0x38,0x00,0x15,0x00,0x16,\ },\ },\ {0x00,\ @@ -177,12 +199,13 @@ },\ {0x00,\ {\ - 0x12,0x06,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x15,0x06,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,\ },\ },\ {0x00,\ {\ - 0x06,0x06,0xf0,0x00,0x83,0x0d,0x8f,\ + 0x06,0x06,0xf0,0x00,0x83,0x26,0xe0,\ },\ },\ } diff --git a/trygvisio_soil_moisture.ino b/trygvisio_soil_moisture.ino index 729f5da..4d5bc9c 100644 --- a/trygvisio_soil_moisture.ino +++ b/trygvisio_soil_moisture.ino @@ -3,6 +3,7 @@ #include #include #include +#include // See config.h on how to configure the sketch #include "config.h" @@ -15,10 +16,9 @@ static void show_pipes(); static services_pipe_type_mapping_t services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT; static const hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] PROGMEM = SETUP_MESSAGES_CONTENT; -static const uint8_t pipe_set = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_SET; -static const uint8_t pipe_tx = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_TX; -static const uint8_t pipe_rx = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO; -static const uint8_t pipe_rx_max_size = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO_MAX_SIZE; +static const uint8_t sm_pipe_set = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_SET; +static const uint8_t sm_pipe_tx = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_TX; +static const uint8_t sm_pipe_rx = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO; static struct aci_state_t aci_state; static hal_aci_evt_t aci_data; @@ -117,8 +117,8 @@ static void setup_rf() { Serial.println(F("lib_aci_init done")); } -static boolean rf_started = false; -static boolean setup_required = false; +static bool rf_started = false; +static bool setup_required = false; static void aci_loop() { uint8_t pipe_number; @@ -188,6 +188,43 @@ static void aci_loop() { // (uint8_t *)&(aci_evt->params.cmd_rsp.params.get_device_version), // sizeof(aci_evt_cmd_rsp_params_get_device_version_t)); } + if (aci_evt->params.cmd_rsp.cmd_opcode == ACI_CMD_GET_TEMPERATURE) { + Serial.print("aci_evt->params.cmd_rsp.params.get_temperature="); + Serial.print(aci_evt->params.cmd_rsp.params.get_temperature.temperature_value, DEC); + Serial.println(); + + int32_t t = aci_evt->params.cmd_rsp.params.get_temperature.temperature_value; + + // t is in 1/4 degrees celcius parts. + + // Multiply t by 25 without having to include float support + t = t * 16 + t * 8 + t; + + uint32_t exponent = 2 << 24; + + // example. reading=111. real temperature = 111 / 4 = 27.75 dec C + // Calculation: t = 2775, exp = 2. formula: 10^exp * 0.t => 10^2 * 0.2775 = 27.75 + + // The value of flags + // bit 0: 0=Celcius, 1=Farenheight + // bit 1: 0=time stamp field not present, 1=present + // bit 2: 0=temperature type field not present, 1=present + // bit 3-7: reserved + // Reference: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature_measurement.xml + struct { + uint8_t flags; + uint32_t value; + // time stamp + // temperature type + } temperature_measurement = { + 0, + exponent | (t & 0x00FFFFFF) + }; + + lib_aci_set_local_data(&aci_state, PIPE_SOIL_MOISTURE_INTERMEDIATE_TEMPERATURE_SET, + (uint8_t *) &temperature_measurement, + sizeof(temperature_measurement)); + } break; case ACI_EVT_CONNECTED: @@ -201,6 +238,8 @@ static void aci_loop() { // This will trigger a ACI_CMD_GET_DEVICE_VERSION. lib_aci_device_version(); + lib_aci_get_temperature(); + sm_on_connect(); break; @@ -228,7 +267,7 @@ static void aci_loop() { // Serial.print(F("ACI_EVT_DATA_RECEIVED: pipe_number=")); // Serial.println(pipe_number, DEC); - if (pipe_number == pipe_rx) { + if (pipe_number == sm_pipe_rx) { on_soil_moisture_ctrl(aci_evt->params.data_received.rx_data.aci_data, aci_evt->len); } break; @@ -326,7 +365,7 @@ void loop() { if (!rf_started) { static int count = 0; - static boolean reset_attempted = false; + static bool reset_attempted = false; count++; if (!reset_attempted) { @@ -420,12 +459,12 @@ void notify_soil_moisture(const struct sm_res& res, uint8_t body_len) { // Serial.print(F("aci_state.data_credit_available=")); // Serial.println(aci_state.data_credit_available, DEC); - boolean available = lib_aci_is_pipe_available(&aci_state, pipe_tx); + bool available = lib_aci_is_pipe_available(&aci_state, sm_pipe_tx); // Serial.print(F("pipe available=")); // Serial.println(available, DEC); // This should probably be an explicit part of the API, but for now it makes it easier to implement a synchronous interface. - lib_aci_set_local_data(&aci_state, pipe_set, (uint8_t *)&res, len); + lib_aci_set_local_data(&aci_state, sm_pipe_set, (uint8_t *)&res, len); // There is no need to lod messages that won't be sent. if (!available) { diff --git a/trygvisio_soil_moisture.xml b/trygvisio_soil_moisture.xml index 3967ed0..97aaba3 100644 --- a/trygvisio_soil_moisture.xml +++ b/trygvisio_soil_moisture.xml @@ -98,6 +98,28 @@ 0 + + Intermediate Temperature + 2a1e + + 0 + 5 + 1 + false + false + + false + false + true + false + false + + true + false + + 0 + + Woot diff --git a/ublue_setup.gen.out.txt b/ublue_setup.gen.out.txt index 2af6f18..38d0450 100644 --- a/ublue_setup.gen.out.txt +++ b/ublue_setup.gen.out.txt @@ -1,28 +1,28 @@ ------------------------------------------------------------------------------ uBlue Setup generation report Generated with uBlue setup DLL version: 1.0.0.16903 - Generated: Sun Jan 04 16:53:23 2015 (UTC) + Generated: Sun Jun 21 20:26:23 2015 (UTC) This file is automatically generated, do not modify ------------------------------------------------------------------------------ [Counts] -Setup data size = 547 bytes -Local database size = 289 bytes -Local attribute count = 5 +Setup data size = 612 bytes +Local database size = 333 bytes +Local attribute count = 6 Remote attribute count = 0 -Total pipe count = 7 -Dynamic data size = 162 bytes (worst case) +Total pipe count = 9 +Dynamic data size = 180 bytes (worst case) [Setup Area Layout] Setup area, total = 1595 bytes -Setup area, used = 370 bytes ( 23% of total ) -Local services = 289 bytes ( 78% of used ) +Setup area, used = 427 bytes ( 26% of total ) +Local services = 333 bytes ( 77% of used ) Remote services = 0 bytes ( 0% of used ) -Pipes = 50 bytes ( 13% of used ) -VS UUID area = 16 bytes ( 4% of used ) -Extended Attr area = 15 bytes ( 4% of used ) +Pipes = 60 bytes ( 14% of used ) +VS UUID area = 16 bytes ( 3% of used ) +Extended Attr area = 18 bytes ( 4% of used ) [Device Settings] @@ -79,6 +79,9 @@ Handle Pipes Structure 0x0011 |----- |Characteristic: "?" (02:0x0011) [rd|wr|not] [rd:allow|wr:none] 0x0012 |Value: {} [rd:allow|wr:allow] 0x0013 |----- |Descriptor: "Client Characteristic Configuration" (01:0x2902) Value: {0x00 0x00} [rd:allow|wr:allow] +0x0014 |----- |Characteristic: "?" (01:0x2A1E) [rd|not] [rd:allow|wr:none] +0x0015 x> |Value: {0xAA 0xBB 0xCC 0xDD 0xEE 0xFF 0x99 0x88 0x77 0x66} [rd:allow|wr:none] +0x0016 |----- |Descriptor: "Client Characteristic Configuration" (01:0x2902) Value: {0x00 0x00} [rd:allow|wr:allow] [Remote Database] @@ -96,11 +99,13 @@ Pipe Store Type Service Char. CPF Desc. 05 Local TX 02:0x0010 02:0x0011 -- -- 06 Local SET 02:0x0010 02:0x0011 -- -- 07 Local RX_AA 02:0x0010 02:0x0011 -- -- +08 Local TX 02:0x0010 01:0x2A1E -- -- +09 Local SET 02:0x0010 01:0x2A1E -- -- [Setup Data] 07-06-00-00-03-02-42-07 -1F-06-10-00-00-00-00-00-00-00-05-00-07-01-01-00-00-06-00-01-D1-0F-18-00-00-00-00-00-00-00-00-00 +1F-06-10-00-00-00-00-00-00-00-06-00-09-01-01-00-00-06-00-01-D1-0F-18-00-00-00-00-00-00-00-00-00 1F-06-10-1C-10-02-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-50-03-90-01-FF 1F-06-10-38-FF-FF-02-58-0A-05-00-00-00-00-00-00-00-10-00-00-00-00-00-00-00-00-00-00-00-00-00-00 05-06-10-54-00-00 @@ -114,9 +119,11 @@ Pipe Store Type Service Char. CPF Desc. 1F-06-20-C4-04-10-10-00-10-28-00-01-3F-D8-1F-4A-8E-BC-D3-70-C5-59-5D-03-10-00-D0-32-04-04-13-13 1F-06-20-E0-00-11-28-03-01-1A-12-00-3F-D8-1F-4A-8E-BC-D3-70-C5-59-5D-03-11-00-D0-32-54-14-14-00 1F-06-20-FC-00-12-00-11-02-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-46-14-03 -0C-06-21-18-02-00-13-29-02-01-00-00-00 +1F-06-21-18-02-00-13-29-02-01-00-00-04-04-05-05-00-14-28-03-01-12-15-00-1E-2A-16-04-0B-0A-00-15 +1C-06-21-34-2A-1E-01-AA-BB-CC-DD-EE-FF-99-88-77-66-46-14-03-02-00-16-29-02-01-00-00-00 1F-06-40-00-2A-00-01-00-80-04-00-03-00-00-2A-19-01-00-80-04-00-0B-00-00-2A-1A-01-00-80-04-00-0D -19-06-40-1C-00-00-2A-1B-01-00-80-04-00-0F-00-00-00-11-02-04-82-04-00-12-00-13 +1F-06-40-1C-00-00-2A-1B-01-00-80-04-00-0F-00-00-00-11-02-04-82-04-00-12-00-13-2A-1E-01-00-82-04 +07-06-40-38-00-15-00-16 13-06-50-00-3F-D8-1F-4A-8E-BC-D3-70-C5-59-5D-03-00-00-D0-32 -12-06-60-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 -06-06-F0-00-83-0D-8F +15-06-60-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 +06-06-F0-00-83-26-E0 -- cgit v1.2.3