Skip to content

Commit

Permalink
Sync Arduino libraries with latest Azure IoT SDK 1.0.42
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Sprowl (Jetstream Software) committed Jan 11, 2018
1 parent 8885d5e commit b5257b9
Show file tree
Hide file tree
Showing 62 changed files with 953 additions and 295 deletions.
6 changes: 6 additions & 0 deletions examples/esp8266/simplesample_http/iot_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@
*/
#define IOT_CONFIG_CONNECTION_STRING "HostName=<host_name>.azure-devices.net;DeviceId=<device_id>;SharedAccessKey=<device_key>"

/**
* Choose the transport protocol
*/
// #define IOT_CONFIG_MQTT // uncomment this line for MQTT
#define IOT_CONFIG_HTTP // uncomment this line for HTTP

#endif /* IOT_CONFIGS_H */
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 */
13 changes: 7 additions & 6 deletions examples/esp8266/simplesample_http/simplesample_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@
#include <stdio.h>
#include <stdint.h>
#include "iot_configs.h"

/* This sample uses the _LL APIs of iothub_client for example purposes.
That does not mean that HTTP only works with the _LL APIs.
Simply changing the using the convenience layer (functions not having _LL)
and removing calls to _DoWork will yield the same results. */
#include "sample.h"

#include "AzureIoTHub.h"


/*String containing Hostname, Device Id & Device Key in the format: */
/* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>" */
static const char* connectionString = IOT_CONFIG_CONNECTION_STRING;
Expand Down Expand Up @@ -247,3 +242,9 @@ void simplesample_http_run(void)
platform_deinit();
}
}


void sample_run(void)
{
simplesample_http_run();
}
91 changes: 24 additions & 67 deletions examples/esp8266/simplesample_http/simplesample_http.ino
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;
}
}
}
17 changes: 17 additions & 0 deletions examples/samd/simplesample_http/sample.h
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 */
6 changes: 6 additions & 0 deletions examples/samd/simplesample_http/simplesample_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,9 @@ void simplesample_http_run(void)
platform_deinit();
}
}

void sample_run(void)
{
simplesample_http_run();
}

124 changes: 22 additions & 102 deletions examples/samd/simplesample_http/simplesample_http.ino
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);
}



2 changes: 1 addition & 1 deletion library.properties
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.
Expand Down
2 changes: 1 addition & 1 deletion src/AzureIoTUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
#include "azure_c_shared_utility/lock.h"
#include "azure_c_shared_utility/threadapi.h"

#define AzureIoTUtilityVersion "1.0.41"
#define AzureIoTUtilityVersion "1.0.42"

#endif //AZUREIOTUTILITY_H
Loading

0 comments on commit b5257b9

Please sign in to comment.