/* ESP32 WiFi Scanning example */
#include "WiFi.h"
String Buffer = "10,20,30,-40,50"; // Example input string
int num1, num2, num3, num4, num5; // Variables to store the split integers
void parseString(String input) {
int commaIndex = input.indexOf(','); // Find the first comma
num1 = input.substring(0, commaIndex).toInt(); // Extract substring before the first comma and convert to integer
input = input.substring(commaIndex + 1); // Remove the extracted substring and the comma
commaIndex = input.indexOf(','); // Find the next comma
num2 = input.substring(0, commaIndex).toInt(); // Extract substring before the next comma and convert to integer
input = input.substring(commaIndex + 1); // Remove the extracted substring and the comma
commaIndex = input.indexOf(','); // Find the next comma
num3 = input.substring(0, commaIndex).toInt(); // Extract substring before the next comma and convert to integer
input = input.substring(commaIndex + 1); // Remove the extracted substring and the comma
commaIndex = input.indexOf(','); // Find the next comma
num4 = input.substring(0, commaIndex).toInt(); // Extract substring before the next comma and convert to integer
input = input.substring(commaIndex + 1); // Remove the extracted substring and the comma
num5 = input.toInt(); // The remaining string should be the last number, so directly convert to integer
// Printing the results
Serial.print("num1: ");
Serial.println(num1);
Serial.print("num2: ");
Serial.println(num2);
Serial.print("num3: ");
Serial.println(num3);
Serial.print("num4: ");
Serial.println(num4);
Serial.print("num5: ");
Serial.println(num5);
}
void setup() {
Serial.begin(9600);
Serial.println("Initializing WiFi...");
WiFi.mode(WIFI_STA);
Serial.println("Setup done!");
parseString(Buffer);
}
void loop() {
// Your code here
}