Retrieving Bitcoin Price Using ESP8266 WiFi Module

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.

wifi.setmode(wifi.STATION)
wifi.sta.config("YOUR_NETWORK_NAME","YOUR_NETWORK_PASSWORD")
print(wifi.sta.getip())
conn=net.createConnection(net.TCP, 0) 
conn:on("receive", function(conn, payload) print(payload) end )
conn:connect(80,"api.coindesk.com")
conn:send("GET /v1/bpi/currentprice.json HTTP/1.1\r\nHost: api.coindesk.com\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")

View raw code

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 how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Recommended Resources

Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.

Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.

Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience!

What to Read Next…


Enjoyed this project? Stay updated by subscribing our newsletter!

17 thoughts on “Retrieving Bitcoin Price Using ESP8266 WiFi Module”

  1. Olá, este modulo é excelente.
    O firmware nodemcu faz deste modulo uma autentica máquina de comunicações e io’s
    Estive a testar comunicação com o site dweet.io , num loop de post’s obtendo tempos de post de dados na ordem dos 124mS
    conn:on(“receive”, function(conn, pl) conn:send(“POST /dweet/for/thing_name?temperature=” .. i) end )

    É mais tipo um ataque ao servidor dweet com o esp8266 : p

    Continuação de bons projetos 🙂

    Reply
  2. Encontrei tambem uma informação relativa à memoria heap, no qual permite libertar alguma memória.
    esp8266.com/viewtopic.php?f=19&t=1940

    Reply
  3. O teu projeto publicado está muito bom, adiciona agr um display oled 0.96″ I2C
    http://www.ebay.com/itm/271778513089?_trksid=p2057872.m2749.l2649&var=570606439260&ssPageName=STRK%3AMEBIDX%3AIT
    Encontras mais barato, mas esse é perfeito para adicionares, tem um contraste otimo, até debaixo de luz intensa
    Assim fica um módulo portátil para ver as cotações ou outras informações, como por exemplo meteorologia, indice radiação uv. etc

    E já está disponivel uma nova versão do firmware build 20150311
    Ainda n sei quais as optimizações, mas decerto que o firmaware é ainda melhor.

    Reply
  4. Hi Rui,
    Just wanted to ask you is it possible to use more than one ESP8266 controlled by the same web server as I want to control power receptacles in various location using wifi.

    Thanks,

    Reply
  5. Hi very good tutorial,
    I am having some trouble, some times my ESP cant connect to the internet,
    it says DNS retry 1, and keeps counting.
    Does anyone has any idea on how to work this out?

    Thanks best regards

    Reply
  6. Hi Rui / Sara,

    I have a project that has become quite complex and now needs the memory and processing capacity of an Arduino Mega 2560 R3. However, I have also been experimenting with ESP32 and found that I can transfer much of my data without cables. That hardware has many remote temperature sensors and controls remote relays.
    I have also adapted and expanded your ESP-NOW tutorial and can send different data in each direction. This is basically implementing the function of the existing cables via WiFi. I receive 10 x DS18B20 readings as Temperature[10] in a struct one way and send bool Relay1, Relay2 etc., back the other way – all works well. Next will be 8 more sensors and 16 more relays to another ‘node’.
    So now I want to transfer some of the Mega hardware sensors / relays out to individual ESP32s and deliver the data via WiFi.
    Is there a way to add WiFi functionality to a Mega without the complication of using an ESP32? I have an ‘Open-Smart’ Serial WiFi V1.0 which is based on ESP8266 and has a serial interface. It looks to be functionaly the same as the ESP8266 WiFi you have used in this tutorial, so I could try that.
    My last question is how do I find out how to send and receive via structs and esp-now functions like in the ESP-Now tutorial, with that arrangement. Presumably I need to get well into Lua? I am good at adapting and expanding code once I have a working sketch, but do not feel confident to do this from scratch. Are there any good guides / tutorials / resources that I could refer to ?
    Many thanks in anticipation.
    Noel

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.