Skip to content

Commit

Permalink
Fixed wrong pool total hashrate, with jsonfilter
Browse files Browse the repository at this point in the history
  • Loading branch information
nitroxgas committed Sep 26, 2023
1 parent 6105c57 commit b6e8119
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,22 @@ pool_data getPoolData(void){
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
// Serial.println(payload);
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);

StaticJsonDocument<300> filter;
filter["bestDifficulty"] = true;
filter["workersCount"] = true;
filter["workers"][0]["sessionId"] = true;
filter["workers"][0]["hashRate"] = true;
DynamicJsonDocument doc(2048);
deserializeJson(doc, payload, DeserializationOption::Filter(filter));
//Serial.println(serializeJsonPretty(doc, Serial));
if (doc.containsKey("workersCount")) pData.workersCount = doc["workersCount"].as<int>();
const JsonArray& workers = doc["workers"].as<JsonArray>();
float totalhashs = 0;
for (const JsonObject& worker : workers) {
totalhashs += worker["hashRate"].as<float>();
totalhashs += worker["hashRate"].as<int>();
/* Serial.print(worker["sessionId"].as<String>()+": ");
Serial.print(" - "+worker["hashRate"].as<String>()+": ");
Serial.println(totalhashs); */
}
pData.workersHash = String(totalhashs/1000);
double temp;
Expand Down

0 comments on commit b6e8119

Please sign in to comment.