I had this happen to me once, I was cycling along a canal towpath which had muddy bits. It was intermittent at first but then just stopped working. It was mud on the chainring which was causing the problem, it seemed to affect the magnets. Anyway, I cleaned it off with a nice big docking leaf...