From 2f50ae8864aa2ba9e5807432eb878552389a9cb2 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 4 Jan 2015 21:02:45 +0100 Subject: o Reworking the code after implementing much more on the Android app. --- .gitignore | 1 + Makefile | 5 +- README.md | 22 ++++- app.cpp | 234 ++++++++++++++++++++++++++++++++++++-------- app.h | 90 +++++++++++++---- services.h | 110 ++++++++------------- services_lock.h | 110 ++++++++------------- trygvisio_soil_moisture.ino | 110 +++++++++------------ trygvisio_soil_moisture.xml | 41 ++++---- ublue_setup.gen.out.txt | 122 +++++++++++++++++++++++ 10 files changed, 562 insertions(+), 283 deletions(-) create mode 100644 .gitignore create mode 100644 ublue_setup.gen.out.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..414487d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build-*/ diff --git a/Makefile b/Makefile index d52f7b7..39aa27c 100644 --- a/Makefile +++ b/Makefile @@ -7,4 +7,7 @@ MONITOR_PORT ?= /dev/ttyACM0 ARDUINO_LIBS = BLE SPI ARDMK_DIR ?= /usr/share/arduino -include $(ARDMK_DIR)/Arduino.mk +-include $(ARDMK_DIR)/Arduino.mk + +$(ARDMK_DIR)/Arduino.mk: + @if [ ! -r $(ARDMK_DIR)/Arduino.mk ]; then echo "You need to install the arduino-mk package"; exit 1; fi diff --git a/README.md b/README.md index 428ce70..7e3bfc0 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,24 @@ -# Endpoints +# UUIDs -## Soil Moisture +Trygvis.io base UUID: 32D0xxxx-035D-59C5-70D3-BC8E4A1FD83F -### Soil Moisture Level +# Services + +## Status Panel: trygvis.io + 0x0001 + +## Soil Moisture: trygvis.io + 0x0010 + +Included characteristics: + + * Soil Moisture Level + +# Characteristics + +## Gauge Data: trygvis.io + 0x0002 + +## Gauge Control: trygvis.io + 0x0004 + +## Soil Moisture Level: trygvis.io + 0x0011 Format: two bytes of data. Byte #1: sensor id, byte #2: sensor level (unsigned int, 0-255). diff --git a/app.cpp b/app.cpp index 909a097..b72b07d 100644 --- a/app.cpp +++ b/app.cpp @@ -11,10 +11,13 @@ // See http://redbearlab.com/blendmicro/ struct sm_sensor { - uint8_t pin; - uint8_t value; -} gauges[SENSOR_COUNT] = { - { 9, 0}, + uint8_t pin; + uint8_t value; + uint16_t warning_value; + uint8_t name_length; + uint8_t name[SENSOR_NAME_LEN]; +} sensors[SENSOR_COUNT] = { + {9, 0, 10, 9, 'sensor #1'}, }; void on_loop() { @@ -25,67 +28,214 @@ void on_loop() { now = millis(); if (now - last > 3000) { last = now; - sm_res data; - data.len = sizeof(struct sm_get_sensor_level_res); - data.code = SM_CMD_GET_SENSOR_LEVEL; - data.get_sensor_level.level = x; + + struct sm_res res; + res.code = SM_CMD_GET_VALUE; + res.get_value.value = x; + x++; if(x == 0) { x = 10; } - if(x % 2 == 0) { - notify_soil_moisture(&data); - } else { - notify_battery_level(x); - } +// if(x % 2 == 0) { +// notify_soil_moisture(res); +// } else { +// notify_battery_level(x); +// } + notify_soil_moisture(res, sizeof(sm_get_value_res)); + } +} + +#ifdef SM_DEBUG + +static void write_name(uint8_t const* name, uint8_t len) { + for(int i = 0; i < len; i++) { + Serial.print((char)name[i]); + } +} + +void write_req(struct sm_req const& req) { + int i; + + Serial.print(">> "); + + switch(req.code) { + case SM_CMD_GET_SENSOR_COUNT: + Serial.print("SM_CMD_GET_SENSOR_COUNT"); + break; + + case SM_CMD_GET_VALUE: + Serial.print("SM_CMD_GET_VALUE"); + Serial.print(": sensor="); + Serial.print(req.get_value.sensor, DEC); + break; + + case SM_CMD_SET_WARNING_VALUE: + Serial.print("SM_CMD_SET_WARNING_VALUE"); + Serial.print(": sensor="); + Serial.print(req.set_warning_value.sensor, DEC); + Serial.print(", warning_value="); + Serial.print(req.set_warning_value.warning_value, DEC); + break; + + case SM_CMD_GET_WARNING_VALUE: + Serial.print("SM_CMD_GET_WARNING_VALUE"); + Serial.print(": sensor="); + Serial.print(req.get_warning_value.sensor, DEC); + break; + + case SM_CMD_SET_SENSOR_NAME: + Serial.print("SM_CMD_SET_SENSOR_NAME"); + Serial.print(": sensor="); + Serial.print(req.set_sensor_name.sensor, DEC); + Serial.print(", name="); + write_name(req.set_sensor_name.name, req.set_sensor_name.length); + break; + + case SM_CMD_GET_SENSOR_NAME: + Serial.print("SM_CMD_GET_SENSOR_NAME"); + break; + + default: + Serial.print("Unknown command!"); } + Serial.println(); } -void on_soil_moisture(uint8_t *data, uint8_t len) { - Serial.print(F("on_soil_moisture, data[0]=")); - Serial.print(data[0], HEX); - Serial.print(F(", data[1]=")); - Serial.println(data[1], HEX); +void write_res(struct sm_res const& res) { + int i; + + Serial.print("<< "); + + switch(res.code) { + case SM_CMD_GET_SENSOR_COUNT: + Serial.print("SM_CMD_GET_SENSOR_COUNT"); + Serial.print(": count="); + Serial.print(res.get_sensor_count.count, DEC); + break; - struct sm_req *cmd = (struct sm_req *) data; + case SM_CMD_GET_VALUE: + Serial.print("SM_CMD_GET_VALUE"); + Serial.print(": value="); + Serial.print(res.get_value.value, DEC); + break; + + case SM_CMD_SET_WARNING_VALUE: + Serial.print("SM_CMD_SET_WARNING_VALUE"); + break; + + case SM_CMD_GET_WARNING_VALUE: + Serial.print("SM_CMD_GET_WARNING_VALUE"); + Serial.print(": warning_value="); + Serial.print(res.get_warning_value.warning_value, DEC); + break; + + case SM_CMD_SET_SENSOR_NAME: + Serial.print("SM_CMD_SET_SENSOR_NAME"); + break; + + case SM_CMD_GET_SENSOR_NAME: + Serial.print("SM_CMD_GET_SENSOR_NAME"); + Serial.print(": name="); + write_name(res.get_sensor_name.name, res.get_sensor_name.length); + break; + + default: + Serial.print("Unknown command!"); + } + Serial.println(); +} +#endif + +void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) { + struct sm_req *req = (struct sm_req *) data; struct sm_res res; + uint8_t sensor; - res.code = cmd->code; +#if SM_DEBUG == 1 + write_req(*req); +#endif - Serial.print("code="); - Serial.println(cmd->code, DEC); + res.code = req->code; + uint8_t body_len; - switch(cmd->code) { + switch(req->code) { case SM_CMD_GET_SENSOR_COUNT: - res.len = sizeof(struct sm_get_sensor_count_res); + body_len = sizeof(sm_get_sensor_count_res); res.get_sensor_count.count = SENSOR_COUNT; break; - case SM_CMD_SET_SENSOR_THRESHOLD: -// res.len = sizeof(struct fsp_set_gauge_res); -// if (cmd->set_gauge.gauge < GAUGE_COUNT) { -// analogWrite(gauges[cmd->set_gauge.gauge].pin, cmd->set_gauge.value); -// gauges[cmd->set_gauge.gauge].value = cmd->set_gauge.value; -// } + case SM_CMD_GET_VALUE: + body_len = sizeof(sm_get_value_res); + sensor = req->get_value.sensor; + + if (sensor < SENSOR_COUNT) { + // TODO: update the sensor's value + res.get_value.value = sensors[sensor].value; + } else { + res.code = SM_CMD_FAIL; + } break; - case SM_CMD_GET_SENSOR_LEVEL: -// res.len = sizeof(struct fsp_get_gauge_res); -// if (cmd->get_gauge.gauge < GAUGE_COUNT) { -// res.get_gauge.gauge = cmd->get_gauge.gauge; -// res.get_gauge.value = gauges[cmd->get_gauge.gauge].value; -// } else { -// res.code = FSP_CMD_FAIL; -// res.len = 0; -// } + + case SM_CMD_SET_WARNING_VALUE: + body_len = sizeof(sm_set_warning_value_res); + sensor = req->set_warning_value.sensor; + + if (sensor < SENSOR_COUNT) { + sensors[sensor].warning_value = req->set_warning_value.warning_value; + } else { + res.code = SM_CMD_FAIL; + } + break; + + case SM_CMD_GET_WARNING_VALUE: + body_len = sizeof(sm_get_warning_value_res); + sensor = req->get_warning_value.sensor; + + if (sensor < SENSOR_COUNT) { + res.get_warning_value.warning_value = sensors[sensor].warning_value; + } else { + res.code = SM_CMD_FAIL; + } + break; + + case SM_CMD_SET_SENSOR_NAME: + body_len = sizeof(sm_set_sensor_name_res); + sensor = req->set_sensor_name.sensor; + + if (sensor < SENSOR_COUNT) { + sensors[sensor].name_length = min(req->set_sensor_name.length, SENSOR_NAME_LEN); + memcpy(sensors[sensor].name, req->set_sensor_name.name, sensors[sensor].name_length); + } else { + res.code = SM_CMD_FAIL; + } + break; + + case SM_CMD_GET_SENSOR_NAME: + body_len = sizeof(sm_get_sensor_name_res); + sensor = req->get_sensor_name.sensor; + Serial.print("sensor="); Serial.print(sensor, DEC); + + if (sensor < SENSOR_COUNT) { + res.get_sensor_name.length = sensors[sensor].name_length; + memcpy(res.get_sensor_name.name, sensors[sensor].name, SENSOR_NAME_LEN); + } else { + res.code = SM_CMD_FAIL; + } break; + default: res.code = SM_CMD_FAIL; - res.len = 0; break; } -// tx_soil_moisture(&res); -} + Serial.println(); + + if (res.code == SM_CMD_FAIL) { + body_len = 0; + } + notify_soil_moisture(res, body_len); +} diff --git a/app.h b/app.h index af3c39a..e13478e 100644 --- a/app.h +++ b/app.h @@ -2,12 +2,18 @@ #define APP_H #include +#include + +#define SENSOR_NAME_LEN 10 enum sm_cmd_code { - SM_CMD_GET_SENSOR_COUNT = 1, - SM_CMD_SET_SENSOR_THRESHOLD = 2, - SM_CMD_GET_SENSOR_LEVEL = 3, - SM_CMD_FAIL = 255, + SM_CMD_GET_SENSOR_COUNT = 1, + SM_CMD_GET_VALUE = 2, + SM_CMD_SET_WARNING_VALUE = 3, + SM_CMD_GET_WARNING_VALUE = 4, + SM_CMD_SET_SENSOR_NAME = 5, + SM_CMD_GET_SENSOR_NAME = 6, + SM_CMD_FAIL = 255, }; struct sm_get_sensor_count_req { @@ -17,50 +23,94 @@ struct sm_get_sensor_count_res { uint8_t count; }; -struct sm_set_sensor_threshold_req { +struct sm_get_value_req { + uint8_t sensor; +}; + +struct sm_get_value_res { + uint8_t value; +}; + +struct sm_set_warning_value_req { uint8_t sensor; - uint8_t threshold; + uint16_t warning_value; }; -struct sm_set_sensor_threshold_res { +struct sm_set_warning_value_res { }; -struct sm_get_sensor_level_req { +struct sm_get_warning_value_req { uint8_t sensor; }; -struct sm_get_sensor_level_res { +struct sm_get_warning_value_res { + uint16_t warning_value; +}; + +struct sm_set_sensor_name_req { uint8_t sensor; - uint8_t level; + uint8_t length; + uint8_t name[SENSOR_NAME_LEN]; +}; + +struct sm_set_sensor_name_res { +}; + +struct sm_get_sensor_name_req { + uint8_t sensor; +}; + +struct sm_get_sensor_name_res { + uint8_t length; + uint8_t name[SENSOR_NAME_LEN]; }; struct sm_req { uint8_t code; union { - struct sm_get_sensor_count_req get_sensor_count; - struct sm_get_sensor_level_req get_sensor_level; - struct sm_set_sensor_threshold_req set_sensor_threshold; + struct sm_get_sensor_count_req get_sensor_count; + struct sm_get_value_req get_value; + struct sm_set_warning_value_req set_warning_value; + struct sm_get_warning_value_req get_warning_value; + struct sm_set_sensor_name_req set_sensor_name; + struct sm_get_sensor_name_req get_sensor_name; }; }; +// len + code +#define SM_RES_HEADER_SIZE 1 + struct sm_res { - uint8_t len; + // header uint8_t code; + + // body union { - struct sm_get_sensor_count_res get_sensor_count; - struct sm_get_sensor_level_res get_sensor_level; - struct sm_set_sensor_threshold_res set_sensor_threshold; + struct sm_get_sensor_count_res get_sensor_count; + struct sm_get_value_res get_value; + struct sm_set_warning_value_res set_warning_value; + struct sm_get_warning_value_res get_warning_value; + struct sm_set_sensor_name_res set_sensor_name; + struct sm_get_sensor_name_res get_sensor_name; }; }; void on_loop(); -bool tx_soil_moisture(struct sm_res *res); -void notify_soil_moisture(struct sm_res *res); +//boolean tx_soil_moisture(struct sm_res& res); +void notify_soil_moisture(const struct sm_res& res, uint8_t body_len); void notify_battery_level(uint8_t value); -void on_soil_moisture(uint8_t *data, uint8_t len); +void on_soil_moisture_ctrl(uint8_t *data, uint8_t len); + +#ifndef SM_DEBUG +#define SM_DEBUG 1 +#endif +#if SM_DEBUG == 1 +void write_req(struct sm_req const& req); +void write_res(struct sm_res const& res); #endif +#endif diff --git a/services.h b/services.h index 0344b5f..bace5e1 100644 --- a/services.h +++ b/services.h @@ -11,72 +11,47 @@ #define SETUP_ID 0 #define SETUP_FORMAT 3 /** nRF8001 D */ -#define ACI_DYNAMIC_DATA_SIZE 165 +#define ACI_DYNAMIC_DATA_SIZE 162 /* Service: Gap - Characteristic: Device name - Pipe: SET */ #define PIPE_GAP_DEVICE_NAME_SET 1 #define PIPE_GAP_DEVICE_NAME_SET_MAX_SIZE 10 -/* Service: Battery - Characteristic: Battery Level - Pipe: BROADCAST */ -#define PIPE_BATTERY_BATTERY_LEVEL_BROADCAST 2 -#define PIPE_BATTERY_BATTERY_LEVEL_BROADCAST_MAX_SIZE 1 - -/* Service: Battery - Characteristic: Battery Level - Pipe: TX */ -#define PIPE_BATTERY_BATTERY_LEVEL_TX 3 -#define PIPE_BATTERY_BATTERY_LEVEL_TX_MAX_SIZE 1 - /* Service: Battery - Characteristic: Battery Level - Pipe: SET */ -#define PIPE_BATTERY_BATTERY_LEVEL_SET 4 +#define PIPE_BATTERY_BATTERY_LEVEL_SET 2 #define PIPE_BATTERY_BATTERY_LEVEL_SET_MAX_SIZE 1 /* Service: Battery - Characteristic: Battery Power State - Pipe: SET */ -#define PIPE_BATTERY_BATTERY_POWER_STATE_SET 5 +#define PIPE_BATTERY_BATTERY_POWER_STATE_SET 3 #define PIPE_BATTERY_BATTERY_POWER_STATE_SET_MAX_SIZE 1 /* Service: Battery - Characteristic: Battery Level State - Pipe: SET */ -#define PIPE_BATTERY_BATTERY_LEVEL_STATE_SET 6 +#define PIPE_BATTERY_BATTERY_LEVEL_STATE_SET 4 #define PIPE_BATTERY_BATTERY_LEVEL_STATE_SET_MAX_SIZE 2 -/* Service: Soil Moisture - Characteristic: Soil Moisture Level - Pipe: BROADCAST */ -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_BROADCAST 7 -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_BROADCAST_MAX_SIZE 5 - -/* Service: Soil Moisture - Characteristic: Soil Moisture Level - Pipe: TX */ -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_TX 8 -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_TX_MAX_SIZE 5 - -/* Service: Soil Moisture - Characteristic: Soil Moisture Level - Pipe: SET */ -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_SET 9 -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_SET_MAX_SIZE 5 - -/* Service: Soil Moisture - Characteristic: Soil Moisture Level - Pipe: BROADCAST */ -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_BROADCAST_1 10 -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_BROADCAST_1_MAX_SIZE 5 +/* Service: Soil Moisture - Characteristic: Soil Moisture Control - Pipe: TX */ +#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_TX 5 +#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_TX_MAX_SIZE 20 -/* Service: Soil Moisture - Characteristic: Soil Moisture Level - Pipe: TX */ -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_TX_1 11 -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_TX_1_MAX_SIZE 5 +/* Service: Soil Moisture - Characteristic: Soil Moisture Control - Pipe: SET */ +#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_SET 6 +#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_SET_MAX_SIZE 20 -/* Service: Soil Moisture - Characteristic: Soil Moisture Level - Pipe: SET */ -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_SET_1 12 -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_SET_1_MAX_SIZE 5 +/* Service: Soil Moisture - Characteristic: Soil Moisture Control - Pipe: RX_ACK_AUTO */ +#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO 7 +#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO_MAX_SIZE 20 -#define NUMBER_OF_PIPES 12 +#define NUMBER_OF_PIPES 7 #define SERVICES_PIPE_TYPE_MAPPING_CONTENT {\ - {ACI_STORE_LOCAL, ACI_SET}, \ - {ACI_STORE_LOCAL, ACI_TX_BROADCAST}, \ - {ACI_STORE_LOCAL, ACI_TX}, \ {ACI_STORE_LOCAL, ACI_SET}, \ {ACI_STORE_LOCAL, ACI_SET}, \ {ACI_STORE_LOCAL, ACI_SET}, \ - {ACI_STORE_LOCAL, ACI_TX_BROADCAST}, \ - {ACI_STORE_LOCAL, ACI_TX}, \ {ACI_STORE_LOCAL, ACI_SET}, \ - {ACI_STORE_LOCAL, ACI_TX_BROADCAST}, \ {ACI_STORE_LOCAL, ACI_TX}, \ {ACI_STORE_LOCAL, ACI_SET}, \ + {ACI_STORE_LOCAL, ACI_RX_ACK_AUTO}, \ } #define GAP_PPCP_MAX_CONN_INT 0xffff /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */ @@ -93,19 +68,19 @@ },\ {0x00,\ {\ - 0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x0c,0x01,0x01,0x00,0x00,0x06,0x00,0x01,\ - 0x81,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x07,0x01,0x01,0x00,0x00,0x06,0x00,0x01,\ + 0xd1,0x0f,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x10,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x90,0x00,0xff,\ + 0x1f,0x06,0x10,0x1c,0x10,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x03,0x90,0x01,0xff,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x10,0x38,0xff,0xff,0x02,0x58,0x0a,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,\ + 0x1f,0x06,0x10,0x38,0xff,0xff,0x02,0x58,0x0a,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,\ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ },\ },\ @@ -122,13 +97,13 @@ },\ {0x00,\ {\ - 0x1f,0x06,0x20,0x1c,0x03,0x00,0x03,0x2a,0x00,0x01,0x77,0x61,0x74,0x64,0x69,0x63,0x73,0x65,0x6d,0x69,\ + 0x1f,0x06,0x20,0x1c,0x04,0x00,0x03,0x2a,0x00,0x01,0x57,0x6f,0x6f,0x74,0x69,0x63,0x73,0x65,0x6d,0x69,\ 0x04,0x04,0x05,0x05,0x00,0x04,0x28,0x03,0x01,0x02,0x05,0x00,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x20,0x38,0x01,0x2a,0x06,0x04,0x03,0x02,0x00,0x05,0x2a,0x01,0x01,0x00,0x00,0x04,0x04,0x05,\ + 0x1f,0x06,0x20,0x38,0x01,0x2a,0x06,0x04,0x03,0x02,0x00,0x05,0x2a,0x01,0x01,0x80,0x01,0x04,0x04,0x05,\ 0x05,0x00,0x06,0x28,0x03,0x01,0x02,0x07,0x00,0x04,0x2a,0x06,\ },\ },\ @@ -141,73 +116,72 @@ {0x00,\ {\ 0x1f,0x06,0x20,0x70,0x04,0x02,0x02,0x00,0x09,0x28,0x00,0x01,0x0f,0x18,0x04,0x04,0x05,0x05,0x00,0x0a,\ - 0x28,0x03,0x01,0x12,0x0b,0x00,0x19,0x2a,0x16,0x04,0x02,0x01,\ + 0x28,0x03,0x01,0x02,0x0b,0x00,0x19,0x2a,0x06,0x04,0x02,0x01,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x20,0x8c,0x00,0x0b,0x2a,0x19,0x01,0x10,0x46,0x14,0x03,0x02,0x00,0x0c,0x29,0x02,0x01,0x00,\ - 0x00,0x04,0x04,0x05,0x05,0x00,0x0d,0x28,0x03,0x01,0x02,0x0e,\ + 0x1f,0x06,0x20,0x8c,0x00,0x0b,0x2a,0x19,0x01,0x10,0x04,0x04,0x05,0x05,0x00,0x0c,0x28,0x03,0x01,0x02,\ + 0x0d,0x00,0x1a,0x2a,0x06,0x04,0x02,0x01,0x00,0x0d,0x2a,0x1a,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x20,0xa8,0x00,0x1a,0x2a,0x06,0x04,0x02,0x01,0x00,0x0e,0x2a,0x1a,0x01,0x00,0x04,0x04,0x05,\ - 0x05,0x00,0x0f,0x28,0x03,0x01,0x02,0x10,0x00,0x1b,0x2a,0x06,\ + 0x1f,0x06,0x20,0xa8,0x01,0x00,0x04,0x04,0x05,0x05,0x00,0x0e,0x28,0x03,0x01,0x02,0x0f,0x00,0x1b,0x2a,\ + 0x06,0x04,0x03,0x02,0x00,0x0f,0x2a,0x1b,0x01,0x00,0x00,0x04,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x20,0xc4,0x04,0x03,0x02,0x00,0x10,0x2a,0x1b,0x01,0x00,0x00,0x04,0x04,0x02,0x02,0x00,0x11,\ - 0x28,0x00,0x01,0x10,0x00,0x04,0x04,0x05,0x05,0x00,0x12,0x28,\ + 0x1f,0x06,0x20,0xc4,0x04,0x10,0x10,0x00,0x10,0x28,0x00,0x01,0x3f,0xd8,0x1f,0x4a,0x8e,0xbc,0xd3,0x70,\ + 0xc5,0x59,0x5d,0x03,0x10,0x00,0xd0,0x32,0x04,0x04,0x13,0x13,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x20,0xe0,0x03,0x01,0x12,0x13,0x00,0x11,0x00,0x16,0x04,0x06,0x05,0x00,0x13,0x00,0x11,0x01,\ - 0xaa,0x55,0xaa,0x55,0xaa,0x46,0x14,0x03,0x02,0x00,0x14,0x29,\ + 0x1f,0x06,0x20,0xe0,0x00,0x11,0x28,0x03,0x01,0x1a,0x12,0x00,0x3f,0xd8,0x1f,0x4a,0x8e,0xbc,0xd3,0x70,\ + 0xc5,0x59,0x5d,0x03,0x11,0x00,0xd0,0x32,0x54,0x14,0x14,0x00,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x20,0xfc,0x02,0x01,0x00,0x00,0x04,0x04,0x02,0x02,0x00,0x15,0x28,0x00,0x01,0x10,0x00,0x04,\ - 0x04,0x05,0x05,0x00,0x16,0x28,0x03,0x01,0x12,0x17,0x00,0x11,\ + 0x1f,0x06,0x20,0xfc,0x00,0x12,0x00,0x11,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x14,0x03,\ },\ },\ {0x00,\ {\ - 0x1e,0x06,0x21,0x18,0x00,0x14,0x04,0x05,0x00,0x00,0x17,0x00,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x46,\ - 0x14,0x03,0x02,0x00,0x18,0x29,0x02,0x01,0x00,0x00,0x00,\ + 0x0c,0x06,0x21,0x18,0x02,0x00,0x13,0x29,0x02,0x01,0x00,0x00,0x00,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x40,0x00,0x2a,0x00,0x01,0x00,0x80,0x04,0x00,0x03,0x00,0x00,0x2a,0x19,0x01,0x00,0x83,0x04,\ - 0x00,0x0b,0x00,0x0c,0x2a,0x1a,0x01,0x00,0x80,0x04,0x00,0x0e,\ + 0x1f,0x06,0x40,0x00,0x2a,0x00,0x01,0x00,0x80,0x04,0x00,0x03,0x00,0x00,0x2a,0x19,0x01,0x00,0x80,0x04,\ + 0x00,0x0b,0x00,0x00,0x2a,0x1a,0x01,0x00,0x80,0x04,0x00,0x0d,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x40,0x1c,0x00,0x00,0x2a,0x1b,0x01,0x00,0x80,0x04,0x00,0x10,0x00,0x00,0x00,0x11,0x01,0x00,\ - 0x83,0x04,0x00,0x13,0x00,0x14,0x00,0x11,0x01,0x00,0x83,0x04,\ + 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,\ },\ },\ {0x00,\ {\ - 0x07,0x06,0x40,0x38,0x00,0x17,0x00,0x18,\ + 0x13,0x06,0x50,0x00,0x3f,0xd8,0x1f,0x4a,0x8e,0xbc,0xd3,0x70,0xc5,0x59,0x5d,0x03,0x00,0x00,0xd0,0x32,\ },\ },\ {0x00,\ {\ - 0x15,0x06,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ - 0x00,0x00,\ + 0x12,0x06,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ },\ },\ {0x00,\ {\ - 0x06,0x06,0xf0,0x00,0x03,0xda,0x64,\ + 0x06,0x06,0xf0,0x00,0x03,0x9c,0x07,\ },\ },\ } #endif + diff --git a/services_lock.h b/services_lock.h index fe0057a..a0e8801 100644 --- a/services_lock.h +++ b/services_lock.h @@ -15,72 +15,47 @@ #define SETUP_ID 0 #define SETUP_FORMAT 3 /** nRF8001 D */ -#define ACI_DYNAMIC_DATA_SIZE 165 +#define ACI_DYNAMIC_DATA_SIZE 162 /* Service: Gap - Characteristic: Device name - Pipe: SET */ #define PIPE_GAP_DEVICE_NAME_SET 1 #define PIPE_GAP_DEVICE_NAME_SET_MAX_SIZE 10 -/* Service: Battery - Characteristic: Battery Level - Pipe: BROADCAST */ -#define PIPE_BATTERY_BATTERY_LEVEL_BROADCAST 2 -#define PIPE_BATTERY_BATTERY_LEVEL_BROADCAST_MAX_SIZE 1 - -/* Service: Battery - Characteristic: Battery Level - Pipe: TX */ -#define PIPE_BATTERY_BATTERY_LEVEL_TX 3 -#define PIPE_BATTERY_BATTERY_LEVEL_TX_MAX_SIZE 1 - /* Service: Battery - Characteristic: Battery Level - Pipe: SET */ -#define PIPE_BATTERY_BATTERY_LEVEL_SET 4 +#define PIPE_BATTERY_BATTERY_LEVEL_SET 2 #define PIPE_BATTERY_BATTERY_LEVEL_SET_MAX_SIZE 1 /* Service: Battery - Characteristic: Battery Power State - Pipe: SET */ -#define PIPE_BATTERY_BATTERY_POWER_STATE_SET 5 +#define PIPE_BATTERY_BATTERY_POWER_STATE_SET 3 #define PIPE_BATTERY_BATTERY_POWER_STATE_SET_MAX_SIZE 1 /* Service: Battery - Characteristic: Battery Level State - Pipe: SET */ -#define PIPE_BATTERY_BATTERY_LEVEL_STATE_SET 6 +#define PIPE_BATTERY_BATTERY_LEVEL_STATE_SET 4 #define PIPE_BATTERY_BATTERY_LEVEL_STATE_SET_MAX_SIZE 2 -/* Service: Soil Moisture - Characteristic: Soil Moisture Level - Pipe: BROADCAST */ -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_BROADCAST 7 -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_BROADCAST_MAX_SIZE 5 - -/* Service: Soil Moisture - Characteristic: Soil Moisture Level - Pipe: TX */ -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_TX 8 -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_TX_MAX_SIZE 5 - -/* Service: Soil Moisture - Characteristic: Soil Moisture Level - Pipe: SET */ -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_SET 9 -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_SET_MAX_SIZE 5 - -/* Service: Soil Moisture - Characteristic: Soil Moisture Level - Pipe: BROADCAST */ -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_BROADCAST_1 10 -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_BROADCAST_1_MAX_SIZE 5 +/* Service: Soil Moisture - Characteristic: Soil Moisture Control - Pipe: TX */ +#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_TX 5 +#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_TX_MAX_SIZE 20 -/* Service: Soil Moisture - Characteristic: Soil Moisture Level - Pipe: TX */ -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_TX_1 11 -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_TX_1_MAX_SIZE 5 +/* Service: Soil Moisture - Characteristic: Soil Moisture Control - Pipe: SET */ +#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_SET 6 +#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_SET_MAX_SIZE 20 -/* Service: Soil Moisture - Characteristic: Soil Moisture Level - Pipe: SET */ -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_SET_1 12 -#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_SET_1_MAX_SIZE 5 +/* Service: Soil Moisture - Characteristic: Soil Moisture Control - Pipe: RX_ACK_AUTO */ +#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO 7 +#define PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO_MAX_SIZE 20 -#define NUMBER_OF_PIPES 12 +#define NUMBER_OF_PIPES 7 #define SERVICES_PIPE_TYPE_MAPPING_CONTENT {\ - {ACI_STORE_LOCAL, ACI_SET}, \ - {ACI_STORE_LOCAL, ACI_TX_BROADCAST}, \ - {ACI_STORE_LOCAL, ACI_TX}, \ {ACI_STORE_LOCAL, ACI_SET}, \ {ACI_STORE_LOCAL, ACI_SET}, \ {ACI_STORE_LOCAL, ACI_SET}, \ - {ACI_STORE_LOCAL, ACI_TX_BROADCAST}, \ - {ACI_STORE_LOCAL, ACI_TX}, \ {ACI_STORE_LOCAL, ACI_SET}, \ - {ACI_STORE_LOCAL, ACI_TX_BROADCAST}, \ {ACI_STORE_LOCAL, ACI_TX}, \ {ACI_STORE_LOCAL, ACI_SET}, \ + {ACI_STORE_LOCAL, ACI_RX_ACK_AUTO}, \ } #define GAP_PPCP_MAX_CONN_INT 0xffff /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */ @@ -97,19 +72,19 @@ },\ {0x00,\ {\ - 0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x0c,0x01,0x01,0x00,0x00,0x06,0x00,0x01,\ - 0x81,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x07,0x01,0x01,0x00,0x00,0x06,0x00,0x01,\ + 0xd1,0x0f,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x10,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x90,0x00,0xff,\ + 0x1f,0x06,0x10,0x1c,0x10,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x03,0x90,0x01,0xff,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x10,0x38,0xff,0xff,0x02,0x58,0x0a,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,\ + 0x1f,0x06,0x10,0x38,0xff,0xff,0x02,0x58,0x0a,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,\ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ },\ },\ @@ -126,13 +101,13 @@ },\ {0x00,\ {\ - 0x1f,0x06,0x20,0x1c,0x03,0x00,0x03,0x2a,0x00,0x01,0x77,0x61,0x74,0x64,0x69,0x63,0x73,0x65,0x6d,0x69,\ + 0x1f,0x06,0x20,0x1c,0x04,0x00,0x03,0x2a,0x00,0x01,0x57,0x6f,0x6f,0x74,0x69,0x63,0x73,0x65,0x6d,0x69,\ 0x04,0x04,0x05,0x05,0x00,0x04,0x28,0x03,0x01,0x02,0x05,0x00,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x20,0x38,0x01,0x2a,0x06,0x04,0x03,0x02,0x00,0x05,0x2a,0x01,0x01,0x00,0x00,0x04,0x04,0x05,\ + 0x1f,0x06,0x20,0x38,0x01,0x2a,0x06,0x04,0x03,0x02,0x00,0x05,0x2a,0x01,0x01,0x80,0x01,0x04,0x04,0x05,\ 0x05,0x00,0x06,0x28,0x03,0x01,0x02,0x07,0x00,0x04,0x2a,0x06,\ },\ },\ @@ -145,73 +120,72 @@ {0x00,\ {\ 0x1f,0x06,0x20,0x70,0x04,0x02,0x02,0x00,0x09,0x28,0x00,0x01,0x0f,0x18,0x04,0x04,0x05,0x05,0x00,0x0a,\ - 0x28,0x03,0x01,0x12,0x0b,0x00,0x19,0x2a,0x16,0x04,0x02,0x01,\ + 0x28,0x03,0x01,0x02,0x0b,0x00,0x19,0x2a,0x06,0x04,0x02,0x01,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x20,0x8c,0x00,0x0b,0x2a,0x19,0x01,0x10,0x46,0x14,0x03,0x02,0x00,0x0c,0x29,0x02,0x01,0x00,\ - 0x00,0x04,0x04,0x05,0x05,0x00,0x0d,0x28,0x03,0x01,0x02,0x0e,\ + 0x1f,0x06,0x20,0x8c,0x00,0x0b,0x2a,0x19,0x01,0x10,0x04,0x04,0x05,0x05,0x00,0x0c,0x28,0x03,0x01,0x02,\ + 0x0d,0x00,0x1a,0x2a,0x06,0x04,0x02,0x01,0x00,0x0d,0x2a,0x1a,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x20,0xa8,0x00,0x1a,0x2a,0x06,0x04,0x02,0x01,0x00,0x0e,0x2a,0x1a,0x01,0x00,0x04,0x04,0x05,\ - 0x05,0x00,0x0f,0x28,0x03,0x01,0x02,0x10,0x00,0x1b,0x2a,0x06,\ + 0x1f,0x06,0x20,0xa8,0x01,0x00,0x04,0x04,0x05,0x05,0x00,0x0e,0x28,0x03,0x01,0x02,0x0f,0x00,0x1b,0x2a,\ + 0x06,0x04,0x03,0x02,0x00,0x0f,0x2a,0x1b,0x01,0x00,0x00,0x04,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x20,0xc4,0x04,0x03,0x02,0x00,0x10,0x2a,0x1b,0x01,0x00,0x00,0x04,0x04,0x02,0x02,0x00,0x11,\ - 0x28,0x00,0x01,0x10,0x00,0x04,0x04,0x05,0x05,0x00,0x12,0x28,\ + 0x1f,0x06,0x20,0xc4,0x04,0x10,0x10,0x00,0x10,0x28,0x00,0x01,0x3f,0xd8,0x1f,0x4a,0x8e,0xbc,0xd3,0x70,\ + 0xc5,0x59,0x5d,0x03,0x10,0x00,0xd0,0x32,0x04,0x04,0x13,0x13,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x20,0xe0,0x03,0x01,0x12,0x13,0x00,0x11,0x00,0x16,0x04,0x06,0x05,0x00,0x13,0x00,0x11,0x01,\ - 0xaa,0x55,0xaa,0x55,0xaa,0x46,0x14,0x03,0x02,0x00,0x14,0x29,\ + 0x1f,0x06,0x20,0xe0,0x00,0x11,0x28,0x03,0x01,0x1a,0x12,0x00,0x3f,0xd8,0x1f,0x4a,0x8e,0xbc,0xd3,0x70,\ + 0xc5,0x59,0x5d,0x03,0x11,0x00,0xd0,0x32,0x54,0x14,0x14,0x00,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x20,0xfc,0x02,0x01,0x00,0x00,0x04,0x04,0x02,0x02,0x00,0x15,0x28,0x00,0x01,0x10,0x00,0x04,\ - 0x04,0x05,0x05,0x00,0x16,0x28,0x03,0x01,0x12,0x17,0x00,0x11,\ + 0x1f,0x06,0x20,0xfc,0x00,0x12,0x00,0x11,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x14,0x03,\ },\ },\ {0x00,\ {\ - 0x1e,0x06,0x21,0x18,0x00,0x14,0x04,0x05,0x00,0x00,0x17,0x00,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x46,\ - 0x14,0x03,0x02,0x00,0x18,0x29,0x02,0x01,0x00,0x00,0x00,\ + 0x0c,0x06,0x21,0x18,0x02,0x00,0x13,0x29,0x02,0x01,0x00,0x00,0x00,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x40,0x00,0x2a,0x00,0x01,0x00,0x80,0x04,0x00,0x03,0x00,0x00,0x2a,0x19,0x01,0x00,0x83,0x04,\ - 0x00,0x0b,0x00,0x0c,0x2a,0x1a,0x01,0x00,0x80,0x04,0x00,0x0e,\ + 0x1f,0x06,0x40,0x00,0x2a,0x00,0x01,0x00,0x80,0x04,0x00,0x03,0x00,0x00,0x2a,0x19,0x01,0x00,0x80,0x04,\ + 0x00,0x0b,0x00,0x00,0x2a,0x1a,0x01,0x00,0x80,0x04,0x00,0x0d,\ },\ },\ {0x00,\ {\ - 0x1f,0x06,0x40,0x1c,0x00,0x00,0x2a,0x1b,0x01,0x00,0x80,0x04,0x00,0x10,0x00,0x00,0x00,0x11,0x01,0x00,\ - 0x83,0x04,0x00,0x13,0x00,0x14,0x00,0x11,0x01,0x00,0x83,0x04,\ + 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,\ },\ },\ {0x00,\ {\ - 0x07,0x06,0x40,0x38,0x00,0x17,0x00,0x18,\ + 0x13,0x06,0x50,0x00,0x3f,0xd8,0x1f,0x4a,0x8e,0xbc,0xd3,0x70,0xc5,0x59,0x5d,0x03,0x00,0x00,0xd0,0x32,\ },\ },\ {0x00,\ {\ - 0x15,0x06,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ - 0x00,0x00,\ + 0x12,0x06,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ },\ },\ {0x00,\ {\ - 0x06,0x06,0xf0,0x00,0x83,0x4b,0xec,\ + 0x06,0x06,0xf0,0x00,0x83,0x0d,0x8f,\ },\ },\ } #endif + diff --git a/trygvisio_soil_moisture.ino b/trygvisio_soil_moisture.ino index b8b3bfd..9d9f9f9 100644 --- a/trygvisio_soil_moisture.ino +++ b/trygvisio_soil_moisture.ino @@ -6,11 +6,19 @@ #include "app.h" static services_pipe_type_mapping_t services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT; -static hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] PROGMEM = SETUP_MESSAGES_CONTENT; +PROGMEM static hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] = SETUP_MESSAGES_CONTENT; static struct aci_state_t aci_state; static hal_aci_evt_t aci_data; -static bool timing_change_done = false; +static boolean timing_change_done = false; + +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 void setup_rf(); +static void show_pipes(); void __ble_assert(const char *file, uint16_t line) { @@ -50,7 +58,7 @@ void setup() { setup_rf(); } -void setup_rf() { +static void setup_rf() { Serial.println(F("setup_rf()")); // Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001 if (NULL != services_pipe_type_mapping) { @@ -91,12 +99,12 @@ void setup_rf() { Serial.println(F("lib_aci_init done")); } -static bool rf_started = false; -static bool setup_required = false; +static boolean rf_started = false; +static boolean setup_required = false; static void aci_loop() { uint8_t pipe_number; - int ret; +// int ret; // We enter the if statement only when there is a ACI event available to be processed if (lib_aci_event_get(&aci_state, &aci_data)) { @@ -126,10 +134,9 @@ static void aci_loop() { else { lib_aci_connect(180/* in seconds */, 0x0050 /* advertising interval 50ms*/); // lib_aci_broadcast(10/* in seconds */, 0x0100 /* advertising interval 100ms */); - ret = lib_aci_open_adv_pipe(PIPE_BATTERY_BATTERY_LEVEL_BROADCAST); - ret = lib_aci_open_adv_pipe(PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_BROADCAST); - Serial.print(F("Advertising started, ret=")); - Serial.println(ret, DEC); +// ret = lib_aci_open_adv_pipe(PIPE_BATTERY_BATTERY_LEVEL_BROADCAST); +// ret = lib_aci_open_adv_pipe(PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_BROADCAST); + Serial.println(F("Advertising started")); } break; case ACI_DEVICE_INVALID: @@ -190,17 +197,7 @@ static void aci_loop() { Serial.println(F("ACI_EVT_DISCONNECTED")); lib_aci_connect(180/* in seconds */, 0x0100 /* advertising interval 100ms*/); - ret = lib_aci_open_adv_pipe(PIPE_BATTERY_BATTERY_LEVEL_BROADCAST); - ret = lib_aci_open_adv_pipe(PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_BROADCAST); - Serial.print(F("Advertising started, ret=")); - Serial.println(ret, DEC); - -// Serial.print(F("ACI_EVT_DISCONNECTED: ")); -// Serial.println(ACI_STATUS_ERROR_ADVT_TIMEOUT == aci_evt->params.disconnected.aci_status ? -// F("Broadcasting timed out") : F("Link loss")); - // lib_aci_broadcast(10/* in seconds */, 0x0100 /* advertising interval 100ms */); - // Serial.print(F("Broadcast advertising started, ret=")); - // Serial.println(ret, DEC); + Serial.println(F("Advertising started")); break; case ACI_EVT_DATA_RECEIVED: @@ -208,24 +205,10 @@ static void aci_loop() { Serial.print(F("ACI_EVT_DATA_RECEIVED: pipe_number=")); Serial.println(pipe_number, DEC); - /* - if (pipe_number == PIPE_FIKEN_STATUS_PANEL_GAUGE_DATA_RX_ACK) { - if (aci_evt->len != PIPE_FIKEN_STATUS_PANEL_GAUGE_DATA_RX_ACK_MAX_SIZE) { - break; - } - on_gauge_data(aci_evt->params.data_received.rx_data.aci_data, aci_evt->len - 2); - lib_aci_send_ack(&aci_state, PIPE_FIKEN_STATUS_PANEL_GAUGE_DATA_RX_ACK); - } - - if (pipe_number == PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_RX) { - uint8_t len = aci_evt->len - 2; - // if (aci_evt->len != PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_RX_MAX_SIZE) { - // break; - // } - - on_gauge_ctrl(aci_evt->params.data_received.rx_data.aci_data, len); + + if (pipe_number == pipe_rx) { + on_soil_moisture_ctrl(aci_evt->params.data_received.rx_data.aci_data, aci_evt->len); } - */ break; case ACI_EVT_DATA_CREDIT: @@ -343,18 +326,13 @@ void loop() { } else if (!setup_required) { value++; -// lib_aci_set_local_data(&aci_state, PIPE_FIKEN_STATUS_PANEL_GAUGE_DATA_SET, &value, 1); -// Serial.print(F("value=")); -// Serial.println(value, HEX); - - // show_pipes(); } } on_loop(); } -void show_pipes() { +static void show_pipes() { for (uint8_t i = 1; i <= NUMBER_OF_PIPES; i++) { uint8_t x = lib_aci_is_pipe_available(&aci_state, i); Serial.print(F("pipe #")); @@ -363,14 +341,14 @@ void show_pipes() { Serial.println(x, DEC); } } - -bool tx__moisture(sm_res *res) { +/* +boolean tx_moisture(sm_res *res) { static const uint8_t pipe = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_TX; uint8_t *data = (uint8_t *)res; uint8_t len = 2 + res->len; - bool status = false; + boolean status = false; - bool available = lib_aci_is_pipe_available(&aci_state, pipe); + boolean available = lib_aci_is_pipe_available(&aci_state, pipe); Serial.print(F("tx_soil_moisture, len=")); Serial.println(len, DEC); @@ -387,7 +365,7 @@ bool tx__moisture(sm_res *res) { } return status; } - +*/ void notify_battery_level(uint8_t value) { static const uint8_t pipe = PIPE_BATTERY_BATTERY_LEVEL_SET; @@ -396,25 +374,33 @@ void notify_battery_level(uint8_t value) { value = value % 101; - lib_aci_set_local_data(&aci_state, pipe, &value, 1); + lib_aci_send_data(pipe, &value, 1); } -void notify_soil_moisture(sm_res *res) { - static const uint8_t pipe = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_LEVEL_SET; +void notify_soil_moisture(const struct sm_res& res, uint8_t body_len) { +#if SM_DEBUG == 1 + write_res(res); +#endif - uint8_t *data = (uint8_t *)res; - uint8_t len = 2 + res->len; - bool status = false; + uint8_t *data = (uint8_t *)&res; + uint8_t len = SM_RES_HEADER_SIZE + body_len; - Serial.print(F("notify_soil_moisture, len=")); - Serial.println(len, DEC); - Serial.print(F("aci_state.data_credit_available=")); - Serial.println(aci_state.data_credit_available, DEC); + Serial.print(F("notify_soil_moisture, code=")); + Serial.print(res.code, DEC); + Serial.print(F(", body_len=")); + Serial.println(body_len, DEC); +// Serial.print(F("aci_state.data_credit_available=")); +// Serial.println(aci_state.data_credit_available, DEC); -// bool available = lib_aci_is_pipe_available(&aci_state, pipe); -// Serial.print(F("available=")); + boolean available = lib_aci_is_pipe_available(&aci_state, pipe_tx); +// Serial.print(F("pipe available=")); // Serial.println(available, DEC); - status = lib_aci_set_local_data(&aci_state, pipe, data, len); + if (available && aci_state.data_credit_available > 0) { + boolean sent = lib_aci_send_data(pipe_tx, data, len); + if (sent) { + aci_state.data_credit_available--; + } + } } diff --git a/trygvisio_soil_moisture.xml b/trygvisio_soil_moisture.xml index 3041f3a..3967ed0 100644 --- a/trygvisio_soil_moisture.xml +++ b/trygvisio_soil_moisture.xml @@ -75,36 +75,36 @@ Soil Moisture - 0010 + 0010 - Soil Moisture Level - 0011 - aa55aa55aa + Soil Moisture Control + 0011 + 0 - 5 - 1 + 20 + 2 false false false - false + true true false - true + false true - false - + true + 0 - wat - 0 - false + Woot + 10 + true 1 - 0000 + 0180 0 0 0 @@ -113,10 +113,10 @@ 7 16 0 - 0 + 50 0 0 - 1000 + 10 0 0 0 @@ -133,12 +133,15 @@ false 5 - 0010 + 0010 + + + 180f 19 - 0000 + 18 @@ -161,7 +164,7 @@ 10 1000 0 - 0 + 98.91 1280 diff --git a/ublue_setup.gen.out.txt b/ublue_setup.gen.out.txt new file mode 100644 index 0000000..2af6f18 --- /dev/null +++ b/ublue_setup.gen.out.txt @@ -0,0 +1,122 @@ +------------------------------------------------------------------------------ + uBlue Setup generation report + Generated with uBlue setup DLL version: 1.0.0.16903 + Generated: Sun Jan 04 16:53: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 +Remote attribute count = 0 +Total pipe count = 7 +Dynamic data size = 162 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 ) +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 ) + +[Device Settings] + +Setup ID = 0x00000000 +Setup Format = 0x03 +Security = OPEN (0) +Bond Timeout = 600 +Security Request Delay = 10 +Change Timing Delay = 5 +Whitelist = Enabled + +[Advertisement Data] + +Bond Advertise = 0x00000000 [] +Bond Scan Resp = 0x00000000 [] +General Advertise = 0x00000050 [LOCAL_NAME_COMPLETE | TX_POWER_LEVEL] +General Scan Resp = 0x00000010 [LOCAL_NAME_COMPLETE] +Broadcast Advertise = 0x00000000 [] +Broadcast Scan Resp = 0x00000000 [] + +Custom Bond Advertise = 0x00 [] +Custom Bond Scan Resp = 0x00 [] +Custom General Advertise = 0x00 [] +Custom General Scan Resp = 0x00 [] +Custom Broadcast Advertise = 0x00 [] +Custom Broadcast Scan Resp = 0x00 [] + +No custom AD types + +[Vendor Specific UUIDs] + +VS UUID #0 (type=0x02): 0x3F 0xD8 0x1F 0x4A 0x8E 0xBC 0xD3 0x70 0xC5 0x59 0x5D 0x03 0x00 0x00 0xD0 0x32 + +[Local Database] + +Handle Pipes Structure +------ ----- --------- +0x0001 +----- Service (Primary): "GAP" (01:0x1800) +0x0002 |----- |Characteristic: "Device Name" (01:0x2A00) [rd|wwr|wr] [rd:allow|wr:none] +0x0003 x |Value: {0x57 0x6F 0x6F 0x74} [rd:allow|wr:allow] +0x0004 |----- |Characteristic: "Appearance" (01:0x2A01) [rd] [rd:allow|wr:none] +0x0005 |Value: {0x80 0x01} [rd:allow|wr:none] +0x0006 |----- |Characteristic: "PPCP" (01:0x2A04) [rd] [rd:allow|wr:none] +0x0007 |Value: {0xFF 0xFF 0xFF 0xFF 0x00 0x00 0xFF 0xFF} [rd:allow|wr:none] +0x0008 +----- Service (Primary): "GATT" (01:0x1801) +0x0009 +----- Service (Primary): "Battery" (01:0x180F) +0x000A |----- |Characteristic: "Batt Lev" (01:0x2A19) [rd] [rd:allow|wr:none] +0x000B x |Value: {0x10} [rd:allow|wr:none] +0x000C |----- |Characteristic: "?" (01:0x2A1A) [rd] [rd:allow|wr:none] +0x000D x |Value: {0x00} [rd:allow|wr:none] +0x000E |----- |Characteristic: "Batt Lev State" (01:0x2A1B) [rd] [rd:allow|wr:none] +0x000F x |Value: {0x00 0x00} [rd:allow|wr:none] +0x0010 +----- Service (Primary): "?" (02:0x0010) +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] + +[Remote Database] + +Handle Pipes Structure +------ ----- --------- + +[Pipe Map] + +Pipe Store Type Service Char. CPF Desc. +---- ------ ------ ---------- --------- ----------- --------- +01 Local SET 01:0x1800 01:0x2A00 -- -- +02 Local SET 01:0x180F 01:0x2A19 -- -- +03 Local SET 01:0x180F 01:0x2A1A -- -- +04 Local SET 01:0x180F 01:0x2A1B -- -- +05 Local TX 02:0x0010 02:0x0011 -- -- +06 Local SET 02:0x0010 02:0x0011 -- -- +07 Local RX_AA 02:0x0010 02:0x0011 -- -- + +[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-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 +1F-06-20-00-04-04-02-02-00-01-28-00-01-00-18-04-04-05-05-00-02-28-03-01-0E-03-00-00-2A-04-14-0A +1F-06-20-1C-04-00-03-2A-00-01-57-6F-6F-74-69-63-73-65-6D-69-04-04-05-05-00-04-28-03-01-02-05-00 +1F-06-20-38-01-2A-06-04-03-02-00-05-2A-01-01-80-01-04-04-05-05-00-06-28-03-01-02-07-00-04-2A-06 +1F-06-20-54-04-09-08-00-07-2A-04-01-FF-FF-FF-FF-00-00-FF-FF-04-04-02-02-00-08-28-00-01-01-18-04 +1F-06-20-70-04-02-02-00-09-28-00-01-0F-18-04-04-05-05-00-0A-28-03-01-02-0B-00-19-2A-06-04-02-01 +1F-06-20-8C-00-0B-2A-19-01-10-04-04-05-05-00-0C-28-03-01-02-0D-00-1A-2A-06-04-02-01-00-0D-2A-1A +1F-06-20-A8-01-00-04-04-05-05-00-0E-28-03-01-02-0F-00-1B-2A-06-04-03-02-00-0F-2A-1B-01-00-00-04 +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-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 +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 -- cgit v1.2.3