finished pi gateway code complete with pi ID