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.42
- Loading branch information
Roy Sprowl (Jetstream Software)
committed
Jan 11, 2018
1 parent
8885d5e
commit b5257b9
Showing
62 changed files
with
953 additions
and
295 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
8 changes: 4 additions & 4 deletions
8
...266/simplesample_http/simplesample_http.h → examples/esp8266/simplesample_http/sample.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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#ifndef SIMPLESAMPLEHTTP_H | ||
#define SIMPLESAMPLEHTTP_H | ||
#ifndef SAMPLE_H | ||
#define SAMPLE_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
void simplesample_http_run(void); | ||
void sample_run(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* SIMPLESAMPLEHTTP_H */ | ||
#endif /* SAMPLE_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
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,86 +1,43 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
// Please use an Arduino IDE 1.6.8 or greater | ||
|
||
// 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> | ||
// You must set the device id, device key, IoT Hub name and IotHub suffix in | ||
// iot_configs.h | ||
#include "iot_configs.h" | ||
|
||
#include <AzureIoTHub.h> | ||
#include <AzureIoTUtility.h> | ||
#include <AzureIoTProtocol_HTTP.h> | ||
#if defined(IOT_CONFIG_MQTT) | ||
#include <AzureIoTProtocol_MQTT.h> | ||
#elif defined(IOT_CONFIG_HTTP) | ||
#include <AzureIoTProtocol_HTTP.h> | ||
#endif | ||
|
||
#include "simplesample_http.h" | ||
#include "iot_configs.h" | ||
#include "sample.h" | ||
#include "esp8266/sample_init.h" | ||
|
||
static char ssid[] = IOT_CONFIG_WIFI_SSID; | ||
static char pass[] = IOT_CONFIG_WIFI_PASSWORD; | ||
|
||
void setup() { | ||
initSerial(); | ||
initWifi(); | ||
initTime(); | ||
sample_init(ssid, pass); | ||
} | ||
|
||
// Azure IoT samples contain their own loops, so only run them once | ||
static bool done = false; | ||
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); | ||
if (!done) | ||
{ | ||
// Run the sample | ||
// You must set the device id, device key, IoT Hub name and IotHub suffix in | ||
// iot_configs.h | ||
sample_run(); | ||
done = 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); | ||
else | ||
{ | ||
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,17 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#ifndef SAMPLE_H | ||
#define SAMPLE_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
void sample_run(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* SAMPLE_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 |
---|---|---|
|
@@ -247,3 +247,9 @@ void simplesample_http_run(void) | |
platform_deinit(); | ||
} | ||
} | ||
|
||
void sample_run(void) | ||
{ | ||
simplesample_http_run(); | ||
} | ||
|
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,123 +1,43 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
// Please Use Arduino IDE 1.6.8 or later. | ||
// Please use an Arduino IDE 1.6.8 or greater | ||
|
||
// You must set the device id, device key, IoT Hub name and IotHub suffix in | ||
// iot_configs.h | ||
#include "iot_configs.h" | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <time.h> | ||
#include <sys/time.h> | ||
#include <SPI.h> | ||
#include <WiFi101.h> | ||
|
||
|
||
#include "simplesample_http.h" | ||
#include "NTPClient.h" | ||
|
||
#include <AzureIoTHub.h> | ||
#include <AzureIoTProtocol_HTTP.h> | ||
|
||
#ifdef ARDUINO_SAMD_FEATHER_M0 | ||
|
||
// Optional LIPO battery monitoring | ||
#define VBAT_ENABLED 1 | ||
#define VBAT_PIN A7 | ||
|
||
#define WINC_CS 8 | ||
#define WINC_IRQ 7 | ||
#define WINC_RST 4 | ||
#define WINC_EN 2 | ||
|
||
#if defined(IOT_CONFIG_MQTT) | ||
#include <AzureIoTProtocol_MQTT.h> | ||
#elif defined(IOT_CONFIG_HTTP) | ||
#include <AzureIoTProtocol_HTTP.h> | ||
#endif | ||
|
||
#include "sample.h" | ||
#include "samd/sample_init.h" | ||
|
||
static char ssid[] = IOT_CONFIG_WIFI_SSID; | ||
static char pass[] = IOT_CONFIG_WIFI_PASSWORD; | ||
|
||
int status = WL_IDLE_STATUS; | ||
WiFiSSLClient sslClient; | ||
|
||
void setup() { | ||
// The Feather M0 loses it's COMn connection with every reset. | ||
// This 10 s delay allows you to reselect the COM port and open the serial monitor window. | ||
delay(10000); | ||
|
||
initSerial(); | ||
|
||
#ifdef ARDUINO_SAMD_FEATHER_M0 | ||
//Configure pins for Adafruit ATWINC1500 Feather | ||
Serial.println(F("WINC1500 on FeatherM0 detected.")); | ||
Serial.println(F("Setting pins for WiFi101 library (WINC1500 on FeatherM0)")); | ||
WiFi.setPins(WINC_CS, WINC_IRQ, WINC_RST, WINC_EN); | ||
// for the Adafruit WINC1500 we need to enable the chip | ||
pinMode(WINC_EN, OUTPUT); | ||
digitalWrite(WINC_EN, HIGH); | ||
Serial.println(F("Enabled WINC1500 interface for FeatherM0")); | ||
#endif | ||
initWifi(); | ||
|
||
initTime(); | ||
sample_init(ssid, pass); | ||
} | ||
|
||
// Azure IoT samples contain their own loops, so only run them once | ||
static bool done = false; | ||
void loop() { | ||
simplesample_http_run(); | ||
} | ||
|
||
void initSerial() { | ||
// Start serial and initialize stdout | ||
Serial.begin(115200); | ||
//Serial.setDebugOutput(true); | ||
} | ||
|
||
void initWifi() { | ||
// Attempt to connect to Wifi network: | ||
Serial.print("\r\n\r\nAttempting 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("."); | ||
if (!done) | ||
{ | ||
// Run the sample | ||
// You must set the device id, device key, IoT Hub name and IotHub suffix in | ||
// iot_configs.h | ||
sample_run(); | ||
done = true; | ||
} | ||
|
||
Serial.println("\r\nConnected to wifi"); | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////////////////////////// | ||
void initTime() { | ||
WiFiUDP _udp; | ||
|
||
time_t epochTime = (time_t)-1; | ||
|
||
NTPClient ntpClient; | ||
ntpClient.begin(); | ||
|
||
while (true) { | ||
epochTime = ntpClient.getEpochTime("0.pool.ntp.org"); | ||
|
||
if (epochTime == (time_t)-1) { | ||
Serial.println("Fetching NTP epoch time failed! Waiting 5 seconds to retry."); | ||
delay(5000); | ||
} else { | ||
Serial.print("Fetched NTP epoch time is: "); | ||
Serial.println(epochTime); | ||
break; | ||
} | ||
else | ||
{ | ||
delay(500); | ||
} | ||
|
||
ntpClient.end(); | ||
|
||
struct timeval tv; | ||
tv.tv_sec = epochTime; | ||
tv.tv_usec = 0; | ||
|
||
settimeofday(&tv, NULL); | ||
} | ||
|
||
|
||
|
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,5 +1,5 @@ | ||
name=AzureIoTUtility | ||
version=1.0.41 | ||
version=1.0.42 | ||
author=Microsoft | ||
maintainer=Microsoft <[email protected]> | ||
sentence=Azure C shared utility library for Arduino. For the Arduino MKR1000 or Zero and WiFi Shield 101, Adafruit Huzzah and Feather M0, or SparkFun Thing. | ||
|
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
Oops, something went wrong.