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 2525#include " NTPUtils.h"
2626
2727#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
2834
2935/* *************************************************************************************
3036 * PUBLIC MEMBER FUNCTIONS
3137 **************************************************************************************/
3238
3339unsigned long NTPUtils::getTime (UDP & udp)
3440{
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+
3745 sendNTPpacket (udp);
3846
3947 bool is_timeout = false ;
@@ -83,4 +91,13 @@ void NTPUtils::sendNTPpacket(UDP & udp)
8391 udp.endPacket ();
8492}
8593
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+
86103#endif /* #ifndef HAS_LORA */
Original file line number Diff line number Diff line change 3737 * CLASS DECLARATION
3838 **************************************************************************************/
3939
40+ #define NTP_DEFAULT_LOCAL_PORT 8888
41+ extern const int MIN_NTP_PORT;
42+ extern const int MAX_NTP_PORT;
43+
4044class NTPUtils
4145{
4246public:
4347
4448 static unsigned long getTime (UDP & udp);
49+ int setRandomPort (int minValue, int maxValue);
4550
4651private:
4752
4853 static size_t const NTP_PACKET_SIZE = 48 ;
4954 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 ;
5156 static unsigned long const NTP_TIMEOUT_MS = 1000 ;
5257 static char constexpr * NTP_TIME_SERVER = " time.arduino.cc" ;
5358
5459 static void sendNTPpacket (UDP & udp);
55-
5660};
5761
5862#endif /* #ifndef HAS_LORA */
You can’t perform that action at this time.
0 commit comments