Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- #include <HTTPClient.h>
- #include <ArduinoJson.h>
- #include "EasyNextionLibrary.h" // Einbinden der Easy Nextion Library
- const char* ssid = "xxxxxxx";
- const char* password = "xxxxxxxx";
- String serverUrl = "xxxxxxxx";
- EasyNex myNex(Serial1);
- void extractCpuPackage(String payload) {
- StaticJsonDocument<2048> doc;
- DeserializationError error = deserializeJson(doc, payload);
- JsonObject CPUWatt = doc["Children"][0]["Children"][0]["Children"][3]["Children"][0]; //cpuWatt
- JsonObject GPUWatt = doc["Children"][0]["Children"][2]["Children"][5]["Children"][0]; //gpuWatt
- JsonObject CPUPackageC = doc["Children"][0]["Children"][0]["Children"][1]["Children"][0]; //cpuTemp
- JsonObject gTempC = doc["Children"][0]["Children"][2]["Children"][1]["Children"][0]; //gpuTemp
- JsonObject CPUTotal = doc["Children"][0]["Children"][0]["Children"][2]["Children"][0]; //cpuLast
- JsonObject gpuCorePerc = doc["Children"][0]["Children"][2]["Children"][2]["Children"][0]; //gpuLast
- String cWatt = String(CPUWatt["Value"]); //String cpuWatt
- String gWatt = String(GPUWatt["Value"]); //String gpuWatt
- String cTemp = String(CPUPackageC["Value"]); //String cpuTemp
- String gTemp = String(gTempC["Value"]); //String gpuTemp
- String cpuPerc = String(CPUTotal["Value"]); //String cpuLast
- String gpuPerc = String(gpuCorePerc["Value"]); //String gpuLast
- cWatt = cWatt.substring(0, cWatt.length() - 2); //entferne letzte Ziffer
- gWatt = gWatt.substring(0, gWatt.length() - 2); //entferne letzte Ziffer
- cTemp = cTemp.substring(0, cTemp.length() - 3); //entferne letzte Ziffer
- gTemp = gTemp.substring(0, gTemp.length() - 3); //entferne letzte Ziffer
- cpuPerc = cpuPerc.substring(0, cpuPerc.length() - 2); //entferne letzte Ziffer
- gpuPerc = gpuPerc.substring(0, gpuPerc.length() - 2); //entferne letzte Ziffer
- // Umwandlung der String-Werte in const char*, um sie an das Nextion-Display zu senden
- const char* cWattChar = cWatt.c_str(); //String in const char* -cpuWatt
- const char* gWattChar = gWatt.c_str(); //String in const char* -gpuWatt
- const char* cTempChar = cTemp.c_str(); //String in const char* -cpuTemp
- const char* gTempChar = gTemp.c_str(); //String in const char* -gpuTemp
- const char* cpuPercChar = cpuPerc.c_str(); //String in const char* -cpuLast
- const char* gpuPercChar = gpuPerc.c_str(); //String in const char* -gpuLast
- // Aktualisierung der Werte auf dem Nextion-Display
- myNex.writeStr("cpuWatt.txt", cWattChar); // schreibe zu Nextion
- myNex.writeStr("gpuWatt.txt", gWattChar); // schreibe zu Nextion
- myNex.writeStr("cpuU.txt", cpuPercChar); // schreibe zu Nextion
- myNex.writeStr("t3.txt", gpuPercChar); // schreibe zu Nextion
- uint32_t cWattGauge = map(cWatt.toInt(), 0, 80, 0, 180); //skalieren von cpuWatt
- uint32_t gWattGauge = map(gWatt.toInt(), 0, 160, 0, 180); //skalieren von gpuWatt
- uint32_t cWattwave = map(cWatt.toInt(), 0, 80, 0, 80); //skalieren von cpuWatt Waveform
- uint32_t gWattwave = map(gWatt.toInt(), 0, 80, 0, 80); //skalieren von gpuWatt
- uint32_t cpuPercGauge = map(cpuPerc.toInt(), 0, 100, 0, 180); //skalieren von cpuLast
- uint32_t gpuPercGauge = map(gpuPerc.toInt(), 0, 100, 0, 180); //skalieren von gpuLast
- uint32_t cpuPerwave = map(cpuPerc.toInt(), 0, 100, 0, 100); //skalieren von cpuLast
- uint32_t gpuPerwave = map(gpuPerc.toInt(), 0, 100, 0, 100); //skalieren von gpuLast
- uint32_t cTempCGauge = map(cTemp.toInt(), 0, 100, 0, 100); //skalieren von cpuTemp
- uint32_t gTempCGauge = map(gTemp.toInt(), 0, 100, 0, 100); //skalieren von gpuTemp
- uint32_t cTempCwave = map(cTemp.toInt(), 0, 100, 0, 100); //skalieren von cpuTemp
- uint32_t gTempCwave = map(gTemp.toInt(), 0, 100, 0, 100); //skalieren von gpuTemp
- myNex.writeNum("cpuW.val", cWattGauge); // schreibe zu Nextion
- myNex.writeNum("gpuW.val", gWattGauge); // schreibe zu Nextion
- myNex.writeNum("cpuUsage.val", cpuPercGauge); // schreibe zu Nextion
- myNex.writeNum("gpuUsage.val", gpuPercGauge); // schreibe zu Nextion
- myNex.writeNum("cpuT.val", cTempCGauge); // schreibe zu Nextion
- myNex.writeNum("gpuT.val", gTempCGauge); // schreibe zu Nextion
- //Cpu Watt Max 95 W
- //Gpu Watt Max 180 W
- /*
- // Serielle Ausgabe
- Serial.print("Cpu Watt: ");
- Serial.print(cWattChar);
- Serial.print(" , ");
- Serial.print("Gpu Watt: ");
- Serial.print(gWattChar);
- Serial.print(" , ");
- Serial.print("Cpu Temp: ");
- Serial.print(cTempChar);
- Serial.print(" , ");
- Serial.print("Gpu Temp: ");
- Serial.print(gTempChar);
- Serial.print(" , ");
- Serial.print("Cpu Last: ");
- Serial.print(cpuPercChar);
- Serial.print(" , ");
- Serial.print("Gpu Last: ");
- Serial.print(gpuPercChar);
- Serial.println("");
- */
- // Waveform CPU Watt
- //myNex.writeNum("cpuWattt.val=", cWattwave);
- /*
- Serial2.print("cpuWattt.val=");
- Serial2.print(cWattwave);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- //Waveform GPU Watt
- Serial2.print("gpuWattt.val=");
- Serial2.print(gWattwave);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- //Waveform CPU %
- Serial2.print("cpuPercc.val=");
- Serial2.print(cpuPerwave);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- //Waveform GPU %
- Serial2.print("gpuPercc.val=");
- Serial2.print(gpuPerwave);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- */
- // Waveform alle
- }
- void setup() {
- Serial.begin(9600);
- myNex.begin(9600);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- //Serial.print(".");
- }
- }
- void loop() {
- if (Serial1.available()) {
- // Lesen Sie die verfügbaren Daten von Serial1
- int receivedChar = Serial1.read();
- Serial.print(receivedChar);
- }
- HTTPClient http;
- http.begin(serverUrl);
- int httpResponseCode = http.GET();
- if (httpResponseCode > 0) {
- String payload = http.getString();
- extractCpuPackage(payload);
- } else {
- //Serial.println("HTTP Request failed");
- }
- http.end();
- delay(50);
- }
- /*
- // Nextion RX SeitenID
- HomeScreen Cpu: .....1010131 255255255....
- Seite 1 X : .....101141 255255255.......
- Seite 2 X : .....101151 255255255.......
- Seite 3 X : .....101161 255255255.......
- Seite 4 X : .....101171 255255255.......
- Seite 5 X : .....101181 255255255.......
- Seite 6 X : .....101191 255255255.......
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement