I will introduce the BPS indices in 4d N=2 supersymmetric field theories which correspond to the generalized Donaldson-Thomas invariants. An important tool for calculating BPS indices is the spectral network. I will describe the technique of spectral networks and show the calculation using them in a non-Lagrangian theory, the Minahan-Nemeschansky E7 theory. I will also discuss an application of the BPS indices and spectral networks to the correspondence between 4d N=2 supersymmetric theories with the insertion of surface defects and the differential equations. They are closely related to the Stokes phenomenon on the differential equation side. I will also briefly introduce some progress in generalizations of the 4d results to 5d.