Simple Ticker - get http value > store value > pass to arduino (in the future) > display on 7 seg

Hello,
This is my first post (yay!)
Could someone help me with a quick pull of some data.
I’d like to build a stock ticker, pulling the price (High/Low/Buy/Sell and so on) from this address
https://btc-e.com/api/2/btc_usd/ticker

I’ll be passing the values to an Arduino for display on a 8 character, 7 segment display panel. Using the arduino as I can not find a library or method to use imp to communicate with a JY-LKM1638 7 Segment display panel (would be awesome if someone knows how to do that as well).

Anyway, would really love some help, Thanks so much!
Gray

Here is an example of how to get the ticker data and pass it down to your device(imp) from the agent. I think it would be easier to send the data directly to the display than to pass it through an Arduino. I could point you to code to write the data to a LCD display, and I think there is code from some other 7 segment displays around…

agent code:
function getTicker() { local reqURL = "https://btc-e.com/api/2/btc_usd/ticker"; server.log(format("Sending request to %s", reqURL)); local req = http.get(reqURL); // send the request synchronously (blocking). Returns an HttpMessage object. local res = req.sendsync(); // check the status code on the response to verify that it's what we actually wanted. server.log(format("Response returned with status %d", res.statuscode)); if (res.statuscode != 200) { server.log("Request for Ticker data failed."); return; } //Decode JSON from the body to a variable local response = http.jsondecode(res.body); //send it to the device. device.send("ticker", response); //refresh the data every 30 seconds. imp.wakeup(30, getTicker); } getTicker();

device code:

agent.on("ticker", function(data) { //Do something with your ticker data server.log(data.ticker.high); });

Here is the datasheet: https://docs.google.com/file/d/0B84N2SrJaybwZTgxYjM4ZmEtY2EyZi00YjVjLWIzOTctYTlhMjJkM2MxMTBl/edit?pli=1

You might be interested in the Emma reference design:

Hi jwehr
Thank you so much for your comments!!! Much appreciated!

I am getting the expected status 200 response (good times!!)
My ‘Electric Imp n00b’ ways are still hurting me, how do I pull out each value from the link (https://btc-e.com/api/2/btc_usd/ticker) and then store & display it.

To help me learn the Imp better I’d love to be able to call each of the values (such as High, Low, Buy, Sell)
server.log(format(“Current buy price”, buy));
server.log(format(“Current sell price”, sell));

And you’re totally correct, it would be soooo much better if I could just pass directly to the display panel, I’ll have a read of the links you provided (currently I’m cheating and just using a pre-built libiary on the Arduino to get the display panel to work).

In the body of the HTTP response to your query is the JSON data with all of the values that you want. When you do this:
local response = http.jsondecode(res.body);
You are asking impOS to decode the JSON data into a table called response.
Now, since you don’t really want to do anything with the data at the agent, you should send it down to the device, which is done in the device.send function.

This function receives our data at the device:
agent.on("ticker", function(data) { //Do something with your ticker data server.log(data.ticker.high); });
Now the JSON data is held in the table “data”, (since that is what I put in the function). At that point you can reference the key:value pairs just like I do in the server.log statement. If I want to get the “high” value, I can reference data.ticker.high. If I want to get the low value, I can reference it by data.ticker.low.
data is our table, and ticker contains the sets of key:value pairs that we want to pull from.
If you added the device code that I listed, you should see it log the “High” value.

You superstar, thank you so much for the explanation!
I’m successfully calling all of the data I need, thanks!!!
(I kept trying to do a server.log from the agent, not the device, whoops!!!)

Thanks again!

You can log from either, it’s a great debug tool.