Skip to content

Instantly share code, notes, and snippets.

@olafloogman
Created November 29, 2014 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olafloogman/17f500c05f53c18b0de1 to your computer and use it in GitHub Desktop.
Save olafloogman/17f500c05f53c18b0de1 to your computer and use it in GitHub Desktop.
WindowsIoT_TemperatureToStorageQueue
// Main.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include "arduino.h"
#include "was/storage_account.h"
#include "was/queue.h"
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
using namespace utility; // Common utilities like string conversions
using namespace web; // Common features like URIs.
using namespace web::http; // Common HTTP functionality
using namespace web::http::client; // HTTP client features
using namespace concurrency::streams; // Asynchronous streams
int tempPin = -1; // The on-board thermal sensor
int _tmain(int argc, _TCHAR* argv[])
{
return RunArduinoSketch();
}
int led = 13; // This is the pin the LED is attached to.
void setup()
{
// TODO: Add your code here
pinMode(led, OUTPUT); // Configure the pin for OUTPUT so you can turn on the LED.
ucout << "setup" << std::endl;
}
// the loop routine runs over and over again forever:
void loop()
{
float temperatureInDegreesCelcius = 1.0f; // Storage for the temperature value
// reads the analog value from this pin (values range from 0-1023)
temperatureInDegreesCelcius = (float)analogRead(tempPin);
Log(L"Temperature: %lf Celcius\n", temperatureInDegreesCelcius);
try
{
utility::string_t storage_connection_string(U("DefaultEndpointsProtocol=https;AccountName=kloud;AccountKey=verysecret"));
// Initialize storage account
azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);
// Create a queue
azure::storage::cloud_queue_client queue_client = storage_account.create_cloud_queue_client();
azure::storage::cloud_queue queue = queue_client.get_queue_reference(U("my-sample-queue"));
bool created = queue.create_if_not_exists();
ucout << "Queueing message " << std::to_wstring(temperatureInDegreesCelcius) << std::endl;
azure::storage::cloud_queue_message msg(utility::conversions::to_string_t(std::to_wstring(temperatureInDegreesCelcius)));
queue.add_message(msg);
}
catch (const azure::storage::storage_exception& e)
{
ucout << U("Error: ") << e.what() << std::endl;
azure::storage::request_result result = e.result();
azure::storage::storage_extended_error extended_error = result.extended_error();
if (!extended_error.message().empty())
{
ucout << extended_error.message() << std::endl;
}
}
catch (const std::exception& e)
{
ucout << U("Error: ") << e.what() << std::endl;
}
Sleep(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment