This project implements a simple console application that reads temperature values from a supported reader, and records the value out to a supported recorder. It is designed to be run from an embedded device, like a Raspberry Pi, and left running to continiously monitor temperature.
- OneDrive for Business / Office 365
- Console output
- Google Cloud PubSub
For more information about the hardware configuration to enable one wire devices with Raspberry Pi, see Adafruit Lesson 11.
To use the temperature recorder with OneDrive for Business, follow the following steps:
- Register a new application using Azure Active Directory. See register your app for OneDrive for Business for more information.
- Make sure to request the
Files.ReadWrite
scope.
- Make sure to request the
- Modify the
~/.iotTempRecorder.rc
file as mentioned below. Be sure to include your client ID, username, and password. This application uses the username+password flow instead of a traditional OAuth flow since it works as a command line utility and cannot use a web interface. - If you are using Mono, ensure that the SSL certificates used by
logon.microsoftonline.com
andgraph.microsoft.com
are trusted by Mono. See Mono FAQ: security for more information.
To record data to Excel, you need to create an Excel file that will hold the data. The tool will write the data values into a table named RecordedData
.
This table is expected to contain the following columns, in order:
- Date and Time
- Temperature (Celsius)
- Temperature (Fahrenheit)
Additional columns can be added to the table after these first three, since the app only expects these columns. The name of the column is not important, only that they are in the correct order.
See ExampleData for an example of the required file format.
To use temperature-recorder with Google Cloud PubSub, first you will need to create a Google Cloud project and decide on a PubSub topic name.
You can use the PubSub Quickstart to quickly setup a GCP Project.
Data is pushed to PubSub with the date_time_utc, device, temp_c, and temp_f values encoded in a JSON string, which is base64 encoded. Subscribers to the PubSub topic can decode this data and choose to record the information however the subscriber desires.
The temperature recorder app looks for a default configuration file at ~/.iotTempRecorder.rc
.
The format of this file is a JSON dictionary that can contain the following properties:
Name | Value | Description |
---|---|---|
TemperaturePollingIntervalSeconds | Int32 | The number of seconds to wait between capturing a temperature data point. Default: 60. |
DataRecorder | String | Specify the data recorder to use. Allowed values are Console , Office365 , and GoogleCloudPubSub . |
TemperatureSource | String | Specify the source of temperature readings. Allowed values are OneWire or Simulator . |
CloudDataFilePath | String | Specify the relative path to an Excel file that will be updated with the recorded values. |
Office365UserName | String | The username for the Office 365 account. |
Office365Password | String | The password for the Office 365 account. |
Office365ClientId | String | The client ID (guid) for the application registered with Azure Active Directory. |
Office365TokenService | String | The token authority for authentication. Should specify https://login.microsoftonline.com/common . |
Office365ResourceUrl | String | The resource URI to generate tokens for. Should specify https://graph.microsoft.com . |
AuthorizationTokenPath | String | Path to a Google Cloud service account private key. Optional. |
GoogleCloudProjectId | String | Project ID (not Project Name) for your Google Cloud project. |
PubSubTopicName | String | The topic to which temperature messages are published. The topic will be created if it does not exist. |
{
"TemperaturePollingIntervalSeconds": 60,
"Office365UserName": "foo@contoso.com",
"Office365Password": "password",
"CloudDataFilePath": "DataLogger/Temperatures.xlsx",
"Office365ClientId": "guid-here",
"Office365TokenService": "https://login.microsoftonline.com/common",
"Office365ResourceUrl": "https://graph.microsoft.com",
"DataRecorder": "Office365",
"TemperatureSource": "OneWire"
}
{
"TemperaturePollingIntervalSeconds": 60,
"DataRecorder": "GoogleCloudPubSub",
"TemperatureSource": "OneWire",
"AuthorizationTokenPath": "path/to/service-account-key.json",
"GoogleCloudProjectId": "project-foo-12345",
"PubSubTopicName": "topic1"
}
Both the data input and recorder output are abstracted through basic interfaces.
To extend this program to support reading from a different type of temperature sensor or recording to a different output device, you just need to implement either IDataRecorder
or ITemperatureReader
.
See License for more details.