Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: **Asynchronous Initialization**
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-10-20 10:20:56
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* merge code. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <TinyGPSPlus.h>
- #include "ACS712.h"
- #include <WiFi.h>
- #include <ESPAsyncWebServer.h>
- #include <SPIFFS.h>
- #include <ArduinoJson.h>
- #include <EEPROM.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #include "X9C10X.h"
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Instantiate library objects
- TinyGPSPlus gps; // GPS object
- ACS712 ACS(A0, 5.0, 1023, 100); // Current sensor object
- OneWire oneWire(2); // OneWire object for temperature sensors
- DallasTemperature sensors(&oneWire); // Temperature sensor object
- X9C10X pot(10000); // Digital potentiometer object
- void setup(void)
- {
- // put your setup code here, to run once:
- // Start Serial for debugging
- Serial.begin(115200);
- delay(1000);
- Serial.println("ciao");
- // Access Point credentials
- char ssid[] = "pleasedontcode.com"; // your network SSID (name)
- char pass[] = "prova1234"; // your network password (use for WPA, or use as key for WEP)
- // Create an instance of the web server
- AsyncWebServer server(80);
- pot.begin(4, 5, 15); // pulse, direction, select // INC = 4, UD = 5, CS = 15
- //NON TOGLIERE - SERVE PER NON FAR SBARELLARE LA MACCHINA
- for(int i=0; i<10; i++)
- {
- setCurrentOutput(0);
- delay(20);
- setCurrentOutput(100);
- delay(20);
- }
- setCurrentOutput(PWM_output_percentage);
- readMinutesCounterFromEEPROM();
- // Initialize GPS
- Serial.println("Initializing GPS...");
- gps.begin(GPSBaud);
- Serial.println("ciao2");
- // Initialize temperature sensors
- sensors.begin();
- smartDelay(1000);
- ACS.setMidPoint(ADC_Offset);
- Serial.println(F("Access Point Web Server"));
- // Initialize SPIFFS
- if (!SPIFFS.begin(true)) {
- Serial.println("An Error has occurred while mounting SPIFFS");
- return;
- }
- WiFi.mode(WIFI_AP); // Set the ESP32 to access point mode
- if (!WiFi.softAP(ssid, pass)) {
- Serial.println("Soft AP creation failed.");
- while(1);
- }
- // Print the IP address of the access point
- IPAddress IP = WiFi.softAPIP();
- Serial.print("Access Point IP Address: ");
- Serial.println(IP);
- // Serve the JPEG image
- server.on("/background.jpg", HTTP_GET, [](AsyncWebServerRequest *request){
- Serial.println("Serving background image");
- request->send(SPIFFS, "/background.jpg", "image/jpeg");
- });
- // Serve the HTML page
- server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
- Serial.println("Serving index page");
- request->send(SPIFFS, "/index.html", "text/html");
- });
- server.on("/UPDATEDATA", HTTP_POST, [](AsyncWebServerRequest *request) {
- // Log post request handling
- Serial.println("Handling postUpdateData");
- // Allocate a temporary JsonDocument
- StaticJsonDocument<512> doc;
- // Gather data and populate JSON
- updateData(doc);
- // Convert the JSON document to string and send it in response
- String response;
- serializeJsonPretty(doc, response);
- request->send(200, "application/json", response);
- });
- // Start the server
- server.begin();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- // No logic in the loop; the server works asynchronously
- readGPSAndCheckSpeed();
- readCurrent();
- readVoltage();
- readWaterTank();
- readTemp1();
- readTemp2();
- updateMinutesCounter();
- checkRegeneration();
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement