{"id":191,"date":"2025-12-05T20:38:27","date_gmt":"2025-12-05T20:38:27","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/g_cruz\/?p=191"},"modified":"2025-12-05T20:38:27","modified_gmt":"2025-12-05T20:38:27","slug":"the-great-fuckup-fix","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/g_cruz\/2025\/12\/05\/the-great-fuckup-fix\/","title":{"rendered":"The Great Fuckup Fix"},"content":{"rendered":"\n<p>The Child&#8217;s (Raspberry Pi Pico W) code has been recovered (thanks to me making a backup) and now there&#8217;s additional code that lets it connect to the internet, currently a router that has no access to the internet.<\/p>\n\n\n\n<p>Currently, I am working with a Potato, dubbed Big Boi, to host a server that the Child will connect to, read, and display messages through its LED strip whenever Big Boi&#8217;s server message changes.<\/p>\n\n\n\n<p>Below will be the current code that has been added since last post&#8217;s <em>slight<\/em> annoyance:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>import os<\/p>\n\n\n\n<p>import ipaddress<\/p>\n\n\n\n<p>import wifi<\/p>\n\n\n\n<p>import socketpool<\/p>\n\n\n\n<p>import adafruit_requests as requests<\/p>\n\n\n\n<p>import time<\/p>\n\n\n\n<p>print()<\/p>\n\n\n\n<p>print(&#8220;Attempting to connect to WiFi&#8230;&#8221;)<\/p>\n\n\n\n<p>print()<\/p>\n\n\n\n<p>wifiConnect = False #flag to see if we are already connected<\/p>\n\n\n\n<p>networkPool = os.getenv(&#8216;CIRCUITPY_NETWORK_COUNT&#8217;)<\/p>\n\n\n\n<p>for networkNum in range(1, int(networkPool) + 1):<\/p>\n\n\n\n<p>&nbsp; &nbsp; ##Try next SSID<\/p>\n\n\n\n<p>&nbsp; &nbsp; if not wifiConnect:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; try:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thisSID = &#8220;CIRCUITPY_WIFI_SSID&#8221; + str(networkNum)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thisKey = &#8220;CIRCUITPY_WIFI_PASSWORD&#8221; + str(networkNum)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wifi.radio.connect(os.getenv(thisSID), os.getenv(thisKey))<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;Success! Connected to WiFi network: &#8221; + os.getenv(thisSID))<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wifiConnect = True #Mark flag so we can stop trying to connect<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pool = socketpool.SocketPool(wifi.radio)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # &nbsp;prints MAC address to REPL<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;My MAC addr:&#8221;, [hex(i) for i in wifi.radio.mac_address])<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # &nbsp;prints IP address to REPL<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;My IP address is&#8221;, wifi.radio.ipv4_address)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; except:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;Failed to connect to Wifi networ+: &#8221; + os.getenv(thisSID))<\/p>\n\n\n\n<p>#Pause if still not connected:<\/p>\n\n\n\n<p>if not wifiConnect:<\/p>\n\n\n\n<p>&nbsp; &nbsp; print(&#8220;=============================================&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; print(&#8220;Failed to connect to all known WiFi networks!&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; print(&#8220;=============================================&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; time.sleep(30)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>After that, this is the code for Big Boi&#8217;s server, quite small in comparison to the WHOLE of the Child&#8217;s code:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>from fastapi import FastAPI, Body<\/p>\n\n\n\n<p>from pydantic import BaseModel<\/p>\n\n\n\n<p>app = FastAPI()<\/p>\n\n\n\n<p># Store the last message in memory<\/p>\n\n\n\n<p>last_message = {&#8220;text&#8221;: None}<\/p>\n\n\n\n<p>class Message(BaseModel):<\/p>\n\n\n\n<p>&nbsp; &nbsp; text: str<\/p>\n\n\n\n<p>@app.get(&#8220;\/message&#8221;)<\/p>\n\n\n\n<p>def get_message():<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;&#8221;&#8221;<\/p>\n\n\n\n<p>&nbsp; &nbsp; Retrieve the last message sent.<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;&#8221;&#8221;<\/p>\n\n\n\n<p>&nbsp; &nbsp; return {&#8220;last_message&#8221;: last_message[&#8220;text&#8221;]}<\/p>\n\n\n\n<p>@app.post(&#8220;\/message&#8221;)<\/p>\n\n\n\n<p>def post_message(message: Message):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;&#8221;&#8221;<\/p>\n\n\n\n<p>&nbsp; &nbsp; Post a new message and update the last message.<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;&#8221;&#8221;<\/p>\n\n\n\n<p>&nbsp; &nbsp; last_message[&#8220;text&#8221;] = message.text<\/p>\n\n\n\n<p>&nbsp; &nbsp; return {&#8220;status&#8221;: &#8220;Message updated&#8221;, &#8220;last_message&#8221;: last_message[&#8220;text&#8221;]}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Child&#8217;s (Raspberry Pi Pico W) code has been recovered (thanks to me making a backup) and now there&#8217;s additional code that lets it connect to the internet, currently a router that has no access to the internet. Currently, I am working with a Potato, dubbed Big Boi, to host a server that the Child [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-191","post","type-post","status-publish","format-standard","hentry","category-progress"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/g_cruz\/wp-json\/wp\/v2\/posts\/191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/g_cruz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/g_cruz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/g_cruz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/g_cruz\/wp-json\/wp\/v2\/comments?post=191"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/g_cruz\/wp-json\/wp\/v2\/posts\/191\/revisions"}],"predecessor-version":[{"id":192,"href":"https:\/\/theroyalscode.com\/students\/g_cruz\/wp-json\/wp\/v2\/posts\/191\/revisions\/192"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/g_cruz\/wp-json\/wp\/v2\/media?parent=191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/g_cruz\/wp-json\/wp\/v2\/categories?post=191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/g_cruz\/wp-json\/wp\/v2\/tags?post=191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}