/* pi_picoCharting_HTTP.ino (c)2026 Forward Computing and Control Pty. Ltd. NSW Australia, www.forward.com.au This code is not warranted to be fit for any purpose. You may only use it at your own risk. This generated code may be freely used for both private and commercial use provided this copyright is maintained. */ /** This example sketch compiles for Pi PicoW, Pi Pico2W The project has been tested using Arduino IDE V2.3.8, Pi Pico board support V5.5.1 This sketch does NOT serve pfodWeb from the micro file system see pi_picoCharting_Server.ino for a sketch that serves pfodWeb directly from the micro Setup Notes: Before running this code. a) Set the ssid and password (see WiFi Settings in the code below) to match your local network's router, ssid and password b) Set a static IP to an unused IP on your network OR leave as blank and check the Serial monitor for the assigned IP c) Upload the sketch, Open the IDE Serial Monitor to see what IP has been assigned d) From the pfodParse library, in sub-directory pfodWeb, open pfodWeb.html in a Chrome or Edge browser (>V141) and selected HTTP connection, fill in the IP for this board, click Connect to display the On/off buttons */ static bool useLittleFSToServe_pfodWeb = false; // do not start LittleFS, need to use pfodWeb.html on computer to display drawing // cacheSec only used if useLittleFSToServe_pfodWeb = true; static uint32_t cacheSec = 0; //if useLittleFSToServe_pfodWeb = true use this to control cache timeout // =================== WiFi settings =================== const char *ssid = "****"; const char *password = "******"; // NOTE: if using PicoProbe to debug, uncomment #define PICO_PROBE to move Serial to Serial1 //#define PICO_PROBE #ifdef ESP8266 #include #else #include #endif IPAddress staticIP; // use auto assigned ip. NOT recommended //IPAddress staticIP(10, 1, 1, 100); // use a static IP, #include #include #include "millisDelay.h" static void setupWiFi(); millisDelay plotDataDelay; unsigned long PLOT_DATA_DELAY_MS = 200; float tempC; float tempF; int ADC_reading; const int ADC_pin = 26; static Stream *debugPtr = NULL; const char version[] = "V1"; // not actually used by Chart Only Print &dataWriter = getRawDataWriter(); // if running under PicoProbe debugging move Serial to Serial1 #ifdef PICO_PROBE #define Serial Serial1 #endif void setup(void) { Serial.begin(115200); for (int i = 10; i > 0; i--) { Serial.print(i); Serial.print(' '); delay(1000); } Serial.println(); setDebugPtr(&Serial); //set global debug debugPtr = getDebugPtr(); // enable extra debug here setupWiFi(); start_pfodWebServer(version, useLittleFSToServe_pfodWeb, cacheSec); // <<<<<<<<< Your extra setup code goes here plotDataDelay.start(PLOT_DATA_DELAY_MS); } // the loop routine runs over and over again forever: void loop() { handle_pfodWebServer(); if (plotDataDelay.justFinished()) { plotDataDelay.restart(); unsigned long ms = millis(); ADC_reading = analogRead(ADC_pin); tempC = analogReadTemp(); // Get internal temperature tempF = tempC * 9.0 / 5.0 + 32.0; // Fahrenheit conversion dataWriter.print(ms); dataWriter.print(','); dataWriter.print(ADC_reading); dataWriter.print(','); dataWriter.print(tempC); dataWriter.print(','); dataWriter.println(tempF); dataWriter.flush(); } } /** sets up WiFi */ static void setupWiFi() { if (debugPtr) { debugPtr->print(F("WiFi setup -- ")); } WiFi.mode(WIFI_STA); if (((uint32_t)staticIP) != 0) { IPAddress gateway(staticIP[0], staticIP[1], staticIP[2], 1); // set gatway to ... 1 if (debugPtr) { debugPtr->print(F("Setting gateway to: ")); debugPtr->println(gateway); } IPAddress subnet(255, 255, 255, 0); WiFi.config(staticIP, gateway, subnet); } WiFi.begin((char *)ssid, (char *)password); if (debugPtr) { debugPtr->print("Connecting to "); debugPtr->println(ssid); } // Wait for connection uint8_t i = 0; while (WiFi.status() != WL_CONNECTED && (i++ < 60)) { //wait 30 seconds before fail if (debugPtr) { debugPtr->print("."); } delay(500); } if (WiFi.status() != WL_CONNECTED) { if (debugPtr) { debugPtr->print("Could not connect to "); debugPtr->println(ssid); } while (1) { delay(500); } } if (debugPtr) { debugPtr->print("Connected! IP address: "); debugPtr->println(WiFi.localIP()); } }