The NFT Coin ticker

This is how I built a NFT (Non fungible token) ticker to have under controll the value of my preferred virtual coin.

If you need additional specific information about this topic or if you want to look it personally please write an email

Bitcoin and other NFTs are now part of our everyday life. No one doesn't know what you can do and how you can use those new coins. Governments are against or in favor of such tokens but there is something no one will never be able to disagree with me. The logic composing a distributed app is something really fascinating.
Honestly, it is not a new concept but it is a concept that we all significantly underestimated in the past few years.

A distributed app is simply an application that does not rely on a central database or on a central service. The database is distributed together with the app and is exactly part of it.
A distributed app is able to update all other databases (scattered across the globe) as soon as someone makes a change (add a transaction) somewhere in the word.
this grant also an incredible level of security because if you want to hack a sequential chain, like the one implemented by a "blockchain", (this is the official name of a distributed database used in DApp technology) you must be the algorithm itself and must be so fast to reach all nodes of the blockchain to copy a fake transaction everywhere.

In few words ... very very very hard.

Distributed apps were realized to manage different subjects. For example, the database of a company who sells cars or database of an airline used to manage their flights. As usual, "at the end of the game", we, "humans", decided to use them for what we can do best .... create and manage money.
Because of this, an anonymous man, many years ago, invented the first digital DApp based on the blockchain concept. It was the Bitcoin. The Bitcoin blockchain is nothing more than a very long long database containing all the transactions made in bitcoin from the beginning of the application epoch 1 to now.

It constantly evolve and, gradually new transactions are added at the end of the database creating what we call: "blocks".

Following the bitcoin blockchain other Dapps were built based on the same logic. The most famous one is, currently, the one named "Ethereum". It is another coin, another value, another chain of transactions and so on.

There is too much to explain about blockchains, but, for now, let's remain concentrated on those digital coins.
The token universe is constantly in evolution. There are thousands of different coins and their price vary and evolves so much that in the evening you can be poor and in the morning you can be rich (not exactly ... but the revenue, or the loss, can be really high sometimes).
For this reason you need to be constantly updated on the value of those coins if you want to play with them, selling and buying at the right time.
In order to be constantly updated, you could connect to the internet with your mobile, install an application to configure alarms or access to sites, named exchange, who constantly can update you on the status of your preferred coin.

Because I like to make things more complex, I decided to build an object called "Ticker". A Ticker is a simple object able to poll on a rest web service and put the result on a display.

The BVRobotics ticker is made using a combo version of an ESP8266 containing a small OLED display. You can find many interesting version of this solution made in china on Amazon or on AliExpress or wish and so on.
The cost is more or less 15 or 20 euro.
The most easy way I found to receive information about a coin value (compared with another coin) is to use a rest function made available thanks to the exchange named Binance. It is free and you don't need an account to be able to access those functions.
Binance gives you some rest calls that you can use to retrieve the value of a specific coin compared with another one (couple of tokens comparison). If, for example, you want to know the value of the Bitcoin (coin code BTC) compared with the Binance stable coin linked to the US dollar (BUSD) then you need just to enter the following link in your browser:
https://api.binance.com/api/v1/ticker/price?symbol=BTCBUSD

This will return you a Json page containing the value of the comparison at the time you make the request.

        {
            "symbol":"BTCBUSD",
            "price":"42651.77000000"
        } 
        
As you can see the result is really easy to understand.

The same is valid for any other coin quoted by Binance. You need just to change the symbol parameter in the REST call.

Here, following, the logic to implement into the ticker I used. When you activate the ticker:

1) The ticker validate if a WIFI configuration already exist if not then it starts in APN mode
2) In APN mode it starts a web server and, using the web server (two simple text boxes and a button), you can enter the home APN to use to connect to the internet.
3) If an APN is already available it simply connect the APN and send rest calls every x seconds to Binance in order to retrieve the coin value constatly.
4) During the startup an allarm layer is retrieved from the EPROM (if configured). You can select max two coins to configure alarms so alarms are loaded and verified at each cycle
5) A new web server is activated to give the user the possibility to log into the ticker and set or change an alarm

In the loop function, at every interval (could be 30 secs or more), I send a REST request using the following function:

                String ReadCoinAPI(int CoinCount) {
  
                  String JSONTranslation;
                  sensorReadings = httpGETRequest(EndPoint[CoinCount]);
  
                  if (HTTPErrorCodeReceived == true) {
                    CoinCount=numberOfAPICalls;
                    return "Error reading data";
                  }
                  Serial.println(sensorReadings);
                  JSONVar myObject = JSON.parse(sensorReadings);

  
                  if (JSON.typeof(myObject) == "undefined") {
                    Serial.println("Parsing input failed!");
                    return "Error reading data";
                  }
                  CoinName[CoinCount] = myObject["symbol"];
                  CoinValue[CoinCount] = myObject["price"];
  
                  Serial.print("JSON object = ");
                  Serial.println(myObject);
                  dCoinValue[CoinCount] = JSON.stringify(CoinValue[CoinCount]).toDouble(); 
                  JSONTranslation = JSON.stringify(CoinName[CoinCount]).substring(1,4) + " = " + JSON.stringify(CoinValue[CoinCount]);

                  return JSONTranslation;

                }

        

The HTTP request string is in the string array EndPoint[CoinCount]. I am using an array because the ticker can display 6 different coins in one screen

ticker img

Now, for any single coin the value returned is tested with the "limit" stored in the alarm. If the limit is reached then the display background color is switched using:


        if  (alarm)   
          {  //Let's go White
              Serial.print("Inverting ...");
              Wire.beginTransmission(0x3c); 
              Wire.write(0x00); 
              Wire.write(0xA7); 
              Wire.endTransmission();
              //display.setColor(INVERSE);
              OLED_out(DisplayMessage);
          }
        

This is done using the WIRE library. For certain feature of the oled display is better to use the registry language like in this case.
As you can see the Tiker is a very basic object that can be expanded with many interesting ideas.
In the first version the 6 coins are fixed in the source code but you could decide to let the user configure the coins he wants to display.
The possibility to save the configuration on the ticker is implemented thanks to the EPROM available in any arduino (or compatible) component. This can be activated using very basic commands.
First of all you need to include the EPROM library:

            #include "EEPROM.h"
        
Then you need to initialize the library
            EEPROM.begin(512);
        
and read (byte by Byte)

            for (int i = 0; i < 32; ++i)
            {
                esid += char(EEPROM.read(i));
            }

        
or write (byte by byte)

        for (int i = 0; i < qpass.length(); ++i)
            {
              EEPROM.write(32+i, qpass[i]);
              Serial.print("Wrote: ");
              Serial.println(qpass[i]); 
            }
        EEPROM.commit();
        
Do not forget to commit ...

Leave a Comment