Prof. J. Walter - Informationstechnik, Mikrocomputertechnik, Digitale Medien Quellcode
Informationstechnik
Remote Entwicklung beim eMalRob
Sommersemester 2021
weel1017@h-ka.de
--

Quellcode

- Verwendete IDE-Version:1.8.3 -

#include <WiFi.h>
#include <Arduino.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
#include <WebSerial.h>
#include "SPIFFS.h"
#include <Arduino_JSON.h>

//**********************************************************************************************************

AsyncWebServer server(80);
//**********************************************************************************************************

// WIFI-Daten
const char ssid[] = "FRITZ!Box ";
const char password[] = "123456789101112131415";

//**********************************************************************************************************

void recvMsg(uint8_t *data, size_t len){
WebSerial.println("Received Data...");
String d = "";
for(int i=0; i < len; i++){
d += char(data[i]);
}
WebSerial.println(d);
}
//variabls for blinking an LED with Millis
const int led = 2; // ESP32 Pin to which onboard LED is connected
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 1000; // interval at which to blink (milliseconds)
int ledState = LOW; // ledState used to set the LED

//**********************************************************************************************************

void setup() {

pinMode(led, OUTPUT);
pinMode(16, OUTPUT); // set the LED pin mode
pinMode(15, OUTPUT); // set the LED pin mode
Serial.begin(115200);
Serial.println("Booting");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);


while (WiFi.waitForConnectResult() != WL_CONNECTED)
{
Serial.println("Connection Failed! Rebooting...");
delay(5000);
ESP.restart();
}
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", "Hi! I am ESP32.");
});
// WebSerial is accessible at "<IP Address>/webserial" in browser
WebSerial.begin(&server);
WebSerial.msgCallback(recvMsg);
AsyncElegantOTA.begin(&server);



server.begin();




Serial.println("Ready");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

}

//**********************************************************************************************************

void loop() {

//loop to blink without delay

AsyncElegantOTA.loop();
WebSerial.println("Test");
digitalWrite(15, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a 3/4 second
digitalWrite(15, LOW); // turn the LED off by making the voltage LOW
delay(250);

}

  Mit Unterstützung von Prof. J. Walter Sommersemester 2021