I've been reading a fascinating book about the meanings of nursery rhythms, Pop goes the Weasel by Albert Jack.
Although I haven't yet gotten to the history behind the eponymous rhyme (hope I used that big word correctly), I can tell you that yes, Humpty was indeed a cannon.
He was deployed in a famous battle between King Whathisname and The Other Guy and located at the top of the tower. As long as it was firing off great balls of lead from there, the home team was unbeatable. But the attacking army managed to do enough damage to the tower to make it fall from its perch and into the swamp below. As you'll have guessed, the King's men weren't able to repair it, and they lost the battle.
Humpty didn't become an egg until he was featured in Lewis Carroll's Alice in Wonderland, by the way.
This book has been great for introducing (or re-introducing) me to many interesting snippets of English history, and there have been many a-ha moments where nonsensical-seeming rhymes suddenly made an awful lot of sense (and were likely to be about really awful events).
It's actually a lot like a good Bill Bryson book. And that might be the most effective description of this work I can come up with.