This repository was archived by the owner on Jul 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
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
581bcdf
commit 5e2d772
Showing
16 changed files
with
612 additions
and
103 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 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
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 |
Oops, something went wrong.