Hi,
As this is the type 1 forum, I am assuming you are on insulin.
If your blood sugar was that high at bedtime and only 40 at 5:30 am, this would indicate that your insulin dose was too large for the foods that you ate. Perhaps the amount of carbs in the food was less than you expected, and thus the amount of insulin injected was too much.
Have you tried basal and bolus testing to determine your ideal rate?