This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from stefangordon/master
Update AzureIoT Library with support for more boards
- Loading branch information
Showing
109 changed files
with
5,614 additions
and
1,369 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
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,75 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
// This example only works with Arduino IDE 1.6.8 or later. | ||
|
||
#include <ESP8266WiFi.h> | ||
#include <time.h> | ||
#include "command_center_http.h" | ||
|
||
|
||
const char ssid[] = "[SSID]"; // your WiFi SSID (name) | ||
const char pass[] = "[PASSWORD]"; // your WiFi password (use for WPA, or use as key for WEP) | ||
const char connectionString[] = "HostName=[HubName].azure-devices.net;DeviceId=[DeviceName];SharedAccessKey=[KEY]"; | ||
|
||
int status = WL_IDLE_STATUS; | ||
|
||
/////////////////////////////////////////////////////////////////////////////////////////////////// | ||
void setup() { | ||
initSerial(); | ||
initWifi(); | ||
initTime(); | ||
|
||
// This function doesn't exit. | ||
simplesample_http_run(); | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////////////////////////// | ||
void loop() { | ||
// Not used. | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////////////////////////// | ||
void initSerial() { | ||
// Start serial and initialize stdout | ||
Serial.begin(115200); | ||
Serial.setDebugOutput(true); | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////////////////////////// | ||
void initWifi() { | ||
// 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: | ||
status = WiFi.begin(ssid, pass); | ||
|
||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
|
||
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; | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.