Dateien hochladen nach „“

This commit is contained in:
Michael Clemens // DK1MI 2023-04-17 07:54:55 +00:00
parent 6d441119ac
commit 406aea9f9a
2 changed files with 231 additions and 0 deletions

View File

@ -0,0 +1,151 @@
/****************************************************************************************************************************
Remote PA Monitor - solution to remotely monitor RF power, SWR and more of QO-100 power amplifiers
For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720)
Uses WebServer_WT32_ETH01, a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer
Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases
Based on Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01
Adapted by Michael Clemens
Licensed under MIT license
Copyright (c) 2015, Majenko Technologies
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of Majenko Technologies nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************************************************************/
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 1
#include <WebServer_WT32_ETH01.h>
#include "index.h" //Web page header file
#ifdef __cplusplus
extern "C" {
#endif
uint8_t temprature_sens_read();
#ifdef __cplusplus
}
#endif
uint8_t temprature_sens_read();
int IO2_FWD = 2;
int IO4_REF = 4;
WebServer server(80);
// Select the IP address according to your local network
IPAddress myIP(192, 168, 88, 247);
IPAddress myGW(192, 168, 88, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
void handleRoot()
{
String s = MAIN_page; //Read HTML contents
server.send(200, "text/html", s); //Send web page
}
void handleNotFound()
{
String message = F("File Not Found\n\n");
message += F("URI: ");
message += server.uri();
message += F("\nMethod: ");
message += (server.method() == HTTP_GET) ? F("GET") : F("POST");
message += F("\nArguments: ");
message += server.args();
message += F("\n");
for (uint8_t i = 0; i < server.args(); i++)
{
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, F("text/plain"), message);
}
void handleFWD() {
String fwdValue = String(analogReadMilliVolts(IO2_FWD));
server.send(200, "text/plane", fwdValue); //Send ADC value only to client ajax request
}
void handleREF() {
String refValue = String(analogReadMilliVolts(IO4_REF));
server.send(200, "text/plane", refValue); //Send ADC value only to client ajax request
}
void handleTEMP() {
int a = (temprature_sens_read() - 32) / 1.8;
String tempValue = String(a);
server.send(200, "text/plane", tempValue); //Send ADC value only to client ajax request
}
void setup()
{
analogReadResolution(12);
Serial.begin(115200);
while (!Serial);
// Using this if Serial debugging is not necessary or not using Serial port
//while (!Serial && (millis() < 3000));
Serial.print("\nStarting AdvancedWebServer on " + String(ARDUINO_BOARD));
Serial.println(" with " + String(SHIELD_TYPE));
Serial.println(WEBSERVER_WT32_ETH01_VERSION);
// To be called before ETH.begin()
WT32_ETH01_onEvent();
ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER);
// Static IP, leave without this line to get IP via DHCP
ETH.config(myIP, myGW, mySN, myDNS);
WT32_ETH01_waitForConnect();
server.on(F("/"), handleRoot);
server.on("/readFWD", handleFWD);
server.on("/readREF", handleREF);
server.on("/readTEMP", handleTEMP);
server.onNotFound(handleNotFound);
server.begin();
Serial.print(F("HTTP EthernetWebServer is @ IP : "));
Serial.println(ETH.localIP());
}
void loop()
{
server.handleClient();
}

80
index.h Normal file
View File

@ -0,0 +1,80 @@
const char MAIN_page[] PROGMEM = R"=====(
<!DOCTYPE html>
<html>
<style>
.card{
max-width: 250px;
min-height: 200px;
background: #02b875;
padding: 30px;
box-sizing: border-box;
color: #FFF;
margin:20px;
box-shadow: 0px 2px 18px -4px rgba(0,0,0,0.75);
}
</style>
<body>
<div class="card">
<h1>FWD Voltage</h1>
<h1><span id="FWDValue">0</span>mV</h1>
</div>
<div class="card">
<h1>REF Voltage</h1>
<h1><span id="REFValue">0</span>mV</h1>
</div>
<div class="card">
<h1>Temperature</h1>
<h1><span id="TEMPValue">0</span>&#8451;</h1>
</div>
<script>
setInterval(function() {
// Call a function repetatively with 1 Second interval
getFWD();
getREF();
getTEMP();
}, 1000); //1000mSeconds update rate
function getFWD() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("FWDValue").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "readFWD", true);
xhttp.send();
}
function getREF() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("REFValue").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "readREF", true);
xhttp.send();
}
function getTEMP() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("TEMPValue").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "readTEMP", true);
xhttp.send();
}
</script>
</body>
</html>
)=====";