static void network_suspend() { // save the current state so it can be restored on wakeup wakeupState.wifi = !SPARK_WLAN_SLEEP; wakeupState.wifiConnected = wakeupState.cloud | network_ready(0, 0, NULL) | network_connecting(0, 0, NULL); #ifndef SPARK_NO_CLOUD wakeupState.cloud = spark_cloud_flag_auto_connect(); // disconnect the cloud now, and clear the auto connect status spark_cloud_socket_disconnect(); spark_cloud_flag_disconnect(); #endif network_off(0, 0, 0, NULL); }
static void network_suspend() { // save the current state so it can be restored on wakeup #ifndef SPARK_NO_CLOUD wakeupState.cloud = spark_cloud_flag_auto_connect(); #endif wakeupState.wifi = !SPARK_WLAN_SLEEP; wakeupState.wifiConnected = wakeupState.cloud || network_ready(0, 0, NULL) || network_connecting(0, 0, NULL); // Disconnect the cloud and the network network_disconnect(0, NETWORK_DISCONNECT_REASON_SLEEP, NULL); #ifndef SPARK_NO_CLOUD // Clear the auto connect status spark_cloud_flag_disconnect(); #endif network_off(0, 0, 0, NULL); }
/* * \brief A function which will be eventually called by NanoStack OS when ever the OS has an event to deliver. * @param event, describes the sender, receiver and event type. * * NOTE: Interrupts requested by HW are possible during this function! */ void tasklet_main(arm_event_s *event) { uint8_t master_key[16]; /**Border Router ND setup*/ static link_configuration_s link_setup; device_configuration_s device_config; uint8_t networkid[16]; uint32_t channel_mask; channel_mask = (uint32_t) 1 << RF_CHANNEL; char psdK[] = "Kukkuu!"; device_config.PSKd_ptr = psdK; device_config.leaderCap = true; int8_t retval; if (event->sender == 0) { arm_library_event_type_e event_type; event_type = (arm_library_event_type_e) event->event_type; switch (event_type) { //This event is delivered every and each time when there is new information of network connectivity. case ARM_LIB_NWK_INTERFACE_EVENT: /* Network Event state event handler */ app_parse_network_event(event); break; case ARM_LIB_TASKLET_INIT_EVENT: /*Event with type EV_INIT is an initialiser event of NanoStack OS. * The event is delivered when the NanoStack OS is running fine. This event should be delivered ONLY ONCE. */ node_main_tasklet_id = event->receiver; /* Bootsrapping Thread network */ arm_nwk_interface_configure_6lowpan_bootstrap_set(net_rf_id, NET_6LOWPAN_ROUTER, NET_6LOWPAN_THREAD); arm_nwk_6lowpan_link_scan_paramameter_set(net_rf_id, channel_list, 5); rf_read_mac_address(link_setup.extended_random_mac); link_setup.extended_random_mac[0] |= 0x02; //Initialize Thread stack to leader mode link_setup.steering_data_len = 0; memcpy(networkid, "Arm Powered Core", 16); memcpy(link_setup.name, networkid, 16); link_setup.panId = THREAD_NTW_PAN_ID; link_setup.rfChannel = RF_CHANNEL; link_setup.Protocol_id = THREAD_PROTOCOL_ID; link_setup.version = THREAD_PROTOCOL_VERSION; memcpy(link_setup.mesh_local_ula_prefix,br_thread_ml_prefix, 8); arm_nwk_6lowpan_gp_address_mode(net_rf_id, NET_6LOWPAN_GP16_ADDRESS, 0xffff, 1); memcpy(master_key, default_net_security_key, 16); memcpy(link_setup.master_key,default_net_security_key, 16 ); link_setup.key_rotation = 3600; link_setup.key_sequence = 0; memcpy(link_setup.mesh_local_ula_prefix,br_thread_ml_prefix, 8); thread_managenet_node_init(net_rf_id, channel_mask, &device_config, &link_setup); retval = arm_nwk_interface_up(net_rf_id); if (retval != 0) { //debug_int(retval); tr_debug("Start Fail code: %d", retval); } else { tr_debug("6LoWPAN IP Bootstrap started"); network_ready(); } break; case ARM_LIB_SYSTEM_TIMER_EVENT: eventOS_event_timer_cancel(event->event_id, node_main_tasklet_id); if(event->event_id == 1) { if(arm_nwk_interface_up(net_rf_id) == 0) { tr_debug("Start Network bootstrap Again"); } } break; default: break; } } }