A Slightly Better NTP Client for the ESP32 (ESPWROOM32) on macOS Catalina


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Programming A Slightly Better NTP Client for the ESP32 (ESPWROOM32) on macOS Catalina
# 1  
A Slightly Better NTP Client for the ESP32 (ESPWROOM32) on macOS Catalina

Currently have two ESP8266 modules testing some Blynk apps, whereI'm not so happy with the Blynk business model for developers, but that's another story.

So, with two of my ESP8266s currently "busy", I decided to work on the ESP32, and in particular the ESPWROOM32.

A Slightly Better NTP Client for the ESP32 (ESPWROOM32) on macOS Catalina-s20200201_012jpg


I installed the recommended Arduino ESP32 libs in my Arduino IDE running the 10.15.2 version of Catalina, and I got mixed results with different board managers. In a nutshell, I was having trouble getting anything more than "Hello World" to work.

So, I wrangled with this for a few hours, trying myriad ESP32 board managers; and finally got it working, by following the manual ESP32 for macOS instructions here:

Code:
https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/mac.md

This install code worked flawlessly for me:

Code:
mkdir -p ~/Documents/Arduino/hardware/espressif && \
cd ~/Documents/Arduino/hardware/espressif && \
git clone https://github.com/espressif/arduino-esp32.git esp32 && \
cd esp32 && \
git submodule update --init --recursive && \
cd tools && \
python get.py

and I was able to get my "A Slightly Better NTP Client for the ESP32" code working on this ESPWROOM32 using the NodeMCU-32S board manager. No other Arduino ESP32 board manager gave me better results; and I was able to get this NTP client working on the this version of the ESP32:

A Slightly Better NTP Client for the ESP32 (ESPWROOM32) on macOS Catalina-screen-shot-2020-02-01-102817-pmjpg


Code:
/*************************************************************
 Slightly Better NTP Client for the ESPWROOM32 v0.1
 Neo www.unix.com 1  Feb 2020
 Use anyway the spirit moves you..... enjoy.
*************************************************************/
#include <NTPClient.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <WiFiUdp.h>
#define MY_TZ_OFFSET_HOURS 7
#define MY_TZ_STRING "Bangkok Time"
const char *ssid     = "YOUR_WIFI_SSID";
const char *password = "YOUR_SECURE_PASSWORD;
bool timeset = false;
const long utcOffsetInSeconds = 3600 * MY_TZ_OFFSET_HOURS;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);

void setup() {
  Serial.begin(115200);

  WiFi.begin(ssid, password);

  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }

  timeClient.begin();
}
unsigned long count = 0;
void loop() {
  count++;
  // My ESP32 is faster than my tested ESP8266, so the modulo function is about one to two seconds (delay) . 
  // will do the math on this another time, but it is definitely faster than my ESP8266 module. as it should be.
  int my_modulo_delayer = 7900000;
  if (timeset == false or count % my_modulo_delayer == 0)
  {
    doTime();
  }

}

void doTime() {
  timeClient.update();

  Serial.print(daysOfTheWeek[timeClient.getDay()]);
  Serial.print(", ");
  Serial.print(timeClient.getHours());
  if (timeClient.getMinutes() < 10)
  {
    Serial.print(":0");
  }
  else {
    Serial.print(":");
  }

  Serial.print(timeClient.getMinutes());

  if (timeClient.getSeconds() < 10)
  {
    Serial.print(":0");
  }
  else {
    Serial.print(":");
  }

  Serial.print(timeClient.getSeconds());
  Serial.print(" ");
  Serial.println(MY_TZ_STRING);
  timeset = true;
  //Serial.println(timeClient.getFormattedTime());
}

... and it worked!

Code:
22:17:45.016 -> Saturday, 22:17:36 Bangkok Time
22:17:45.016 -> Saturday, 22:17:38 Bangkok Time
22:17:45.016 -> Saturday, 22:17:40 Bangkok Time
22:17:45.016 -> Saturday, 22:17:41 Bangkok Time
22:17:45.016 -> Saturday, 22:17:43 Bangkok Time
22:17:49.984 -> Saturday, 22:17:45 Bangkok Time
22:17:49.984 -> Saturday, 22:17:47 Bangkok Time
22:17:49.984 -> Saturday, 22:17:48 Bangkok Time
22:17:52.303 -> Saturday, 22:17:50 Bangkok Time
22:17:52.932 -> Saturday, 22:17:52 Bangkok Time
22:17:54.683 -> Saturday, 22:17:54 Bangkok Time
22:17:56.441 -> Saturday, 22:17:56 Bangkok Time
22:17:58.177 -> Saturday, 22:17:57 Bangkok Time

But I think I will take a diversion from the ESP modules play around with my RFID module, the RFID-522, and see if I can read some RFID devices I have on my keychain and then attempt to clone them with this $1 to $2 USD RFID board.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #132
Difficulty: Easy
Many of the command line and graphical utilities in a Linux distro are very similar to a Unix system.
True or False?

10 More Discussions You Might Find Interesting

1. OS X (Apple)

MacOS 10.15.2 Catalina display crash and system panic

MacPro (2013) 12-Core, 64GB RAM (today's crash): panic(cpu 2 caller 0xffffff7f8b333ad5): userspace watchdog timeout: no successful checkins from com.apple.WindowServer in 120 seconds service: com.apple.logd, total successful checkins since load (318824 seconds ago): 31883, last successful... (3 Replies)
Discussion started by: Neo
3 Replies

2. Programming

ESP32 (ESP-WROOM-32) as an MQTT Client Subscribed to Linux Server Load Average Messages

Here we go.... Preface: ..... so in a galaxy far, far, far away from commercial, data sharing corporations..... For this project, I used the ESP-WROOM-32 as an MQTT (publish / subscribe) client which receives Linux server "load averages" as messages published as MQTT pub/sub messages.... (6 Replies)
Discussion started by: Neo
6 Replies

3. Programming

A Slightly Better NTP Client for the ESP8266

Was not really happy with the NTP clients for the ESP8266 because, after a few years of game engine programming, I am not a fan of a lot of code and delays in the main loop, so here is a "slightly better NTP client" for the ESP8266. In a nutshell, instead of having a delay in the main loop as a... (0 Replies)
Discussion started by: Neo
0 Replies

4. Windows & DOS: Issues & Discussions

Poor Windows 10 Performance of Parallels Desktop 15 on macOS Catalina

Just a quick note for macOS users. I just installed (and removed) Parallels Desktop 15 Edition on my MacPro (2013) with 64GB memory and 12-cores, which is running the latest version of macOS Catalina as of this post. The reason for this install was to test some RIGOL test gear software which... (6 Replies)
Discussion started by: Neo
6 Replies

5. Programming

Python Screen Capture of RIGOL 1054Z on macOS Catalina Using NI-VISA

On the NI-VISA boards there has been some frustration where folks cannot get NI-VISA to work on macOS Catalina because Catalina (macOS 10.15.x) is "not supported" by NI-VISA (for many months, it seems). Currently, the README shows: NI-VISA 19.0 for macOS supports the following platforms: ... (10 Replies)
Discussion started by: Neo
10 Replies

6. OS X (Apple)

MacOS 10.15 Catalina Crashes and Freezes on Boot

Sadly, I have turned off my access to the Apple Developers Beta program after installing macOS 10.15 Catalina a few days ago. After the install, I rebooted by MacBook Air and it "hard froze" and we were heading out of town so I grabbed a backup MBA running Mojave. Then, after getting back at... (10 Replies)
Discussion started by: Neo
10 Replies

7. OS X (Apple)

MacOS 10.15 (Catalina) switches from bash to zsh

Interestingly Apple has decided to switch the default shell for new users from bash to zsh in MacOS Catalina (10.15) Use zsh as the default shell on your Mac - Apple Support Another interesting fact is that Catalina also comes with /bin/dash (5 Replies)
Discussion started by: Scrutinizer
5 Replies

8. Red Hat

Ntp client sync with local over ntp server

Hi, I have two ntp servers in my cluster and I want all the nodes in my cluster to sync with either of the ntp servers or just one. Unfortunately it keep rotating the sync, between my ntp server 1, ntp server 2 and local. Is there anyway I can change the sync to avoid local? # ntpq -p ... (3 Replies)
Discussion started by: pjeedu2247
3 Replies

9. Solaris

Cannot configure NTP client

Hi, I am trying to configure NTP client on my Solaris server, but I am getting error like: Jan 13 10:53:33 SPOTS ntpdate: no server suitable for synchronization foundMy ntp.conf file: bash-3.00# pwd /etc/inet bash-3.00# bash-3.00# bash-3.00# cat ntp.conf # ident "@(#)ntp.client... (5 Replies)
Discussion started by: nypreH
5 Replies

10. Solaris

ntp server and ntp client

All, How do you set a Solaris 9 server which received ntp updates from a ntp server to broadcast them on a local subnet. I have created a /etc/inet/ntp.conf file to receive the updates from a server on network and need to make this server become like a ntp relay from the main server. Any... (1 Reply)
Discussion started by: bubba112557
1 Replies

Featured Tech Videos