Prof. J. Walter - Informationstechnik, Mikrocomputertechnik, Digitale Medien Quellcode
Hochschule Karlsruhe Logo Informationstechnik
Entwicklung und Updates Ventilator
Sommersemester 2021
teel1011
hier1011

Quellcode

Verwendete IDE:

Arduino IDE  - Version 1.8.13
<OTAProgram_Webserial>

#include "ESP_Remote.h"
#include <WebSerial.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
/***********************Program includes******************************/

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

/**********************Globals for Remote*****************************/
//Start server
AsyncWebServer server(80);

//Wifi data
const char* ssid = "FRITZ!Box 7590 UP";//Wifi Name
const char* password = "45525509900873963179";//Wifi password
char* ota_pass = "..."; //set ota access password

//function for Webserial message Callback
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);
}
/************************Program globals*******************************/

/**********************************************************************/
void setup() {
Serial.begin(115200);

/*******************************Remote Setup*************************/
Easy_OTA_Setup(ssid, password, ota_pass);
WebSerial.begin(&server);
WebSerial.msgCallback(recvMsg);
server.begin();
/**********************************my Setup code*********************/

}

void loop() {
/*******************************Remote Handle************************/
ArduinoOTA.handle();
/**********************************my code Starts hier***************/

/*************Debug Example******************************************/
/*webserial monitor -> type in browser: <esp32 ip-adresss>/webserial*/
WebSerial.println("Debug");


}

<ESP_Remote.h>

#ifndef ESP_Remote_h
#define ESP_Remote_h

#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

void Easy_OTA_Setup(const char *ssid, const char *passwort, const char *OTA_passwort);

#endif

<ESP_Remote.cpp>

#include "ESP_Remote.h"

void Easy_OTA_Setup(const char *ssid, const char *passwort, const char *OTA_passwort)
{
/*********************passwort*************************/
ArduinoOTA.setPassword(OTA_passwort);

/*******************OTA Setup**************************/

Serial.println("Booting");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, passwort);
while (WiFi.waitForConnectResult() != WL_CONNECTED)
{
Serial.println("Connection Failed! Rebooting...");
delay(5000);
ESP.restart();

}

ArduinoOTA
.onStart([]()
{
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";

// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("Start updating " + type);
})
.onEnd([]()
{
Serial.println("\nEnd");
})
.onProgress([](unsigned int progress, unsigned int total)
{
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
})
.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});

ArduinoOTA.begin();

Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}


 

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