3636 */
3737#define ADVERTISING_INTERVAL 3000
3838
39+ /**
40+ * config mode timeout
41+ *
42+ * This setting will specify for how long the device will remain on "config mode" before start
43+ * advertising the location beacon. Actually you can config the device on "advertising mode" but
44+ * on "config mode" it will broadcast its name.
45+ */
46+ #define CONFIG_MODE_TIMEOUT APP_TIMER_TICKS(60000L) // 60 seconds
47+
48+ // Define the "config mode" timer
49+ APP_TIMER_DEF (config_mode_timer );
50+
51+ /**
52+ * This is the default public key. You can either modify this variable or patch the binary firmware
53+ * once compiled, which is the preferred way since it can be done without recompilation.
54+ */
3955static char public_key [28 ] = "OFFLINEFINDINGPUBLICKEYHERE!" ;
4056
4157//Test1
@@ -64,17 +80,43 @@ static void timers_init(void)
6480 uint32_t err_code = app_timer_init ();
6581 APP_ERROR_CHECK (err_code );
6682
67- // Create timers.
83+ err_code = app_timer_create (& config_mode_timer ,
84+ APP_TIMER_MODE_SINGLE_SHOT ,
85+ config_timer_handler );
86+ APP_ERROR_CHECK (err_code );
87+
88+
89+ }
90+
91+ /**@brief The handler of the config timer
92+ *
93+ * @details this function will be called when the timer timeouts
94+ */
95+ static void config_timer_handler (void * p_context )
96+ {
97+ // Variable to hold the data to advertise
98+ uint8_t * ble_address ;
99+ uint8_t * raw_data ;
100+ uint8_t data_len ;
101+
102+ // Set key to be advertised
103+ data_len = setAdvertisementKey (public_key , & ble_address , & raw_data );
68104
69- /* YOUR_JOB: Create any timers to be used by the application.
70- Below is an example of how to create a timer.
71- For every new timer needed, increase the value of the macro APP_TIMER_MAX_TIMERS by
72- one.
73- uint32_t err_code;
74- err_code = app_timer_create(&m_app_timer_id, APP_TIMER_MODE_REPEATED, timer_timeout_handler);
75- APP_ERROR_CHECK(err_code); */
105+ // Update advertisement
106+ updateAdvertisementData (raw_data , data_len );
76107}
77108
109+ /**@brief Function to start the timers
110+ *
111+ */
112+ static void timers_start (void )
113+ {
114+ ret_code_t err_code ;
115+ err_code = app_timer_start (config_mode_timer ,
116+ CONFIG_MODE_TIMEOUT ,
117+ NULL );
118+ APP_ERROR_CHECK (err_code );
119+ }
78120
79121/**@brief Function for the Power manager.
80122 */
@@ -100,10 +142,9 @@ int main(void) {
100142 // Variable to hold the data to advertise
101143 uint8_t * ble_address ;
102144 uint8_t * raw_data ;
103- uint8_t data_len ;
104145
105146 // Set key to be advertised
106- data_len = setAdvertisementKey (public_key , & ble_address , & raw_data );
147+ setAdvertisementKey (public_key , & ble_address , & raw_data );
107148
108149 // Timers
109150 timers_init ();
@@ -121,7 +162,11 @@ int main(void) {
121162
122163 advertising_init (ADVERTISING_INTERVAL );
123164
124- // Set advertisement data
165+ // Enable services
166+ services_init ();
167+ conn_params_init ();
168+
169+ // Start timers if the device is configured
125170 if (public_key [0 ] == 'O' &&
126171 public_key [1 ] == 'F' &&
127172 public_key [2 ] == 'F' &&
@@ -131,13 +176,9 @@ int main(void) {
131176 public_key [6 ] == 'E' ) {
132177 // Leave unconfigured
133178 } else {
134- setAdvertisementData ( raw_data , data_len );
179+ timers_start ( );
135180 }
136181
137- // Enable services
138- services_init ();
139- conn_params_init ();
140-
141182 // Start advertising
142183 startAdvertisement ();
143184
0 commit comments