diff --git a/Makefile b/Makefile index 6d3b382..e94607c 100644 --- a/Makefile +++ b/Makefile @@ -94,7 +94,7 @@ remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-ou C_SOURCE_FILES += src/main.c src/config.c src/sensor.c src/app_cmd.c \ src/scheduler.c src/proximity.c src/heartbeat.c src/battery.c src/shoe_accel.c \ - src/app_evt.c bsp/bsp.c + src/app_evt.c src/mesh_control.c bsp/bsp.c C_SOURCE_FILES += $(COMPONENTS)/libraries/timer/app_timer.c CXX_SOURCE_FILES += $(SIMBLEE_BASE)/libraries/SimbleeBLE/SimbleeBLE.cpp diff --git a/README.md b/README.md index 69238b7..36f01b8 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,10 @@ Program a shoe sensor with id 1, turning off serial for power savings `make program SERIAL_PORT=/dev/cu.usbserial-FTZ86FTC SENSOR_CONFIGURATION_OPTIONS="--no-serial" TARGET_BOARD=BOARD_SHOE_SENSOR SENSOR_ID=1` +Program an area sensor with id 3, turning off serial for power savings: + +`make program SERIAL_PORT=/dev/cu.usbserial-AI04QL7P SENSOR_CONFIGURATION_OPTIONS="--no-serial" TARGET_BOARD=BOARD_LESSON_TRACKER SENSOR_ID=3` + Program a master listening device that doesn't sleep, and listens all the time. `make program SERIAL_PORT=/dev/cu.usbserial-DN00CSZ7 SENSOR_CONFIGURATION_OPTIONS="--no-sleep” TARGET_BOARD=BOARD_RFD77201 SENSOR_ID=51` diff --git a/pyaci/upload.py b/pyaci/upload.py index 860caf0..c9a2315 100755 --- a/pyaci/upload.py +++ b/pyaci/upload.py @@ -17,6 +17,8 @@ class Uploader(object): # Synchronize once every minute TIME_SYNC_INTERVAL=60 + MESH_HANDLE_MESH_CONTROL = 0x0201 + def __init__(self, sensei_config): api_url = sensei_config["server"]["url"] + 'api/v1/' self.api = Api(api_url, sensei_config["server"]["username"], sensei_config["server"]["password"]) @@ -45,6 +47,10 @@ def sync_time(self): def get_config(self): return self.run_app_command(sensei_cmd.GetConfig()) + def set_mesh_control(self, wake_interval): + data = struct.pack(" #include #include @@ -70,8 +71,8 @@ static void rbc_mesh_event_handler(rbc_mesh_event_t* p_evt) case RBC_MESH_EVENT_TYPE_CONFLICTING_VAL: case RBC_MESH_EVENT_TYPE_NEW_VAL: case RBC_MESH_EVENT_TYPE_UPDATE_VAL: - if (p_evt->params.rx.value_handle == TEST_LED_HANDLE) { - //led_config(LED_BLUE, p_evt->params.rx.p_data[0]); + if (p_evt->params.rx.value_handle == MESH_CONTROL_HANDLE) { + mesh_control_update_config((mesh_control_t*)p_evt->params.rx.p_data); } break; case RBC_MESH_EVENT_TYPE_TX: @@ -120,6 +121,8 @@ int main(void) bsp_init(BSP_INIT_BUTTONS & BSP_INIT_LED, 0, 0); + mesh_control_init(); + /* Enable Softdevice (including sd_ble before framework */ SOFTDEVICE_HANDLER_INIT(MESH_CLOCK_SRC, NULL); softdevice_ble_evt_handler_set(rbc_mesh_ble_evt_handler); @@ -189,9 +192,12 @@ int main(void) sensor_init(); } - error_code = rbc_mesh_value_enable(TEST_LED_HANDLE); + error_code = rbc_mesh_value_enable(MESH_CONTROL_HANDLE); APP_ERROR_CHECK(error_code); + // error_code = rbc_mesh_value_enable(TEST_LED_HANDLE); + // APP_ERROR_CHECK(error_code); + // Start clock start_clock(0); diff --git a/src/mesh_control.c b/src/mesh_control.c new file mode 100644 index 0000000..7c0db55 --- /dev/null +++ b/src/mesh_control.c @@ -0,0 +1,17 @@ + +#include "mesh_control.h" + +static mesh_control_t m_config; + +void mesh_control_init() { + m_config.wake_interval = DEFAULT_WAKE_INTERVAL; + m_config.enable_ble = 0; +} + +uint16_t mesh_control_get_wake_interval() { + return m_config.wake_interval; +} + +void mesh_control_update_config(mesh_control_t *new_config) { + m_config = *new_config; +} diff --git a/src/mesh_control.h b/src/mesh_control.h new file mode 100644 index 0000000..7aefa12 --- /dev/null +++ b/src/mesh_control.h @@ -0,0 +1,25 @@ +#ifndef MESH_CONTROL_H +#define MESH_CONTROL_H + +#include +#include "toolchain.h" + +// Default wake interval is 10 seconds +#define DEFAULT_WAKE_INTERVAL (10) + +typedef __packed_armcc struct +{ + uint16_t wake_interval; + uint8_t enable_ble; // Not used yet... +} __packed_gcc mesh_control_t; + + +void mesh_control_init(); + +// Wake interval controls the cycle of waking and sleeping +// current_epoch % wake_interval == 0 indicates the start of a wake period +uint16_t mesh_control_get_wake_interval(); + +void mesh_control_update_config(mesh_control_t *new_config); + +#endif // MESH_CONTROL_H diff --git a/src/scheduler.c b/src/scheduler.c index 6c30cb3..300f7de 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -9,6 +9,7 @@ #include "sensor.h" #include "rbc_mesh.h" #include "handles.h" +#include "mesh_control.h" // Timer settings #define APP_TIMER_PRESCALER 15 // divisor value - 1 @@ -52,8 +53,7 @@ static void periodic_timer_cb(void * p_context) m_current_time += 1; DBG_TICK_PIN(6); - - if (m_current_time % 10 == 0) { + if (m_current_time % mesh_control_get_wake_interval() == 0) { //report_debug_register(); SET_LED(LED_GREEN); app_timer_cnt_get(&m_clock_second_start_counter_value); @@ -210,7 +210,6 @@ uint16_t get_clock_version() { return m_clock_version; } - bool clock_is_synchronized() { - return m_last_sync > 0 && (m_current_time - m_last_sync) < (60 * 60); + return m_last_sync > 0; // && (m_current_time - m_last_sync) < (60 * 60); }