Skip to content

Commit 823c088

Browse files
committed
add NTP and DNS examples
1 parent 41647a9 commit 823c088

File tree

7 files changed

+73
-3
lines changed

7 files changed

+73
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

Examples/.DS_Store

14 KB
Binary file not shown.

Examples/DNSResolve/DNSResolve.ino

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <Arduino.h>
2+
#include <AltSoftSerial.h>
3+
#include "Dns.h"
4+
5+
AltSoftSerial bc95serial;
6+
7+
DNSClient dns;
8+
IPAddress remoteip;
9+
10+
void setup() {
11+
bc95serial.begin(9600);
12+
BC95.begin(bc95serial);
13+
BC95.reset();
14+
15+
Serial.begin(9600);
16+
Serial.println(F("Starting..."));
17+
18+
while (!BC95.attachNetwork()) {
19+
Serial.println("...");
20+
delay(1000);
21+
}
22+
Serial.println(F("NB-IOT attached.."));
23+
24+
dns.begin();
25+
dns.getHostByName("gogole.com", remoteip);
26+
27+
Serial.print("The resolved IP address is : ");
28+
Serial.println(remoteip);
29+
}
30+
31+
void loop() {
32+
33+
}
34+

Examples/NTPClient/NTPClient.ino

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <Arduino.h>
2+
#include <AltSoftSerial.h>
3+
#include "NTPClient.h"
4+
5+
AltSoftSerial bc95serial;
6+
7+
BC95UDP udp;
8+
NTPClient ntpclient(udp);
9+
10+
void setup() {
11+
bc95serial.begin(9600);
12+
BC95.begin(bc95serial);
13+
BC95.reset();
14+
15+
Serial.begin(9600);
16+
Serial.println(F("Starting..."));
17+
18+
while (!BC95.attachNetwork()) {
19+
Serial.println("...");
20+
delay(1000);
21+
}
22+
Serial.println(F("NB-IOT attached.."));
23+
24+
ntpclient.begin();
25+
ntpclient.update();
26+
Serial.print("The current GMT time is : ");
27+
Serial.println(ntpclient.getFormattedTime());
28+
}
29+
30+
void loop() {
31+
32+
}
33+

NTPClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class NTPClient {
1212
BC95UDP* _udp;
1313
bool _udpSetup = false;
1414

15-
const char* _poolServerName = "pool.ntp.org";
15+
const char* _poolServerName = NTP_DEFAULT_SERVER;
1616
int _port = NTP_DEFAULT_LOCAL_PORT;
1717
long _timeOffset = 0;
1818

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version=0.8.0
33
author=Chavee Issariyapat <[email protected]>
44
maintainer=Chavee Issariyapat <[email protected]>
55
sentence=A network library for BC95 NB-IOT module on Arduino platform.
6-
paragraph=This library transforms AT-commands on BC95 NB-IOT module into a familiar arduino UDP functions. The UDP protocols like CoAP, DNS and NTP are also included.
6+
paragraph=This library transforms AT-commands on BC95 NB-IOT module into a familiar arduino UDP functions. Application protocols based on UDP like CoAP, DNS and NTP are also included.
77
category=Communication
88
url=https://github.com/nexpie/bc95-arduino
9-
architectures=arduino
9+
architectures=avr

settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ This software is released under the MIT License.
2020
#define DNS_MAX_RETRY 5
2121
#define DNS_DEFAULT_SERVER IPAddress(8,8,8,8)
2222

23+
#define NTP_DEFAULT_SERVER "time.nist.gov"
24+
2325
#define COAP_ENABLE_ACK_CALLBACK 0
2426

2527
#endif

0 commit comments

Comments
 (0)