Skip to content

Commit 5012fb8

Browse files
committed
Merge branch 'main' into 27-rpcresult-improvements
# Conflicts: # src/monitor.h # src/tcp_client.h
2 parents 8b6a32d + 5189ec5 commit 5012fb8

File tree

16 files changed

+1775
-12
lines changed

16 files changed

+1775
-12
lines changed

.github/workflows/arduino-lint.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Arduino Lint
2+
3+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
4+
on:
5+
push:
6+
pull_request:
7+
schedule:
8+
# Run every Tuesday at 8 AM UTC to catch breakage caused by new rules added to Arduino Lint.
9+
- cron: "0 8 * * TUE"
10+
workflow_dispatch:
11+
repository_dispatch:
12+
13+
jobs:
14+
lint:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Arduino Lint
22+
uses: arduino/arduino-lint-action@v2
23+
with:
24+
compliance: specification
25+
library-manager: update # Change to 'update' once the library is published.
26+
official: true # Always use this setting for official repositories.
27+
project-type: library
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Source: https://github.com/per1234/.github/blob/main/workflow-templates/compile-examples-private.md
2+
name: Compile Examples
3+
4+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
5+
on:
6+
push:
7+
paths:
8+
- ".github/workflows/compile-examples.ya?ml"
9+
- "library.properties"
10+
- "examples/**"
11+
- "src/**"
12+
pull_request:
13+
paths:
14+
- ".github/workflows/compile-examples.ya?ml"
15+
- "library.properties"
16+
- "examples/**"
17+
- "src/**"
18+
schedule:
19+
# Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms).
20+
- cron: "0 8 * * TUE"
21+
workflow_dispatch:
22+
repository_dispatch:
23+
24+
env:
25+
UNIVERSAL_SKETCH_PATHS: |
26+
- examples
27+
SKETCHES_REPORTS_PATH: sketches-reports
28+
SKETCHES_REPORTS_ARTIFACT_NAME: sketches-reports
29+
30+
jobs:
31+
build:
32+
name: ${{ matrix.board.fqbn }}
33+
runs-on: ubuntu-latest
34+
permissions:
35+
contents: read
36+
pull-requests: read
37+
38+
strategy:
39+
fail-fast: false
40+
41+
matrix:
42+
board:
43+
- fqbn: arduino:zephyr:unoq
44+
platforms: |
45+
- name: arduino:zephyr
46+
artifact-name-suffix: arduino-uno_q
47+
48+
steps:
49+
- name: Checkout repository
50+
uses: actions/checkout@v5
51+
52+
- name: Compile examples
53+
uses: arduino/compile-sketches@v1
54+
with:
55+
github-token: ${{ secrets.GITHUB_TOKEN }}
56+
fqbn: ${{ matrix.board.fqbn }}
57+
platforms: ${{ matrix.board.platforms }}
58+
libraries: |
59+
# Install the library from the local path.
60+
- source-path: ./
61+
- name: Arduino_RPClite
62+
# Additional library dependencies can be listed here.
63+
# See: https://github.com/arduino/compile-sketches#libraries
64+
sketch-paths: |
65+
${{ env.UNIVERSAL_SKETCH_PATHS }}
66+
${{ matrix.board.additional-sketch-paths }}
67+
enable-deltas-report: true
68+
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
69+
70+
- name: Save sketches report as workflow artifact
71+
uses: actions/upload-artifact@v5
72+
with:
73+
if-no-files-found: error
74+
name: sketches-report-${{ matrix.board.artifact-name-suffix }}
75+
path: ${{ env.SKETCHES_REPORTS_PATH }}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Report Size Deltas
2+
3+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
4+
on:
5+
push:
6+
paths:
7+
- ".github/workflows/report-size-deltas.yml"
8+
schedule:
9+
# Run at the minimum interval allowed by GitHub Actions.
10+
# Note: GitHub Actions periodically has outages which result in workflow failures.
11+
# In this event, the workflows will start passing again once the service recovers.
12+
- cron: "*/5 * * * *"
13+
workflow_dispatch:
14+
repository_dispatch:
15+
16+
jobs:
17+
report:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Comment size deltas reports to PRs
21+
uses: arduino/report-size-deltas@v1
22+
with:
23+
# Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow
24+
sketches-reports-source: ^sketches-report-.+
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
Udp NTP Client
3+
4+
Get the time from a Network Time Protocol (NTP) time server
5+
Demonstrates use of UDP sendPacket and ReceivePacket
6+
For more on NTP time servers and the messages needed to communicate with them,
7+
see https://en.wikipedia.org/wiki/Network_Time_Protocol
8+
9+
Example freely inspired from the Arduino Ethernet library
10+
https://github.com/arduino-libraries/Ethernet/blob/master/examples/UdpNtpClient/UdpNtpClient.ino
11+
12+
This code is in the public domain.
13+
*/
14+
15+
#include <Arduino_RouterBridge.h>
16+
17+
unsigned int localPort = 8888; // local port to listen for UDP packets
18+
const char timeServer[] = "time.nist.gov"; // time.nist.gov NTP server
19+
int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
20+
21+
// A UDP instance to let us send and receive packets over UDP
22+
BridgeUDP<4096> Udp(Bridge);
23+
24+
void setup() {
25+
Monitor.begin();
26+
Udp.begin(localPort);
27+
}
28+
29+
void loop() {
30+
sendNTPpacket(timeServer); // send an NTP packet to a time server
31+
32+
// wait one second to see if a reply is available
33+
Udp.setTimeout(1000);
34+
if (Udp.parsePacket()) {
35+
// We've received a packet, read the data from it
36+
byte packetBuffer[NTP_PACKET_SIZE];
37+
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
38+
39+
// the timestamp starts at byte 40 of the received packet and is four bytes,
40+
// or two words, long.
41+
42+
// First, extract the two words:
43+
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
44+
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
45+
46+
// combine the four bytes (two words) into a long integer
47+
// this is NTP time (seconds since Jan 1 1900):
48+
unsigned long secsSince1900 = highWord << 16 | lowWord;
49+
Monitor.print("Seconds since Jan 1 1900 = ");
50+
Monitor.println(secsSince1900);
51+
52+
// now convert NTP time into everyday time:
53+
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
54+
const unsigned long seventyYears = 2208988800UL;
55+
// subtract seventy years:
56+
unsigned long epoch = secsSince1900 - seventyYears;
57+
Monitor.print("Unix time = ");
58+
Monitor.println(epoch);
59+
60+
// print the hour, minute and second:
61+
Monitor.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT)
62+
Monitor.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day)
63+
Monitor.print(':');
64+
if (((epoch % 3600) / 60) < 10) {
65+
// In the first 10 minutes of each hour, we'll want a leading '0'
66+
Monitor.print('0');
67+
}
68+
Monitor.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
69+
Monitor.print(':');
70+
if ((epoch % 60) < 10) {
71+
// In the first 10 seconds of each minute, we'll want a leading '0'
72+
Monitor.print('0');
73+
}
74+
Monitor.println(epoch % 60); // print the second
75+
}
76+
77+
// wait ten seconds before asking for the time again
78+
delay(10000);
79+
}
80+
81+
// send an NTP request to the time server at the given address
82+
void sendNTPpacket(const char * address) {
83+
byte packetBuffer[NTP_PACKET_SIZE]; // buffer to hold incoming and outgoing packets
84+
85+
// set all bytes in the buffer to 0
86+
memset(packetBuffer, 0, NTP_PACKET_SIZE);
87+
88+
// Initialize values needed to form NTP request
89+
// (see URL above for details on the packets)
90+
packetBuffer[0] = 0b11100011; // LI, Version, Mode
91+
packetBuffer[1] = 0; // Stratum, or type of clock
92+
packetBuffer[2] = 6; // Polling Interval
93+
packetBuffer[3] = 0xEC; // Peer Clock Precision
94+
// 8 bytes of zero for Root Delay & Root Dispersion
95+
packetBuffer[12] = 49;
96+
packetBuffer[13] = 0x4E;
97+
packetBuffer[14] = 49;
98+
packetBuffer[15] = 52;
99+
100+
// all NTP fields have been given values, now
101+
// you can send a packet requesting a timestamp:
102+
if (Udp.beginPacket(address, 123)) { // NTP requests are to port 123
103+
Udp.write(packetBuffer, NTP_PACKET_SIZE);
104+
Udp.endPacket();
105+
} else {
106+
Monitor.println("Failed to send NTP request.");
107+
}
108+
}
109+

0 commit comments

Comments
 (0)