After some troubleshooting, the problem ended up being with the section of this section of the code.
count+=1; //quit script after the execution of two loops
if (count==2) //ens script
clearTimeout(timer_id); //stop timer
client.end();
Once I removed this section, I was able to...