pleasedontcode

Multicore Setup rev_02

Nov 9th, 2025
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Multicore Setup
  13.     - Source Code compiled for: XIAO ESP32S3
  14.     - Source Code created on: 2025-11-09 23:58:12
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Include in requirements the integration of Wi-Fi */
  21.     /* connectivity for remote monitoring and data */
  22.     /* transfer, utilizing the ESP32S3’s built-in */
  23.     /* wireless capabilities for IoT applications. Split */
  24.     /* two cores managing wifi and sensor reading send */
  25.     /* info on wifi. */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28.  
  29.  
  30.  
  31. /* START CODE */
  32.  
  33. // Multicore example for XIAO ESP32S3
  34. // Demonstrates basic setup for a multicore enabled program
  35.  
  36. // Include necessary libraries
  37. #include <WiFi.h>
  38.  
  39. // Wi-Fi credentials
  40. const char* ssid = "yourSSID";
  41. const char* password = "yourPassword";
  42.  
  43. // Function to set up Wi-Fi connection
  44. void setupWiFi() {
  45.     WiFi.mode(WIFI_STA);
  46.     WiFi.begin(ssid, password);
  47.     Serial.print("Connecting to WiFi...");
  48.     while (WiFi.status() != WL_CONNECTED) {
  49.         delay(500);
  50.         Serial.print(".");
  51.     }
  52.     Serial.println("Connected!");
  53.     Serial.print("IP address: ");
  54.     Serial.println(WiFi.localIP());
  55. }
  56.  
  57. // Task to handle Wi-Fi connection
  58. void wifiTask(void* parameter) {
  59.     setupWiFi();
  60.     while (true) {
  61.         // Periodically check Wi-Fi connection
  62.         if (WiFi.status() != WL_CONNECTED) {
  63.             WiFi.disconnect();
  64.             setupWiFi();
  65.         }
  66.         vTaskDelay(10000 / portTICK_PERIOD_MS); // Check every 10 seconds
  67.     }
  68. }
  69.  
  70. // Task to handle sensor reading or other work
  71. void sensorTask(void* parameters) {
  72.     while (true) {
  73.         // Placeholder for sensor reading code
  74.         // For example, reading temperature, humidity, etc.
  75.         // Send data over Wi-Fi
  76.         // ....
  77.         vTaskDelay(1000 / portTICK_PERIOD_MS); // Run every second
  78.     }
  79. }
  80.  
  81. // Setup function runs once at startup
  82. void setup() {
  83.     Serial.begin(115200);
  84.     while (!Serial); // Wait for serial to initialize
  85.     Serial.println("Multicore Wi-Fi sensor example starting...");
  86.     // Create separate tasks for Wi-Fi and sensors
  87.     xTaskCreatePinnedToCore(wifiTask, "WiFi Task", 4096, NULL, 1, NULL, 0); // Run on core 0
  88.     xTaskCreatePinnedToCore(sensorTask, "Sensor Task", 4096, NULL, 1, NULL, 1); // Run on core 1
  89. }
  90.  
  91. // Main loop does nothing here
  92. void loop() {
  93.     delay(1000); // Idle delay
  94. }
  95.  
  96. /* END CODE */
  97.  
Advertisement
Add Comment
Please, Sign In to add comment