This project is based on internet yahoo finance API to get data about certain Stock holder like google international company as in this example.
Code
C/C++you need to change the GOGL characters in the request link to yours.
also you need to change +0123456789 to the desired destination phone number.
last step is to change 3.20 , 3.00 to your desired numbers.
also you need to change +0123456789 to the desired destination phone number.
last step is to change 3.20 , 3.00 to your desired numbers.
#define CUSTOM_SETTINGS
#define INCLUDE_INTERNET_SHIELD
#define INCLUDE_TERMINAL_SHIELD
#define INCLUDE_SMS_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
/* Create an Http request with openweathermap.org api url. */
/* It's important to be created here as a global object. */
/* the link consists from 3 parts
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20%28%27
GOGL
%27%29&format=json&diagnostics=true&env=http://datatables.org/alltables.env
where GOGL is the holder indicator
*/
HttpRequest request("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20%28%27GOGL%27%29&format=json&diagnostics=true&env=http://datatables.org/alltables.env");
static boolean isSent = false;
void setup()
{
/* Start communication. */
OneSheeld.begin();
/* Subscribe to success callback for the request. */
request.setOnSuccess(&onSuccess);
/* Subscribe to json value replies. */
request.getResponse().setOnJsonResponse(&onJsonReply);
/* Subscribe to response errors. */
request.getResponse().setOnError(&onResponseError);
/* Subscribe to Internet errors. */
Internet.setOnError(&onInternetError);
Internet.performGet(request);
}
void loop()
{
}
void onSuccess(HttpResponse & response)
{
/* Using the response to query the Json chain till the required value. */
/* i.e. Get the value of 'main' in the first object of the array 'weather' in the response. */
/* Providing that the response is in JSON format. */
response["query"]["results"]["quote"]["LastTradePriceOnly"].query();
}
void onJsonReply(JsonKeyChain & hell,char * output)
{
/* 1Sheeld responds using text-to-speech shield. */
Terminal.println(output);
float x=atof(output);
if(x > 3.20){
if(!isSent){
Terminal.println("Arrow is high! It's time to sell.");
SMS.send("+0123456789","Arrow is high! It's time to sell.");
isSent = true;
}
}else if(x < 3.0){
if(!isSent){
Terminal.println("Arrow is low! It's prefered to buy now.");
SMS.send("+0123456789","Arrow is low! It's prefered to buy now.");
isSent = true;
}
}else{
isSent = false;
}
OneSheeld.delay(10000);
Internet.performGet(request);
}
void onResponseError(int errorNumber)
{
/* Print out error Number.*/
Terminal.print("Response error:");
switch(errorNumber)
{
case INDEX_OUT_OF_BOUNDS: Terminal.println("INDEX_OUT_OF_BOUNDS");break;
case RESPONSE_CAN_NOT_BE_FOUND: Terminal.println("RESPONSE_CAN_NOT_BE_FOUND");break;
case HEADER_CAN_NOT_BE_FOUND: Terminal.println("HEADER_CAN_NOT_BE_FOUND");break;
case NO_ENOUGH_BYTES: Terminal.println("NO_ENOUGH_BYTES");break;
case REQUEST_HAS_NO_RESPONSE: Terminal.println("REQUEST_HAS_NO_RESPONSE");break;
case SIZE_OF_REQUEST_CAN_NOT_BE_ZERO: Terminal.println("SIZE_OF_REQUEST_CAN_NOT_BE_ZERO");break;
case UNSUPPORTED_HTTP_ENTITY: Terminal.println("UNSUPPORTED_HTTP_ENTITY");break;
case JSON_KEYCHAIN_IS_WRONG: Terminal.println("JSON_KEYCHAIN_IS_WRONG");break;
}
}
void onInternetError(int requestId, int errorNumber)
{
/* Print out error Number.*/
Terminal.print("Request id:");
Terminal.println(requestId);
Terminal.print("Internet error:");
switch(errorNumber)
{
case REQUEST_CAN_NOT_BE_FOUND: Terminal.println("REQUEST_CAN_NOT_BE_FOUND");break;
case NOT_CONNECTED_TO_NETWORK: Terminal.println("NOT_CONNECTED_TO_NETWORK");break;
case URL_IS_NOT_FOUND: Terminal.println("URL_IS_NOT_FOUND");break;
case ALREADY_EXECUTING_REQUEST: Terminal.println("ALREADY_EXECUTING_REQUEST");break;
case URL_IS_WRONG: Terminal.println("URL_IS_WRONG");break;
}
}
1Sheeld
Comments