From 360b65f6000010b02e826cca7050383ef963db4b Mon Sep 17 00:00:00 2001 From: Michael Clemens Date: Thu, 11 Nov 2021 23:55:27 +0100 Subject: [PATCH] =?UTF-8?q?=E2=80=9Ehr50-remote-display.ino=E2=80=9C=20hin?= =?UTF-8?q?zuf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hr50-remote-display.ino | 92 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 hr50-remote-display.ino diff --git a/hr50-remote-display.ino b/hr50-remote-display.ino new file mode 100644 index 0000000..bd7068c --- /dev/null +++ b/hr50-remote-display.ino @@ -0,0 +1,92 @@ +#include +#include +#include "Arduino.h" +#include "heltec.h" +#include + +const char* ssid = ""; +const char* 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(); + + if ( obj != NULL ) { + String band = obj["BND"].as(); + String pep = obj["PEP"].as(); + String avg = obj["AVG"].as(); + String swr = obj["SWR"].as(); + String voltage = obj["VLT"].as(); + String power = pep + "W/" + avg + "W"; + String ptt = obj["PTT"].as(); + String temp = obj["TMP"].as(); + + // 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!"); + } +}