Here is how I have learned to deal with law enforcement:
First, be professional, courteous and do not act nervous. Do not have an attitude and do not have any fear. Cops hate both of these. They hate sensing fear in people because it suggests the person has done something wrong and this requires the cop to work harder to find out why the person is nervous.
Second, understand the law enforcement official has a job to do and pride to protect. Do not challenge them on anything unless it is absolutely necessary. ALWAYS give them a graceful out. Never allow the exchange to turn into something where the cop has to look bad in order for you to get back on the road.
Third, do not make yourself a target. Drive safely, keep the inside of your truck clean and neat. Take off the sunglasses in the weigh stations. Keep your dash clear.
If you get out of your truck lock the door behind you. This will prevent the cops from entering the vehicle without talking to you first. If they ask to search your vehicle it's usually best to say yes. If you say no, just say no, don't attach any attitude. Just say: "I'm sorry sir/maam, but I am not going to consent to a search of my vehicle." Then just be quiet and let them decide what they want to do. If it's a situation where consent is not required, just be patient and courteous and ask yourself what you could have done to prevent the search. If it was truly a random search with no cause of any kind, then just figure it wasn't your lucky day.
Never get into any kind of conversation about what the cops can and cannot do legally. When you are on the side of the road in the middle of the night what is legal don't mean diddly. What matters is who has the gun and the state behind them, and it's not you. Remember this: All you have on your side is your ability to appeal to the cop's sense of right and wrong and his sense of whether you are a person who needs to be given a hard time. Many cops (like many people) are more apt to let a friendly and relaxed person go than a person who is hostile, impatient or nervous.
The last time I had a safety inspection I acted like I had been hoping he would pick me. I pretended I was his assistant and we were going over my truck with the exclusive goal of making sure it was safe. I did all of this with no sarcasm and no attitude. I feel like it got me out of there quicker than any other approach would have.