Detect a Waves Balance Update with an ESP8266 to turn on an LED

Description: A Wemos Lolin D1 Mini Pro V2 connected to WiFi and a Waves Node Server sends a GET Request every 5 seconds to retrieve Waves Blockchain JSON data for a particulary Waves Address via the browser. If a change to the JSON “balance” data is detected, a green LED light will turn ON for 5 seconds.

Detect a Waves Balance Update with an ESP8266 to turn on LED

Notes: Scan the Waves QR code with Waves wallet, such as the Exodus Wallet. Send any amount of Waves to the address and within a few seconds the green LED will turn ON if the Waves transaction is successful. Make sure to set the baud rate to 115200 in the Serial Monitor.

Serial Monitor Detect Waves Blockchain Balance Change

Helpful Resources:

https://docs.waves.tech/en/

https://arduinojson.org/v6/assistant/

Supplies:

1 – Breadboard 400 Points
1 – Wemos Lolin D1 Mini Pro V2
1 – LED
1 – 220 Ohm Resistor

Arduino Code:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>

const char* ssid = "Network Name";
const char* password = "password";

long int oldbalance = 0;

#define led 5

void setup() {

  pinMode(led, OUTPUT);

  Serial.begin(115200);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to WiFi  ");

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print("*");
  }

  Serial.print("  Connected!");
  Serial.println();
  Serial.println();

}

void loop() {

  if (WiFi.status() == WL_CONNECTED) {

    WiFiClient client;
    HTTPClient http;  // HTTPClient class object
    http.begin(client, "http://nodes.wavesnodes.com/addresses/balance/3P272McBt9uTUthmQS8dazkbdQbz9Hgi7HG");

    // get json data
    int httpCode = http.GET();

    if (httpCode > 0) {  //Check the returning code
      
      const char* json = http.getString().c_str();
      Serial.println(json);

      // Stream& input;

      StaticJsonDocument<128> doc;

      DeserializationError error = deserializeJson(doc, json);

      if (error) {
        Serial.print(F("deserializeJson() failed: "));
        Serial.println(error.f_str());
        return;
      }

      const char* address = doc["address"]; // "3P272McBt9uTUthmQS8dazkbdQbz9Hgi7HG"
      int confirmations = doc["confirmations"]; 
      long balance = doc["balance"];

      delay(5000);

      if(balance != oldbalance) {
       digitalWrite(led, HIGH);
       delay(5000);
       digitalWrite(led, LOW);
       Serial.println(balance);
       oldbalance = balance;
      
      }
    }
  }
}

Leave a Comment

− 2 = 2