CCCPaste

Button Webserver rev_01

/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: Button Webserver
	- Source Code NOT compiled for: ESP32 DevKit V1
	- Source Code created on: 2024-10-07 16:32:39

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* generate an arduino sketch for an ESP32-C6 and a */
	/* W550 SPI1 connected, which handle a ethernet tcp */
	/* socket server in port 3000 */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 	//https://github.com/evert-arias/EasyButton
#include 	//https://github.com/khoih-prog/AsyncWebServer_ESP32_SC_W5500
#include  // Include Ethernet library for ESP32

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t nose_PushButton_PIN_D4 = 4;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
// Create an instance of EasyButton for the push button
EasyButton button(nose_PushButton_PIN_D4);

// Create an instance of AsyncWebServer on port 3000
AsyncWebServer server(3000);

/****** FUNCTION PROTOTYPES FOR BUTTON CALLBACKS *****/
void onButtonPressed(void);

/****** SETUP FUNCTION *****/
void setup(void)
{
	// Initialize serial communication
	Serial.begin(115200);
	
	// Initialize the button
	button.begin();
	
	// Attach the callback function to the button press event
	button.onPressed(onButtonPressed);
	
	// Set the push button pin mode
	pinMode(nose_PushButton_PIN_D4, INPUT_PULLUP);
	
	// Start the Ethernet connection
	ETH.begin(); // Start Ethernet with default settings
	ETH.config(IPAddress(192, 168, 1, 100), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0)); // Static IP configuration

	// Start the server and define the root endpoint
	server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
		request->send(200, "text/plain", "Hello from AsyncWebServer on port 3000!");
	});
	
	// Start the server
	server.begin();
}

/****** LOOP FUNCTION *****/
void loop(void)
{
	// Continuously read the button state
	button.read(); 
}

/****** BUTTON CALLBACK FUNCTION *****/
void onButtonPressed(void)
{
	Serial.println("Button pressed");
}

/* END CODE */