Random Nerd Tutorials
Share

Retrieving Bitcoin Price Using ESP8266 WiFi Module

Share

In this project you’re going to create a simple HTTP client with an ESP8266 WiFi module. Having your ESP8266 connected to your network, it requests the current Bitcoin price. This is an example on how to  retrieve data from the web.

esp8266_thumbnail

Before you read this post, I recommend reading these tutorials about the ESP8266:

First, flash your ESP8266 module with NodeMCU

NodeMCU is a firmware that allows you to program the ESP8266 modules with LUA script. And you’ll find it very similar to the way you program your Arduino. With just a few lines of code you can establish a WiFi connection, control the ESP8266 GPIOs, turning your ESP8266 into a web server and a lot more. Follow this tutorial to Flash your ESP8266 with NodeMCU.

Where to buy?

You can click here to compare the ESP-01 Board price at different stores (read Best ESP8266 Wi-Fi Development Board)

Schematics (3.3V FTDI Programmer)

The schematics for this project are very straight forward. You only need to establish a serial communication between your FTDI programmer and your ESP8266. You can check this page to get an FTDI programmer at the best price.

esp8266_pinout_h-569x236Wiring:

  • RX -> TX
  • TX -> RX
  • CH_PD -> 3.3V
  • VCC -> 3.3V
  • GND -> GND

ESP-Bitcoin-price_bb

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Downloading ESPlorer

I recommend using the ESPlorer program created by 4refr0nt to create and save LUA files into your ESP8266. Follow these instructions to download and install ESPlorer:

  1. Click here to download ESPlorer
  2. Unzip that folder
  3. Go to the dist folder (here’s the path: ESPlorer-master\ESPlorer\dist)
  4. Run ESPlorer.jar. It’s a JAVA program, so you need JAVA installed on your computer.
  5. Open the ESPlorer

esplorer start

How to send commands to your ESP8266

When you open the ESPlorer you should see a window similar to the preceding Figure, follow these instructions to send commands to your ESP8266:

  1. Connect your FTDI programmer to your computer
  2. Select your FTDI programmer port (COM8, for example)
  3. Press Open/Close
  4. Select NodeMCU+MicroPtyhon tab
  5. Copy the following script into ESPlorer

Note: You need to add your own network credentials to line 2.

cloud-download

Then you simply click the button Send to ESP. And you should see a query appearing in your screen with the current Bitcoin price and a few other detailsEverything that you need to worry about or change is highlighted in red box in the following Figure.

esplorer_bitcoin_price

Retrieved Data

Here’s the data that your ESP8266 is requesting, you can access it with your web browser right now: http://api.coindesk.com/v1/bpi/currentprice.json

Below you can see the data that your ESP8266 requested which is the current price of Bitcoins in USD, GPB and EUR.

{“time”:{“updated”:”Mar 4, 2015 15:10:00 UTC”,”updatedISO”:”2015-03-04T15:10:00+00:00″,”updateduk”:”Mar 4, 2015 at 15:10 GMT”},”disclaimer”:”This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org”,”bpi”:{“USD”:{“code”:”USD“,”symbol”:”$”,”rate”:”282.5891“,”description”:”United States Dollar”,”rate_float”:282.5891},”GBP”:{“code”:”GBP“,”symbol”:”£”,”rate”:”184.6234“,”description”:”British Pound Sterling”,”rate_float”:184.6234},”EUR”:{“code”:”EUR“,”symbol”:”€”,”rate”:”254.3166“,”description”:”Euro”,”rate_float”:254.3166}}}

Troubleshooting

Sometimes your ESP8266 doesn’t have enough time to send the HTTP request when you press “Send to ESP”. So It won’t show any data retrieved. You might want to use this feature on the ESPlorer that is called “Send current line to ESP8266“. And send each line of your script at a time.

send_current_line

Taking it further

You’re requesting the current Bitcoin price, that doesn’t seem that useful… right? Wrong! Just think for one second with a $4 WiFi module you can request any data from the web, how awesome is that?

Now my question is: which data is important for your project? The weather? Sport scores? Just type in your search engine: “weather api”, “finances api”, pretty much any term that contains some sort of data followed by api will be available to retrieve data.

Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog and my Facebook Page.


Learn ESP32 with Arduino IDE

This our complete guide to program the ESP32 with Arduino IDE, including projects, tips, and tricks! The registrations are open, so SIGN UP NOW »

Leave a Comment:

Add Your Reply

⏰ Registrations are open ⏰
Sign up for "Learn ESP32 with Arduino IDE" Course