Sounds like you were illegally detained. The cops can’t keep you there JUST to wait for the K9 unit. They can only keep you long enough to conduct the stop and write a ticket unless they have probable cause.
Correction. Sounds like the pills gave them PC. NEVER consent to a search.
The best thing to do is get the prescriptions together, go into see the detective and give an exceedingly boring description of whatever causes you to need the medication.
Misuse of prescription drugs is a huge problem these days along with poor management by physicians. People that really need meds are caught in the middle.
You’re being harassed. Get an attorney, any attorney if money is a problem. Find a local attorney who specializes in Civil Rights / police brutality, etc.. and make an appointment for a free consultation.