what is causing my esp8266 setup function to reinitialise?
When a program crashes, you can debug the crash based on the Fatal exception number.

 Exception (9)  Unaligned read/write operation addresses
     1. Unaligned read/write Cache addresses
     2. Wild pointers


This leads than as Juraj points out to a WD reset:

 rst:4     Hardware WDT reset


To get the exact part of the code paste the &gt;&gt;&gt;stack&gt;&gt;&gt; into the window of the espExeption decoder in the ArduinoIDE. Details how to install and use.

My educated guess is that the heavy use of String class in combination with lot of String operations with the getHotspot function leads to heap corruption and crashes the Esp8266. Try defining fixed char arrays and get rid of the String class to get a stable running system. Post the espExeption decoder result as edit to your question if you thing something else might be fishy