NPR recounts it:
The Oxford English Dictionary says the first published use of "hello" goes back only to 1827. And it wasn't mainly a greeting back then. Ammon says people in the 1830's said hello to attract attention ("Hello, what do you think you're doing?"), or to express surprise ("Hello, what have we here?"). Hello didn't become "hi" until the telephone arrived.