File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change 25
25
#include " NTPUtils.h"
26
26
27
27
#include < Arduino.h>
28
+ #ifdef BOARD_HAS_ECCX08
29
+ #include < ArduinoECCX08.h>
30
+ bool has_crypto = 1 ;
31
+ #else
32
+ bool has_crypto = 0 ;
33
+ #endif
28
34
29
35
/* *************************************************************************************
30
36
* PUBLIC MEMBER FUNCTIONS
31
37
**************************************************************************************/
32
38
33
39
unsigned long NTPUtils::getTime (UDP & udp)
34
40
{
35
- udp.begin (NTP_LOCAL_PORT);
36
-
41
+ NTPUtils randomPort;
42
+ int _randomPort = randomPort.setRandomPort (MIN_NTP_PORT, MAX_NTP_PORT);
43
+ udp.begin (_randomPort);
44
+
37
45
sendNTPpacket (udp);
38
46
39
47
bool is_timeout = false ;
@@ -83,4 +91,13 @@ void NTPUtils::sendNTPpacket(UDP & udp)
83
91
udp.endPacket ();
84
92
}
85
93
94
+ int NTPUtils::setRandomPort (int minValue, int maxValue) {
95
+ if (has_crypto) {
96
+ return ECCX08.random (minValue, maxValue);
97
+ } else {
98
+ randomSeed (analogRead (0 ));
99
+ return random (minValue, maxValue);
100
+ }
101
+ }
102
+
86
103
#endif /* #ifndef HAS_LORA */
Original file line number Diff line number Diff line change 37
37
* CLASS DECLARATION
38
38
**************************************************************************************/
39
39
40
+ #define NTP_DEFAULT_LOCAL_PORT 8888
41
+ extern const int MIN_NTP_PORT;
42
+ extern const int MAX_NTP_PORT;
43
+
40
44
class NTPUtils
41
45
{
42
46
public:
43
47
44
48
static unsigned long getTime (UDP & udp);
49
+ int setRandomPort (int minValue, int maxValue);
45
50
46
51
private:
47
52
48
53
static size_t const NTP_PACKET_SIZE = 48 ;
49
54
static int const NTP_TIME_SERVER_PORT = 123 ;
50
- static int const NTP_LOCAL_PORT = 8888 ;
55
+ static int const NTP_LOCAL_PORT = NTP_DEFAULT_LOCAL_PORT ;
51
56
static unsigned long const NTP_TIMEOUT_MS = 1000 ;
52
57
static char constexpr * NTP_TIME_SERVER = " time.arduino.cc" ;
53
58
54
59
static void sendNTPpacket (UDP & udp);
55
-
56
60
};
57
61
58
62
#endif /* #ifndef HAS_LORA */
You can’t perform that action at this time.
0 commit comments