On reading all of this it seems to me that the issue is in the wiring from the speed sensor to the TSM and ECU, either a break in a wire somewhere or a loose/dirty connection. I suppose the best solution would be to clean the connectors then if no improvement obtain a new wiring loom, not sure how easy to obtain or expensive that is though.
Bruce 1964 4/4 Series V Comp (Megan) 1994 +8 (Maurice) tis no more 2013 M3W (Olga)