mirror of
https://codeberg.org/mclemens/hr50-remote-display.git
synced 2024-09-26 13:55:55 -04:00
„hr50-remote-display.ino“ hinzufügen
This commit is contained in:
parent
8926005d53
commit
360b65f600
92
hr50-remote-display.ino
Normal file
92
hr50-remote-display.ino
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
#include <WiFi.h>
|
||||||
|
#include <HTTPClient.h>
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "heltec.h"
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
const char* ssid = "<WIFI-SSID>";
|
||||||
|
const char* password = "<WIFI-PASSWORD>";
|
||||||
|
String api_url = "http://192.168.99.193:5000/status";
|
||||||
|
|
||||||
|
int first_row = 0;
|
||||||
|
int second_row = 24;
|
||||||
|
int third_row = 48;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Heltec.begin(true /*DisplayEnable Enable*/, false /*LoRa Disable*/, false /*Serial Enable*/);
|
||||||
|
Heltec.display->flipScreenVertically();
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
delay(4000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printError(String err){
|
||||||
|
Heltec.display->clear();
|
||||||
|
Heltec.display->setFont(DialogInput_plain_16);
|
||||||
|
Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
|
Heltec.display->drawString(0, second_row, err );
|
||||||
|
Heltec.display->display();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
//Check WiFi connection status
|
||||||
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
|
HTTPClient http;
|
||||||
|
String payload = "";
|
||||||
|
http.begin(api_url.c_str());
|
||||||
|
|
||||||
|
// Send HTTP GET request
|
||||||
|
int httpResponseCode = http.GET();
|
||||||
|
|
||||||
|
if (httpResponseCode > 0) {
|
||||||
|
payload = http.getString();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printError("HTTPError: " + (String)httpResponseCode);
|
||||||
|
}
|
||||||
|
// Free resources
|
||||||
|
http.end();
|
||||||
|
|
||||||
|
StaticJsonDocument<200> doc;
|
||||||
|
deserializeJson(doc, payload);
|
||||||
|
JsonObject obj = doc.as<JsonObject>();
|
||||||
|
|
||||||
|
if ( obj != NULL ) {
|
||||||
|
String band = obj["BND"].as<String>();
|
||||||
|
String pep = obj["PEP"].as<String>();
|
||||||
|
String avg = obj["AVG"].as<String>();
|
||||||
|
String swr = obj["SWR"].as<String>();
|
||||||
|
String voltage = obj["VLT"].as<String>();
|
||||||
|
String power = pep + "W/" + avg + "W";
|
||||||
|
String ptt = obj["PTT"].as<String>();
|
||||||
|
String temp = obj["TMP"].as<String>();
|
||||||
|
|
||||||
|
// clear the display
|
||||||
|
Heltec.display->clear();
|
||||||
|
Heltec.display->setFont(DialogInput_plain_16);
|
||||||
|
// print left column
|
||||||
|
Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
|
Heltec.display->drawString(0, first_row, band );
|
||||||
|
Heltec.display->drawString(0, second_row, power );
|
||||||
|
Heltec.display->drawString(0, third_row, voltage );
|
||||||
|
// print right column
|
||||||
|
Heltec.display->setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||||
|
Heltec.display->drawString(128, first_row, swr );
|
||||||
|
Heltec.display->drawString(128, second_row, ptt );
|
||||||
|
Heltec.display->drawString(128, third_row, temp );
|
||||||
|
Heltec.display->display();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// print a "(!)" centered in the third row
|
||||||
|
// this happens when the TRX/PA is transmitting
|
||||||
|
// or otherwise an empty response was send by the API
|
||||||
|
Heltec.display->setFont(DialogInput_plain_16);
|
||||||
|
Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
|
Heltec.display->drawString(58, third_row, "(!)" );
|
||||||
|
Heltec.display->display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printError("No WiFi!");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user