mirror of
https://codeberg.org/mclemens/hr50-remote-display.git
synced 2024-11-08 06:37:20 -05:00
93 lines
2.7 KiB
C++
93 lines
2.7 KiB
C++
#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 and obj["PTT"].as<String>() != "ERR") {
|
|
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!");
|
|
}
|
|
}
|