forked from Azure/azure-iot-arduino-utility
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync Arduino libraries with latest Azure IoT SDK 1.0.41
- Loading branch information
1 parent
823d67a
commit 8885d5e
Showing
32 changed files
with
800 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments. | ||
This project has adopted the | ||
[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). | ||
For more information see the | ||
[Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact | ||
[[email protected]](mailto:[email protected]) with any additional questions or comments. | ||
|
||
# AzureIoTHub - Azure IoT Hub library for Arduino | ||
# AzureIoTUtility - Azure IoT Utility library for Arduino | ||
|
||
This library is a port of the [Microsoft Azure C Shared Utility](https://github.com/Azure/azure-c-shared-utility/blob/master/c/readme.md) to Arduino. It allows you to use several Arduino compatible boards with Azure IoT Hub. Please submit any contribution directly to [azure-c-shared-utility](https://github.com/Azure/azure-c-shared-utility). | ||
This library is a port of the | ||
[Microsoft Azure C Shared Utility](https://github.com/Azure/azure-c-shared-utility/blob/master/c/readme.md) | ||
to Arduino. It allows you to use several Arduino compatible boards with Azure IoT Hub. | ||
|
||
Currently supported hardware: | ||
## Contributors | ||
|
||
### **Pull request caution!** | ||
All of the files in these Arduino library directories are auto-generated | ||
by the Azure IoT C SDK release process, so pull requests cannot be | ||
accepted in this repo. | ||
Your Arduino-specific contributions will be welcomed with open arms in these locations: | ||
* [AzureIoTHub Arduino-specific sources](https://github.com/Azure/azure-iot-pal-arduino/tree/master/build_all/base-libraries/AzureIoTHub) | ||
* [AzureIoTProtocol_HTTP sources](https://github.com/Azure/azure-iot-pal-arduino/tree/master/build_all/base-libraries/AzureIoTProtocol_HTTP) | ||
* [AzureIoTProtocol_MQTT Arduino-specific sources](https://github.com/Azure/azure-iot-pal-arduino/tree/master/build_all/base-libraries/AzureIoTProtocol_MQTT) | ||
* [AzureIoTUtility Arduino-specific sources](https://github.com/Azure/azure-iot-pal-arduino/tree/master/build_all/base-libraries/AzureIoTUtility) | ||
|
||
Contributions for code that is not Arduino-specific can be made to the | ||
[Azuure IoT C SDK](https://github.com/azure/azure-iot-sdk-c) | ||
|
||
## Currently supported hardware | ||
- Atmel SAMD Based boards | ||
- Arduino/Genuino [MKR1000](https://www.arduino.cc/en/Main/ArduinoMKR1000) | ||
- Arduino/Genuino [Zero](https://www.arduino.cc/en/Main/ArduinoBoardZero) and [WiFi Shield 101](https://www.arduino.cc/en/Main/ArduinoWiFiShield101) | ||
- Adafruit [Feather M0](https://www.adafruit.com/products/3010) | ||
- ESP8266 based boards with [esp8266/arduino](https://github.com/esp8266/arduino) | ||
- SparkFun [Thing](https://www.sparkfun.com/products/13711) | ||
|
@@ -16,25 +35,17 @@ Currently supported hardware: | |
## Prerequisites | ||
|
||
You should have the following ready before beginning with any board: | ||
- [Setup your IoT hub](https://github.com/Azure/azure-iot-sdks/blob/master/doc/setup_iothub.md) | ||
- [Provision your device and get its credentials](https://github.com/Azure/azure-iot-sdks/blob/master/doc/manage_iot_hub.md) | ||
- [Setup your IoT hub](https://github.com/Azure/azure-iot-device-ecosystem/blob/master/setup_iothub.md) | ||
- [Provision your device and get its credentials](https://github.com/Azure/azure-iot-device-ecosystem/blob/master/setup_iothub.md#create-new-device-in-the-iot-hub-device-identity-registry) | ||
- [Arduino IDE 1.6.12](https://www.arduino.cc/en/Main/Software) | ||
- Install the `AzureIoTHub` library via the Arduino IDE Library Manager | ||
- Install the `AzureIoTUtility` library via the Arduino IDE Library Manager | ||
- Install the `AzureIoTProtocol_HTTP` library via the Arduino IDE Library Manager | ||
- Install the [`AzureIoTHub`](https://github.com/Azure/azure-iot-arduino) library via the Arduino IDE Library Manager | ||
- Install the [`AzureIoTUtility`](https://github.com/Azure/azure-iot-arduino-utility) library via the Arduino IDE Library Manager | ||
- Install the [`AzureIoTProtocol_HTTP`](https://github.com/Azure/azure-iot-arduino-protocol-http) library via the Arduino IDE Library Manager | ||
|
||
# Simple Sample Instructions | ||
|
||
## MKR1000 or Zero + Wifi101 | ||
1. Open the `simplesample_http` example from the Arduino IDE File->Examples->AzureIoTHub menu. | ||
2. Install the `WiFi101` library from the Arduino IDE Library Manager. | ||
3. Install the `NTPClient` library from the Arduino IDE Library Manager. | ||
4. Install the `RTCZero` library from the Arduino IDE Library Manager. | ||
5. Update Wifi SSID/Password in simplesample_http.ino | ||
* Ensure you are using a wifi network that does not require additional manual steps after connection, such as opening a web browser. | ||
6. Update IoT Hub Connection string in simplesample_http.c | ||
## Simple Sample Instructions | ||
|
||
## ESP8266 | ||
### ESP8266 | ||
##### Sparkfun Thing, Adafruit Feather Huzzah, or generic ESP8266 board | ||
|
||
1. Install esp8266 board support into your Arduino IDE. | ||
|
@@ -43,29 +54,24 @@ You should have the following ready before beginning with any board: | |
* Open Boards Manager from Tools > Board menu and install esp8266 platform 2.2.0 or later | ||
* Select your ESP8266 board from Tools > Board menu after installation | ||
|
||
2. Open the `simplesample_http` example from the Arduino IDE File->Examples->AzureIoTHub menu. | ||
3. Update the sketch as directed by comments in the sample to support the ESP8266 board. | ||
4. Update Wifi SSID/Password in simplesample_http.ino | ||
2. Open the `simplesample_http` example from the Arduino IDE File->AzureIoTHub->ESP8266->Examples menu. | ||
4. Update Wifi SSID/Password and IoT Hub Connection string in iot_configs.h | ||
* Ensure you are using a wifi network that does not require additional manual steps after connection, such as opening a web browser. | ||
5. Update IoT Hub Connection string in simplesample_http.c | ||
6. Access the [SparkFun Get Started](https://azure.microsoft.com/en-us/documentation/samples/iot-hub-c-thingdev-getstartedkit/) tutorial to learn more about Microsoft Sparkfun Dev Kit. | ||
7. Access the [Huzzah Get Started](https://azure.microsoft.com/en-us/documentation/samples/iot-hub-c-huzzah-getstartedkit/) tutorial to learn more about Microsoft Huzzah Dev Kit. | ||
|
||
|
||
## Adafruit Feather M0 | ||
### Adafruit Feather M0 | ||
1. Install Feather M0 board support into your Arduino IDE. | ||
* Start Arduino and open Preferences window. | ||
* Enter `https://adafruit.github.io/arduino-board-index/package_adafruit_index.json` into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas. | ||
* Open Boards Manager from Tools > Board menu and install `Arduino SAMD Boards` and `Adafruit SAMD Boards` 1.0.7 or later. | ||
* Select your `Adafruit Feather M0` from Tools > Board menu after installation | ||
2. Install the `WiFi101` library from the Arduino IDE Library Manager. | ||
3. Install the `RTCZero` library from the Arduino IDE Library Manager. | ||
4. Install the `NTPClient` library from the Arduino IDE Library Manager. | ||
5. Open the `simplesample_http` example from the Arduino IDE File->Examples->AzureIoTHub menu. | ||
6. Update the sketch as directed by comments in the sample to support the ESP8266 board. | ||
7. Update Wifi SSID/Password in simplesample_http.ino | ||
5. Open the `simplesample_http` example from the Arduino IDE File->AzureIoTHub->M0->Examples menu. | ||
4. Update Wifi SSID/Password and IoT Hub Connection string in iot_configs.h | ||
* Ensure you are using a wifi network that does not require additional manual steps after connection, such as opening a web browser. | ||
8. Update IoT Hub Connection string in simplesample_http.c | ||
9. Access the [Feather M0 WiFi Get Started](https://azure.microsoft.com/en-us/documentation/samples/iot-hub-c-m0wifi-getstartedkit/) tutorial to learn more about Microsoft Feather M0 WiFi Dev Kit. | ||
|
||
## License | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
### simplesample_http | ||
|
||
Instructions for this sample are | ||
[here in the Azure IoT HTTP protocol library for Arduino.](https://github.com/Azure/azure-iot-arduino-protocol-http) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#ifndef IOT_CONFIGS_H | ||
#define IOT_CONFIGS_H | ||
|
||
/** | ||
* WiFi setup | ||
*/ | ||
#define IOT_CONFIG_WIFI_SSID "<Your WiFi network SSID or name>" | ||
#define IOT_CONFIG_WIFI_PASSWORD "<Your WiFi network WPA password or WEP key>" | ||
|
||
/** | ||
* Find under Microsoft Azure IoT Suite -> DEVICES -> <your device> -> Device Details and Authentication Keys | ||
* String containing Hostname, Device Id & Device Key in the format: | ||
* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>" | ||
*/ | ||
#define IOT_CONFIG_CONNECTION_STRING "HostName=<host_name>.azure-devices.net;DeviceId=<device_id>;SharedAccessKey=<device_key>" | ||
|
||
#endif /* IOT_CONFIGS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
|
||
// Use Arduino IDE 1.6.8 or later. | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <time.h> | ||
#include <sys/time.h> | ||
|
||
// for ESP8266 | ||
#include <ESP8266WiFi.h> | ||
#include <WiFiClientSecure.h> | ||
#include <WiFiUdp.h> | ||
|
||
#include <AzureIoTHub.h> | ||
#include <AzureIoTUtility.h> | ||
#include <AzureIoTProtocol_HTTP.h> | ||
|
||
#include "simplesample_http.h" | ||
#include "iot_configs.h" | ||
|
||
static char ssid[] = IOT_CONFIG_WIFI_SSID; | ||
static char pass[] = IOT_CONFIG_WIFI_PASSWORD; | ||
|
||
void setup() { | ||
initSerial(); | ||
initWifi(); | ||
initTime(); | ||
} | ||
|
||
void loop() { | ||
simplesample_http_run(); | ||
} | ||
|
||
void initSerial() { | ||
// Start serial and initialize stdout | ||
Serial.begin(115200); | ||
Serial.setDebugOutput(true); | ||
} | ||
|
||
void initWifi() { | ||
|
||
// check for the presence of the shield : | ||
if (WiFi.status() == WL_NO_SHIELD) { | ||
Serial.println("WiFi shield not present"); | ||
// don't continue: | ||
while (true); | ||
} | ||
|
||
// attempt to connect to Wifi network: | ||
Serial.print("Attempting to connect to SSID: "); | ||
Serial.println(ssid); | ||
|
||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network: | ||
WiFi.begin(ssid, pass); | ||
|
||
Serial.print("Waiting for Wifi connection."); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
Serial.print("."); | ||
delay(500); | ||
} | ||
|
||
Serial.println("Connected to wifi"); | ||
} | ||
|
||
void initTime() { | ||
time_t epochTime; | ||
|
||
configTime(0, 0, "pool.ntp.org", "time.nist.gov"); | ||
|
||
while (true) { | ||
epochTime = time(NULL); | ||
|
||
if (epochTime == 0) { | ||
Serial.println("Fetching NTP epoch time failed! Waiting 2 seconds to retry."); | ||
delay(2000); | ||
} else { | ||
Serial.print("Fetched NTP epoch time is: "); | ||
Serial.println(epochTime); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (c) Arduino. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#if defined(ARDUINO_ARCH_SAMD) | ||
#include "NTPClient.h" | ||
|
||
#define LOCAL_UDP_PORT 2390 | ||
|
||
NTPClient::NTPClient() : | ||
_udp() | ||
{ | ||
} | ||
|
||
int NTPClient::begin() | ||
{ | ||
return _udp.begin(LOCAL_UDP_PORT); | ||
} | ||
|
||
uint32_t NTPClient::getEpochTime(const char* host, int port, unsigned long timeout) | ||
{ | ||
if (host == NULL || port < 1) { | ||
return (uint32_t)-1; | ||
} | ||
|
||
prepareRequest(); | ||
sendRequest(host, port); | ||
|
||
if (!receiveResponse(timeout)) { | ||
return (uint32_t)-1; | ||
} | ||
|
||
return parseResponse(); | ||
} | ||
|
||
void NTPClient::end() | ||
{ | ||
_udp.stop(); | ||
} | ||
|
||
void NTPClient::prepareRequest() | ||
{ | ||
memset(_buffer, 0, NTP_PACKET_SIZE); | ||
|
||
// Initialize values needed to form NTP request | ||
_buffer[0] = 0b11100011; // LI, Version, Mode | ||
_buffer[1] = 0; // Stratum, or type of clock | ||
_buffer[2] = 6; // Polling Interval | ||
_buffer[3] = 0xEC; // Peer Clock Precision | ||
|
||
// 8 bytes of zero for Root Delay & Root Dispersion | ||
|
||
_buffer[12] = 49; | ||
_buffer[13] = 0x4E; | ||
_buffer[14] = 49; | ||
_buffer[15] = 52; | ||
} | ||
|
||
void NTPClient::sendRequest(const char* host, int port) | ||
{ | ||
_udp.beginPacket(host, port); | ||
_udp.write(_buffer, NTP_PACKET_SIZE); | ||
_udp.endPacket(); | ||
} | ||
|
||
int NTPClient::receiveResponse(unsigned long timeout) | ||
{ | ||
long start = millis(); | ||
int size = 0; | ||
|
||
while(size == 0 && (millis() - start) < timeout) { | ||
size = _udp.parsePacket(); | ||
} | ||
|
||
if (size != NTP_PACKET_SIZE) { | ||
return 0; | ||
} | ||
|
||
_udp.read(_buffer, NTP_PACKET_SIZE); | ||
|
||
return 1; | ||
} | ||
|
||
uint32_t NTPClient::parseResponse() | ||
{ | ||
uint16_t high = word(_buffer[40], _buffer[41]); | ||
uint16_t low = word(_buffer[42], _buffer[43]); | ||
uint32_t ntpTime = high << 16 | low; // since 1900 | ||
uint32_t epoch = ntpTime - 2208988800UL; // since 1970 | ||
|
||
return epoch; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) Arduino. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#include <WiFi101.h> | ||
#include <WiFiUdp.h> | ||
|
||
#ifndef NTPCLIENT_H | ||
#define NTPCLIENT_H | ||
|
||
#define NTP_PACKET_SIZE 48 | ||
#define NTP_PORT 123 | ||
|
||
#define DEFAULT_NTP_TIMEOUT 10000 | ||
|
||
class NTPClient | ||
{ | ||
public: | ||
NTPClient(); | ||
int begin(); | ||
uint32_t getEpochTime(const char* host, int port = NTP_PORT, unsigned long timeout = DEFAULT_NTP_TIMEOUT); | ||
void end(); | ||
|
||
private: | ||
void prepareRequest(); | ||
void sendRequest(const char* host, int port); | ||
int receiveResponse(unsigned long timeout); | ||
uint32_t parseResponse(); | ||
|
||
char _buffer[NTP_PACKET_SIZE]; | ||
WiFiUDP _udp; | ||
}; | ||
|
||
#endif // NTPCLIENT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
### simplesample_http | ||
|
||
Instructions for this sample are | ||
[here in the Azure IoT HTTP protocol library for Arduino.](https://github.com/Azure/azure-iot-arduino-protocol-http) |
Oops, something went wrong.