Skip to content

Commit 2f2a227

Browse files
committed
Merge pull request Azure#1 from stefangordon/master
Update AzureIoT Library with support for more boards
2 parents 7998856 + e0136d6 commit 2f2a227

File tree

109 files changed

+5614
-1369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+5614
-1369
lines changed

README.md

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,59 @@
1-
# AzureIoT - Azure IoT library for Arduino
1+
# AzureIoT - Azure IoT Hub library for Arduino
22

3-
This library is a port of the [Microsoft Azure IoT device SDK for C](https://github.com/Azure/azure-iot-sdks/blob/master/c/readme.md) to Arduino. It allows you to use your Arduino/Genuino with the [Azure IoT Hub](https://azure.microsoft.com/en-us/services/iot-hub/).
3+
This library is a port of the [Microsoft Azure IoT device SDK for C](https://github.com/Azure/azure-iot-sdks/blob/master/c/readme.md) to Arduino. It allows you to use several Arduino compatible boards with Azure IoT Hub.
44

5-
For the Arduino/Genuino [MKR1000](https://www.arduino.cc/en/Main/ArduinoMKR1000) or [Zero](https://www.arduino.cc/en/Main/ArduinoBoardZero) and [WiFi Shield 101](https://www.arduino.cc/en/Main/ArduinoWiFiShield101) only.
5+
Currently supported hardware:
6+
- Atmel SAMD Based boards
7+
- Arduino/Genuino [MKR1000](https://www.arduino.cc/en/Main/ArduinoMKR1000)
8+
- Adafruit [Feather M0](https://www.adafruit.com/products/3010)
9+
- Arduino/Genuino [Zero](https://www.arduino.cc/en/Main/ArduinoBoardZero) and [WiFi Shield 101](https://www.arduino.cc/en/Main/ArduinoWiFiShield101)
10+
- ESP8266 based boards with [esp8266/arduino](https://github.com/esp8266/arduino)
11+
- SparkFun [Thing](https://www.sparkfun.com/products/13711)
12+
- Adafruit [Feather Huzzah](https://www.adafruit.com/products/2821)
613

714
[![Microsoft Azure Certified][Microsoft-Azure-Certified-Badge]][azure-certifiedforiot]
815

9-
## Getting started
10-
11-
See the [Microsoft Azure IoT device SDK for C - Arduino WiFi Shield 101 and MKR1000 Setup Guide](https://github.com/Azure/azure-iot-sdks/blob/master/c/doc/run_sample_on_arduino_wifi101.md).
16+
## Prerequisites
17+
18+
You should have the following ready before beginning with any board:
19+
- [Setup your IoT hub](https://github.com/Azure/azure-iot-sdks/blob/master/doc/setup_iothub.md)
20+
- [Provision your device and get its credentials](https://github.com/Azure/azure-iot-sdks/blob/master/doc/manage_iot_hub.md)
21+
- [Arduino IDE 1.6.8](https://www.arduino.cc/en/Main/Software)
22+
- Install the `AzureIoTHub` library via the Arduino IDE Library Manager
23+
24+
## ESP8266
25+
##### Sparkfun Thing, Adafruit Feather Huzzah, or generic ESP8266 board
26+
27+
1. Install esp8266 board support into your Arduino IDE.
28+
* Start Arduino and open Preferences window.
29+
* Enter `http://arduino.esp8266.com/stable/package_esp8266com_index.json` into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.
30+
* Open Boards Manager from Tools > Board menu and install esp8266 platform 2.1.0 or later
31+
* Select your ESP8266 board from Tools > Board menu after installation
32+
33+
2. Open the AzureIoTHub ESP8266 sample from the Arduino IDE File->Examples menu.
34+
3. Update Wifi SSID/Password in simplesample_http.ino
35+
* Ensure you are using a wifi network that does not require additional manual steps after connection, such as opening a web browser.
36+
4. Update IoT Hub Connection string in simplesample_http.c
37+
38+
39+
## Adafruit Feather M0
40+
1. Install Feather M0 board support into your Arduino IDE.
41+
* Start Arduino and open Preferences window.
42+
* 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.
43+
* Open Boards Manager from Tools > Board menu and install Adafruit SAMD Boards 1.0.7 or later.
44+
* Select your Adafruit Feather M0 from Tools > Board menu after installation
45+
2. Install the [Adafruit WINC1500 wifi library](https://learn.adafruit.com/adafruit-feather-m0-wifi-atwinc1500/using-the-wifi-module)
46+
3. Install the `RTCZero` library from the Arduino IDE Library Manager.
47+
2. Open the AzureIoTHub SAMD sample from the Arduino IDE File->Examples menu.
48+
3. Update Wifi SSID/Password in simplesample_http.ino
49+
* Ensure you are using a wifi network that does not require additional manual steps after connection, such as opening a web browser.
50+
4. Update IoT Hub Connection string in simplesample_http.c
51+
52+
## MKR1000 or Zero + Wifi101
53+
1. Open the AzureIoTHub SAMD sample from the Arduino IDE File->Examples menu.
54+
2. Update Wifi SSID/Password in simplesample_http.ino
55+
* Ensure you are using a wifi network that does not require additional manual steps after connection, such as opening a web browser.
56+
3. Update IoT Hub Connection string in simplesample_http.c
1257

1358
## License
1459

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
// This example only works with Arduino IDE 1.6.8 or later.
5+
6+
#include <ESP8266WiFi.h>
7+
#include <time.h>
8+
#include "command_center_http.h"
9+
10+
11+
const char ssid[] = "[SSID]"; // your WiFi SSID (name)
12+
const char pass[] = "[PASSWORD]"; // your WiFi password (use for WPA, or use as key for WEP)
13+
const char connectionString[] = "HostName=[HubName].azure-devices.net;DeviceId=[DeviceName];SharedAccessKey=[KEY]";
14+
15+
int status = WL_IDLE_STATUS;
16+
17+
///////////////////////////////////////////////////////////////////////////////////////////////////
18+
void setup() {
19+
initSerial();
20+
initWifi();
21+
initTime();
22+
23+
// This function doesn't exit.
24+
simplesample_http_run();
25+
}
26+
27+
///////////////////////////////////////////////////////////////////////////////////////////////////
28+
void loop() {
29+
// Not used.
30+
}
31+
32+
///////////////////////////////////////////////////////////////////////////////////////////////////
33+
void initSerial() {
34+
// Start serial and initialize stdout
35+
Serial.begin(115200);
36+
Serial.setDebugOutput(true);
37+
}
38+
39+
///////////////////////////////////////////////////////////////////////////////////////////////////
40+
void initWifi() {
41+
// Attempt to connect to Wifi network:
42+
Serial.print("Attempting to connect to SSID: ");
43+
Serial.println(ssid);
44+
45+
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
46+
status = WiFi.begin(ssid, pass);
47+
48+
while (WiFi.status() != WL_CONNECTED) {
49+
delay(500);
50+
Serial.print(".");
51+
}
52+
53+
Serial.println("Connected to wifi");
54+
}
55+
56+
///////////////////////////////////////////////////////////////////////////////////////////////////
57+
void initTime() {
58+
time_t epochTime;
59+
60+
configTime(0, 0, "pool.ntp.org", "time.nist.gov");
61+
62+
while (true) {
63+
epochTime = time(NULL);
64+
65+
if (epochTime == 0) {
66+
Serial.println("Fetching NTP epoch time failed! Waiting 2 seconds to retry.");
67+
delay(2000);
68+
} else {
69+
Serial.print("Fetched NTP epoch time is: ");
70+
Serial.println(epochTime);
71+
break;
72+
}
73+
}
74+
}
75+

0 commit comments

Comments
 (0)